{expansion} is about expanding tokens, including the manipulation of expansion order and the suppressing of expansion.

learn more… | top users | synonyms

4
votes
2answers
85 views

expl3: \cs_generate_variant broke with the last update: undefined control sequence \::T [closed]

The last expl3 update broke my "continue" detection for the index. Here is a MWE: (EDIT: I realized it is possible to reduce it even further) \documentclass{minimal} \usepackage{expl3,xparse} ...
6
votes
2answers
462 views

Nesting of test commands (IfStrEq, IfSubStr etc.) of xstring

The following code does not work: \documentclass{article} \usepackage{xstring} \newcommand\checkempty[1]{ \IfStrEq{#1}{}{% Empty }{% NonEmpty } } \begin{document} ...
4
votes
2answers
45 views

How to write \StrGobbleLeft output to an external file?

I have not learnt how the TeX expansion works behind the scene. Shortly speaking, how to write \StrGobbleLeft output to an external file? \documentclass{article} \usepackage{filecontents} ...
2
votes
1answer
184 views

expandable optional parameter to enumerate environment

The MWE below, by using paralist package, is supposed to allow \begin{enumerate}[...] where ... is flexible in "some way" (inherits from enumerates above). \documentclass[a4paper,10pt]{report} ...
8
votes
1answer
118 views

'Fake' variants in expl3

Suppose you have a function that operates on three tokens, \cs_new:Nn \@@_on_three:NNN { #1, #2, #3 } And you have a variable whose value is the three tokens: \tl_set:Nn \l@@_three_tl { foo } ...
5
votes
3answers
232 views

Expanding an argument of code added by \g@addto@macro

I would like to have the following (it's a part of a large code block): \def\C{foobar} \def\A{} \g@addto@macro\A{\B{\C}} Now \show\A outputs \B{\C} I would like to modify the 3rd line so that ...
12
votes
1answer
330 views

How to expand a macro used in the range of a foreach loop?

Motivating Example: Suppose that I want to draw the following tree: root / \ / \ / \ A B C D This is easy enough to do by explicitly drawing the two subtrees as children of ...
42
votes
3answers
1k views

Advantages and disadvantages of fully expandable macros

As I currently understand them, fully-expandable macros are analogous to pure/effect-free functions in functional programming. Correspondingly, things that are not expandable, such as \def, are ...
5
votes
2answers
261 views

\@startsection, hyperref and newunicodechar; protection needed?

When working with custom defined environments using \@startsection I found, after switching to newunicodechar for defining my unicode characters, that the sectioning headings give this peculiar ...
9
votes
3answers
330 views

Implementing car and cdr in TeX

I've been trying to implement a macro that reads and transforms its argument into a different form...but I'm having quite a bit of trouble finding or creating even the most basic parsing tools. Case ...
6
votes
3answers
423 views

Expandable string substitution

I am trying to define a macro \formatstr{\mystring}{(string empty)}{the string is: #1} which expands to (string empty) when \mystring is empty (as judged, e.g. by etoolbox's \csdefempty) and ...
5
votes
2answers
278 views

Define command either with or without \csname

I'm trying to do the same as this one, but with \def, \gdef or \xdef instead. Very quick summary of the other question: I wanted to print the command (not the contents of the command) regardless of ...
8
votes
1answer
341 views

Print name of command, defined by \csname

First off: I do not understand \expandafter and \noexpand completely which is probably the main problem. I have found a question that explains what it does, but still I cannot seem to make it work. I ...
24
votes
3answers
977 views

How to know whether or not we need \expandafter?

The following is quoted from Peter Grill's answer on question LaTeX dynamic macro definition. The \expandafter is requried as the \newcommand needs to be dealt with after the \csname. As a ...
27
votes
1answer
410 views

Why six \noexpand in a row?

Trying to understand TeX's rules for parsing dimensions, I came up with the following weird behaviour: \dimen0=1\noexpand\noexpand\noexpand\noexpand\noexpand\empty pt is valid, but ...
11
votes
3answers
272 views

Expandable 'character scanning' command that preserves spaces

David Carlisle recently offered a clean and rather elegant TeX solution to a question about expandable 'character scanning' commands. Unfortunately, David's solution does not preserve spaces in the ...
10
votes
2answers
589 views

How to use \noexpand in an \edef?

Continuing with my struggle to deal with expansion issues, I am stuck on how to use an \edef properly. The code below with the switches set as: %\def\ApplyColorToTitle{} %\def\UseMathrmInTitle{} ...
10
votes
1answer
433 views

Extract the logically first slide in a Beamer overlay specification?

When writing Beamer slides for a talk, I find that I often want to have some text (usually math) visible on a group of slides and be alerted on only the first slide in the group. For example, I can ...
8
votes
1answer
152 views

On pitfalls of robust commands

These days, I’m more and more defining robust commands, e.g., using \newrobustcmd (etoolbox package) or \NewDocumentCommand (xparse package). Robust commands seem advantageous to me in many respects ...
6
votes
3answers
188 views

How to “demux” several aspects from a `\foreach` variable with `\ifstrequal`?

How can I "demux" several features from a mode specification given in a \foreach? I would like to use a \foreach to draw several nodes in a TikZ picture. The loop will specify a mode for each ...
6
votes
1answer
155 views

How can I inhibit expansion through several layers of \edef?

I'm using a macro I've defined based on some suggestions here to automate the creation of tables. For example something like \newcommand{\clearrows}{\let\matrixcontent\empty} ...
60
votes
1answer
2k views

A LaTeX log analyzer application (visualizing TeX expansion)

Consider the following MWE, test.tex: \documentclass[12pt]{article} \begin{document} \tracingassigns=1 \tracingmacros=1 \def\aaa{something} \def\bbb{else \aaa, else} \edef\ccc{third \bbb, level} ...
7
votes
1answer
852 views

A \typeout (or expandable command) that can expand once - or with variable levels of expansion?

Consider the following MWE: \documentclass[12pt]{article} \begin{document} \def\aaa{something} \typeout{=1==\aaa==} \typeout{=1==\meaning\aaa==} \typeout{} \def\bbb{else \aaa, else} ...
6
votes
2answers
248 views

How to redefine commands and environments, and make them acceptable for `\write`

My general problem is the following. I want to "convert" many .tex files into some other format (xml-like). I don't want to modify the tex files, I can only build a documentclass. The texfiles are ...
1
vote
0answers
175 views

how to create a fully-expandable environment [closed]

I know DeclareDocumentCommand from the package xparse. I am wondering if there is a version for environment ? I could also imagine a trick based on : declare the environment with ...
9
votes
2answers
395 views

Expandable author names from biblatex?

Knowing that \printnames command in biblatex is not expandable as it is protected, and I cannot otherwise do much about it; I thought about going through biblatex.sty and reconstructing \printnames ...
7
votes
1answer
286 views

Defining inside an \edef

The following throws an "Undefined control sequence" error: \edef\testa{\edef\testb{foobar}\testb} when it gets to expanding \testb. This problem is also mentioned in "TEX by Topic" 12.6.2. But no ...
24
votes
4answers
2k views

On testing two fully expanded character strings for equality

I know three macros that test two fully expanded character strings for equality: \ifthenelse{\equal{<op1>}{<op2>}}{<true>}{<false>} (ifthen package) ...
12
votes
1answer
295 views

Why does \expandafter not expand the full { } group?

I thought I had understood the principle of expansion ... but apparently not! \def\a{AAA} \def\b{BBB} \expandafter\detokenize\expandafter{\a\b} I thought that the 2 \expandafter would store ...
2
votes
2answers
304 views

An expandable 'character scanning' command?

Please consider the following MWE, for a "character scanning" command "\looper" which utilizes \@tfor: \documentclass{minimal} \usepackage{trace} \makeatletter \newcommand\looper[1]{% % ...
3
votes
1answer
227 views

Showing expanded `\let` command with `\typeout`

I have already seen the related page macros - What is the difference between \let and \edef?, but I'm afraid it still doesn't expain to me the following MWE: \documentclass{minimal} ...
12
votes
4answers
378 views

Create a capitalized macro token using \csname

Two things I understand and one thing I don't: I often use \csname to create user-defined tokens. For instance, the following code uses \expandafter to expand everything between \csname and ...
6
votes
2answers
447 views

On unprotecting (expanding) \protected macros (or, “the space after command name”)

I quite often come into a situation, where I need to obtain some text produced by a package macro as a string, like in say: Expanding (edef) a lipsum command? How do I "unprotect" an ...
9
votes
6answers
814 views

Defining new commands inside a for loop

I would like to define a number of related commands by using the counter in a for-loop. For example, I want to define 26 commands like this: \newcommand{\calA}{{\cal A}} \newcommand{\calB}{{\cal B}} ...
6
votes
3answers
130 views

Expansion issue: How Check if options passed to an environment were used

I have an environment with portions of the content that being conditionally typeset based on options passed to the environment. The content of this environment is predefined elsewhere so depending on ...
7
votes
3answers
453 views

\expandafter parameters that are not commands

I'm using a custom command to format all tables in a document. Some tables share properties other than style, such as column definitions and headers, which is why this answer inspired me to even more ...
4
votes
2answers
352 views

expand macro in single byte encoded code

In this minimal (not) working example, I try to use single-byte latin10-encoded source file, and expand a command-macro containing a character with \catcode254: % -*- mode: latex; unibyte: t; ...
5
votes
2answers
171 views

Latex3 input/output and expansion of macros

I have a package that formats a course outline and have a macro that reads a formatted user file and turns it into a section. \documentclass{article} \usepackage{xparse} \ExplSyntaxOn \tl_new:N ...
4
votes
3answers
199 views

Using a macro evaluating to a set of xkeyval arguments as argument to another command

I am trying to code a macro that adds xkeyval arguments contained in a macro to a list of default xkeyval arguments. The following minimal example explains better what I want to do. ...
8
votes
1answer
545 views

'Undefined control sequence' error when defining a color through a macro

I'm trying to color a cell using its data value. However, when I try to compute some value (using the content of the cell) then the definition of the color color!\somemacro in the \cellcolor does not ...
5
votes
1answer
206 views

Print the counter given as an argument

I have a counterA and a counterB. I want to define a command \PrintCounter, which gets either A or B as argument, and then prints the value of the corresponding counter. I wrote the following code: ...
2
votes
1answer
231 views

How to add \hline to macro expansion?

I want to add one \hline to the macro expansion of this code, that is minimally modified version of David Carlisle's answer to Generating LaTeX tabular code during compilation. Compiling this with ...
5
votes
1answer
323 views

\unexpanded fails with undefined LaTeX symbols?

I'm actually not sure if the title of this post is correct. However, what is happening is that the following MWE \documentclass{article} \begin{document} \unexpanded{$\undefsym{x}$} \end{document} ...
10
votes
2answers
188 views

Execute non-expandable code inside a tabular environment

As there is no Expandable version of \InputIfFileExists or \IfFileExists, the question arises whether it is possible to execute non-expandable code in a tabular environment after all: File main.tex: ...
14
votes
3answers
1k views

Expandable version of \InputIfFileExists or \IfFileExists

From this question: Cannot use \toprule when doing \input inside tabular -- why? I know that everything inside the tabular environment should better be expandable. The MWE below suggests that ...
8
votes
2answers
2k views

Cannot use \toprule when doing \input inside tabular — why?

Using \input inside a tabular environment does not seem to work in all cases, but I don't see why. The MWE below gives the following error message: ! Misplaced \noalign. \toprule ->\noalign ...
9
votes
2answers
551 views

Force the expansion of a macro parameter without \edef or \xdef

Two days I am looking for a solution but I have no more idea. This is my problem. I'm trying to create a macro to automatically define new other macros to write references in a document. I want to ...
4
votes
1answer
87 views

How to use a counter in a \bookmark dest name within \BookmarkAtEnd?

I'm trying to do something similar as in this question. I would like to use the value of a counter in the name of a \hypertarget and in addition, I want to be able to refer to this name in a ...
7
votes
2answers
341 views

Convert string to file name and use in \href

I have a bunch of individual .tex files and want to be able to click on a link in one PDF file and have the appropriate PDF file open. These are small files, so don't really need to index into them, ...
12
votes
2answers
593 views

Macro to do nothing via a \def

I have encountered another expansion issue and have narrowed it down to this simple test case of a macro that does nothing, well at least it tries to do nothing, but is not all that successful. If I ...