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

learn more… | top users | synonyms

16
votes
2answers
309 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
47 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
37 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 ...
1
vote
1answer
73 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
46 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
49 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
72 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 ...
3
votes
2answers
32 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
131 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
77 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
29 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
79 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
149 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 ...
3
votes
1answer
69 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
61 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
135 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
172 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
144 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
67 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
149 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
220 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
207 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
67 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
89 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
378 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
49 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 ...
3
votes
2answers
87 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
40 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
51 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
154 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
102 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
46 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
78 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
534 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
116 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
114 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
211 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
186 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
132 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
59 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
46 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
121 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
77 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
106 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
134 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
55 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
59 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
25 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
140 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 ...
13
votes
2answers
168 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 ...