Tagged Questions

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

learn more… | top users | synonyms

6
votes
3answers
138 views

reproduce section at different position

I would like to reproduce a \section at a later position, with the same number as at the original position. I tried \newsavebox{\meinebox} \savebox{\meinebox}[80mm][l]{\section{Hier}} ...
7
votes
1answer
215 views

\ifmmode self-contradictory in amsmath (OK in just LaTeX)

File: \documentclass[11pt]{article} \usepackage{amsmath} \newcommand{\argghhh}{\relax\ifmmode\bar\else\expandafter\=\fi} \begin{document} $ \argghhh a $ \end{document} produces error (but ...
3
votes
1answer
106 views

using \ForEach to input chapters in a document

I have several chapters in the folder /Chapters and I have the following LaTeX code: \newcommand\chapnames{Chap1, Chap2, Chap3, Chap4, Chap5, Chap6} \ForEach {,} {\input{./Chapters/\thislevelitem}} ...
18
votes
1answer
350 views

Unusual numbering: combine alph, Alph, arabic

I would like to have an unusual numbering aAa going as follows: 0 -> * ------------------------- 1 -> a 2 -> b ... 25 -> y 26 -> z ------------------------- 27 -> A 28 -> B ...
2
votes
1answer
74 views

Pass the contents of an \input command to a macro

I am having some difficulty with the expansion of LaTeX. I would like to expand the contents of an \input command before passing them to macro, in a pattern similar to the following: \outer{\inner} ...
8
votes
1answer
103 views

Omitting arguments in macro expansion

Changing a simple TeX macro like \def\macro#1 #2{#1 #2} into \def\macro#1 #2{#1} alters the output of \macro Hello world surprisingly for me to Helloorld My expectation would have been to ...
4
votes
1answer
143 views

Expansion Issue with omit list provided to \DTLdisplaydb

In my DB the number of columns is rather large. Hence, I am trying to eliminate any columns which contain only 0 entries. The number of columns, nor the column keys, are know upfront. So, I step ...
5
votes
1answer
98 views

String lowercase equality (newbie question)

i'd like to test if a string, once transformed into lowercase is equal to a given string. Here a MWE of what i'm talking about : \documentclass[a4paper,10pt]{report} \usepackage[francais]{babel} ...
10
votes
3answers
194 views

\expandafter and counters not playing nicely

My google-fu has finally failed me... I'm trying to write a package that will allow you say \addauthor{name, email} several times and have the title page properly formatted. Here is a minimal example ...
10
votes
1answer
133 views

Environment with delayed expansion

I'm trying to define an environment test that stores its contents unexpanded in a macro \testcontents. For example, the code \newcommand{\cmd}{bad} \begin{test} \cmd \end{test} ...
9
votes
3answers
302 views

Write on a file and input it

I'm trying to redefine a \tableofcontents-like command. I proceed this way : the displayed elements are written to a file, and the file is input when I want the display. If I know the toc will be ...
9
votes
5answers
328 views

Parse dotted string, extracting last part

I want a macro that will separate a string like "1.2.3" into two parts: the part until the last dot (call that the context) and the last number. This seems a pretty basic application of a helper ...
9
votes
1answer
280 views

Using \typeout behaviour different with \newtoks vs. \def

I feel as I really should know this, but sadly I don't. Why is the output of \typeout{\the\myToken} not the same as having it printed in the PDF as \the\myToken. No problem with a \def, just with ...
3
votes
1answer
86 views

how to return protected command with one argument already validated in latex/tex?

I want a command that will create an unevaluated bit of LaTeX/TeX code (to be evaluated at the end of an environment, but this is not necessary information) that has been created using an evaluated ...
16
votes
3answers
422 views

(Why) Can't we get 'fully expandable' versions of every command?

I'm just starting to figure out what 'expandable' means in LaTeX, and why it is useful to have commands that expand as far as possible. In particular: If you want to \typeout some string to the log ...
6
votes
3answers
159 views

Expansion issue when adding to CSV list from within a \foreach

Another expansion issue that I am unable to guess at the correct combination of \edef/\expandafters to get to work. Background: Below I have defined \AddToCommaSeparateList which uses \g@addto@macro ...
2
votes
1answer
164 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
86 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
465 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
317 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
108 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 ...
14
votes
1answer
144 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
365 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
276 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
112 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: ...
8
votes
1answer
120 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
242 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
92 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
542 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
53 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
209 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
280 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
372 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 ...
50
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
281 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
379 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
487 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
326 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
396 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 ...
26
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
421 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
293 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
674 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
456 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
164 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
198 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
163 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
1k 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} ...