In the LATEX book, I have examples printed side-by-side with their source code. This is managed by setting a pair of \vboxes inside an \hbox inside displayed math so I could take advantage of the display math spacing before and after. While working on the chapter on \newtheorem  I noticed that the cross-reference information was coming out wrong. It was somehow picking up the number of the subsection (the fact that it’s unnumbered and shouldn’t be calling \refstepcounter in the first place is its own issue I need to track down but never mind that for now). After far too long digging into source code (remember, \ShowCommand is your friend), I realized that what was happening was that I was getting the special handling of \label inside display math from the amsmath package. The simple fix was to change the \[\] entry into display math to $$$$.

I’m setting the body of my LATEX book in Monotype Ehrhardt. I have a long sentimental attachment to this typeface and I’m on my second purchased copy of the face (I bought it originally in PC Type 1 format and now I have the Opentype version on my Mac). Unfortunately, I decided to cheap out and I didn’t buy the Pro version of the font since I figured I wouldn’t need the Eastern European accents. Oops, it turns out that I do kind of want to have access to hačeks and also the macron accent for a section where I talk about mahāprañāpāramita. But how to get these? Well, the macron accent wasn’t even present in the font, giving a missing character symbol where the accent should appear, so I decided, given its typographic simplicity, that I’d “borrow” it from Latin Modern which I knew had the character.

The thing is, the \accent primitive is a finicky beast. As anyone who’s ever tried to do something like \’{\textbf{a}} would know, you can’t just throw anything inside an accent command. Instead, a more subtle approach is necessary. Thankfully, this already exists thanks to the \t accent. Here’s the definition from plain.tex:

\def\t#1{{\edef\next{\the\font}\the\textfont1\accent"7F\next#1}}

What’s happening here is that TEX saves the current font in the \next macro, changes to \textfont1¹ and issues the accent command and then returns the font to the saved font.² I ended up doing the following in my class file to give me access to the accent from Computer Modern (well, actually Latin Modern).

{\fontfamily{lmr}\selectfont
\xdef\thelmrfont{\the\font}}
\def\=#1{{\edef\@tempa{\the\font}\thelmrfont\accent"0304\@tempa#1}}

 I could have gotten away with replacing the whole song and dance around \thelmrfont by using \csname TU/lmr/m/n/10\endcsname  but I want the flexibility to adjust the font—I’m already thinking that changing the size to, e.g., 9.5pt might not be a bad idea to make the accent blend better with the provided ñ.  


  1. \textfont1 is math italic in plain TEX.
  2. \the\font or \the\textfont1 expand to the command to load the appropriate font, which under LaTeX will be an otherwise difficult to obtain name like \TU/lmr/bx/n/10.

I have the files for The Preppy Lion books in a folder on my hard drive that’s gone through moves from who knows how many computers since around 1990ish and I found a letter to an editor at Springer-Verlag from November 1992 with this gem of a sentence:

Because LATEX 3 is likely to appear in approximately two years, the latter volumes are currently at a low priority.

Also, loads of old stuff for volumes 2, 3 and 5 that I’d forgotten about.

I had a bit of a shock while looking over a section of my book on typesetting special characters to discover that my example of how to typeset a four-dot ellipsis in LATEX was coming out like:

This….

when I was pretty sure it was supposed to look like:

This....

 It was pretty easy to discover that this was because in XeLATEX (and LuaLATEX), \ldots was no longer typesetting spaced dots but using the Unicode … character instead. The appearance, as evidenced above is quite different and the Unicode character doesn’t compose nicely with a following period (as required by some styles, most notably MLA, but some others as well—the example made it into the book originally because it was repeatedly asked about when I was teaching LaTeX classes back in the 80s/90s).

With some digging into source2e.pdf, I turned up \UndeclareTextCommand which lets me undo this. It’s just a matter of adding 

\UndeclareTextCommand{\textellipsis}{TU}

to my document class to get the intended result and my ellipses are returned to normal. Unfortunately, I’ll also need to include a mention of this into a sidebar for those who might encounter this edge case on their own.

Update: While writing the text for the book, I discovered that the sequence …. came out almost correct in Monotype Ehrhardt (the spacing is still a little uneven, but not as dramatically so as with Latin Modern), which made it a little complicated to write the sidebar. I had to switch to Latin Modern for those ellipses to illustrate the problem. It looks fine on the blog too. Latin Modern’s ellipsis is broken!

I just posted the table of contents of the book on the site, but I ended up spending a day fiddling with things to enable me to print the LATEX logo formatted in the fancy way. For the table of contents, this was pretty straightforward: Add some CSS to the site, and since the table of contents is generated automatically from the .toc file, it’s a simple matter to replace \LaTeX with LATEX (do your own view source to see the ugly details). But then I wanted to put this into the site’s tagline and also in the page title. I spent about a day digging into how WordPress works to find where I could add a PHP function to keep all the ugly HTML/CSS from being printed literally, but then when it came to the page title, I realized I had a new problem. The PHP solution felt fragile to me. So instead, I ended up adding a bit of JavaScript to find the string LaTeX in a page title and replace it with LATEX. A day spent on aesthetics instead of writing.

As I’m working on The Preppy Lion, I was not happy with how the LaTeX logo was being typeset in the main body typeface that I’m using, Monotype Ehrhardt. I decided to make some small adjustments to the spacing and decided that I also wanted to make slight variations if the logo was being typeset in bold or italic or bold italic. The catch was being able to identify what the current font was.

This should be simple. I could simply compare \f@shape to \itdefault or \f@series to \bfdefault. Problem solved right?

So I did the following in my code:

\ifx\f@shape\itdefault
   italic code
\else
   non-italic code
\fi

and discovered that it didn’t work.

I typeset the values of \f@shape and \itdefault and they looked the same. So I turned to some TeX debugging skills and typeset \texttt{\meaning\f@shape} and \texttt{\meaning\itdefault} instead and discovered that \itdefault was defined as a long macro thanks to having been defined in latex.ltx with \newcommand{\itdefault}{it} instead of \newcommand*{\itdefault}{it}. I suspected that this might be a subtle bug in LaTeX, did the workaround of adding \renewcommand*{\itdefault}{it} to my class file and started working on the bold adjustments.

These also weren’t working. I’d done the same \renewcommand magic for \bfdefault but something was still wrong. It appeared that the fontspec package was adding \@empty to the end of the \bfdefault definition.

The old-school way to deal with this would be to write something like:

\edef\next{\bfdefault}
\ifx\f@series\next ...

but this was ugly. It turned out though, while digging through the fontspec code in search of where the \@empty was being added that there was a simpler approach. The expl3 macros provide a way to compare the fully expanded definitions of two macros with the \str_if_eq:eeTF command. I ended up creating two utility macros to handle the checks for bold and italic as:

\DeclareDocumentCommand{\ForIt}{ mm }
   {
      \str_if_eq:eeTF
        \f@shape
        \itdefault
        {#1}
        {#2}
   }


\DeclareDocumentCommand{\ForBf}{ mm }
   {
      \str_if_eq:eeTF
        \f@series
        \bfdefault
        {#1}
        {#2}
   }

and was able to make my adjustments without difficulty afterwards.

While working on the manuscript for the book, I noticed that one of my page headings was being rendered as

Putting together a document—part i

thanks to my writing “part I” using a small caps i for the “I.” I was also getting an annoying warning on every odd page:

LaTeX Font Warning: Font shape `TU/EhrhardtMTStd(0)/m/scit' undefined
(Font)              using `TU/EhrhardtMTStd(0)/m/sc' instead on input line 12.

Monotype Ehrhardt does not have an italic small caps and normally I would shun the use of obliquing against the designer’s wishes but here it was going to be a limited case of a single character which, if it were to exist would be obliqued (in fact, other than losing hinting, there’s not a strong argument against using a mechanical oblique for italic small caps, especially not for a small caps I). The catch was how to persuade fontspec to let me do this.

It took a bit of digging through the documentation of fontspec to figure this out (most of the discussion on the topic on Stack Exchange was to express horror at fake italic small caps), but I eventually managed to get the desired result which I present here for anyone trying to solve this particular problem:

\setmainfont[Numbers=OldStyle,Mapping=tex-text,
    ItalicFeatures=
       {
           SmallCapsFont={Ehrhardt MT Std},
           SmallCapsFeatures={FakeSlant=0.2, Letters=SmallCaps}
       }
   ]{Ehrhardt MT Std}