[lucida] How to check prior loading of Lucida OpenType in a document

Bruno Voisin bvoisin at icloud.com
Sat Jun 4 15:38:01 CEST 2016


Hi,

The following is more a fontspec issue than a Lucida one, but since it occurred with Lucida I'm posting it first, see what comes out.

In a LaTeX letter class I've written (departmental letterhead), a few fixed fonts are loaded for the header and footer, like CM Sans Serif regular, semibold condensed and bold:

\DeclareFixedFont{\addfont}{\encodingdefault}{cmss}{m}{n}{8}
\DeclareFixedFont{\baddfont}{\encodingdefault}{cmss}{sbc}{n}{8}
\DeclareFixedFont{\bbaddfont}{\encodingdefault}{cmss}{bx}{n}{8}

Then, in an \AtBeginDocument declaration, prior loading of the LW 35 fonts is checked and if so cmss is replaced by Helvetica:

\ifthenelse{\equal{\sfdefault}{phv}}{%
  \DeclareFixedFont{\addfont}{\encodingdefault}{phv}{m}{n}{8}
  \DeclareFixedFont{\baddfont}{\encodingdefault}{phv}{bc}{n}{8}
  \DeclareFixedFont{\bbaddfont}{\encodingdefault}{phv}{b}{n}{8}
}{}

Similarly for Lucida Sans Type 1:

\ifthenelse{\equal{\sfdefault}{hls}}{%
  \DeclareFixedFont{\addfont}{\encodingdefault}{hls}{m}{n}{7.8}
  \DeclareFixedFont{\baddfont}{\encodingdefault}{hls}{b}{n}{7.8}
  \DeclareFixedFont{\bbaddfont}{\encodingdefault}{hls}{ub}{n}{7.8}
}{}

This is easy because the font family name is fixed when using the helvetica and lucidabr/lucimatx packages.

Just recently I tried to extend this to Lucida OpenType, in which case, as mentioned in §5.2 of the fontspec doc ("Specifically choosing the NFSS family"), the font family name is not fixed: it is built on the font or file name, without spaces, plus a number in parentheses referring I think to the current number of times the font has been called in the document, starting from 0.

Introducing a test

\ifthenelse{\equal{\sfdefault}{LucidaSansOT(0)}\or
  \equal{\sfdefault}{LucidaSansOT.otf(0)}}

works well enough, but only provided the fonts have been loaded so that the number is 0.

The fontspec doc advises against such approach, and recommends instead LaTeX3-style commands described in its § 17.3 ("Functions for querying font families"). I couldn't figure out how these commands are used (that, and my very poor knowledge of the LaTeX3 syntax).

Instead, I've looked for a way to check whether the family name contains the string "LucidaSansOT", which I think it should whatever the form in which the font has been called.

At StackExchange <http://tex.stackexchange.com/questions/26870/>, Enrico Gregorio points at the LaTeX kernel command \in@ as a way to solve this problem. It is (poorly) documented in § 33 ("Interface commands") of the documented LaTeX source code source2.pdf, as

"\@in is a utility macro with two arguments. It determines whether its first argument occurs in its second and sets the switch \ifin@ accordingly."

Enrico goes further and provides a user-level command for using \in@,

\def\instring#1#2{TT\fi\begingroup
  \edef\x{\endgroup\noexpand\in@{#1}{#2}}\x\ifin@}

allowing to write

\if\instring{LucidaSansOT}{\sfdefault}
  <code-for-when-Lucida-Sans-OT-has-been-loaded>
\fi

This does work, but I don't feel comfortable using a definition I don't understand; and that for \instring is definitely well above my knowledge of TeX.

So after some trial-and-error I ended up writing

\in@{\string{LucidaSansOT}}{\sfdefault}
\ifthenelse{\boolean{in@}}{%
  <code-for-when-Lucida-Sans-OT-has-been-loaded>
}{}

which works too.

Is this a problem which sounds familiar to any of you? Is there a better approach?

All in all, the final code I'm using for now is

\in@{\string{LucidaSansOT}}{\sfdefault}
\ifthenelse{\boolean{in@}}{%
  \renewcommand{\addfont}{\fontsize{7.8}{0pt}%
    \fontspec{LucidaSansOT.otf}}
  \renewcommand{\baddfont}{\fontsize{7.8}{0pt}%
    \fontspec{LucidaSansOT-Demi.otf}[FakeStretch=0.8]}
  \renewcommand{\bbaddfont}{\fontsize{7.8}{0pt}%
    \fontspec{LucidaSansOT-Demi.otf}}
}{}

Bruno Voisin




More information about the lucida mailing list