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.
Asked
Active
Viewed 203 times
4
bp2017
- 3,756
- 1
- 13
- 33
1 Answers
8
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
Phelype Oleinik
- 70,814
-
1@bp2017 Don't worry, it happens to everyone ;-) (to be honest, I also didn't know this before your question :-) – Phelype Oleinik Nov 19 '19 at 20:02
-
-
2@PhelypeOleinik Didn't you read https://tex.stackexchange.com/a/38680/4427 ?
;-)– egreg Nov 19 '19 at 21:35 -
@egreg Oh, I remember that one, when I learned about
\the:-) At the time I had no idea what\fontwas, so it didn't stick to my memory – Phelype Oleinik Nov 19 '19 at 21:43 -
-
@egreg Not overloaded enough:
! You can't use `\thesis' after \the.:( – Phelype Oleinik Nov 19 '19 at 23:32

\fontloading at all? – David Carlisle Nov 19 '19 at 20:37\the\fontunder “Special uses” in https://tex.stackexchange.com/a/38680/4427 – egreg Nov 19 '19 at 21:34\fontitself 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\fontor\countdefor for that matter\def, then at some point something will break, but however it breaks it will, by definition, be user error. – David Carlisle Nov 19 '19 at 21:40\defand many have to, given the limitations of LaTeX. (l3 changes this quite a bit, but setting that aside.) [I'd agree that using\defwhere you could use\newcommandor whatever is unnecessarily dangerous, but you can't avoid all the dangers. The path is full of perils.) – cfr Nov 20 '19 at 01:20\font. Any user of the package after selecting the font is going to expect\largeto make the text larger and that will not happen if you switch using a command defined with\font, or rather the text will get larger but be in the font that the latex font system thinks is current ie the last font loaded via a supported command. – David Carlisle Nov 20 '19 at 09:17