# Optimized TeX macros

TeX is a strange programing language, and it reflects in the manner in which TeX macros are optimized. I find the following macro from core-env.mki(i|v) really ammusing.

% handy for mp

\def\booleanmodevalue#1% can be \relax
{\expandafter\ifx\csname\@mode@#1\endcsname\relax
fals%
\else\ifnum0\csname\@mode@#1\endcsname=0
fals%
\else
tru%
\fi\fi e}


So much effort to save two “e “

## 5 thoughts on “Optimized TeX macros”

1. I don’t think this is really an optimisation, just a cute example 🙂 The macros would be exactly the same if the “e” were inside the conditionals.

• From what I understand, using this trick saves a few bytes in the size of the format file.

• Oh sure, but I don’t consider that much of an optimisation — take a look at the source for \prg_replicate:nn in l3prg.dtx for an example of some more hairy optimised looping code 🙂 (And anything else, pretty much, written by David Kastrup.)

• Oh, you didn’t catch the sarcasm in the title 🙂 I always marvel how much effort the TeX wizards put in to get the macro packages to work efficiently.

• Heh, right, I see what you mean. In some cases, the TeX programming language can be great fun to work with in a puzzle-solving kind of sense.

Keep up the writing, by the way. Good stuff.