# Tag Info

48

The main reason why people may consider ifthen obsolete (last version is of 2001/05/26 with about one page of user manual plus four pages of code documentation) is that it is superseded by e.g. etoolbox, which uses the advanced possibilities of eTeX. Using these allows faster processing. You still can use ifthen for your existing and new documents if you ...

39

You can inhibit page breaks in the middle of paragraphs by saying in you preamble \widowpenalties 1 10000 \raggedbottom Without \raggedbottom (that the article class does automatically) the pages would be awful. The primitive \widowpenalties is an extension to the original TeX program, present in e-TeX based engines (pdftex, xetex and luatex). It ...

27

From my experience in various forums and newsgroups, ifthen often seems to do more harm than good, especially when used by newbies. The main \ifthenelse command is fragile, so something like \section{\ifthenelse{\equal{a}{a}}{b}{c}} doesn't work. The comparison is not expandable, so that the command "possibly has only limited usefulness for macro code ...

23

A lot of server-based set ups are very conservative. For example, I write achemso to support submissions to the American Chemical Society. On the servers they have to take author .tex files and produce .pdf files, the e-TeX extensions are not available. (I am told an upgrade is planned for later this year.) These systems are often based on custom additions ...

22

e-TeX provides lots of additional features for package writers such as an increased number of registers. The thing I find most useful is its extended tracing ability which I usually access through the trace package. In particular, tracing commands and tracing assignments are extremely helpful when trying to diagnose a problem. e-TeX also provides a \middle ...

22

\marks is an etex primitive command. It extends the \mark command of the original tex. You can use it to store text on the current page which you want to use at shipout in the headers. \documentclass{article} \usepackage{etex} \newmarks\mymark \usepackage{fancyhdr} \pagestyle{fancy} \fancyhf{} \lhead{\topmarks\mymark, \botmarks\mymark, \firstmarks\mymark} ...

18

The \scantokens primitive is described in the e-TeX manual as working in a similar manner to the following code: \toks0={...}% '...' is the rescanned material \immediate\openout0=file \immediate\write0{\the\toks0} \immediate\closeout0 \input file but without the use of files and in an expandable manner. However, it does use the some of the same internals ...

16

Looking at the e-TeX extensions in general, I'd highlight two points that have not been mentioned by others. First, e-TeX provides primitives for carrying out calculations when assignin integers, dimensions, etc. For example \newcount\mycount \mycount\numexpr 1 + 2 * 3\relax \showthe\mycount will give 7. Now, you can do something similar with the calc ...

15

It should be pointed out that already a number years ago the LaTeX Project officially announced that LaTeX is expected to be run on an e-TeX-based enabled engines. In other words: all functionality available in e-TeX is supposed to be available for the LaTeX kernel and any add-on packages. So far, the LaTeX Project Team hasn't made changes to the "kernel" ...

14

There may be a generalisable mechanism: Using e-TeX and its \clubpenalties command. In the following example, patching \@afterheading seems to do the trick. \documentclass{article} \usepackage{etex} \usepackage{etoolbox} \makeatletter \patchcmd{\@afterheading}% {\clubpenalty \@M}{\clubpenalties 3 \@M \@M 0}{}{} \patchcmd{\@afterheading}% ...

14

In short, yes. Try \edef\foo{\scantokens{Test\noexpand}} or \everyeof={\noexpand} \edef\foo{\scantokens{text}} in which the \noexpand ‘hides’ the EOF marker by turning it into \relax. You might like to take a look at the definition of expl3's \tl_rescan:nn and \tl_set_rescan:Nnn, both wrappers for \scantokens based on the ideas in Heiko Oberdiek's ...

14

To add to what Hendrik says, I think the overall point was that \numexpr, \dimexpr, etc. can be used in a full expansion context without leaving a stray \relax or space: \edef\example{\the\dimexpr 10 pt + 20 pt \relax} gives \example defined as 30pt with no unexpected tokens. That is in many ways much 'neater' than the alternative of leaving the \relax in ...

13

Now I found the etoolbox package. It's a toolbox of programming facilities providing LaTeX frontends to some new e-TeX primitives and further features. It supports Definition of "robust" commands: \newrobustcmd, \renewrobustcmd etc. Patching existing commands to be robust: \robustify Protecting entire chunks of code by \protecting Defining counters and ...

12

etex.sty seems aim to be to LaTeX as etex.src is to plain TeX. It seems to be useful for giving nice names to e-TeX (the engine)'s magic constants, so you can write \hboxgrouptype for 2, \ligaturenode for 7, and so on. It is loaded internally by quite a lot of packages. Another feature it provides is transparently making the extended register pool available ...

11

Current ConTeXt code uses \dimexpr and \numexpr from e-TeX a lot, because most of ConTeXt predates luatex. If you want to do a quick calculation in lua, you can just do something trivial like this: \def\evaluate#1{\directlua{tex.sprint(tostring(#1))}} then you can write: \evaluate{10.2+1e6} \evaluate{10.2/0} et cetera. Best wishes, Taco

11

It means that the format is set up to use the etex primitives such as \dimexpr All formats do this by default these days except tex which is set up to not use the extensions and use dvi output so that it is classic plain TeX. LaTeX always uses this mode (whether or not shell escape is used) see $pdflatex \\relax This is pdfTeX, Version ... 10 I'm now fairly certain this this is a bug in the current implementation of linebreak_filter. What seems to happen is the following: when TeX builds a list (in this case a vertical list) it keeps track of it through a pointer to the head and to the tail of that list. Now when a paragraph is broken into lines those lines get appended to the current vertical ... 9 This is the relevant part from etex.ch: 5247 @ The function |quotient(n,d)| computes the rounded quotient 5248$q=\lfloor n/d+{1\over2}\rfloor$, when$n$and$d\$ are positive. 5249 5250 @<Declare subprocedures for |scan_expr|@>= 5251 function quotient(@!n,@!d:integer):integer; 5252 var negative:boolean; {should the answer be ...

9

I would say this makes it easy to delimit a \dimexpr in a fully expandable way. Putting a \relax is a usual way to delimit TeX dimensions, which I learned the hard way: It's always a good idea to put a \relax after something like \hskip1pt. Now it seems that eTeX just made a principle out of this. (An alternative is to put a space to delimit a TeX ...

9

Without the e-TeX extensions, you need to use a toks to have control of expansion inside an \edef. Usually, this is done using \toks@, and so to avoid any issues with other code a group is normally employed \begingroup \toks@\expandafter{\@freelist\@elt}% \edef\@freelist{\the\toks@\expandafter\noexpand\ExtraFloatCommand}% \expandafter\endgroup ...

9

I believe not, hence the addition of \ifincsname in pdfTeX (and XeTeX, I think). This came out of discussions way back when on detecting/testing all of the different expansion contexts, but IIRC the csname expansion was the only one that was easy or maybe unambiguous to implement. Er, sorry for the vague answer; I'll pull up some references if they come to ...

8

Short answer: no. Longer answer: To detect this would require a primitive which 'knows' about expansion. However, writing one is non-trivial: see the issues surrounding \ifincsname for demonstrations of why detection of this sort of thing is hard. If you look at the LaTeX kernel, the \protect mechanism is about expansion. To work, it all has to be set up ...

8

I solved this with the needspace and titlesec packages, as in: \usepackage{titlesec} \usepackage{needspace} ... \titleformat{\section} {\needspace{1in}\Large\bfseries}{\thesection}{1em}{} Hardcoding 1in is crude -- should probably be a multiple of line height. At any rate, this works great in my documents without the need for hand tuning each section.

8

For now, I'll answer only your second question, about the example from e-TeX. The \expandafter are used to force TeX to actually do the computation before calling \foo recursively, and to clear the finale \fi so that the recursion is terminal. This isn't strictly necessary but is an optimisation. Here is a way to visually check my first assertion: ...

8

Knuth refers to this mechanism on page 278 of the TeXbook: \TeX\ takes precautions so that constructions like ‘\chardef\cs=10\cs’ and ‘\font\cs=name\cs’ won't expand the second \cs until the assignments are done. If you add \chardef\cs=63 you'll find in the log {changing \cs=undefined} {into \cs=\relax} {changing \cs=\relax} {into \cs=\char"3F} ...

8

You can get the lists programmatically, using LuaTeX, provided you are interested in the new primitives provided by one of the dialects of TeX supported by that engine. By changing the values of the dialect variable in proc = tex.initialize () dialect = "etex" -- The dialect identifiers accepted are: tex (i.e., original Knuth, without Plain Tex macros), -- ...

7

The e-TeX extensions were finalised in 1999 and are available in the common engines: pdfTeX, LuaTeX and XeTeX. With a recent-ish TeX system (say anything released in the last 5-8 years), the extensions are enabled in the LaTeX format files as standard. The only 'common' case where the extensions are not enabled is when using 'classical' TeX: tex ...

7

I see two cases where \the\numexpr...\relax works, but \pdfstrcmp{}{...} will blow up, excluding the obvious case where ... is replaced by 0\relax\undefined, terminating the \numexpr prematurely. TeX interprets \a as a number, without expanding \a. Hence, \the\numexpr\a\relax expands to 97 (the character code of a), whereas \pdfstrcmp{}{`\a} blows up if ...

7

The answer is a qualified 'no', not because of macro limitations (which could be addressed) but because even with newer engines the maximum \insert number remains at 255, at least for pdfTeX and XeTeX. Thus if you try \insert256{} with one of these engines you will get the error ! Bad register code (256). <to be read again> { ...

7

Now, concerning your first question. There is no double recursion going on. You seem to believe the macros recurse-loops to print 1, 2, 3, 4, 5 and the recurse-loops again to print all the TeXs. The truth is, there is only one recursion, but the final TeX are kept on a pile and poped at the end of the recursion. That is, when the final call to \foois made, ...

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