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

learn more… | top users | synonyms

8
votes
2answers
144 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
47 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
46 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
24 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
113 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
189 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
498 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
35 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
134 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
125 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
18 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
78 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
122 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
62 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
45 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
40 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
43 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
67 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
94 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. ...
13
votes
1answer
174 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 ...
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 ...
7
votes
1answer
111 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 ...
17
votes
2answers
348 views

Why does this simple \ifx test fail?

This should be easy, but I don't understand why the test below fails... I expected Hurrah! to be printed when the \currentchar count reaches 90 (i.e. the character code of Z). There must be some ...
6
votes
1answer
56 views

Expand package option, to make contained character math-active

In an answer to another question of mine, egreg posted code, which activates a character in math mode and gives it the function of \operatorname. Now I want to put this into a package and set the ...
7
votes
2answers
157 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]{ ...
42
votes
4answers
1k views

What is “expansion”?

I'm relatively new to (La)TeX, but I have a reasonable amount of experience with computational programming languages. Until I began learning (La)TeX, I'd never heard of "expansion"... So, what is ...
7
votes
2answers
90 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
2answers
145 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}{} ...
4
votes
1answer
138 views

Is it possible to define abbreviations for coding?

I am using the tikz-timing package to create a timeline since chronosys and chronology wouldn't cooperate and were too limited and archaic-looking to suit my purposes, and moderntimeline unfortunately ...
3
votes
1answer
63 views

How to expandafter an environment?

I have the following problem: I want to create a beamer presentation and introduced a new environment using xparse. The environment has one optional argument (+ two mandatory). Now I want to create an ...
4
votes
2answers
108 views

Concatenate macro with string

I try to expand a macro containing a string with another string. It is in the document and thus I want to avoid using @. I tried the following using etoolbox ...
8
votes
1answer
64 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 ...
4
votes
2answers
64 views

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

this thing 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 ...
4
votes
1answer
39 views

Expl3 prop doesn't seem to work when the key is a macro value

I'd expect this example code to give two identical lines, however \usevalue{\xyz} doesn't result in XYZ as the other. Can I force the key to be expanded to make \usevalue{\xyz} and \usevalue{0} refer ...
6
votes
1answer
75 views

Macro expanding to comma separated list

I'm trying to use a macro for pgfplotstable labels but the macro is treated as a single entry of a csl rather than a csl. The Question asked in Using a macro as value of addtotoc in \includepdf ...
5
votes
1answer
108 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? ...
5
votes
1answer
80 views

\begingroup, \endgroup expansion problem “Undefined control sequence.”

I just created an answer that uses a temporary variable with \write\@auxout and thought it would be good idea to scope with \begingroup, \endgroup. For some Reason this results in: ! Undefined ...
1
vote
0answers
34 views

What's the shortest input that makes TeX and/or TeX-based systems go into a loop? [duplicate]

The following 12-character input causes TeX to go into a loop. \def\x{\x}\x It won't crash, it won't produce an error message, it'll just sit there for ever, trying to compile the document (but not ...
1
vote
0answers
66 views

About those magic primitives

While learning TeX, I found some primitives are magic (e.g., \expandafter \futurelet \aftergroup). These primitives can change the expansion order of the input stream. Have anyone made any ...
5
votes
2answers
65 views

Comparing the arguments passed to a macro

I want to write a command which makes a norm of a vector, with following syntax: \xnorm{v}. I want the norm delimiters to adapt to the size of the expression contained in \xnorm{}, BUT I want also an ...
6
votes
3answers
167 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, ...
5
votes
2answers
73 views

How to get character code defined with \let (! Improper alphabetic constant)

Here's a example with the "! Improper alphabetic constant" error: %% this is ok \newcount\mychar \mychar=\number`a\relax \showthe a % shows You can't use `the letter a' after \the ...
6
votes
1answer
82 views

Expanding a macro as many times as possible without error

I'd like compute cosets using the permute package. Here's what I have so far: \documentclass{article} \usepackage{expl3,xparse,permute} \ExplSyntaxOn % Create a new command to compute the right ...
5
votes
1answer
52 views

Using xstring macros in edef

I've tried to use \protect to make the following \edef work but no luck. Can it be done somehow? \documentclass{article} \usepackage{xstring} \begin{document} \def\abc{a,b,c} ...
8
votes
1answer
53 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} ...
7
votes
1answer
47 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 { ...
10
votes
1answer
55 views

Reading (input) a file whose name is created with a label

I don't want to get into the details of why I want to do this, but I would like to: create a new counter called filenumber; create a file whose filename is \jobname\thefilenumber.txt and write to ...
0
votes
0answers
21 views

“Expanding” locally defined commands [duplicate]

I wrote a paper using custom ("locally defined") commands and environments (e.g. a new quote environment, loads of abbreviations, etc.). The journal requires me eliminate all non-standard LaTeX ...
4
votes
1answer
73 views

Expanding a variable within a protected label

I have some trouble with expanding variables within a protected label. I need a automatisated caption with a label all inside a command. Within the caption I want to have a two digit number ...
4
votes
2answers
74 views

Creating a new array column type dynamically

I am evaluating toks registers for various uses - they are still fairly new to me. I'm using them to construct a table column-wise. During this, I have come across an issue I have failed to find a ...