What macros should be used as 'scratch space'?

What macros should be used as 'scratch space'?



The LaTeX kernel provides the 'scratch' macros @tempa, etc., and reserved@a, etc. These are used for a variety of purposes. Which should be used as temporary space by general users/programmers?


@tempa


reserved@a





Oh I just noticed you asked this question! (I'd seen your answer:-)
– David Carlisle
Aug 24 at 20:18





@DavidCarlisle Yes: it came up in another question and I felt an question/answer covering the status of the reserved@... macros was useful.
– Joseph Wright
Aug 24 at 20:21


reserved@...





I have to admit I have been using the plain TeX conventions here, using , 1, etc. But I never dared let any code that I don't have complete control over run between defining and using these macros. Havn't been burned by it yet.
– Harald Hanche-Olsen
Aug 24 at 21:07



1





I happened to stumble across this similar question: tex.stackexchange.com/questions/88252/…
– David Purton
Aug 25 at 15:49




3 Answers
3



The reserved@... macros are reserved for use by the LaTeX team only: they should not be used by others. On the other hand, the macros @temp... are available for general scratch use.


reserved@...


@temp...



This is because low-level parts of the kernel need to have reliable storage for internal use. The reserved@... series provide this, and using them may cause unexpected issues in apparently unrelated code. No such reliance takes place with the @temp... series.


reserved@...


@temp...



If you are patching a kernel macro and using the reserved names exactly as the kernel does, you might of course need to use one. This is however an extremely limited set of circumstances.



LaTeX2.09 used @tempa, ... as scratch macros, but by the time LaTeX2e was being designed so many style files (packages) were using the same "scratch" macros they were not really "safe" any more so we used reserved@a,... in the format code, documented as not to be used by other packages. So @tempa and friends have no special status now, although they are commonly used because many common packages have a history that goes back to latex2.09 (ie before 1994).


@tempa


reserved@a


@tempa



But really for any package being written now there is no need to use these generic scratch macros at all. If your package is called wibble.sty use wibble@a, wibble@b,... etc.


wibble.sty


wibble@a


wibble@b



In 1994, on a 640K PC running emtex there were only about 50 command names left after loading latex2e+amsmath, and so it made sense for as much code as possible to re-use the same command names. With a modern texlive or miktex installation there are typically several hundred thousand command names available in the string pool and obfuscating the code and running the risk of clashes with other packages by re-using some generic command names is probably taking a risk with no actual potential gain.





The 'throw away' temporaries are handy for ad hoc code, mainly: that was the context in which the initial query arose.
– Joseph Wright
Aug 24 at 20:22





@JosephWright yes but one person's ad hoc code ends up being someone else's go-to package 20 years later:-)
– David Carlisle
Aug 24 at 20:24





I just got bitten by @tempdima being used both by rule and by l@section: I was hacking into l@section and trying to use the @tempdima configured by it in the parameters of an extra rule, but to no avail of course as rule itselfs resets @tempdima.
– jfbu
Aug 25 at 9:59



@tempdima


rule


l@section


l@section


@tempdima


rule


rule


@tempdima



When writing code from scratch that might be used by people other than me, then I tend to write everything within an own namespace where each macro-name has its own prefix formed by the name of the project/package, trailed by an @ and an acronym denoting the person who wrote that code. E.g., for project foobar I don't use @tempa but I use foobar@UD@tempa. If I could easily use digits within names of control sequences, I would in many places include version number / date of submission into the namespace-prefix also.

Exception: Macro-names for macros for the user-level.


@


@tempa


foobar@UD@tempa



Besides this I tend to redefine whatsoever "scratch" macros not introduced by me within local scopes only, where at the moment of finishing producing whatsoever boxes, these local scopes are already closed again so that my temporary redefinitions don't interfere during moments where the output-routine is in action. (One can have fun in situations where globaldefs might have a positive value. ;-) )


globaldefs



Another issue are macros where hooks like everypar or everyeof get modified. Modifying somebody else's macros, e.g., scratch-macros from the kernel, might probably affect the way in which things triggered by those hooks are done. This in turn might cause problems.


everypar


everyeof



E.g., recently there was a thread macros - inaccurate hyperlink to customly defined theorems where changing the kernel's box-register @labels happened even without the user being aware of that:


@labels



The labels of the text of a theorem-like environment were to be nested into another itemize-like environment. First the material for typesetting both the theorem-like environment's label and for placing an anchor for hyperlinks was placed into the box-register @labels. Theorem-like environments rely on everypar for typesetting the content of that box-register. But the content of that box-register was replaced due to the itemize-like-environment before the `everypar´-hook was carried out. This time with material where no anchor for hyperlinks was placed. Thus hyperref-functionality was broken.


@labels


everypar



So, problems with changing things belonging to the kernel can even happen without users knowing/intending that.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)