In my attempt to venture in the realm of LaTeX3 coding, I was wondering if a list of answers, in LaTeX3, can be made? That is, a list of links to answer in which users here at TeX.SX have used such coding. This will enable me to look at this post and look at samples instead of searching for examples everywhere on the website.
[Tex/LaTex] Learning LaTeX3
expl3latex3
Related Solutions
An expandable command is one which can be converted 'fully' into it's output inside a TeX \edef
or \write
(and a few other places). Thus for example
\def\testa{\testb}
\def\testb{\testc}
\def\testc{d}
\edef\teste{\testa}
\show\teste
will give
> \teste=macro:
->d.
i.e. all of the steps have been expanded, and we have just characters.
For text, this is nice and simple, but when you get TeX primitives involved things are more complex as some are expandable and some are not. Broadly, anything which performs an assignment is unexpandable. So if we have
\def\testa{\testb}
\def\testb{\testc}
\def\testc{\def\ARG{d}}
\def\ARG{}
\edef\teste{\testa}
\show\teste
we get
> \teste=macro:
->\def {d}.
Notice how the \def
is left unchanged but the \ARG
has vanished: it got expanded to what it is defined as (empty).
e-TeX allows us to define a protected macro. These do not expand inside an \edef
, so
\def\testa{\testb}
\def\testb{\testc}
\def\testc{\def\NOTARG{d}}
\protected\def\NOTARG{}
\edef\teste{\testa}
\show\teste
now yields
> \teste=macro:
->\def \NOTARG {d}.
There is a subtle but important point here: \def
is an unexpandable primitive, while \NOTARG
is now a protected macro. You can tell that \NOTARG
is protected using \show
:
> \NOTARG=\protected macro:
->.
where the \protected
tells us what we need to know. However, you have to know that \def
is not expandable.
In the LaTeX3 documents, rather than expect people to learn the rules we've gone with a different approach: we document which functions are expandable (they are marked with a star). The reason everything else is then protected is that 'partial' expansion is a real issue. If you do
\def\testa{\let\testb\testc}
\edef\testb{\testa}
you get
! Undefined control sequence.
\testa ->\let \testb
\testc
as \let
is unaffected by the \edef
but \testb
is undefined. This gets worse when you look at 'real' documents, as the problem can be hidden many layers down.
Many of the issues people see in real LaTeX2e documents, for example where they forget \protect
and have trouble, would be bypassed if most commands were protected. In general, you find a lot more (La)TeX code that is not expandable than code that is, so the position for LaTeX3 is that this is the exception, certainly for document commands. (Typesetting is not expandable, and that's what happens in documents.)
This leads us on to what I call the 'sheep and goats' approach to protected functions: all LaTeX3 code is either protected or fully expandable ['safe' (will give the expected result) inside \edef
/x
-type expansion], even if we are talking about auxiliary functions. The result is that we can always be sure if a function can be used in an expansion context: if it can, it's marked with a star, otherwise it will be protected and won't expand part way. So the 'correct' way to write LaTeX3 code is that if you use anything that is not expandable (i.e. not starred in the documentation) in your code, then you have to use \cs_new_protected:Npn
or similar, and not \cs_new:Npn
, etc.
Best Answer
Almost all LaTeX3 answers will use
expl3
orxparse
packages, or as egreg says use\ExplSyntaxOn
(which is the LaTeX3 analogue of\makeatletter
to allow package code in the preamble) thus a link such ashttps://tex.stackexchange.com/search?q=expl3
will show most of the things that you wish to find.
or of course those explicitly tagged:
https://tex.stackexchange.com/questions/tagged/latex3