Questions tagged [expansion]

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

Filter by
Sorted by
Tagged with
0
votes
1answer
41 views

Expandable contact information

Introduction I am sorry for the long MWE, but I was not able to make it shorter and still illustrate my problem. Again I am working on streamlining the creation of exams for my university. In the ...
0
votes
1answer
173 views

Gnuplottex: Pass latex command to gnuplot script

I want to access and plot the same data from different LaTeX documents (a paper and a beamer presentation) using gnuplottex. The data and the gnuplot script is stored at some individual position ...
6
votes
2answers
284 views

Issue with Expansions of Nested Macros

I am trying to incorporate membership checking macros by marmot and Phelype Oleinik (thanks to both of them for their neat solutions) into an argument of another macro: \singleBox{\...
1
vote
2answers
43 views

How can I avoid to copy and paste this code (similar newcommand definitions using different functions) :

I've been improving my code thanks to you guys, but this still looks improvable as it looks like an ugly copy/paste : \newcommand*{\LegendFlecheInf}[5]{ \coordinate (C2) at (axis cs:#2, { \...
0
votes
1answer
46 views

How to define a macro with digits in its name using \def and a counter value?

I need a \def whose name involves a number, with that number being value of a counter. \documentclass[varwidth,border=5mm]{standalone} \begin{document} % COUNTER \newcounter{myC} \addtocounter{myC}{...
0
votes
1answer
43 views

Passing arguments using pgfkeys to a macro for including PDF files, using pdfpages

This is a slightly simplified version of a macro I've been writing (using pgfkeys and pdfpages) to include PDF files. This seems to be working. I ran into one bump. includepdf does not like it when ...
1
vote
1answer
33 views

Problem with expansion in xparse

I am trying to use function from this answer \documentclass{article} \usepackage{xparse} \ExplSyntaxOn \NewExpandableDocumentCommand{\switchcondition}{ O{string} m m m } { \use:c { ...
0
votes
0answers
32 views

Writing into a file, strange behavior with expansion

I want to write some data into a file, but I need to replace a subtring in these data beforehand. For some reason, the expansion through the \write macro does not give the expected result. Instead, a ...
2
votes
1answer
55 views

\protect'ing a token list

To prevent expansion of a macro in expansion contexts we can define the macro as \protected. I'm wondering if there's a way to do the same for an arbitrary token list. So is it possible to define a ...
0
votes
1answer
37 views

newcommand counter expansion problem

I am trying to write a macro to support producing a sequence of storyboards for an appendix in a two column IEEE paper. Can the value of a counter be expanded immediately for a macro? Currently the ...
70
votes
4answers
5k 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 "...
4
votes
2answers
107 views

pgfkeys: .store in constructed macro

I'm trying to store a value in a macro that is constructed from the arguments of another macro, but I must be missing something because the macro is not created. MWE: \documentclass{article} \...
76
votes
1answer
2k views

A LaTeX log analyzer application (visualizing TeX expansion)

This question led to a new package: unravel Consider the following MWE, test.tex: \documentclass[12pt]{article} \begin{document} \tracingassigns=1 \tracingmacros=1 \def\aaa{something} \def\bbb{...
4
votes
3answers
109 views

fully expand toks and save for later (appendix with exact copies of tables from the main text)

I have a document with some complex tables, defined by a command called \Rule with named parameters (using the keyval package). The individual rows of the table are first stored into a token list ...
1
vote
1answer
57 views

Is \scalebox guaranteed to fully expand its first two arguments?

In this answer, I've been conservative and used the following code: \expandafter\scalebox\expandafter{\my@scale}{\usebox{\my@box}} to make sure not to rely on undocumented (?) behavior of \scalebox ...
5
votes
1answer
62 views

Why is \unexpanded not respected after an \if?

I was surprised to find that the argument of an \unexpanded is expanded if the \unexpanded is within the first two tokens after an \if. Using Knuth TeX's \noexpand instead works but I am curious where ...
2
votes
0answers
92 views

How do use {<setup>} in \tl_set_rescan:Nnn to replace \scantokens?

This question is related to (Changing escape character in \tl_set_rescan:Nnn) and (https://tex.stackexchange.com/a/496258/7832) but is not the same. I've tried to change this: \exp_args:NNx \...
3
votes
2answers
57 views

Expansion of an optional parameter for an environment

I want to define a custom environment, which takes an optional parameter, and I want be able to link to the environment using nameref. To this end, I tried something similar to the following MWE: \...
1
vote
1answer
41 views

Expanding a command when assigning values to an array

I'll explain what I mean with an example. \documentclass{article} \usepackage{arrayjobx} \newcounter{foo} \setcounter{foo}{0} \renewcommand{\bar}{\addtocounter{foo}{1}Some text} \newarray\baz % ------...
0
votes
3answers
51 views

Package soul underline problem with macro text

I have been slowly learning LaTeX over the past few years. I have been mostly successful in these efforts. Recently, I stumbled across a problem, I know is probably quite simple to fix, but it has me ...
2
votes
2answers
65 views

Definition-time expansiton of command line input

I'm trying to make the following code work correctly. I'm using command line call to python to check whether a number is in a list (no clue how to do this in pure LaTeX(?)). I then want to check ...
1
vote
1answer
119 views

How do you compact a code that expands \macro and store it in an expl3 sequence?

I'm trying to rewrite some of the codes I have by following the correct expl3 rules. With the following code I define the scontents environment that encapsulates the filecontentsdefmacro environment ...
64
votes
3answers
2k 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
2answers
72 views

Expand command in an argument before the main command

Related to my problem for xsim here. I want to use commands \ExOption and \ExPart to implement more easily my collection in xsim package. But i'm facing the problem that my commands do not expand in \...
10
votes
1answer
117 views

\ifnum expanding too much - what is happening?

Consider the following example: \documentclass{article} \makeatletter \newcommand\fail[1]{% \ifnum1=#1% <- here a space is missing \expandafter \@firstoftwo \else \...
5
votes
2answers
255 views

New primitives and grammar for replacing horrible \expandafter

Time and time when I am trying to read or write some macros, I'm always frustrated by lots of \expandafters inside them. Why don't we add some new primitives and grammar into TeX engines to make ...
11
votes
1answer
645 views

Forcing macro expansion

I have done my best to understand \expandafter, \edef and friends, but I can't find a way of using them to force expansion of the parameter passed in to the macro \FormatDate in the following example. ...
5
votes
3answers
118 views

Indirectly defined macros: Undefined macro with “@” does not trigger compile error

I defined two macros \newfoo{#1}{#2} and \foo{#1}. The first parameter is used as a key and must be a valid LaTeX macro name (without the backslash). The second parameter is a short piece of text. ...
2
votes
1answer
138 views

Capturing the definition of a LaTeX command in a Lua variable

I'd like to get the meaning of a LaTeX command in fully expanded form in a lua variable. What is the easiest way of getting there? In other words, what should I be replacing the function getmeaning ...
5
votes
1answer
115 views

\string-primitive works in unexpected ways in LuaTeX — Where can I find exact documentation of the \string-primitive in LuaTeX?

Where can I find exact documentation of the \string-primitive in LuaTeX? I ask this question because I encounter some unexpected (at least by me) behavior when compiling the example below with LuaTeX....
1
vote
1answer
35 views

Starred version of macro causes hyperref error if used in section command

In the following MWE \documentclass{article} \usepackage[T1]{fontenc} \usepackage{lmodern} \usepackage[utf8]{inputenc} \usepackage[pdftex,unicode,final]{hyperref} \input{glyphtounicode} \...
9
votes
2answers
533 views

Question about exercise 11.5 in TeXbook

In answer to exercise 11.5 there is this comment: \def\\{\if\space\next\ % assume that \next is unexpandable What does this comment mean? If \next may be expandable, must we use the following ...
4
votes
1answer
61 views

expl3 function for fixed number of expansion steps

In expl3, say we want to assign a value to a token list variable \l_foo_tl while expanding the value a certain number of times. For a single expansion the easiest way is \tl_set:No \l_foo_tl { ... } ...
1
vote
1answer
20 views

expanding \ref in \write with \classicthesis

The following code: \documentclass{scrbook} % \usepackage{classicthesis} \newwrite\myauxfile \immediate\openout\myauxfile=test.myaux \begin{document} \begin{figure} This is a figure \caption{...
3
votes
2answers
59 views

Expansion and formatting commands

I'm trying to accomplish something similar to autoref, but more customizable. In particular, I'm making a command which takes in a name for a label, and the text that should be output when that label ...
6
votes
5answers
161 views

Appending to a command while also expanding a counter

I want to append some text to a command but expand a counter while doing so. Here is an example of what the problem is: MWE: \documentclass{article} \newcommand{\topics}{} \newcounter{topic} \...
1
vote
0answers
31 views

How to check if attempts at totally expanding the tokens of an arbitrary sequence of tokens would yield an error?

How to check if attempts at totally expanding the tokens of an arbitrary sequence of tokens would yield an error? How to check if attempts at totally expanding the tokens of an arbitrary sequence of ...
4
votes
5answers
247 views

How to epxand macro with optional argument equal to (x,y) so that it becomes part of \path(x,y)--(a,b); inside another macro (expansion problem)?

When \myCoordinate accepts MANDATORY argument, following works: \documentclass{standalone} \usepackage{tikz} \newcommand\myCoordinate[1]{#1} \newcommand\myPath[1][(1,1)]{\path[draw=red]\myCoordinate{#...
5
votes
1answer
60 views

Expansion of \ifnum creates a weird \relax token

There was I, procrastinating over some TeX code while I should have been writing my dissertation. The code was working more or less fine (better than the writing, at least), until a mysterious \relax ...
4
votes
2answers
154 views

\TeX and \LaTeX differently expl3-x-written (exhaustive expansion) to an auxiliary file

As pointed out by the following MCE, \TeX and \LaTeX are expl3-written to an auxiliary file: the same way when no manipulation is involved (\iow_now:Nn) (but that is useless for my real use case): \...
5
votes
2answers
98 views

Test whether a string is in a list with variable

Based on this question, I'd like the following \newcommand{\word}{Paul} \newcommand{\butnot}{Joe} \IfStringInList{\word}{George,John,Paul,Ringo}{Beat it}{Roll it} \IfStringInList{\butnot}{George,John,...
1
vote
2answers
35 views

pgfkeys: expand inside a command containing style

I need to define a style contained in a macro without expanding this macro. The problem is that if the macro contains several keys like or sets a value to a key like here: \def\myconfiguration{text={...
27
votes
7answers
2k views

Are there purely expandable variants of \MakeUppercase?

\MakeUppercase and \uppercase use TeX's uccode, and they are not purely expandable. Say, \edef\temp{\MakeUppercase{abc}} will fail. Sometimes purely expandable macros are very useful. They are ...
7
votes
1answer
122 views

Does \expanded replace the \romannumeral trick for expansion?

TeXLive 2019 is here :D One of its awaited features is the new \expanded primitive now available in all of the main engines (only available in LuaTeX in previous years) thanks to Joseph Wright. What ...
4
votes
1answer
83 views

Seemingly unused \edef prior to an \ifx mysteriously affects the outcome of the \ifx. Why?

It is my understanding that in \ifx\x\y xx \else yy \fi, \ifx does NOT expand its arguments. If you want \ifx to compare the expanded values of \x and \y, then we need to do the expansion ourselves ...
3
votes
2answers
60 views

Expand macro inside lstlisting and apply syntax highlighting

I'm wondering if there's a way to expand a macro inside a lstlisting environment which automatically applies syntax highlighting to the expanded text. For example, the listing in \documentclass{...
10
votes
1answer
120 views

Using expanded macro as search pattern for \patchcmd

Is there any way to use the value of an expanded macro as the search pattern for etoolbox's \patchcmd (or xpatch's \xpatchcmd, etc), so that one can have some sort of a "dynamic" patch, by way of ...
9
votes
2answers
837 views

\ifcase and macro expansion

There are some code. I strip out unrelated parts and get test one: \documentclass[a4paper,11pt]{extarticle} \begin{document} \newcommand{\mystrA}{% a% \or b% \or c% \else d% } \newcommand{\...
5
votes
1answer
70 views

xkeyval — read keys from file

I want to read xkeyval options from an external file, like: \setkeys{my@keys}{\input{conf}} I tried several combinations of \edef and \expandafter, but to no avail. Any ideas? Best regards, ...
182
votes
5answers
44k views

When to use \edef, \noexpand, and \expandafter?

I'm quite happy hacking TeX macros and cobbling together bits and pieces from different style files to suit my own ends, but I have a suspicion that my resulting hacks are not quite as elegant as they ...