I do \font\testFont="Arial"\testFont
to set the font to Arial
(or to any font I need), but after I'm done displaying some characters I need to revert to previous font. What can be done to achieve this, aside from enclosing the above font change within {}
(a group)? I use XeTeX so you can rely on XeTeX-related functionality, but non-XeTeX solutions (that would work there) are welcome too.
1 Answer
You can expand \font
with \the
, so \edef\lastfont{\the\font}
should work (notice how the name "Arial" comes out different when typeset... weird ;-)
\edef\lastfont{\the\font}
Computer Modern
\font\testFont="Arial"\testFont
Arial
\lastfont
Computer Modern Again
\bye
-
1@bp2017 Don't worry, it happens to everyone ;-) (to be honest, I also didn't know this before your question :-) Nov 19, 2019 at 20:02
-
-
2@PhelypeOleinik Didn't you read tex.stackexchange.com/a/38680/4427 ?
;-)
– egregNov 19, 2019 at 21:35 -
@egreg Oh, I remember that one, when I learned about
\the
:-) At the time I had no idea what\font
was, so it didn't stick to my memory Nov 19, 2019 at 21:43 -
\font
loading at all?\the\font
under “Special uses” in tex.stackexchange.com/a/38680/4427\font
itself isn't especially bad it is the general principle I am questioning that using tex primitives in a latex document is somehow normal. It is open source and due to the macro expansion nature of the system hard to prevent, but if you use commands (that are not mentioned in any user facing latex documentation) like\font
or\countdef
or for that matter\def
, then at some point something will break, but however it breaks it will, by definition, be user error.\def
and many have to, given the limitations of LaTeX. (l3 changes this quite a bit, but setting that aside.) [I'd agree that using\def
where you could use\newcommand
or whatever is unnecessarily dangerous, but you can't avoid all the dangers. The path is full of perils.)