9

In LaTeX internal code I came accross \@@par. How is this different from \par or \newline. When should I use \@@par if I am writing a package or class file?

In general, there are so many other internal commands/macros (e.g., \z@, \p@, \protected@edef, etc) in LaTeX which I come accross while studying the internal code. Is there some documentation available regarding when and how to use them if I am writing a package or class file? Should I really bother about them at all?

  • 1
    \@@par and \@par are only copies of \par (using \let) to save the meaning of the TeX primitive \par – user31729 May 19 '15 at 6:29
  • @ChristianHupfer. Thanks! I have updated my question while you were answering, I guess. – RavBell May 19 '15 at 6:32
  • 1
    Yes, obviously -- I didn't notice the update. You could have a look into source2e, which describes the internals of the LaTeX Kernel. If you don't want to bother with such low-level kernel macros you can use some intermediate packages such as etoolbox etc. even in your class or package file to simplify some setups. \z@ and \p@ are just dimension registers, \protected@edef prevents expansion of the defined macro, making it robust and non-fragile – user31729 May 19 '15 at 6:35
  • 1
    In addition, the vertical spacing introduced by \par is generally bigger than the value used by \newline – user31729 May 19 '15 at 7:48
  • \@@par has the same meaning has \endgraf so this question is essentially the same as tex.stackexchange.com/questions/96865/… – David Carlisle May 19 '15 at 8:21
9

In LaTeX the \par command gets redefined several times during a run over a document. For example, inside a tabular it does nothing: an input such as

\begin{tabular}{l}
\ttfamily\meaning\par
\end{tabular}

would print

macro:->.

(after the colon the parameter text is shown; after -> up to the period the replacement text is shown). This way, users aren't bothered with empty lines inside a tabular.

In a center, flushleft or flushright environment, the definition is more complicated, but eventually the macro \par will execute {\@@par}, where \@@par is defined in the kernel by

\let\@@par\par

at a moment when \par still has its primitive meaning. In normal situations, \par will have the primitive meaning and, in general, one should use \par in macros.

Another example: when a \parbox or minipage is started, the \@parboxrestore command is executed, which also does \let\par\@@par. Why? Because the \parbox or minipage could be in a tabular or any other place where \par has been redefined.

The kernel has an interesting set of macros:

\def\@setpar#1{\def\par{#1}\def\@par{#1}}
\def\@par{\let\par\@@par\par}
\def\@restorepar{\def\par{\@par}}

The macro \@setpar changes the meaning of \par and \@par; why making a copy of the new meaning of \par into \@par? Because one can always say \@restorepar which will restore the meaning of \par as defined with \@setpar, in cases when it's not certain that \par has the wanted meaning. The default definition of \@par is to restore the primitive meaning.

Of course, grouping plays an essential role here. For instance, \par does nothing in tabular, but as soon as \end{tabular} is executed, \par will get back the meaning it had before \begin{tabular}. So a restoration with \let\par\@@par is rarely needed; an exception is \@parboxrestore, that's intended to bring LaTeX into a fresh state as if a new document should be started (we're in a \parbox or minipage and this indeed makes sense).

Your question has probably been prompted by the line

\newenviron{solution}{}{\xappto{\temp@solnlist}{\solutionbody {\@@par}}}

in your code at Problems using listxadd and xappto

Well, this is a place where a plain \par should be used:

\newenviron{solution}
  {}
  {\xappto{\temp@solnlist}{\expandonce{\solutionbody}\noexpand\par}}

The \noexpand is needed because of \xappto and the fact that we want \par to be stored, not its expansion at the uncontrolled moment the \xappto command is performed.

1

The easiest way to find what a command does is to create a minimal and run:

\makeatletter\ttfamily
\meaning\par \\
\meaning\@@par \\
\meaning\p@

As you go along studying the LaTeX2e kernel you can grow this minimal with notes etc.

The best study source for coding LaTeX2e style packages and macros is the source itself, as well as packages. All these assignments were done to save memory at the time and are unessecary in a modern class, where I would opt for readabilty.

Don't start a modern class from scratch, rather start from an existing class. I suggest you have a look at the tufte-book for inspiration. The class started from another base class and also used packages effectively.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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