# What are benefits of e-TeX for LaTeX users?

The etex package provides an interface to e-TeX features. What advantages does it offer to LaTeX users?

Are there any possible disadvantages like incompatibility to any other package or can I just use it without worries?

-
Your question title says 'e-TeX' (the extended engine), but the body says 'etex' (the LaTeX package). I'm a bit confused: do you mean the extensions or just the package. – Joseph Wright Aug 19 '10 at 20:16
Mainly the difference I can achieve by using the etex package - but additional e-TeX infos are very welcome. – Stefan Kottwitz Aug 19 '10 at 20:59

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 delimiter that works like \left and \right which can be helpful.

$\left\{\sum_{i=0}^n a_i\ \middle|\ a_0<a_1<\dotsb<a_n\right\}$

Edit: While writing an answer to another question, I just remembered two pretty useful extensions in e-TeX. The first is \unless which lets you negate the arms of an \if. It's especially useful in loops where you want to loop unless some condition is true. Reading files was my example.

\loop\unless\ifeof\file
% Do something with \foo
\repeat

This also shows the second of the two extensions: \readline. It acts exactly like \read except that all of the characters are given category code other or space. It's very handy for reading in text that contains characters like \$, %, ^, &, _, or \. For example, here's a cheater's quine.

\openin\file\jobname
\endlinechar-1
\tt
\loop\unless\ifeof\file
\noindent\foo\endgraf
\repeat
\bye

There are other category changing commands like \scantokens and \detokenize, but I've never used either.

-
So, \middle comes from e-Tex. Good to know, I've seen people writing it would come from amsmath. I checked it, there's no such definition in the ams files. Just tried \middle: it works in a minimal document without any package, not even \usepackage{etex} is necessary. – Stefan Kottwitz Aug 19 '10 at 16:27
One thing about eTeX is there seems no good manual for it. Am I right? – Leo Liu Aug 19 '10 at 17:54
@Leo: The e-tex manual is at tug.org/texmf-dist/doc/etex/base/etex_man.pdf – Lev Bishop Aug 19 '10 at 17:59
@Leo: With TL 2009 I got the manual (20 pages) by texdoc etex. – Stefan Kottwitz Aug 19 '10 at 18:26
@Lev Bishop: The registers are from the engine, but you need to load the etex package to be able to use them from LaTeX. Loading etex as the very first package is often a good choice in large documents, since it prevents LaTeX from running out of registers when lots of packages are loaded. – Philipp Aug 21 '10 at 12:18

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 assigning 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 package, but only for LaTeX-managed variables. I find the e-TeX primitives particularly handy with Tikz, as it uses TeX registers directly and so does not work with the calc package. e-TeX means that things like

\tikzset{ key-name = \dimexpr 3 * \SomeDimension\relax }

work nicely.

Secondly, and more 'conceptually', LaTeX users get the benefit from packages that use e-TeX primitives for the code; one I'd point to is biblatex. As a programmer, the e-TeX extensions make many things much easier, and also allow programming ideas that simply don't work with TeX82 (i.e. TeX written by Knuth). The direct influence of e-TeX may not show up to users, but the availability of packages certainly does.

-
Write: This is sort of tangential, but why rename the registers yet again? LaTeX already changes some names, for example skips are called lengths, counts were changed to counter—but with the bizarre addition of c@. Why rename them to ints now? – TH. Aug 23 '10 at 23:29
They used to be called "cnt" in latex3 but it was long ago decided that name was a little awkward and perhaps rude. Besides, what other language doesn't call them "int"? – Will Robertson Aug 24 '10 at 3:59

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" that would not run without e-TeX, but there are packages including some maintained by the team that do require this functionality. This is in particular true for all work on LaTeX3, e.g., the expl3 based packages.

The etex.sty package is the core package for LaTeX2e enabling those e-TeX extensions that are not automatically available when using the right formatter. It is based on Peter Breitenlohner's package etex.src.

-

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 lengths with arithmetic expressions (\defcounter, \deflength)

• Using hooks similar to \AtBeginDocument but in different variants: \AfterPreamble, \AtEndPreamble, \AfterEndPreamble and \AfterEndDocument

• Many shorthands for macro definitions (corresponding to \def, \gdef, \edef, \let etc. but with control sequences as first argument and robust)

• Undefining macros

• Arithmetic definitions (similar to \def, \edef etc. but with integer expressions)

• Expansion control (useful in \edef and the like) by \expandonce

• Hook management: appending and prepending to hooks

• Patching of existing commands: extracts the text of a command, does search&replace in the code, and reassembles it - nice for workarounds

• Appending and prepending to commands

• Control sequence tests (if defined, if empty, equality)

• String tests (equality, empty or blank)

• Artihmetic tests

• Two different interfaces to boolean switches

• List processing

If some of the features seem to be interesting for you, there's documentation available: texdoc etoolbox at the command prompt or the package documentation on CTAN, a reference manual with 30 pages.

The package etextools bases on etoolbox and provides many further macros. You can access its documentation also by texdoc and on CTAN.

-
Rather more on the 'programmers' side than the 'users' side :-) I'd point out that there is quite a bit of overlap with ideas in expl3 (although the two approaches have arrived that way independently). – Joseph Wright Aug 23 '10 at 16:18
I should also note that a bit of etoolbox is things that don't depend on e-TeX but simply things that should be in LaTeX that are not – Joseph Wright Aug 23 '10 at 18:03
True, the manual says it further contains 'some generic tools which are not related to e-TeX but match the profile of this package'. – Stefan Kottwitz Aug 23 '10 at 18:41

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 if the normal pool gets exhausted. It is recommended for the user to load it to help with 'no room for a new thing' errors, as in this FAQ answer

-
Yes, we've got such an error here: tex.stackexchange.com/questions/1680/table-notes-in-memoir. – Stefan Kottwitz Aug 19 '10 at 18:27
The etex package is loaded by a number of other LaTeX packages which require e-TeX, for example biblatex and expl3. (I guess you could say that the availability of e-TeX depended package is a benefit to LaTeX users, as by using e-TeX the package authors have provided things which are hard to do otherwise.) – Joseph Wright Aug 19 '10 at 18:53
@Joseph: you are right. I had a bug in my grep commandline, so I fixed my answer. – Lev Bishop Aug 19 '10 at 20:12
I was going on the rather more basic 'I know this as I've read/written the code'! – Joseph Wright Aug 19 '10 at 20:15
@Stephen since about 2004 LaTeX officially requires e-TeX as an underlying processor (or rather a processor that supports all of the e-TeX extensions). As a project we make this switch finally when for already a number of years all major distributions where based on eTeX or at least has the processor on board. – Frank Mittelbach Jan 10 '12 at 18:09

If one wants to implement some sort of multiline widow/orphan control (e.g. "For the first paragraph following a sectional heading, page breaks are allowed only after the third and following lines"), standard (La)TeX only offers approximate solutions (mostly involving the needspace package). With e-TeX, exact solutions are possible using the \widowpenalties and \clubpenalties macros. See this answer for an example.

Joseph Wright has already mentioned biblatex as a "user-relevant" package which uses e-TeX primitives; another one is marginnote which (contrary to standard LaTeX's \marginpar command) allows margin notes for floats and footnotes.

-