Tag Info

108

Penalties are the main value that TeX tries to minimise when line or page breaking, They may be inserted explicitly (\penalty125 means that the penalty for breaking at that point is 125). Some penalties are built in to the TeX system and inserted automatically, LaTeX for example sets these default values for built in penalties \linepenalty=10 the penalty ...

66

latex.ltx says \newdimen\z@ \z@=0pt % can be used both for 0pt and 0 so as it says it is short (and efficient) way of getting 0. You should always have a copy of the latex source file latex.ltx in a text editor window while reading package code:-), or perhaps, if you prefer, the typeset version of that, without the comments being removed, source2e.pdf, ...

55

I now compiled such a document listing all internal macros of LaTeX2e which are also useful for package authors. The work title is "List of internal LaTeX2e Macros useful to Package Authors" and I'm planning to release it on CTAN 'soon' (e.g. as 'macros2e') when its out of the beta stage. The beta release can be found on my website. There is also a feedback ...

42

\z@ is a LaTeX “constant” that's defined to be zero. Package developers can use it to assign or test against the value 0 and it can also replace a length of 0pt. Similar constants are \@ne (one) \tw@ (two) and so on. Due to the @ they can only be used in packages or between \makeatletter and \makeatother.

42

This is a very important function in the LaTeX kernel. The macro \@ifnextchar takes three argument. The first one should be a single token, usually [ but not necessarily. When the input stream has the following tokens \@ifnextchar<token>{<true>}{<false>} TeX will look at the next token (skipping spaces) and compare it to the ...

41

Penalties are used by TeX for controlling the line and page break routines. Some of them are inserted implicitly, others can be added by the user (usually via macros). A penalty issued in horizontal or math mode will influence line breaking, one issued in vertical mode will influence page breaking decisions. The list of "implicit penalties" can be found in ...

40

\@ifnextchar is a LaTeX conditional that peeks ahead at the following character. So, \@ifnextchar[ looks ahead to see if the following character in the input stream is a [ (opening left bracket). If this is true, then it executes the immediately following token, otherwise, it skips it and executes the token following that. The first token, executed upon a ...

40

The output routine is called either by TeX's normal page-breaking mechanism, or by a macro putting a penalty of < or = -10000 in the output list. These large penalties communicate with the OTR. For example a penalty of -10001 is a clearpage, whereas a -10004 is a float insertion etc. Information on LaTeX output routine is very hard to find - and guessing ...

30

The actual command, including its formal definition posted by @JoshLee is contained in the LaTeX 2e source, section 61.2 Sectioning (p 283). It forms part of ltsect.dtx, the bundle containing all sectioning commands for LaTeX. It even includes a pseudo-code interpretation of the actual macro. Here is an extract: The ...

29

You are missing two very important \expandafters. The normally used, "correct" code is: \def\ifeq#1#2{% \ifx#1#2\relax \expandafter\@firstoftwo \else \expandafter\@secondoftwo \fi } The difference to a macro which uses #3 and #4 is that the if-statement is fully processed before the first or second of the next two arguments is processed. This ...

27

This is the kind of question that is fairly difficult to answer after 20 years. But basically because it was not considered so important. One has to remember that the implementation of 2e was guided by space and speed restriction, So initially we spend an enormous amount of time optimizing the kernel for speed and space. 2e introduced a lot of new code ...

24

\@ifnextchar\bgroup See the definition of \input in the kernel: \def\input{\@ifnextchar\bgroup\@iinput\@@input} where \@iinput is able to cope with \input{file} and \@@input is an alias for the primitive \input so \input file will be processed as well. \@ifnextchar has three arguments: (1) the token to be looked for, (2) what to do if it's found, and ...

24

The use of scratch registers and macros in TeX/LaTeX date back to the time when it was absolutely essential to conserve memory consumption, because TeX's memory (both in terms of token/macro memory as well as number of available registers) was very limited and one could easily run out of space just by loading a few packages on top of the main format. Traces ...

24

The LaTeX kernel allocates some scratch registers and defines a scratch conditional. The complete list is \newcount\@tempcnta \newcount\@tempcntb \newif\if@tempswa \newdimen\@tempdima \newdimen\@tempdimb \newdimen\@tempdimc \newbox\@tempboxa \newskip\@tempskipa \newskip\@tempskipb \newtoks\@temptokena Notice that for the first two \newcount is used, ...

22

It was when the code was written, but is not now (in my opinion). The current LaTeX2e kernel was released in 1992 and carries forward a lot of material from LaTeX2.09. Even with these optimisations and the old 'autoload' system, there were a lot of systems that LaTeX was too big for on release. So looked at in the early 1990s this was entirely sensible. I'd ...

22

Let's assume you have \include{fileA} \include{fileB} If there is no \clearpage when fileA ends and TeX starts reading fileB, there might be a \write relative to fileA pending and it will get lost: the \write commands relative to \label are performed at shipout, not immediately. When the next shipout occurs, the fileA.aux file will have already been ...

20

I guess texdoc source2e is the answer to many of your questions. Both the macro's you mentioned are discussed in the manual, which is basically a documented source of LaTeX2e. As for learning these commands, it's reading existing packages, reading the documentation and reading tex.stackexchange.com. At least it is for me :).

20

Since the fixltx2e package ends with \MakeRobust$$\MakeRobust$$ \MakeRobust$\MakeRobust$ \MakeRobust\makebox \MakeRobust\savebox \MakeRobust\framebox \MakeRobust\parbox \MakeRobust\rule \MakeRobust\raisebox it is probably safe to say that it was simply a mistake that was left around because the kernel can't change at this point. It's also worth ...

20

\@let@token is assigned by \futurelet to the next token after the \@ifnextchar, i.e. it is the next character. The \futurelet\@let@token\@ifnch code means "assign the next token to \@let@token and then process \@ifnch". Inside \@ifnch the \@let@token macro is tested if it is equal to the (first token of the) first argument of \@ifnextchar, i.e. \reserved@d ...

20

This is abbreviated notation for a 1pt dimension, as included in latex.ltx and therefore common to all LaTeX documents: \newdimen\p@ \p@=1pt % this saves macro space and time \newdimen\z@ \z@=0pt % can be used both for 0pt and 0 As such, you can use it in calculation with dimensions, such that 60\p@ translates to 60 times 1pt, or 60pt. In a similar ...

19

\p@ is a LaTeX2e kernel dimension, equal to 1 pt. It is used as this saves some tokens in the kernel, and also makes it possible to write thinks like 0\pt, which TeX interprets as 0 times 1 pt. So written out 'long hand' the definition is '1pt'. (That token-saving was really important when LaTeX2e was written: \p@ is one token, 1pt is three. Today, it is ...

18

The correct syntax for \ifeq should be \def\ifeq#1#2{% \ifx#1#2\relax \expandafter\@firstoftwo \else \expandafter\@secondoftwo \fi } Martin has explained well the reasons for preferring this approach than the "four argument" one. What about \@firstofone? Well it may be used for stripping a pair of braces around an argument, for example. Another ...

18

\documentclass{book} \usepackage{caption} \makeatletter \def\InFloat{\ifnum\@floatpenalty<0\relax in float \else outside float \fi} \makeatother \begin{document} \begin{figure}\relax [figure]: \InFloat \end{figure} \begin{center} [center]: \InFloat \end{center} \captionsetup{type=figure} \begin{center} [center]: \InFloat \end{center} ...

18

It essentially checks if the token after \CJ@title is [ or not, in order to pass to the main command the same argument twice, if [ is not found. The command \CJ@title must be defined by \def\CJ@title[#1]#2{...} so that, with a call such as \title{xyz} the expansions will be (successively} \@dblarg\CJ@title{xyz} ...<some complex action>... ...

17

These are LaTeX kernel macros that are associated with environments. In simple terms anything that is enclosed with a \begin{foo}...\end{foo} is an environment. For example a figure or a table. Every time you insert a table a counter is incremented. This counter let us call it foo has an associated macro named \p@foo. This macro expands to a printed ...

17

The definition is found in latex.ltx: % latex.ltx, line 481: \def\m@th{\mathsurround\z@} OK, it's just an abbreviation for \mathsurround\z@ which in turn is an abbreviation for \mathsurround=0pt Now, what's \mathsurround? The syntax says it's a parameter, which has a length as value. It contains the amount of blank space that's inserted at either side ...

17

When LaTeX2e was released, personal computers had much less power than nowadays. Moreover, TeX was often compiled with a rather small amount of available memory. The inclusion of the New Font Selection Scheme (NFSS2), in particular, posed some challenges when LaTeXing big documents. So the developers provided a solution for people with limited memory ...

17

For our purposes, \begin{#1} is roughly \begingroup \@endpefalse \csname #1\endcsname and \end{#1} is roughly \csname end#1\endcsname\expandafter \endgroup \if@endpe \@doendpe \fi Since \expandafter expands \if@endpe before the group ends, the value of the switch that is used is the one within the environment. If the \csname #1\endcsname part of a ...

16

Some packages (particularly the AMS packages) redefine \@ifnextchar. Usually the redefined version has all of the properties of the original, but there are some places where the original is needed, which is what \kernel@ifnextchar is for. If you look at the places where it is used, you'll find that it is mainly used in the definitions associated to ...

16

Since they are \let equal to each other there clearly isn't much difference, but there is the issue of the different naming schemes for document level and package level commands, see Macro naming best practice? and making \usepackage an error helped ease people from the LaTeX 2.09 to LaTeX 2e syntax. Also (hard to remember now) there may have been a ...

Only top voted, non community-wiki answers of a minimum length are eligible