2015-05-23 Math examples in TeX, part III

In the two previous posts, I wrote about my macros to typeset examples of math typesetting for the book on LaTeX I was coauthoring. I promised that there will be the third (and last) part of that series – so here it is.

One more thing I needed was to be able to split the source code into more than one line. Due to the catcode changes, it was not possible using \\. Why not use something that should not appear anywhere in (legal) LaTeX code then? I was thinking about various possibilities, and then it struck my mind: why not use some control character (not in TeX sense, but in ASCII sense)? Well, there is that TeX syntax for control characters, where ^^A means ASCII code 1 (i.e., C-a in Emacs notation), but since I was changing the catcode of ^, I couldn’t use that. What I could do, however, is to embed the character with ASCII code 1 directly in the file. This is easy if you happen to use Emacs: you just press C-q C-a, and you see a red ^A in the file. Pressing C-x = confirms that this is exactly what we needed.

The rest is (relatively) easy. You can make ^A active and redefine it to something which will start a new line (I chose \null\par) when typesetting the source, and redefine it to an empty macro when typesetting the result.

Yet another problem I had was that the book was typeset using Lato (which is a nice font), but I really wanted math examples to use Whatever Modern, so that they looked exactly like what the reader would see without extra font packages. That was also easy: I just put \fontfamily{lmr}\selectfont when typesetting my examples.

So, that’s it. As I mentioned some time ago, you can download the book (which is written in Polish) here.

CategoryEnglish, CategoryBlog, CategoryTeX, CategoryLaTeX, CategoryEmacs