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

learn more… | top users | synonyms

9
votes
2answers
285 views

How can I encode the current document as a QR code with pst-barcode?

\documentclass{article} \usepackage{pst-barcode} \begin{document} \begin{pspicture} \psbarcode{\input{\jobname.tex}}{}{qrcode} \end{pspicture} \end{document} I tried placing \expandafters before ...
9
votes
3answers
230 views

Completely expandable loop macro that also works in tabular

Since I normally use tikz in my documents, I mostly use the \foreach \x in \list loop to repeat things. However, this famously fails in tabular environments and also everywhere where things must be ...
9
votes
1answer
294 views

Expansion of macros and box contents

I don't understand the following behavior. Intro First, here is a simplified version of a macro I am using (which is itself a hacked version of a macro found in gloss.tex). If you have a string ...
9
votes
2answers
217 views

Still having difficulty with use of `\expandafter`

Firstly, my apologies for any previous confusion, I've separated out various questions onto distinct pages. This problem came up in the context of trying to split a decimal number. Good solutions to ...
9
votes
1answer
156 views

Is there a way of defining a command which is automatically converted to a no-op after its first execution?

Is there a way of defining a command that can be executed only once and is then redefined to be a no-op? Related: Is there a way of defining a command \nullifyifmoved{arg} that will normally act ...
9
votes
3answers
384 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 ...
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 ...
9
votes
1answer
226 views

Expansion inside \AtBeginDocument

I'd like to expand a macro inside \AtBeginDocument, although I guess the concrete macro does not matter. \documentclass{article} \makeatletter \@for\x:=1,2,3\do{% ...
9
votes
1answer
2k views

Difference between \newcommand and \pgfmathsetmacro used in TikZ \coordinate

Consider the following code: \documentclass{article} \usepackage{tikz} \begin{document} \begin{tikzpicture} \newcommand{\MA}{4} \pgfmathsetmacro{\MB}{4}; \coordinate (V11) at (0,0); ...
9
votes
3answers
311 views

Write on a file and input it

I'm trying to redefine a \tableofcontents-like command. I proceed this way : the displayed elements are written to a file, and the file is input when I want the display. If I know the toc will be ...
9
votes
1answer
289 views

Using \typeout behaviour different with \newtoks vs. \def

I feel as I really should know this, but sadly I don't. Why is the output of \typeout{\the\myToken} not the same as having it printed in the PDF as \the\myToken. No problem with a \def, just with ...
9
votes
1answer
1k views

Expansion in \numexpr…\relax versus \pdfstrcmp

The \numexpr...\relax construction in eTeX allows to evaluate numerical expressions, and it expands tokens fully as it goes. The \pdfstrcmp{...}{...} construction in pdfTeX lets us compare two lists ...
9
votes
2answers
277 views

Expansion problems with pgfkeys

I'm using pgfkeys, and a fairly adventurous syntax in which the values for some keys contain additional key/value pairs. (For instance, the value of the nodes key is a list of pairs, and the second ...
9
votes
1answer
232 views

“Flatten” macros prior to sharing LaTeX file

Is there a way/an existing tool to process a LaTeX source document such that for a given list of macro definitions (using \newcommand), calls to those macros are replaced by their expanded version? ...
9
votes
1answer
835 views

Highlighting line ranges in a lstlisting: partial solution, but expansion issues

In my quest for a better solution for How to change appearance of a particular line when using \lstincludelisting, I came across the linebackground= option Martin Scharrer added to the listings ...
8
votes
4answers
270 views

Does macros get applied to the source code before compilation?

I wonder if this is true. The latex compiler first run though the document, and search for all the macro declarations. the compiler then go though the document, apply each macro as a string ...
8
votes
3answers
536 views

Without any built-in looping macro, can we just use a recursive macro to get a-b-c-d-e?

Without any built-in looping macro, can we just use a recursive macro to get an output of a-b-c-d-e? \def\aaa #1{#1-\aaa} \aaa abcde % expected result : a-b-c-d-e \bye Edit: Probably the best way ...
8
votes
4answers
187 views

Problem with csname macro expansion

I want to dynamically define some macros that essentially create a list of \refs. I seem to be able to define these macros but then I am unable to print them. Here is my M(non)WE: ...
8
votes
3answers
211 views

Arguments possibly delimited by \bgroup and \egroup

I still don't see (and haven't thought about) pros and cons of making available the arguments as \foo{…} or \foo\bgroup …\egroup (or even unbalanced, \bgroup …} and {…\egroup). But I'm curious about ...
8
votes
2answers
117 views

How to use \edef to wrap an existing macro with @inmatherr?

I have a handful of existing macros that I want to wrap in some custom processing. Here's an example of the kind of thing I'm aiming to do: \makeatletter \let\olddag\textdagger ...
8
votes
3answers
215 views

Nested use of \ifcsname needs protection

I have a macro \command to ensure that the names of macros in my documentation are consistently formatted. Been work great, until I had an urge to procrastinate and had this brilliant idea that I can ...
8
votes
3answers
483 views

colortbl: new environments and how to apply \expandafter

This is a followup question from one asked by Andrew Howard. After some discussion, it became clear that colortbl has some issues with the names that can be used for a \newcolumntype. The result of ...
8
votes
2answers
262 views

How to control whether and when a macro gets expanded during another definition?

I wish to define a meta-command that, whenever invoked, will define an instance of another command; but this inner command must include a progressive number (somewhat similar to what happens with ...
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 ...
8
votes
2answers
458 views

How can I allow a command to be used without braces around its argument, when the argument has an argument?

I've defined a couple simple macros to make my life a little easier: \newcommand{\curl}[1]{\ensuremath{\nabla\times #1}} \renewcommand{\v}[1]{{\ensuremath{\vec{#1}}}} This way, in text mode I can ...
8
votes
1answer
103 views

Omitting arguments in macro expansion

Changing a simple TeX macro like \def\macro#1 #2{#1 #2} into \def\macro#1 #2{#1} alters the output of \macro Hello world surprisingly for me to Helloorld My expectation would have been to ...
8
votes
2answers
323 views

How to create an inline list via a macro

I want to create a macro that yields an inline lists. I can easily do this using enumerate* form the the enumitem package, but when I attempt to wrap this in a macro, I get: Extra }, or forgotten ...
8
votes
6answers
427 views

Is it possible to define a command that can be used where literal <comma-separated-list> is normally required?

I suspect I'm asking for magic, but I'll go ahead anyway. Suppose I have a command that accepts an arbitrary-sized list of comma-separated terms. One that we're all familiar with is \usepackage ...
8
votes
1answer
116 views

How can I force expansion within this optional argument?

Oh look, a real question! In trying to actually complete something, I came across the following limitation of this lambda macro creator: it apparently does not work in the use case it was intended ...
8
votes
4answers
1k views

How to write a command to file

I am trying to write to a auxillary file using \newwrite\tempfile [...] \immediate\openout\tempfile=list.tex \immediate\write\tempfile{Text to write to file} \immediate\closeout\tempfile It works ...
8
votes
2answers
275 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 ...
8
votes
1answer
110 views

Implement functionality equivalent to many thousand \savebox

I have a large (approx 600 pages) index of files, and for each file entry significant computation is required so that additional links can be added. The computation of these links takes quite a bit ...
8
votes
1answer
272 views

\href is not working inside \xdef

this is my first question here. I've already spent a substantial amount of time searching this before posting it here. This is my code: \documentclass[]{article} \usepackage{hyperref} ...
8
votes
2answers
395 views

Package xparse \SplitList last token

I need to create a macro to render lists with a variable number of arguments (1+), e.g. \mylist{1,2,3} should expand to $\tilde{1}$--$\tilde{2}$--$\tilde{3}$. I'm trying to use xparse and \SplitList, ...
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 } ...
8
votes
2answers
170 views

How does expansion matter?

\newcount\@repeat% \def\repeat#1#2{% \@repeat#1\relax% \ifnum#1>\z@\relax% \advance\@repeat by -1\relax% \repeat{\@repeat}{#2}#2% \fi}% \repeat{2}{1}\\% \repeat{11}{f}\\% ...
8
votes
1answer
401 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 ...
8
votes
1answer
614 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 ...
8
votes
1answer
157 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 ...
8
votes
2answers
281 views

Preparing macro content in a loop (calling \foreach from \edef)

I need to do something like \def\MyArray{{1, 2, 3, 4}} but with a dynamical number of elements. The following command makes the string: \newcommand{\MakeArray}[1]{\{ 1 \foreach \x in {2, ..., #1}{ , ...
8
votes
1answer
852 views

Problem with environment expansion and the Tikz external library.

I've created my own environment mytikz, which basically looks like this (full MWE): \documentclass[a4paper]{article} \usepackage{tikz} \usetikzlibrary{external} \newenvironment{mytikz}{%begin code ...
8
votes
1answer
98 views

How do the \xx_case: functions work?

In the process of answering expl3 switch for booleans: Is there a \bool_case:Nnn?, I tried to make sense of the various \xx_case: functions Expl3 provides. Here, for example, is \tl_case:Npn: ...
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 ...
8
votes
1answer
80 views

How can I expand macros and write the expansion to an external file?

I'm trying to do a bit of single-sourcing with my resume, and would like to write given information to an external text file. \documentclass{article} \usepackage{expl3,xparse} \ExplSyntaxOn ...
8
votes
1answer
78 views

A proxy command for deprecation

I'm interested in defining a macro to deprecate other macros. The system on which we are working goes through a lot of refactorings and is used by more than a couple people, so we want to be able to ...
8
votes
1answer
122 views

Package providing fully expandable conditionals

Is there a package providing a collection of fully expandable conditionals like this one: \newcommand\myif@num[1] {\ifnum#1\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi} Background: ...
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 ...
8
votes
1answer
285 views

How do I store the upper case counterpart of a string?

I have a string stored in a variable \word, and I want to store its upper case counterpart in another variable \WORD. If I try \def\WORD{\MakeUppercase{\word}} \show\WORD then the message ...
8
votes
2answers
273 views

reversing the order of expansion

Is there a non-expl3 expandable function for reversing the order of expansion of an arbitrary number of tokens or macros? For example, \reverseexpansion<n>\a\b ...
8
votes
1answer
214 views

Understanding token expansion

First of all, note that this question is to be regarded as a learning question as I am not looking for a package (I know very well the xparse package). I am attempting to write a macro which has the ...