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

learn more… | top users | synonyms

3
votes
2answers
49 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
30 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
30 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} ...
5
votes
3answers
147 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 ...
2
votes
0answers
86 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 ...
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 ...
3
votes
1answer
38 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 ...
8
votes
3answers
516 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
89 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
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
187 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
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" ...
4
votes
2answers
118 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
39 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
84 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: ...
5
votes
1answer
64 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 ...
3
votes
3answers
77 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 ...
4
votes
3answers
102 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} ...
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 ...
12
votes
2answers
157 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
42 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 ...
2
votes
1answer
26 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
36 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 ...
10
votes
2answers
112 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
222 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
167 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
67 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. ...
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
48 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
220 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
158 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
25 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 ...
10
votes
2answers
165 views

Save counter value inside command?

I'm trying to automatically generate commands based on the value of a counter: \documentclass{article} \newcounter{count} \newcommand\generator[1]% {% \stepcounter{count}% ...
2
votes
1answer
90 views

Macro for pgfplot cycle list entry

I'm trying to define multiple cycle lists based on macro variables. The reason for this is that I need more than one list and I want to be able to change the appearance quickly while keeping the ...
1
vote
1answer
59 views

Check the value of a pgfkey

I need to be able to check if the value of a pgfkey is empty or not. A solution I have tried (using package etoolbox): \edef\temp{\pgfkeysvalueof{/path/key}}% ...
4
votes
1answer
54 views

Changing the default value of a pgfkey

I want to create a command that can change the default value of my pgfkeys. I think the problem is that the value set as default is not expanded. Therefore the icondefaultsa below doesn't work. ...
2
votes
1answer
56 views

Expanding beamer arguments

I have created a new command that takes beamer-arguments (<...>), but I'm not able to pass them on. I suppose it's a \expandafter problem. Does anyone have a clue? \documentclass{beamer} ...
4
votes
1answer
86 views

Passing variable as argument

I need to pass a variable to a command, but I cannot get it to work. Here is a short example that shows that #1 can be sent to a command, but not a variable that is a copy of #1. Why is this? ...
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. ...
14
votes
1answer
189 views

A problem with counters

While trying to answer a question I came upon a problem with counters and I need some help. The idea is to collect answers to some numbered exercises, so the collected answers can be all typeset at ...