Tag Info

Hot answers tagged

112

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 ...


68

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 ...


43

\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 ...


42

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 ...


41

\@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 ...


25

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 ...


25

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, ...


25

Any command may be used as an environment, and if surrounding large blocks of text it is often convenient, so {\small zzz\par} and \begin{small}% zzzz \end{small} are more or less equivalent. Note however that unlike \small, spaces after \begin{small} are not dropped due to normal TeX tokenization rules. Also you almost always need a \par or blank ...


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 ...


23

Actually, the “LaTeXbook” (properly “LaTeX. A Document Preparation System”, by Leslie Lamport) endorses the use of such environments: at the end of page 27 we find: Every declaration has a corresponding environment of the same name (minus the \ character). Typing \begin{em} ... \end{em} is equivalent to typing {\em ... }. In particular, the ...


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

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 ...


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 ...


21

A macro is any control sequence (or active character) defined with \def, \gdef, \edef or \xdef. TeX macros support up to nine arguments, which contradicts your statement about it not having the notion of arguments to control sequences. The most common usage of arguments is in the “undelimited” form; say that you do \def\foo#1{--#1--} so \foo takes an ...


20

You can use any LaTeX command defined by \newcommand and wrap a \begin{}...\end{} pair around it, however, it's not recommended, since this is not an environment. The interesting thing is, however, that grouping works anyway, but this is consequence of \begin...\end. There are no fontsize environments like \begin{small} etc, as there aren't ...


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

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

\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 ...



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