[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


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:


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


Similarly for Lucida Sans Type 1:


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


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@,


allowing to write


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


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


Bruno Voisin

More information about the lucida mailing list