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

learn more… | top users | synonyms

3
votes
1answer
20 views

datetime2's \DTMsavetimestamp can't read from macro - expansion or catcode issue?

What already works I am using \immediate\write18 to let the GNU date command do some date/time arithmetic. The resulting timestamp in ISO format (e.g., 2011-09-09T09:59:59Z) is written to a temporary ...
2
votes
1answer
58 views

Using an undefined token as argument

I have a (probably) quite uncommon problem. Pseudocode: \def\head{\titel } % \titel = undefined \func{\head} % func is defined and handles \titel without any issues \func{\titel} % throws an ...
4
votes
3answers
86 views

How can I write <section counter value>:<section title>:<page>:<file>:<line> to the log whenever (and whereever) a macro is called?

I am working on context-based log entries. Each time a selected (patched) macro is called, it should provide its contents along with a meaningful log entry. "Meaningful" log entry defined: The ...
5
votes
2answers
61 views

How do I perform an expandable string comparison?

I need to perform a string comparison (string equality). If the macro is non-expandable (e.g. contains \def or \let), it causes problems in the place where it is used. I tried using \ifthenelse from ...
2
votes
1answer
33 views

In expl3, how to use normal spaces instead of ~ in a portion of text?

In a previous question, I learned that \ExplSyntaxOn and \ExplSyntaxOff should be put around a command because of the order in which expansion works in TeX. Suppose now that I want to put things at ...
1
vote
0answers
26 views

.tex file with catchfilebetweentags macros expanded

I have a .tex file, say original.tex, where I have imported snippets from several other files using the \catchfilebetweentags command. For archiving, I wish to produce a version of original.tex that ...
1
vote
2answers
63 views

How can I pass expanded material to a macro at definition time (context-specific macro tracker)?

Expansion gives me headaches. I could use some help. The problem is identified under the heading: Log Output Snippet AtEndAfterFileList. This is an extension of my context-based log entry question: ...
5
votes
2answers
74 views

Necessity of braces when creating newcommand using csname

Why does \expandafter\newcommand\csname hello\endcsname{Hello world} create a new macro while \expandafter\newcommand{\csname hello\endcsname}{Hello world} creates garbage? Form what I understand, \...
7
votes
2answers
266 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 ...
1
vote
0answers
26 views

Expand variable in pgfplots key

In the example below I am trying to set explicitly some numbered styles and then loop through those styles in a plot. However the variable \i doesn't seem to expand correctly in mystyle\i (however it ...
9
votes
1answer
239 views

Using {\AA} when \r is redefined

I'd like to use {\AA} to input a capital A with a ring above. However, the document I am writing has to import some definitions which I have no control over. One of the definitions changes \r: \...
1
vote
1answer
29 views

Why does embedded \g@addto@macro sometimes fail?

I decided to test my understanding of expansion and embed \g@addto@macro within another three macros. \g@addto@macro \appendmacro \layertwo \activatelayerone From my understanding, the ...
5
votes
4answers
196 views

Macros that define other macros, which also define other macros

I would like to define a TeX 'macro-building' command (let us call it \buildmacro) that takes as argument a string of 'normal' characters (e.g., Title) and which satisfies the followings: the ...
3
votes
1answer
45 views

How to make \tl_upper_case:n in section's argument bookmark compliant?

Thanks to recent revision of the coverage of UTF-8 input for pdfTeX and accents with the expl3 (see updated answer of http://tex.stackexchange.com/a/286703/18401), the following code works nicely: \...
3
votes
1answer
53 views

“Something's wrong--perhaps a missing \item” error in \newenvironment using a \vtop box

In attempting an answer to "How to label a list / make a line before list stick with the list?" I answered using a \vtop box to contain the entire list including the label. I then, trying to improve ...
4
votes
2answers
40 views

Detect first character in list with macros

I have a comma separated list that I process with \foreach. This has been working for quite some time. Decided to make a minor tweak and that is to allow for an optional leading * in which case I want ...
3
votes
1answer
39 views

\expandafter to expand macro before macro call

I am trying to include an image: \documentclass{article} \usepackage{graphicx} \begin{document} \newcommand{\ext}{.pdf} \def\incPIC#1{ \expandafter\includegraphics{#1}} { \tracingmacros=1 \...
3
votes
1answer
75 views

Defining and expanding macros In loops

I want to define and expand macros in a \foreach loop. The names of the macros depend on the iteration step. The macros I define are interpreted as strings rather than sets of numbers that I actually ...
2
votes
0answers
87 views

How to force edef to execute def [closed]

Since I haven't given up on my problem from yesterday, I've been messing around with \edef, \def, \unexpanded, \expandafter and some other stuff. I also read about fragile commands and robust commands....
3
votes
2answers
42 views

PDF plain text for a macro with a starred version

I'm typesetting a document with PDFLaTeX. In some section titles, I use a macro which has a starred version. In the PDF index (the table of contents that PDF viewers typically show in a side pane), I ...
3
votes
1answer
108 views

Robust handler of arguments with conditionals and complex elements

Context This question is a follow up of the answer of this question Spurious space on moderncv \cventry using \if Problem The problem is that complex content (for example, itemize on the content of ...
9
votes
2answers
174 views

How to save and restore the nodes between tikzpictures?

My English is not good enough so I beg you to excuse me if the question is long The next code is not very interesting but it may illustrate correctly my problem. I have a lot of macros and I need ...
5
votes
4answers
176 views

Tricky macro expansion and list

I posted these two question Tricky macro expansion Tricky list Now I would like to merge the two issues: \documentclass{article} \makeatletter \newcounter{a@c} \newcounter{b@c} \newcounter{c@c}...
2
votes
1answer
60 views

Alternative to `foreach` loop to use an `edef`

I need to create some dynamic name macro and I want to create them from a coma separated list of parameter in #1 in one loop. foreach is not the solution because it forces the use of gdef and I want ...
0
votes
2answers
31 views

How to span or expand a a table

How can I expand a table like the one in the picture? I tried the following code: \begin{tabularx}{\textwidth}{x x} \hline \textsf{Australia} & \textsf{OECD} \\ \hline \rowcolor{gray!40} \...
2
votes
1answer
57 views

Expansion problem

In this example, I want to create nodes generically named (for the user) \N{a}, \N{b} ... in each macro but named differently (for tikz) to avoid confusion and overwriting when calling macro ...
4
votes
2answers
250 views

Tricky expansion in macro

I wrote the following code \documentclass{article} \makeatletter \newtoks\a@toks \newtoks\b@toks \newcounter{a@counter}% \newcounter{b@counter}% \setcounter{a@counter}{0}% \setcounter{b@counter}...
5
votes
2answers
39 views

How can I use \apptocmd within a macro, passing the appended's macro's parameter back to itself?

Let's say I have the following \newcommand\app[1]{\textbf{#1}} % <- #1 is appended's macro's parameter \apptocmd{\app}{#1}{}{} % <- passing appended macro's parameter to appended macro again \...
6
votes
2answers
76 views

counter in TOC fails when using xparse command instead of LaTeX2e command

Here I define a custom sectioning command, \Unit, which prints a numbered subject heading and adds it to the table of contents. If I use \newcommand for the command that creates the numbered label, ...
1
vote
0answers
24 views

Need help with grouping and expansion control

I am trying to define macros, which take a delimited list and pass each element to a macro (that takes one argument). I have fully working versions of them that iterate over 1) all elements in a list, ...
4
votes
3answers
68 views

Inserting hyphenation file into \babelhyphenation

\documentclass{article} \usepackage[british]{babel} \usepackage{filecontents} \begin{filecontents*}{english.yp} hom-ony-mous gene-ral-ly \end{filecontents*} \makeatletter \babelhyphenation[...
1
vote
1answer
21 views

Inputting a separate hyphenation file

\documentclass{article} \usepackage[english]{babel} \usepackage{filecontents} \begin{filecontents*}{english.yp} hom-ony-mous gene-ral-ly \end{filecontents*}{english.yp} \hyphenation{ \...
2
votes
1answer
38 views

Getting user defined constants into the preamble

I think this is a problem of expandable content, a concept I haven't quite got the hang of yet... Lets say I have a preamble or cls file that is trying to configure hyperref. If I have manually setup ...
0
votes
1answer
24 views

\expandafter \the\everypar - undefined control sequence

From here, I got this snippet: \everypar=\expandafter{\the\everypar\loosness=-1 } However, this produces this error: ! Undefined control sequence. <everypar> ...ubpenalty \everypar {}\fi \...
4
votes
4answers
105 views

Generating a table from key-value pairs

I want to automatically generate a table from a comma separated list of key-value pairs such as {{x=1,y=2},{x=3,y=1},{x=2,y=3}}. In each "row" the "keys" are always the same (they become the column ...
1
vote
1answer
59 views

Convert text from mixed case to start case

I'd like to change the capitalization of a macro from mixed case to start case. Let's say the following macro is already defined: \newcommand{\tostring}{toString} I can change the first letter to ...
190
votes
3answers
14k views

What is the difference between Fragile and Robust commands?

So I've read a few times about this, the “moving arguments” and all that. But what does it really mean? Could someone explain in a few words what is going on at the TeX level, what is the difference ...
4
votes
1answer
54 views

How do I expandably extract the length of a box

I thought that the construction \wd\bopxcontrolsequence was expandable. But in mucking around in things, it seems not to be. At least in the following, the code demonstrates that \wd\aetmpbox never ...
0
votes
2answers
61 views

reverse expansion order with optional parameters

Trying to implement a command with more than nine parameters (that also reverses things about) when there are, e.g., 8 of them, the first invocation is temporarily saved with \def\mytemp{\mycommandtwo{...
3
votes
1answer
58 views

How can I set the PDF TrimBox dynamically (with a macro) and compiler independent?

Introduction At the moment I’m preparing a custom class which is likely to be compiled with XeTeX or LuaTeX. It is for a book layout that should be professionally printed and therefor I want to set ...
17
votes
5answers
689 views

Basics of parsing

I'm trying to master the art of parsing 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 ...
4
votes
2answers
57 views

How to use \nameref with xstring package to check string length

I need to measure a number of characters in string, that I returned from label through \nameref command. Here is my MWE: \documentclass{article} \usepackage{hyperref} \usepackage{xstring} \begin{...
3
votes
1answer
65 views

xdef and cedille

I need to xdef some data. In rare cases it'll contain cedilles like: \xdef\xxx{spam\c{e}eggs} \bye Unfortunately this failes. Is there a chance to get this working? (I'm on LaTeX in my code, using ...
7
votes
2answers
132 views

Expansion of \char in \def

In answering another question, I ran into some issues trying to use a combination of \def and \char. Consider the following example: \documentclass{minimal} \usepackage{etoolbox} \usepackage{xstring}...
1
vote
1answer
133 views

Expandability: LaTeX3 VS LaTeX

The expandability is the heart of macros/functions. I wonder to know: If a better understanding of expandability in LaTeX3 can only be through a good background of expandability in LaTeX. How far ...
4
votes
1answer
43 views

\ThisStyle \SavedStyle painfully slow … alternatives?

While working with customised hat glyphs using the first version of this solution, pdflatex started taking a long time compiling a document. That linked answer notes that it's a slower solution, but ...
3
votes
2answers
187 views

Drawbacks of csname method to avoid spaces after command

I had a similar problem as this one: Space after LaTeX commands My first attempt was something like this: \newcommand{\satip}{SAT\textgreater IP} This leads to the known Problem, that spaces after ...
2
votes
0answers
48 views

Macro with \afterassignment syntax?

Say for some reason I want to make a macro with input stream behaviour mimicking that of \afterassignment and \aftergroup. Namely, I want to absorb exactly one token from the input stream following ...
3
votes
3answers
45 views

Macro expansion and biocon package

I'm using the biocon package to organize plants in an academic work. I created new taxons as needed in the text, for instance, the family. In the final chapter of the work, I have a large table (about ...
56
votes
4answers
3k 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 "...