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

learn more… | top users | synonyms

7
votes
2answers
61 views

How to manage expansion for this case?

My objective is to automatically compile parameterized template from within a main input file. For each compilation, a unique jobname and parameter are passed to the compiler. The problem is, passing ...
7
votes
1answer
203 views

\ifmmode self-contradictory in amsmath (OK in just LaTeX)

File: \documentclass[11pt]{article} \usepackage{amsmath} \newcommand{\argghhh}{\relax\ifmmode\bar\else\expandafter\=\fi} \begin{document} $ \argghhh a $ \end{document} produces error (but ...
7
votes
2answers
220 views

Expanding a sequence inside a TikZ path

I am trying to draw a simple path using TikZ, with a custom syntax to specify it. This works: \documentclass{article} \usepackage{tikz} \begin{document} \newcommand{\latticepath}[1]{ ...
7
votes
2answers
297 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. ...
7
votes
1answer
832 views

\newif conditional causing problem in \typeout or \edef

The following code produces result as expected, i.e., False True on the typeset document. \documentclass{minimal} \newif\iftest \newcommand{\test}[2]{ \iftest #1 \else #2 \fi } ...
7
votes
2answers
155 views

\g@addto@macro appending code using parameter

After a lot of trial and error, I haven't been able to solve the following problem: A simplified version: I want to use \g@addto@macro to add code to another macro wich will use a command of the ...
7
votes
3answers
128 views

Command that expands to the contents of a file

I'd like to make a macro that expands to the contents of a file. Basically something like \def{\mycommand}{\input{file.txt}} % file.txt contains "Hello%" \anothercommand{\mycommand} ...
7
votes
2answers
155 views

How to put a conditional construct in \edef

\ifthenelse works fine normally, but when used in \edef: \documentclass{article} \usepackage{ifthen} \newcommand\testing[1][]{% \edef\tmp{\ifthenelse{\equal{#1}{}}{Blank}{#1}}% } \begin{document} ...
7
votes
2answers
542 views

Expansion issue with \begingroup and \foreach

This question led to a new package: nowidow I'm trying to define a dynamic \begingroup command to get rid of widows: \usepackage{pgffor} \newcommand{\nowidow}[1][2]{% ...
7
votes
1answer
868 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} ...
7
votes
1answer
301 views

Replacement for \unexpanded without eTeX extension

As comment on Can the extended register pool be used for \newinsert?, there is a reference to Dealing with tons of floats. It is interesting but uses \unexpanded: \edef\@freelist{% ...
7
votes
1answer
179 views

expansion of loop macro

I have a macro that contains a loop using \@for and it works until I try to write its output to a file. The following document shows the problem. \documentclass{article} \makeatletter ...
7
votes
1answer
101 views

Make the pattern of a \def depend on another macro

I would like to set up a macro defined something like this: \def\processline string: #1.#2\relax{\gdef\errorline{#1}} The catch is that the string should be given by the contents of another macro. ...
7
votes
2answers
345 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, ...
7
votes
2answers
256 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 ...
7
votes
1answer
472 views

Is there a robust \renewcommand replacement?

Replacing \newcommand by \DeclareRobustCommand makes a new command robust. But what about \renewcommand? Is there a command to robustly renew a command? It would be possible to first use ...
7
votes
1answer
229 views

\forcsvlist and expansion

I've got an expansion issue with the following code: \def\sizes{huge, LARGE, Large, large, normalsize, small, footnotesize, scriptsize, tiny} \forcsvlist\sampletext{\sizes} My problem is that ...
7
votes
2answers
1k views

Building labels out of counters

There is a simple version to my question, and a complex version. First, the simple version: I want to generate label names by combining a constant string with a counter's value, something like what is ...
7
votes
1answer
95 views

Define macro based on Datatool contents

I can define a macro of the form \csname../dirX Color\endcsname manually and use it as desired. However, I am unable to do the same thing based on the contents as read by the datatool package. The ...
7
votes
1answer
287 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 ...
7
votes
1answer
140 views

Forcing macro expansion with keyval

While trying to provide an answer to this question, I've run into a stumbling block that I can't seem to get over. The listings package (like many others) uses keyval to handle configuration. What ...
7
votes
1answer
53 views

expl3: \tl_put_right:Nx chokes on \{

I am trying to compose a command into a token list. \documentclass{article} \usepackage{expl3} \begin{document} \ExplSyntaxOn \tl_new:N \__a \tl_new:N \__b \tl_new:N \__c \tl_set:Nn \__a { ...
7
votes
1answer
141 views

String Comparison with a \protected\def

I am using a \protected\def as that solved an earlier issue of mine. I need to compare this value of the token to see if it is initialized to the same value as the \protected\def in different ways. ...
7
votes
1answer
135 views

Modified \overline over first character of complex argument

I've been using zref to handle my references. It has allowed me to customize a reference the way I want through its property lists. In particular, I reference a variety of structures in my document ...
7
votes
2answers
627 views

Using \nameref within \path

Background Looking to apply a consistent style to file and directory names. The book's appendix has a subsection for every file referenced by the book. Every subsection has a label whose value is ...
7
votes
1answer
124 views

I'm confused about how expansion is happening here

I was really pleased that I could come up with a means of building the contents of a tabular environment using \foreach \x in {...} {...} structure. But I was curious about what exactly it would take ...
7
votes
1answer
86 views

Expand macro at float typesetting (not at definition) time

To my knowledge, the contents of a float environment are put into a box when the float is defined. Is it possible to proccess a user defined command/macro when the float is actually typeset, e.g. to ...
7
votes
1answer
127 views

Prevent \caption from expanding argument too early

I have a macro that defines some internal macros and does so locally as to not clutter the global namespace. However, \caption seems to expand the macro's argument too early. Here is a minimal ...
7
votes
1answer
229 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 ...
6
votes
2answers
457 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 ...
6
votes
4answers
356 views

Signalling error in “expandable context”

I'm reviewing a few old macros of mine to make them fully expandable. One of the macros takes one argument, which should either be a two-digit or a four-digit integer (>1955). The macro then converts ...
6
votes
2answers
375 views

Expand command read from file

I have a file, that contains a list of latex commands each command per line. Now I want to read this file line per line and execute/expand the macros automatically. I tried the following but this only ...
6
votes
3answers
120 views

Report all duplicate macro names defined by \newcommand

I have a shell script that produces a large list of macros in an external file in the form: \expandafter\newcommand\csname XX Name ABC\endcsname{some text ABC 1} \expandafter\newcommand\csname XX ...
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
3answers
147 views

Expansion issue when adding to CSV list from within a \foreach

Another expansion issue that I am unable to guess at the correct combination of \edef/\expandafters to get to work. Background: Below I have defined \AddToCommaSeparateList which uses \g@addto@macro ...
6
votes
2answers
466 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} ...
6
votes
4answers
164 views

Expansion of commands in errmessage

When I run \documentclass{article} \def\pet{dog} \errmessage{My \pet\ is {sick}} \begin{document} My \pet\ is {sick}. \end{document} the error message is: My dog\ is {sick}. but the PDF ...
6
votes
2answers
163 views

Delaying command expansion that appears in \begin handler until \end handler executes

I have a custom environment for handling a code interface declaration that is specified as: \begin{decl}{FOO} \param{in}{bar} the bar input parameter \param{out}{baz} the baz input parameter ...
6
votes
2answers
224 views

\StrMid and \MakeUppercase problem

What's wrong with this: \documentclass{minimal} \usepackage{xstring} \begin{document} \newcommand{\cim}{c1095} \StrMid{\MakeUppercase{\cim}}{1}{1} \StrMid{\cim}{2}{100} \end{document} ...
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 ...
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 ...
6
votes
2answers
526 views

Expanding (edef) a lipsum command?

Just trying to debug some stuff, and I thought about 'expanding' a \lipsum[1-2] statement using \edef into a new command (that would contain the "raw" text); strangely I cannot get it to work; this ...
6
votes
4answers
217 views

How to fill a dynamically generated table with dynamic content?

how do I generate a tabular dynamically while filling it with dynamic data? Example: Let's say I have \def\N{10} and I want to generate a table with \N columns, where the top cell of each column ...
6
votes
3answers
214 views

How can I get these two nested \foreach loops to work?

I try to use nested \foreach loops to create edges between many nodes. \documentclass{standalone} \usepackage{tikz} \begin{document} \begin{tikzpicture} \node (a) at (0, 1) {}; \node (b) at (0, ...
6
votes
2answers
133 views

Use of a macro to set counter value in another macro

I am trying to simply set the value of the counter try which I defined previously to the value of the output of the \foo command. However this does not work. I guess that the problem is coming from ...
6
votes
2answers
1k views

Save current value of counter in a command

I would like to define kind of an own index, that collects certain information and one counter value - in the following small example the \addstuff-command that may get the value of a counter as its ...
6
votes
2answers
505 views

Forcing tikz/pgf to expand macros within commands

I would like to use simple macros within tikz commands, but it seems tikz doesn't expand them in the ways I would expect. For instance, the code ...
6
votes
2answers
126 views

Using an expanded macro for optional environment argument

I'd like to open an environment, passing the content of a macro to the optional arguments. Up to now I tried different approaches using \expandafter, however I could not get the expected behaviour. ...
6
votes
3answers
426 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 ...
6
votes
1answer
173 views

How do I implement a string buffer in TeX?

I've recently learned how to create a macro to iterate over a token sequence using \afterassignment and \let in TeX. Currently, I'm trying to apply this to a tokenization macro (where "tokenization" ...