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

learn more… | top users | synonyms

9
votes
1answer
232 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
1answer
62 views

LaTeX3 Property lists and expansion

So, I'm trying to pass the "date" value associated with the current environment to a property list defined by a macro. It doesn't seem to work and I'm not sure why. Here's a MWE: ...
9
votes
2answers
243 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
753 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
266 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
518 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
159 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
2answers
90 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
185 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
455 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
242 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
409 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
300 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
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
1answer
253 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 ...
8
votes
6answers
422 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
2answers
99 views

Apply command to list of elements separated by \and

I am trying to build a command similar to the \author command. It takes one argument with is actually a list of arguments separated by \and. The command needs to apply another command like \underline ...
8
votes
1answer
105 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
1answer
102 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
264 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
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
4answers
962 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
168 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
2answers
340 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
343 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
549 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
151 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
265 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
767 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
95 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
1answer
72 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
72 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
153 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
281 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
267 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
188 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 ...
8
votes
1answer
213 views

Expandable, standard TeX only way to compare balanced token lists

Is there a (reasonably) efficient macro that does something similar to \long\def\comparets#1#2{\def\aa{#1}\def\bb{#2}\ifx\aa\bb true\else false\fi} except is expandable (i.e. ...
8
votes
1answer
60 views

Moving the optional argument

When I create macros using \newcommand, I usually provide default variants setting some of the first arguments in a sort of partial application style \newcommand\five[5]{#1,#2,#3,#4,#5} ...
8
votes
1answer
127 views

Formatting code fragments extracted from file with minted

I would like to use the catchfilebetweentags package to grab code snippets from a source file and use minted to highlight them. Imagine I have the following in program.scala: //<a def ...
8
votes
0answers
98 views

Can I detect (from within a macro) if I'm in an \edef (or similar)? [duplicate]

Possible Duplicate: Are we inside an edef? I've defined a macro that changes its behaviour depending on the next character, so it uses \@ifnextchar. This makes it behave badly inside ...
7
votes
3answers
195 views

Are we inside an edef?

How would you test whether we are in an expansion only context (i.e., \edef, \xdef, \write,...) or not? The only ways I could think of leave things behind (but the full expansion of that extra stuff ...
7
votes
3answers
519 views

Command that changes its definition the nth time it's used

I need a command to behave differently the first time than the next times it's called. Right now I use \newcommand\foo{First\gdef\foo{Next}}, that is, it redefines itself the first time. Moreover, I ...
7
votes
2answers
114 views

Is there a way of defining a command \nullifyifmoved{arg} that will normally act like its argument but act like a no-op if the macro is “moved”?

I'm interested in a macro \nullifyifmoved that takes one argument arg and acts like arg in normal contexts, except it acts like a no-op wherever it is written to a file. Some background: Martin ...
7
votes
2answers
157 views

Expand LaTeX macros to modify

I am using the polynom package for polynomial long division. For example: \documentclass{article} \usepackage{polynom} \begin{document} \polylongdiv{x^3-x^2+d}{x-2} \end{document} Notice that I ...
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} ...
7
votes
3answers
457 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 ...
7
votes
3answers
715 views

\uline within a pgfmath expression produces an error

Why does using \uline within a pgfmath expression result in an error? \documentclass{article} \usepackage[normalem]{ulem} \usepackage{tikz} \begin{document} \pgfmathparse{width("\uline{blabla}")} ...
7
votes
2answers
157 views

Expanding all arguments of a command before appending it to another macro

\documentclass{article} \makeatletter \usepackage{ltxcmds} \newcounter{mycounter} \setcounter{mycounter}{7} \newcommand{\mysndc}[3]{#1 #2 #3} \newcommand{\mycommand}{} ...