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

learn more… | top users | synonyms

5
votes
2answers
77 views

Use \foreach loop to execute macro with parameters of macro provided in a list

I have to execute a macro a number of times, and would like to provide a list of the parameters to be executed. So, instead of \FormatLinks*[Main Search Site]{Google}{http://www.google.com} ...
4
votes
1answer
21 views

How can I set a style in `\forestset` which requires delayed calculations with the results of node walks?

What is the correct way to wrap the specification for the tree below into the my binomial style defined in \forestset and why? The following code works fine: ...
2
votes
1answer
39 views

newcommand that does not expand at all

How do I define a command that exactly inserts its contents back into the source file without any reinterpretation, expansion, etcetera? In other words, I want there never to be a difference ...
2
votes
1answer
28 views

How can I use a variable from xstring with the text along path decoration from tikz?

Issue How can I get proper text expansion for text=\somevariable in a tikz text decoration. I think I have an expansion problem here. Set \releasedate Extract year from \releasedate in ...
4
votes
2answers
100 views

How to get LaTeX to expand at the correct position?

I have a latex document which in the main part lists a number of "tasks" (for students to solve); to each task belongs a "script", however, all scripts are supposed to be printed in an appendix at the ...
11
votes
5answers
459 views

Basics of scanning

I'm trying to master the art of scanning text one character at a time. The following is what I've discovered so far. Is this as good as it gets? I would really prefer not to do all those \edefs as ...
19
votes
2answers
400 views

\expandafter and \aftergroup: where do the 2n+1 and n^2-1 rules come from?

Both TeX primitives \expandafter and \aftergroup have "rules of thumb" stating that \expandafter should be used 2n+1 times to look n tokens ahead (is this correct?). A similar "rule of thumb" holds ...
3
votes
1answer
31 views

Problem with expansion of \@ifnextchar inside tabular environment

I'd like to define a macro that expands to \hline and \cline inside the tabular environment depending on the next character: \documentclass{standalone} \makeatletter ...
11
votes
1answer
139 views

Why this output using \string on the empty csname

How does this exactly work? \expandafter\string\csname\endcsname I don't know what I would expect to come from there, but definitely not \csname\endcsname_ where _ is a space. I thought ...
2
votes
1answer
67 views

Define an expandable function for comparing a token list to a string in LaTeX3

In LaTeX3, I could define a function for comparing a token list to a string \cs_generate_variant:Nn \tl_if_eq:nnTF { V } \cs_new_nopar:Npn \module_compare:n #1 { \tl_if_eq:VnTF \g_some_tl { #1 ...
8
votes
3answers
108 views

Appending active and expansion sensitive characters to a macro

This question comes up pretty often when people want to build tables with empty columns or similarly building up some active characters inside a macro hoping to expand them at the right time right ...
1
vote
1answer
39 views

Command containing babel shorthand not expanding [duplicate]

Greetings to the distinguished gathering of TeXperts! My problem is: if a macro is defined with a babel shorthand containing the quote mark (") as an active character, it does not expand when ...
6
votes
1answer
62 views

Delimited \def's and expansion

I try to understand how work the macro named \separator in MWE . \documentclass[]{article} \def\separator#1\separator#2{% \unexpanded{#1}% \ifx*#2% \else , \expandafter\separator\expandafter#2% \fi ...
8
votes
2answers
243 views

Could someone explain the tokenization process that's leading the whitespace creeping in here?

Here's a MWE that creates spurious whitespace: \documentclass{article} \usepackage[T1]{fontenc} \usepackage{lmodern} \newcommand\aetest[2][\relax]{%% \def\aejunk{<#2>}%% \ifx\relax#1 ...
4
votes
2answers
85 views

loop in tabular that uses \the\count to access current line number

I would like to generate an autmatic table using loop. As suggested here before, it is best to first generate the lines in a toks and then pass them to tabular. However, I have problems with accessing ...
3
votes
2answers
58 views

Expand \def value from optional default argument? - Bug in \oldacronym (glossaries v4.02) - first use not respected and funny effects?

Edit: Bug only in glossaries v4.02. -> Update! \edef\args{[#4]{#1}{#2}{#3}}% \expandafter\newacronym\args% may be a way to expand unexpaned args. Is there a bug in the glossaries ...
6
votes
2answers
148 views

TeX/LaTeX: Macro for getting a length as number

I would like to write a macro getlengthin to get a length or dimen as floating point number in a specified unit. Here is what I have created so far: \documentclass{article} ...
6
votes
4answers
83 views

How to expand a macro into viewport= arguments(includegraphics)

How do I properly expand a macro \myviewport so that it is parsed as the viewport=0pt 10pt 100pt 200pt argument of \includegraphics[clip, \myviewport]{somepdf.pdf}? \documentclass{article} ...
5
votes
2answers
95 views

Inserting Macros in argument of \sindex[]{} aren't expanded

I've to build an individual register with \sindex[]{} from the splitxdx package from an outside generated TeX code. The call name of people with two firstnames is sometimes put in braces, sometimes ...
4
votes
1answer
45 views

Macro expansion and href with hyperlink

I have very simple question I hope! I am writing a book on MPASM (PIC) assembler and there will be very many similar links to programs, hex files, videos etc. These will be enclosed in a standard ...
1
vote
1answer
94 views

Refers to a node on a chemfig inside a node in a tikzpicture. Macro definitions

Consider the minimal example: \documentclass[12pt]{article} \usepackage{tikz} ...
2
votes
1answer
53 views

In expl3, how do I smuggle in a three arguments when threading sequences?

I've got some code which essentially works as in this MWE: \documentclass{article} \usepackage{xparse} \ExplSyntaxOn \tl_new:N \l_aellett_current_choice_tl \tl_new:N ...
5
votes
2answers
63 views

LaTeX3 Expansion without \exp_after:wN

LaTeX3 reduces the need to use \expandafter/\exp_after:wN tremendously. But what is the LaTeX3 way for this problem? \documentclass{article} \usepackage{expl3} \begin{document} \ExplSyntaxOn ...
11
votes
1answer
135 views

Expansion of verbatim material

I am passing a file name in the command line which contains underscores and would like to print the name of the file in the resulting PDF. So, need some expansion magic so that the output is: The ...
18
votes
2answers
436 views

Could someone further elucidate expansion, catcodes, and scantokens…?

In response to my question "With TikZ is it possible to pass the node content through a preprocessor?", @MarkWibrow suggested a solution using \scantokens. {\catcode`\_=13 ...
1
vote
1answer
66 views

How to parse a macro that contains a \let?

My situation is similar to, but hopefully different from How do I ‘expand’ a control sequence \let to a character?, as that question does not admit a positive answer. I want to parse, not expand, but ...
3
votes
1answer
71 views

Expand arguments in string substitution macro

Rewritten as minimum non-working example: \documentclass{article} \makeatletter \usepackage{xstring} \usepackage{xparse} \newcommand\textfromcase[1]{% \IfEqCase{#1}{% for the purposes of this ...
4
votes
2answers
155 views

How to pass parameters to Sage from Sagetex?

I haven't found a way to pass parameters to a sagesilent environment, so I wonder if it's possible. My final purpose is to combine sagetex with probsoln. The package probsoln lets you manage a problem ...
3
votes
1answer
55 views

Expansion for Macro to pass to scaleBox

I am trying to calculate some width in a macro and use the macro for scalebox. However I get a flood of errors when I try to pass the macro to scalebox. MinimalExample: \documentclass{article} ...
0
votes
0answers
62 views

Ignoring parts of text inside macro

Consider the following code: \documentclass{book} \usepackage{pgffor} \begin{document} \newcommand\containers{ \cont{aaa{\bf don't xstring me}aaa} \cont{bbb\large bbb} ...
4
votes
2answers
152 views

Conditional horizontal lines in tables

I am trying to typeset data that is read from CSV files using the csvsimple package. In the input data, there is a column that will tell me where to place a horizontal line between the rows. (In the ...
4
votes
2answers
52 views

Appending a command with evaluated parameters to a macro

I'm trying to have a command \appendtocmd that does that: \def\contents{Files:} \def\value{yo man} \appendcmdto{contents}{section}{\value} contents contains now "Files: \section{yo man}" so when I ...
4
votes
3answers
166 views

Expansion Issues When Passing TikZ Styles to Macro Created by Macro

I'm struggling (again) with expansions. This time I have a generic function \misdirection that creates a TikZ environment subject to a few options. Then, I create a macro \freezeStyle that creates a ...
4
votes
2answers
106 views

Passing the string value of a variable

The MWE bellow uses exsheets package to print the solutions to questions at the end of a book. The code doesn't work as it should as it seems to be an expansion issue. When, instead of ...
4
votes
1answer
54 views

Defining xkeyval keys within a loop

I have a project for which I make extensive use of the great xkeyval package. However, I'm still struggling with some more extravagant things. For example, I want to use enumerated keys (key1 to keyN, ...
3
votes
3answers
92 views

\input{} as argument for \inputgraphic{}

I got a question very similar to this post (\includegraphics{\input{|shell command}}) which unfortunately hasn't been really answered. The aim is to make a command that invokes a python script to ...
7
votes
2answers
171 views

How to use the total page count in a conditional expression?

I would like to have different footer or page style depending on whether the document has one or more pages. I am not very experienced with TeX programming, so the answers about "Comparing an argument ...
4
votes
1answer
76 views

ConTeXt: Macro within macro for URLs

Background Would like to define a base URL that can be reused by other macros. Problem Using the \goto macro requires a fully expanded URL. Minimum Working Example Here's code that illustrates ...
4
votes
1answer
82 views

Expanding arguments to pgf/tikz styles

In an answer on this site is proposed a method to draw arrows on paths. For example, using the style [arrow inside={pos=0.2}] will put an arrow at position 0.2 on the path : \begin{tikzpicture} ...
10
votes
1answer
206 views

Macro parameter delimited by more than one delimiter

TeX user can simply create the macro with a parameter delimited by an arbitrary sequence of tokens. For example \def\macro #1delimiter{...#1...} Is it possible to create a macro with a parameter ...
15
votes
2answers
191 views

\expandafter with \uppercase ordering

As I understand it, the behavior of \expandafter is such that if \a and \b are macros, then \expandafter\a\b will first expand \b then \a. But my understanding must be wrong, because I don't ...
4
votes
4answers
198 views

Expand a macro with parameters in tabular head

My eventual goal is to create my own tabular-like environment in which all entries are in math-mode by default, let's call it fancytable. (One requirement is that the first column be separated from ...
3
votes
1answer
81 views

Dump command as readable text?

Is it possible to dump the expanded form of a command as text? E.g. when I write a macro \newcommand{\mytest}[1]{\texttt{#1}} I would want to define a macro \mydump such that ...
14
votes
1answer
168 views

Workaround for open lualatex bug in \scantokens?

As package author I am in need of writing a manual with lots of examples. Now I started to make heavy use of lualatex in order to speed up operations which take a long time in TeX (of my package, not ...
9
votes
3answers
286 views

Completely expandable loop macro that also works in tabular

Since I normally use tikz in my documents, I mostly use the \foreach \x in \list loop to repeat things. However, this famously fails in tabular environments and also everywhere where things must be ...
8
votes
3answers
249 views

Arguments possibly delimited by \bgroup and \egroup

I still don't see (and haven't thought about) pros and cons of making available the arguments as \foo{…} or \foo\bgroup …\egroup (or even unbalanced, \bgroup …} and {…\egroup). But I'm curious about ...
3
votes
2answers
98 views

How to expand a macro to use it inside a question in AMC?

Context I'm trying to use AMC to produce an exam with code in it. However, the use of verbatim code inside the questions is beyond the scope of the package. They suggest to declare boxes and used ...
3
votes
0answers
101 views

\if and \fi inside different \def macros

Recently I failed to solve specific task in LaTeX. I wanted to make document with several sections, each divided on several subsections. Each section I had placed to separate files, and used \input ...
10
votes
4answers
394 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
56 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 ...