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

learn more… | top users | synonyms

11
votes
3answers
296 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
693 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
465 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
166 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
202 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
165 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
1k 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
256 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
182 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
460 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
300 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
328 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
344 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]{% % ...
4
votes
1answer
294 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
434 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
525 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
919 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
135 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
513 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
393 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
177 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
203 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
615 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
251 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
244 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
348 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
198 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: ...
15
votes
3answers
2k 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
706 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
89 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
371 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
663 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 ...
13
votes
2answers
492 views

\expandafter within a \begingroup … \endgroup [duplicate]

Possible Duplicate: What does \begingroup\expandafter…\endgroup do? In many of Heiko Oberdiek's packages one sees this type of construction: ...
6
votes
1answer
174 views

How to extend the \romannumeral-based \fullyexpand to handle empty/all-space arguments?

In Expandable full expansion of tokens that preserves catcodes, Joseph Wright presents the following code: \long\def\fullyexpand#1{% \csname donothing\fullyexpandauxi{#1}{}% } ...
3
votes
2answers
139 views

Can Texinfo's @value macro be made to work in the filename argument to @xref and friends?

Given a file xref-and-value.texi with contents: \input texinfo @c -*- TeX-PDF-mode: t; -*- @setfilename xref-and-value.info @settitle @code{@@xref} and @code{@@value} in \pdftex @set fngccint ...
7
votes
1answer
231 views

Why do some arguments in a macro need to be preceded by \noexpand?

I keep on studying the use of nested tikzpicture environments (sorry) and I discover the next problem. I'm not sure but it sounds like a problem with "fragile" commands. Perhaps, the problem is the ...
7
votes
5answers
2k views

\includegraphics: a command in the optional argument

I want to pass some arguments to \includegraphics via a command, but I can't get it working as I would expect. My M(n)WE: \documentclass{article} \usepackage{graphicx} \begin{document} ...
6
votes
1answer
451 views

How to expand values stored in a token defined by newtoks

In this project, the directory structure and file names are based on three parameters, with there being one exception to both. Directory Path: \GetTexFilePath{}{}{} The directory path is based on ...
10
votes
1answer
2k views

Add space after LaTeX command

I'd like to call a command from LaTeX, which looks like this: bash -c "\myCommand -Tpdf #2.dot > #2.pdf" \myCommand is replaced by string variable, however the space after is also removed so I ...
20
votes
2answers
326 views

Get the lion to run in loops. Tersely

Various constructions can cause TeX (aka the lion) to go into an infinite loop. The simplest example is \def~{~}~, which defines ~ to expand to itself, then expands it. Now, if we exclude macro ...
15
votes
4answers
641 views

Detokenizing without extra spaces?

I have a need to pass through potentially arbitrary characters untouched and found this macro: \def\test#1{\expandafter\zap@space\detokenize{#1} \@empty} The problem is that \detokenize inserts ...
3
votes
3answers
428 views

Problem with expansion of \BODY

In the following MWE, the command \testStringNotEmpty tests if the argument is empty. This test is robust in the sense that the argument can contain a command or an environment... The environment ...
8
votes
2answers
278 views

Hyperref to expand macro in argument

I am confused as to why the edef below does not get expanded in the link? The \GetTexFilePath is from Text being output when none should be, which is expandable, and the \GetTexFilePathOld is the ...
14
votes
1answer
568 views

Why is \input not expandable?

In latex.ltx I found \def\input{\@ifnextchar\bgroup\@iinput\@@input} where \@@inputis expandable. I would like to know if there is an expandable version of \input. The problem comes from an example ...
12
votes
1answer
295 views

Text being output when none should be

I am confused as to why the MWE below produces any black text. As the code is below, the output is: However, if you comment out the \IfStrEq line then it works fine and the black text goes away? ...
8
votes
1answer
158 views

Feeding a macro with the expansion of an other defined “by” \csname

I have a macro \mymacro@i that I want to "feed" with the expansion of another \test. With \expandafter\mymacro@i\test, it works. Now, the \test macro can be defined by using \csname, say a /test ...
7
votes
2answers
320 views

Why does this protection not work?

The answers to this question explain in detail what protection is so I'm not wondering about that. My question is why a certain command definition with expl3 does not give a protected command. ...