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:

   italic code
   non-italic code

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:

\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 }

\DeclareDocumentCommand{\ForBf}{ mm }

and was able to make my adjustments without difficulty afterwards.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>