Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

What practices are there regarding the use or avoidance of "internal" TeX or LaTeX commands? (About "command" vs "macro", there is some discussion in this TeX.SX answer, though I don't know whether this is the last word.)

The Guide to LaTeX (4th ed.) writes this (D.1.3, pp. 429-430):

[P]rimitive TeX commands [should] be shunned[.] [...] [That] primitive TeX commands might be removed from a future LaTeX version [...] is not really the point. [...] In spite of the desirability of employing only official LaTeX commands, there are many occasions when either the internal LaTeX commands or the TeX primitives just must be used. The risk of future incompatibility must be taken in order to have a workable package now. However, one should not take this risk lightly where a high-level equivalent is available.

In D.1.2 (pp. 427-429) it writes

A question that confronts LaTeX programmers is to what extent the internal LaTeX commands may be used in class and package files. There is always a danger that such commands may vanish in later versions, since they have never been documented in the official books [...].

and also distinguishes between different "levels" of commands: user commands, class and package commands, internal LaTeX commands, low-level TeX commands, internal private commands. (Again, this might not be the last word on the matter.)

  • Which internal TeX commands should be avoided? For example, people universally agree that \over and \choose are superseded by \frac and \binom, respectively, and that \atop and \above should be equally avoided (use \genfrac).
  • Which internal LaTeX commands should be avoided?
  • Which internal TeX commands can be considered widely used and unavoidable for the non-casual user?
  • Which internal LaTeX commands can be considered widely used and unavoidable for the non-casual user?

A good description of TeX commands is David Bausum's excellent TeX reference. LaTeX2e is well-documented in texdoc source2e and latex2e-help-texinfo/latex2e.pdf.

What is an "internal" command anyway? This concept seems to be rough around the edges for (La)TeX, especially with some package documentations encouraging the programmer to redefine "internal" commands for certain purposes. I think that avoidance of "internal" commands is also a matter of programming style (and of how pure and principled one wants to be). One view is that internal commands are those marked by an @, though the Guide to LaTeX's typology of commands (mentioned above) is finer-grained.

For example, experienced user egreg

who has, this very day of 2013-Jul-11 UTC, surpassed the 200k mark for TeX.SX rep :-)

writes that "in documents" \nobreak/\allowbreak/\break should be avoided whereas "in lower level programming" they're okay. But it's not like every command definition is lower-level programming. Which internals are more widely used, and which are taboo? If people use \patchcmd (which violates the programming principle of encapsulation/abstraction as much as is imaginable), it seems like nothing is off-limits.

share|improve this question
    
on command naming and @ there is tex.stackexchange.com/questions/48195/… –  David Carlisle Jul 11 '13 at 10:00
add comment

1 Answer

In a document, the rule should be simple, don't use any internal commands (with @) or tex primitives (unless like they are explicitly documented as being available for use in LaTeX). (eg \noindent, although some would argue not unreasonably that you shouldn't use that in a document either).

Any code in the preamble (especially if it uses \makeatletter) should be considered as package code for a package you just haven't built yet. It's convenient at first to put in small extensions using \makeatletter But you can always instead but them in mylocalstuff.sty and just have \usepackage{mylocalstuff} in your preamble. Your document will look cleaner and it's easier to resuse the code if that is done.

So that just leaves the question of how much you should use TeX primitives and LaTeX internals in package code. In an ideal world the answer would be never, but if you look at the code for more or less any distributed package, you may find that the world is not always ideal. LaTeX2e just doesn't have documented interfaces that do everything that people need to do in packages. You just have to use care and judgement.

share|improve this answer
    
You wrote: "LaTeX2e just doesn't have documented interfaces that do everything that people need to do in packages." Will this issue be solved with LaTeX3? –  Lover of Structure Jul 14 '13 at 8:25
    
@LoverofStructure the issue will be addressed with L3, but it probably can't be completely solved. With an open source system written in a macro extension language, whatever boundaries you set, someone will always want to push against them, and sometimes they are not wrong to do so. –  David Carlisle Jul 14 '13 at 16:43
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.