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

learn more… | top users | synonyms

2
votes
1answer
143 views

Use result from pgfmath with xifthen

I try to use the results of pgfmath calculations with cnttest from xifthen, but it fails: \documentclass{article} \usepackage{pgf,xifthen} \begin{document} \pgfmathparse{42+77}% ...
4
votes
1answer
83 views

Error with expansions

I am getting an error while trying to compile this minimal example: min.cls: \ProvidesClass{min} \LoadClass{minimal} \NeedsTeXFormat{LaTeX2e} \newenvironment{myenv}{}{ \def\aaa{test } ...
3
votes
2answers
400 views

How to expand an argument defined with \csname…\endcsname?

Similar to the situation described in Expand after all that stuff?, I have a macro looking like \somecommand{Some Argument}{\secondarg}. I also need to expand the argument \secondarg before using ...
8
votes
2answers
302 views

How to create an inline list via a macro

I want to create a macro that yields an inline lists. I can easily do this using enumerate* form the the enumitem package, but when I attempt to wrap this in a macro, I get: Extra }, or forgotten ...
0
votes
2answers
106 views

suppress expansion in macro call

What I would like is to suppress the expansion of the group as a parameter to a macro so that it can be expanded later. For example we want to pass the paramater unmodified as a string to lua or to a ...
13
votes
1answer
140 views

\( \) don't work with TOC?

If i write this line of code \subsection{Ranger \( n \) boules distinguables dans \( M \) boîtes} I obtain an error over the second \) (./Probabilité.toc ./Probabilité.toc:8: LaTeX Error: Bad ...
5
votes
2answers
357 views

Expand command and put result into a macro: Use of \value doesn't match its definition

I still struggle with the expansion of Latex. I try to calculate the a real number from a date format and put this into a macro \value. I need to expand the command with \edef because I plan to use ...
5
votes
1answer
252 views

Use macro to draw inside pgfplot/axis

I would like to implement a gantt chart function inside pgfplots. To draw the tasks, I have a macro that calculates the start and finish time of a task. However, when I use multiple tasks, the values ...
4
votes
1answer
108 views

Expanding command in \addchaptertocentry

I'm using a counter to increment months in a journal and the datetime package to turn the counter into months. The months then become chapter titles in the document, so I have something like this: ...
7
votes
1answer
115 views

Package providing fully expandable conditionals

Is there a package providing a collection of fully expandable conditionals like this one: \newcommand\myif@num[1] {\ifnum#1\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi} Background: ...
3
votes
2answers
228 views

Providing data series for sparkline environment

I would like to have the data series for a sparkline defined in terms of a macro -- or some alternative -- as opposed to have it set explicitly in the sparkline environment itself. My attempts so far ...
4
votes
2answers
87 views

expl3: \cs_generate_variant broke with the last update: undefined control sequence \::T [closed]

The last expl3 update broke my "continue" detection for the index. Here is a MWE: (EDIT: I realized it is possible to reduce it even further) \documentclass{minimal} \usepackage{expl3,xparse} ...
6
votes
2answers
498 views

Nesting of test commands (IfStrEq, IfSubStr etc.) of xstring

The following code does not work: \documentclass{article} \usepackage{xstring} \newcommand\checkempty[1]{ \IfStrEq{#1}{}{% Empty }{% NonEmpty } } \begin{document} ...
4
votes
2answers
49 views

How to write \StrGobbleLeft output to an external file?

I have not learnt how the TeX expansion works behind the scene. Shortly speaking, how to write \StrGobbleLeft output to an external file? \documentclass{article} \usepackage{filecontents} ...
2
votes
1answer
192 views

expandable optional parameter to enumerate environment

The MWE below, by using paralist package, is supposed to allow \begin{enumerate}[...] where ... is flexible in "some way" (inherits from enumerates above). \documentclass[a4paper,10pt]{report} ...
8
votes
1answer
118 views

'Fake' variants in expl3

Suppose you have a function that operates on three tokens, \cs_new:Nn \@@_on_three:NNN { #1, #2, #3 } And you have a variable whose value is the three tokens: \tl_set:Nn \l@@_three_tl { foo } ...
5
votes
3answers
253 views

Expanding an argument of code added by \g@addto@macro

I would like to have the following (it's a part of a large code block): \def\C{foobar} \def\A{} \g@addto@macro\A{\B{\C}} Now \show\A outputs \B{\C} I would like to modify the 3rd line so that ...
12
votes
1answer
343 views

How to expand a macro used in the range of a foreach loop?

Motivating Example: Suppose that I want to draw the following tree: root / \ / \ / \ A B C D This is easy enough to do by explicitly drawing the two subtrees as children of ...
49
votes
3answers
1k 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 ...
5
votes
2answers
272 views

\@startsection, hyperref and newunicodechar; protection needed?

When working with custom defined environments using \@startsection I found, after switching to newunicodechar for defining my unicode characters, that the sectioning headings give this peculiar ...
9
votes
3answers
358 views

Implementing car and cdr in TeX

I've been trying to implement a macro that reads and transforms its argument into a different form...but I'm having quite a bit of trouble finding or creating even the most basic parsing tools. Case ...
6
votes
3answers
440 views

Expandable string substitution

I am trying to define a macro \formatstr{\mystring}{(string empty)}{the string is: #1} which expands to (string empty) when \mystring is empty (as judged, e.g. by etoolbox's \csdefempty) and ...
5
votes
2answers
300 views

Define command either with or without \csname

I'm trying to do the same as this one, but with \def, \gdef or \xdef instead. Very quick summary of the other question: I wanted to print the command (not the contents of the command) regardless of ...
8
votes
1answer
356 views

Print name of command, defined by \csname

First off: I do not understand \expandafter and \noexpand completely which is probably the main problem. I have found a question that explains what it does, but still I cannot seem to make it work. I ...
24
votes
3answers
1k views

How to know whether or not we need \expandafter?

The following is quoted from Peter Grill's answer on question LaTeX dynamic macro definition. The \expandafter is requried as the \newcommand needs to be dealt with after the \csname. As a ...
27
votes
1answer
413 views

Why six \noexpand in a row?

Trying to understand TeX's rules for parsing dimensions, I came up with the following weird behaviour: \dimen0=1\noexpand\noexpand\noexpand\noexpand\noexpand\empty pt is valid, but ...
11
votes
3answers
278 views

Expandable 'character scanning' command that preserves spaces

David Carlisle recently offered a clean and rather elegant TeX solution to a question about expandable 'character scanning' commands. Unfortunately, David's solution does not preserve spaces in the ...
10
votes
2answers
616 views

How to use \noexpand in an \edef?

Continuing with my struggle to deal with expansion issues, I am stuck on how to use an \edef properly. The code below with the switches set as: %\def\ApplyColorToTitle{} %\def\UseMathrmInTitle{} ...
10
votes
1answer
439 views

Extract the logically first slide in a Beamer overlay specification?

When writing Beamer slides for a talk, I find that I often want to have some text (usually math) visible on a group of slides and be alerted on only the first slide in the group. For example, I can ...
8
votes
1answer
155 views

On pitfalls of robust commands

These days, I’m more and more defining robust commands, e.g., using \newrobustcmd (etoolbox package) or \NewDocumentCommand (xparse package). Robust commands seem advantageous to me in many respects ...
6
votes
3answers
190 views

How to “demux” several aspects from a `\foreach` variable with `\ifstrequal`?

How can I "demux" several features from a mode specification given in a \foreach? I would like to use a \foreach to draw several nodes in a TikZ picture. The loop will specify a mode for each ...
6
votes
1answer
156 views

How can I inhibit expansion through several layers of \edef?

I'm using a macro I've defined based on some suggestions here to automate the creation of tables. For example something like \newcommand{\clearrows}{\let\matrixcontent\empty} ...
60
votes
1answer
2k views

A LaTeX log analyzer application (visualizing TeX expansion)

Consider the following MWE, test.tex: \documentclass[12pt]{article} \begin{document} \tracingassigns=1 \tracingmacros=1 \def\aaa{something} \def\bbb{else \aaa, else} \edef\ccc{third \bbb, level} ...
7
votes
1answer
948 views

A \typeout (or expandable command) that can expand once - or with variable levels of expansion?

Consider the following MWE: \documentclass[12pt]{article} \begin{document} \def\aaa{something} \typeout{=1==\aaa==} \typeout{=1==\meaning\aaa==} \typeout{} \def\bbb{else \aaa, else} ...
6
votes
2answers
251 views

How to redefine commands and environments, and make them acceptable for `\write`

My general problem is the following. I want to "convert" many .tex files into some other format (xml-like). I don't want to modify the tex files, I can only build a documentclass. The texfiles are ...
1
vote
0answers
175 views

how to create a fully-expandable environment [closed]

I know DeclareDocumentCommand from the package xparse. I am wondering if there is a version for environment ? I could also imagine a trick based on : declare the environment with ...
9
votes
2answers
415 views

Expandable author names from biblatex?

Knowing that \printnames command in biblatex is not expandable as it is protected, and I cannot otherwise do much about it; I thought about going through biblatex.sty and reconstructing \printnames ...
7
votes
1answer
290 views

Defining inside an \edef

The following throws an "Undefined control sequence" error: \edef\testa{\edef\testb{foobar}\testb} when it gets to expanding \testb. This problem is also mentioned in "TEX by Topic" 12.6.2. But no ...
24
votes
4answers
2k views

On testing two fully expanded character strings for equality

I know three macros that test two fully expanded character strings for equality: \ifthenelse{\equal{<op1>}{<op2>}}{<true>}{<false>} (ifthen package) ...
12
votes
1answer
307 views

Why does \expandafter not expand the full { } group?

I thought I had understood the principle of expansion ... but apparently not! \def\a{AAA} \def\b{BBB} \expandafter\detokenize\expandafter{\a\b} I thought that the 2 \expandafter would store ...
2
votes
2answers
316 views

An expandable 'character scanning' command?

Please consider the following MWE, for a "character scanning" command "\looper" which utilizes \@tfor: \documentclass{minimal} \usepackage{trace} \makeatletter \newcommand\looper[1]{% % ...
4
votes
1answer
247 views

Showing expanded `\let` command with `\typeout`

I have already seen the related page macros - What is the difference between \let and \edef?, but I'm afraid it still doesn't expain to me the following MWE: \documentclass{minimal} ...
12
votes
4answers
393 views

Create a capitalized macro token using \csname

Two things I understand and one thing I don't: I often use \csname to create user-defined tokens. For instance, the following code uses \expandafter to expand everything between \csname and ...
6
votes
2answers
474 views

On unprotecting (expanding) \protected macros (or, “the space after command name”)

I quite often come into a situation, where I need to obtain some text produced by a package macro as a string, like in say: Expanding (edef) a lipsum command? How do I "unprotect" an ...
9
votes
6answers
837 views

Defining new commands inside a for loop

I would like to define a number of related commands by using the counter in a for-loop. For example, I want to define 26 commands like this: \newcommand{\calA}{{\cal A}} \newcommand{\calB}{{\cal B}} ...
6
votes
3answers
131 views

Expansion issue: How Check if options passed to an environment were used

I have an environment with portions of the content that being conditionally typeset based on options passed to the environment. The content of this environment is predefined elsewhere so depending on ...
7
votes
3answers
473 views

\expandafter parameters that are not commands

I'm using a custom command to format all tables in a document. Some tables share properties other than style, such as column definitions and headers, which is why this answer inspired me to even more ...
4
votes
2answers
361 views

expand macro in single byte encoded code

In this minimal (not) working example, I try to use single-byte latin10-encoded source file, and expand a command-macro containing a character with \catcode254: % -*- mode: latex; unibyte: t; ...
5
votes
2answers
174 views

Latex3 input/output and expansion of macros

I have a package that formats a course outline and have a macro that reads a formatted user file and turns it into a section. \documentclass{article} \usepackage{xparse} \ExplSyntaxOn \tl_new:N ...
4
votes
3answers
202 views

Using a macro evaluating to a set of xkeyval arguments as argument to another command

I am trying to code a macro that adds xkeyval arguments contained in a macro to a list of default xkeyval arguments. The following minimal example explains better what I want to do. ...