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

learn more… | top users | synonyms

10
votes
4answers
343 views

Changing the behavior of $$ but not of $

I am trying to set things up so that occurrences of $$ are replaced by \] if in math mode, \[ otherwise. My strategy is to make $ active and have it behave differently depending on whether the ...
0
votes
0answers
31 views

Prepend and append options to options list in environment

I need to define a macro superenv that expands to the usage of an environment which accepts key-value options. superenv should have three arguments: the environment name, the list of options, and the ...
49
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 ...
2
votes
0answers
89 views

Checking if first portion of an environment's content is empty

Motivation: I am working on a very personalized Exercise/Answer package for my colleagues. The exercise, exsheets, etc. packages don't do what I need. To accomplish this, I create an exercises ...
3
votes
2answers
54 views

Problems in expansion of a setcounter macro (Use of \csname doesn't match its definition)?

Followup to Split the reference counter for any numbered item (like with subequations) : I was trying to make a generic subanything macro, and I fail miserably - see MWE below for what I get as error ...
3
votes
1answer
31 views

Replacing some macro tokens in a list before \write ing

I'm trying to hack a bibliography package (amsrefs), and fall into the following problem. I'm trying to convert the amsrefs format back to .bib files. This doesn't quite work, because strings get ...
1
vote
1answer
31 views

BibLaTeX' \citefield not expanded as expected

I have run into what looks like a macro expansion issue. Consider the following example: \documentclass{article} \usepackage{hyperref} \usepackage{biblatex} \begin{filecontents}{expprob.bib} ...
3
votes
1answer
39 views

Expansion in \endnote-argument for hints after exercises

A desired feature for the latex-templates that we're using for exercises is to give hints in a way that the students have the option of trying to solve the exercise without it (i.e. not directly below ...
5
votes
3answers
149 views

Trim braces from macro content

I'm having macros with a content which may or may not have extra curly braces. I want to trim the extra braces but without expanding the rest of the content, if possible. The following code shows the ...
4
votes
1answer
43 views

How do you define a command to select nested groups?

Assuming a pair structure (2-tuple) is defined using groups {{<tokens1>}{<tokens2>}} is it possible to define a command \first#1{...} (and \last#1{...}) taking the surrounding group as ...
8
votes
3answers
519 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
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
1answer
106 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
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 ...
6
votes
1answer
175 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" ...
4
votes
2answers
119 views

\expandafter, \expandbefor : what else?

I have a macro that prints exactly what I want, but I can't use it nested in another one. As far as I understand it is because the fist one is not completely executed and commands from first macro ...
4
votes
1answer
41 views

\newrobustcmd not expandable as key-value?

I do some TeX experiments with 'postponed' content, writing it to some file to be included later on (not necessarily at end, but most time it would be appropriate to place it there) I defined some ...
4
votes
1answer
32 views

Iterating over pgfkey list - macros inaccessible

I have to draw a number of annotated number lines such as this: For this I adapt the pgfplots interface with a few extra keys. \begin{tikzpicture} \begin{axis}[ number line, ...
5
votes
2answers
87 views

How can I force lstlisting to expand an argument?

I'm trying to use the listings package with a variable language (it's actually for a package). However, I can't seem to pass a macro as the value half of a key-value pair. Here's a simple example: ...
3
votes
3answers
80 views

Vertical line in \halign with interrow spacing - LaTeX error

\documentclass[12pt, russian]{article} \tracingall \tracingassigns=5 \tracingmacros=2 \tracingcommands=2 \tracingrestores=1 \tracingstats=0 \tracingoutput=10 \tracinggroups=10 \tracingonline0 ...
5
votes
1answer
68 views

How to store tcolorbox's (multiple) settings in a macro?

I'd like to store tcolorbox' (multiple) settings in a (single) macro (in fact, a xkeyval's \cmdKV@fam@key macro) and use them afterwards via this macro (I know I should use pgfkeys instead, but my ...
4
votes
3answers
104 views

Macro concatenation via expansion multiple times with some tokens protected?

In the MWE below, I want to create a \doPlotCoords macro from scratch, by appending \addplot commands: \documentclass{article} \usepackage{pgfplots} \usepackage{pgfplotstable} \usepackage{adjustbox} ...
3
votes
1answer
41 views

Expanding expl3 counter test at the right moment

I'm trying to get a counter to work, called \l__ioiooiioio_args_second_int in the example below, and I've declared to increment at each loop through \int_incr:N \l__ioiooiioio_step_int, but apparently ...
2
votes
1answer
44 views

Using a fp variable in a longtabu header

So, I am using the tabu package (which I need to use over tabular others for several reasons) to make a long table spanning several pages. This table contains currency amounts in a column, and I'd ...
2
votes
1answer
21 views

Footnote in \setarrayelement with memoir class

I'm using the memoir document class. I have problems storing a \footnote command using \setarrayelement. Here's a simple document: \documentclass{memoir} \newarray{aaa}{1}{1} ...
4
votes
2answers
104 views

How to deal with macro expansion and 'TeX capacity exceeded' when using write18?

This issue is driving me nuts. Ever since the friendly and knowledgeable people here on tex SE have guided me to doing multiple string replacements the proper way, I've been trying to incorporate that ...
6
votes
3answers
122 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 ...
12
votes
2answers
159 views

Why does this use of `\expandafter` not work?

I've written the following code: \newif\ifconsecutive \consecutivefalse \newcommand{\myfirst}[1]{#1\consecutivetrue\expandafter\consecutivefalse} \newcommand{\mysecond}[1]{\ifconsecutive ...
6
votes
1answer
43 views

Using \pgfplotstablesort with a dynamically named macro

I have a moderately large number of data files that I need to read in with \pgfplotstablesort, and in each case the data read in should be assigned to a macro for later use in a plot. The filenames ...
7
votes
1answer
230 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 ...
2
votes
1answer
28 views

Macro defining another macro with spaces in its name

I am trying to use the KOMA-Script command \newcaptionname which takes a macro name as its second argument, but I need spaces in it: \documentclass{scrartcl} ...
3
votes
1answer
38 views

Create bibliography categories and headings based on a list

I would like to be able to specify a list that will create categories and add entries to them. I am using pgffor for specifying the category name and the heading title in a convenient way. The ...
8
votes
2answers
266 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}{ , ...
10
votes
2answers
113 views

Expandably change letter case and use inside \csname, without a package

I want to change the letter-case of a single character argument, and use that changed letter inside a \csname. And I want to do it without an additional package. For example, I want to pass a macro ...
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 ...
11
votes
2answers
228 views

Define and set length in one command

Sorry this might be a very simple question, I am trying to cleanup a style file, and would like to write a command that basically runs the following code: ...
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}\\% ...
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: ...
3
votes
2answers
68 views

Generate comma separated list with some non-empty strings

I'm trying to generate a comma separated list that uses strings that may or may not be empty. For example \mylist{\stringA,\stringB,\stringC} would expand to A, C if B is empty or B, C if A is empty, ...
0
votes
0answers
29 views

Show expansion of words [in popup] when mouse hover over abbreviation [duplicate]

I have quite a lot of technical abbreviations in my resume, is there a method to popup the expansion of the words when user hovers their mouse on the word ?
20
votes
1answer
122 views

Is implicit `\relax` in conditionals explained anywhere in the TeXbook?

I have been relying for years on TeX's behavior where, say \if1\fi expands to nothing and \if1\else\fi does the same. In the second case TeX inserts an 'implicit' \relax when it tries to expand \else. ...
22
votes
3answers
295 views

Why the \expandafter\@firstoftwo idiom?

I see a lot of macros which are conditional tests followed by a {true}{false} pair defined so that they result in either: \expandafter\@firstoftwo or \expandafter\@secondoftwo Why are these ...
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. ...
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 ...
4
votes
1answer
49 views

Expand macro into xparse \SplitList macro

I had help making a macro to process a list of arguments separated by ; into an itemize environment. To achieve this, xparse was used. When I tried to wrap the lists of arguments in a macro, nothing ...
6
votes
4answers
224 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 ...
8
votes
4answers
163 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: ...
5
votes
1answer
26 views

Selectively apply \global to some tokens set via an \input file

This should be simple, but I can't quite guess the correct combination of \expandafter needed. The value of \MyTokenGlobal should not be changed via the \input, but the value of \MyTokenLocal should ...
7
votes
1answer
87 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 ...
36
votes
4answers
2k views

How does your mind bend \expandafter to its will?

Expansion is often cited as one of the most arcane aspects of TeX, more akin to witchcraft than to something easily picked up by the newcomer. There are many great questions and great answers about ...