# Tag Info

3

If the restriction that no assignments (in particular, no definitions) must intervene in the test for equality can be partially lifted, as one of the comments seems to permit, in the sense that they may be allowed in a “preliminary” phase in which one sets a “constant” name against which subsequent tests for equality will be made using expansion alone, the ...

8

Taking your requirements at face value, we can't use \pdfstrcmp or equivalent as it's not part of e-TeX (it's a pdfTeX primitive available in XeTeX under a different name and in LuaTeX using Lua emulation). What we can do is a token-by-token comparison of the \string versions of the two macro names. This will work provided there are no spaces in the names. ...

6

If \pdfstrcmp is allowed (or its friends in other TeX compilers like \strcmp in XeTeX), it's quite simple: Example for plain-TeX: \input pdftexcmds.sty\relax \catcode\@=11 \long\def\someIf#1#2{% \ifnum\pdf@strcmp{\noexpand#1}{\noexpand#2}=0 % } % Testing \def\msg#{\immediate\write16} \someIf\foo\bar \msg{equal}% \else \msg{not equal}% \fi ...

5

No, you cannot compare two control sequence names in expandable way unless you turn them into strings. The available test is \ifx, which compares the meaning. This requires e-TeX, runs with pdftex, xetex and luatex: \input pdftexcmds.sty \catcode@=11 \def\STRINGEQ#1#2{TT\fi \ifnum\pdf@strcmp{\detokenize{#1}}{\detokenize{#2}}=\z@ } \catcode@=12 ...

18

The four expression primitives (\numexpr, \dimexpr, \glueexpr, \muexpr) can be used anywhere that a register of the same type can be. This means that \numexpr produces integers, \dimexpr produces dimensions, \glueexpr produces glue expressions and \muexpr produces muskip values. As such, something like the example in the question \the\dimexpr 12pt / ...

5

The classical TeX has limited arithmetic, so the division of decimal numbers is processed by division by integers and the optimum of precision is found via loop with multiple two (see the answer by 1010011010). But, if you are using eTeX (this is common extension of TeX today) then you can utilize the fact that the integer arithmetic is 64bit when \numexpr ...

8

Here's a completely plain tex solution. It´s adapted from the graphics package. \catcode@=11 \begingroup \catcodeP=12 \catcodeT=12 \lowercase{ \def\x{\def\rem@pt##1.##2PT{##1\ifnum##2>\z@.##2\fi}}} \expandafter\endgroup\x \def\strip@pt{\expandafter\rem@pt\the} \def\setdimenzerotofontheightanddepth#1#2{ \dimen8=\fontcharht\font#1 ...

10

Graphics package has code to divide dimens: \documentclass{article} \usepackage{graphics} \makeatletter \begin{document} \def\setdimenzerotofontheightanddepth#1#2{ \dimen8=\fontcharht\font#1 \advance\dimen8 by \fontchardp\font#1 \ifx#2 \else \advance\dimen8 by \fontcharht\font#2 \advance\dimen8 by \fontchardp\font`#2 \fi } ...

8

The syntax rules of TeX tell you that you can \divide\dimen0 by <number> where <number> is an integer. In your case, the expansion of \dimzeroamt is 13.19443, so TeX duly divides \dimen0 by 13 and prints .19443. You can do it with expl3 (also in Plain TeX): \input expl3-generic \ExplSyntaxOn \cs_new_protected:Nn \ioiooiioio_getfactor:Nnnn ...

0

Idea: Instead of writing a command that does some funny stuff to detect whether \global or another prefix came before, modify \global etc. to look ahead and use a protocol to inform the appropriate macro that it is to consider itself prefixed. The following is not working code and is intended to suggest an approach \let\ea\expandafter \makeatletter ...

Top 50 recent answers are included