Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [expansion]

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

2
votes
2answers
44 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
83 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
251 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
610 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
111 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
132 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
113 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
34 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
521 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 ...
3
votes
1answer
37 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{...
68
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{...
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
156 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
243 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{#...
4
votes
1answer
58 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
150 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
97 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
28 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 ...
6
votes
1answer
95 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
80 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
56 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
119 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
808 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
68 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, ...
181
votes
5answers
43k 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 ...
4
votes
2answers
103 views

Different macro behavior when used in another macro

Please consider the following MWE : \documentclass{article} \newcommand{\mymargin}{\hspace*{3em}} \newcommand{\innerbox}[1]{\mymargin\fbox{#1}\mymargin} \newcommand{\outerbox}[1]{\fbox{#1}} \begin{...
1
vote
1answer
46 views

Prevent macro expansion within setbox

Following code is the quintessence of a problem i'm facing: \documentclass{minimal} \newbox\boxa \newbox\boxb \newbox\boxc \parindent=0pt \begin{document} \setbox\boxc\hbox{Hello World!} \def\...
3
votes
2answers
45 views

how to pass xkeyval cmdkey to macro

I want to pass a cmdkey from the xkeyval package to a macro. I can print the value of the cmdkey to a message, but when used with \in@ it seems to be unexpanded. Example below. I expect to see the ...
1
vote
1answer
41 views

Problem with expand, all restatable theorems points to the same theorem

I'm trying to manually do a small script that let me put proofs at the end, restate theorem... But I'm having some troubles with the restate, because all the theorems have the same name, so when I ...
0
votes
1answer
161 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 ...
2
votes
1answer
27 views

`\unexpand\expandafter` add spaces : how to append a text at the end of a file

I'd like to append code to a file containing latex code... So I tried the solution proposed here, but unfortunately it fails when there are backslash in the file: How can I open a file in "append&...
1
vote
1answer
130 views

How to expand a \macro (or a copy) to save in a list at end of environment in xparse (expl3)?

I am trying to encapsulate a couple of environments to pass them to lists using xparse/expl3. I have defined a one command and two environments and I have had a problem with one of them. I use the ...
0
votes
1answer
67 views

practical use of `\noexpand` outside`\edef`(`\xdef`) and `\write`(`\messge`)?

After reading (and searching through) TeXbyTopic.pdf I have the impression that practical use of \noexpand falls into one of the following three cases, Inside \edef or \xdef, including the cases ...
5
votes
3answers
105 views

Macro expansion inside \href

I want to make a shortcut for \href{tel:0123456789}{01\,23\,45\,67\,89} I can use \StrSubstitute from the xstring package as \StrSubstitute{01 23 45 67 89}{ }{\,} inside the second argument to ...
1
vote
1answer
38 views

Definition before \multicolumn or the like?

Is it possible to have definitions take effect at the beginning of the first cell of a tabular row (using array.sty, if relevant), and still leave room for \multicolumn, \hline, etc.? The problem is, ...
3
votes
3answers
81 views

Check if a point is right or left of another one in TikZ

Trying to implement a handy way to check if a TikZ point is right or left of another one, I came up with the following MWE. \documentclass[border=1mm, tikz]{standalone} \makeatletter % prints 1 if #...
7
votes
1answer
59 views

Use of \noexpand in the implementation of \TextOrMath for eTeX

In latexrelease 2015/01/01, there are two implementations of \TextOrMath: one for regular TeX, the other one for eTeX-like engines (more precisely: those which support \protected). My question ...
6
votes
2answers
158 views

Create test of text direction (luatex)

With luatex there is \textdir to change text direction and tex.textdir which give string representing text direction. I have created this macro to test text direction which supposedly gives TLT ...
13
votes
3answers
527 views

How can I know the number of expandafters when appending to a csname macro?

I am looking for an informative answer here. If I want to append to a macro, I have a couple of options, each depending on whether I want the items fully expanded, partially expanded (a certain number ...
1
vote
0answers
28 views

Arguments stops being evaluated inside tikz node [closed]

In the following example, the code \textwidth-1mm is "evaluated" in the first page, but on the second page (where I add a node around it), the text is not evaluated anymore and I can see a bit -1mm in ...
2
votes
2answers
35 views

Using macros in \pgfkeys command

Is there a general way to pass a <key list> contained inside a macro to the \pgfkeys command, in order to process it in the usual way? In simple examples, \expandafter helps but I do not really ...
0
votes
1answer
47 views

Expansion of macro in environment argument

I'd like to generate an environment that changes a bit according to an argument given for it. The reason is having different locales in the document. I have defined a command, EmitLanguageStr that ...
3
votes
2answers
146 views

How to implement \expandbefore, similarly to \expandafter?

I am trying to define a new command, but specifying the new control string "on the fly" using csname and endcsname. (This is for the purpose of implementing a dependency injection pattern.) **...
0
votes
0answers
23 views

New command and catcode [duplicate]

I have a command that may contain the ampersand charater: &. Sometimes, when I use this command, I want that ampersand interpreted as a space. This is why I wanted to use the TeX command \catcode. ...
1
vote
0answers
105 views

Creating a custom node shape with a variable number of anchors

For the sake of training my self on PGF, I want to create such node shape having multiply ports with a selecting switch as shown below This is my attempt to create this node for a particular number ...
2
votes
1answer
51 views

Assigning a value from xstring

I'm trying to write some basic validation of user input to a command \noinsuit which takes two parameters, an integer in [0, 13] and a letter indicating the suit. So I expect \noinsuit{1}{C} to be ...
7
votes
2answers
124 views

Problem with my understanding of expandafter and newcommand with arguments and sout

I've tried for days to get my head around the expansion of code. Sadly, I don't get it. I try to pass a command with arguments as an argument to sout. \documentclass{article} \usepackage{ulem,lipsum}...