1

The expandability is the heart of macros/functions. I wonder to know:

  1. If a better understanding of expandability in LaTeX3 can only be through a good background of expandability in LaTeX. How far could they be considered as independent?
  2. More precisely, if the features offered by l3expan are enough to handle all the expandability need. In other words, within LaTeX3, "LaTeX expandability" is supported but can be totally substituted.
  3. Is there a way to check the steps in-between while the expandability process is performed (i.e. some output files, profiling options, ...)
ALOUI
  • 322
  • 2
    Your question is very unclear (I couldn't attempt an answer in this form) note that expansion is a property of tex rather than latex, and latex2e and the experimental latex3 code are both written in tex. – David Carlisle Feb 18 '16 at 00:21
  • Perhaps my misunderstanding of the expandability that makes my question somehow unclear. So I try to express myself differently. Currently LaTeX3 gives new features to deal with expandability. When studying it, I have to make a strategic decision: should I focus only on studying l3expan or turn back and start with the native TeX commands? – ALOUI Feb 18 '16 at 00:59
  • l3expan is now obsolete (as of 2014-09-06, if not earlier): you want to load/use expl3. But I doubt it's ever 'wrong' to start with TeX. As for #3, there are many \tracing* commands. – jon Feb 18 '16 at 01:49
  • @jon Not exactly: we simply switched from allowing loading of l3expan on it's own to requiring all of expl3 be loaded together. – Joseph Wright Feb 18 '16 at 07:17
  • @JosephWright -- Ah, yes, I see (and should have checked the 'interfaces3' document before I chimed in). – jon Feb 18 '16 at 08:46
  • Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. – samcarter_is_at_topanswers.xyz Oct 22 '16 at 16:06

1 Answers1

4

Not having done it myself, my belief is that for a new LaTeX programmer it's easier to start to with the functions defined by loading expl3 (otherwise known as the LaTeX3 kernel, or l3kernel) than to first learn basic TeX programming and move up.

The reason for this is that expl3 gives you a very nice abstraction layer that is powerful and internally consistent. With TeX programming you very quickly have to move to learning ‘tricks’ to do rather simple things.

For example, if you're talking about two commands \foo and \baz, to make \foo a copy of \baz you write

\let\foo\baz

But what if you need to refer to them by name instead of control sequence? For example, you might be defining something to do this:

\defineacronym{baz}{BAZ}
\useacronym{baz} % => \textsc{\MakeLowercase{BAZ}}

This can be defined with

\makeatletter
\newcommand\defineacronym[2]{%
  \@namedef{acronym@#1}{\textsc{\MakeLowercase{BAZ}}}%
}
\newcommand\useacronym[1]{%
  \@nameuse{acronym@#1}%
}
\makeatother

So far so good. But to define a command like \copyacronym{foo}{baz}, you have to write:

\newcommand\copyacronym[2]{%
  \expandafter\let\csname acronym@#1\expandafter\endcsname\csname acronym@#2\endcsname
}

This is easy to follow for a seasoned TeX programmer, but is not very nice for a new one.

In expl3 this would be written as:

\ExplSyntaxOn
\newcommand\copyacronym[2]{
  \cs_set_eq:cc {acronym@#1} {acronym@#2}
}
\ExplSyntaxOff

The goal of expl3 is to make TeX programming more structured and therefore easier. We hope that this is the case even more so with new TeX programmers than with old ones.


For your final question, the answer is sort of. Bruno Le Floch has written the unravel package, which can certainly show you what's going on with expansion. After writing

\usepackage{unravel}
\def\baz{BAZ}
\unravel{\expandafter\let\csname foo\expandafter\endcsname\csname baz\endcsname}

it returns the following:

======== Welcome to the unravel package ========
    "<|" denotes the output to TeX's stomach.
    "||" denotes tokens waiting to be used.
    "|>" denotes tokens that we will act on.
    Press <enter> to continue; 'h' <enter> for help.

|| 
|> \expandafter \let \csname foo\expandafter \endcsname \csname baz\endcsname 

[===== Step 1 =====] \expandafter \let 

[===== Step 2 =====] \csname = \csname
|| \expandafter \let 
|| \csname 
|> foo\expandafter \endcsname \csname baz\endcsname 

[===== Step 3 =====] \expandafter \endcsname 
|| \expandafter \let 
|| \csname foo
|| \expandafter \endcsname 
|> \csname baz\endcsname 

[===== Step 4 =====] \csname = \csname
|| \expandafter \let 
|| \csname foo
|| \expandafter \endcsname 
|| \csname 
|> baz\endcsname 

[===== Step 5 =====] \endcsname 
|| \expandafter \let 
|| \csname foo
|| \expandafter \endcsname 
|| \csname baz\endcsname 
|> 

[===== Step 6 =====] \csname baz\endcsname =\baz 
|| \expandafter \let 
|| \csname foo
|| \expandafter \endcsname 
|> \baz 

[===== Step 7 =====] back_input: \expandafter \endcsname 
|| \expandafter \let 
|| \csname foo
|> \endcsname \baz 

[===== Step 8 =====] \endcsname 
|| \expandafter \let 
|| \csname foo\endcsname 
|> \baz 

[===== Step 9 =====] \csname foo\endcsname =\foo 
|| \expandafter \let 
|> \foo \baz 

[===== Step 10 =====] back_input: \expandafter \let 
|| 
|> \let \foo \baz 

[===== Step 11 =====] \let \foo 
|| \let \foo 
|> \baz 

[===== Step 12 =====] Set \foo=macro:->BAZ
|| 
|> 

[===== End =====]

As you can see, even with a simple case it gives you quite a mouthful. (An easy to digest one, but even still.) Especially when debugging expl3 as a new user, this may only be useful in certain situations.