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

learn more… | top users | synonyms

13
votes
2answers
495 views

\expandafter within a \begingroup … \endgroup [duplicate]

Possible Duplicate: What does \begingroup\expandafter…\endgroup do? In many of Heiko Oberdiek's packages one sees this type of construction: ...
13
votes
2answers
172 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 ...
13
votes
2answers
1k views

Allow underscore in PGFPlots tick labels read from table

I'm trying to use the text data from a table column as the tick labels in a plot. The text data contains underscores, which makes LaTeX throw a Missing $ inserted error. I'd usually get around this by ...
12
votes
4answers
434 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 ...
12
votes
2answers
928 views

Minimal \protected@edef example

I recently came across \protected@edef in the/a LaTeX2e source. Can anyone give me a minimal or simple example, where I need this? I know this has to do with fragile commands/robustness, but I am ...
12
votes
2answers
664 views

Macro to do nothing via a \def

I have encountered another expansion issue and have narrowed it down to this simple test case of a macro that does nothing, well at least it tries to do nothing, but is not all that successful. If I ...
12
votes
3answers
334 views

Expansion of first token in a tabular cell

Background I currently do some work on the collcell package which collects the content of a tabular/array cell and provides it to a user defined macro, e.g. using ...
12
votes
1answer
328 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 ...
12
votes
1answer
295 views

Text being output when none should be

I am confused as to why the MWE below produces any black text. As the code is below, the output is: However, if you comment out the \IfStrEq line then it works fine and the black text goes away? ...
12
votes
1answer
2k views

renewcommand in a newcommand

I have a command \putansline{1}{2} that inserts 1 line of dots and prints the total score as [2]. I want to define a new command that if issued, will redefine this command so that it prints only the ...
12
votes
1answer
387 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 ...
11
votes
4answers
202 views

Partially expanding a command

My \john command is defined like so: \def\john{\DontExpandMe} I would now like to repeatedly change its definition, to keep adding some extra stuff on the front. \foreach\i in {ape,bat,cow,dog} { ...
11
votes
3answers
190 views

How to pass a macro as the argument to \selectlanguage

The following mwe throws the error You haven't defined the language lang yet. \documentclass{article} \usepackage[american]{babel} \newcommand{\lang}{american} \selectlanguage{\lang} \begin{document} ...
11
votes
3answers
298 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 ...
11
votes
2answers
382 views

Define and set length in one command

Sorry this might be a very simple question, I am trying to cleanup a style file, and would like to write a command that basically runs the following code: ...
11
votes
2answers
762 views

Tricks to make macros expandable

Expandable macros are useful (I find working in the lion's mouth super cool). But they are difficult to write. Can more experienced users give hints that help achieve expandability? For example, we ...
11
votes
1answer
659 views

How to do \scantokens inside \edef without triggering “Runaway definition”

I'm trying to find a way to use the e-TeX \scantokens command inside [the equivalent of] an \edef (well, actually an \xdef, but presumably this does not make any real difference since that's just the ...
11
votes
1answer
124 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 ...
11
votes
4answers
657 views

What's the best/right way to test an argument to a macro?

This is essentially asking how to do a case switch in LaTeX. I want to define a macro so that if the argument passed is one thing, then something happens, and if not then something else happens. I ...
11
votes
1answer
88 views

\toks register expansion issue - or is it?

I am trying to assemble a table that occurs multiple times throughout a document. It always consists of some fixed columns, followed by a set of columns that appear in one table but are not needed in ...
11
votes
1answer
190 views

expandable unit conversion

I'm writing a package to assist typesetting documents for some special Pen & Paper Fantasy RPG. In this fantasy setting, there are three types of coins: gold, silver and copper pieces, which ...
10
votes
5answers
506 views

How to create a “delay expansion” environment?

I don't want to use the following \begingroup \edef\next{\endgroup \noexpand\const{Xp}{\X(tp)} \noexpand\const{Yp}{\Y(tp)} \noexpand\const{Xf}{\X(tf)} \noexpand\const{Yf}{\Y(tf)} ...
10
votes
4answers
271 views

why can't \the be expanded?

\documentclass{article} \begin{document} \tracingmacros=2 \newlength{\len} \setlength{\len}{1cm} we want to write out \verb$\len$ in cm \the\len { oops, answer in pt} \setlength{\len}{0.0352\len} ...
10
votes
3answers
197 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
2answers
326 views

How do I pass an expanded optional argument using expl3/xparse?

I have a command defined using xparse syntax: \DeclareDocumentCommand \foo { O{} m } {} Inside some other command (say, \bar), I want to call this command. The calling command (\bar) has to ...
10
votes
2answers
700 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
2answers
169 views

Preserving (and Controlling) Expandedness

In most cases, by the time output gets to your screen, arguments are fully expanded and my question is moot. But sometimes (verbatim being a common example), one wishes to operate on arguments with ...
10
votes
2answers
198 views

Execute non-expandable code inside a tabular environment

As there is no Expandable version of \InputIfFileExists or \IfFileExists, the question arises whether it is possible to execute non-expandable code in a tabular environment after all: File main.tex: ...
10
votes
2answers
550 views

Concurrently interleaving execution of Lua and TeX in LuaTeX

The usual way to interleave Lua and TeX in generating documents is by invoking Lua from Tex through the \directlua facility and generate Tex from Lua using tex.print(). For example, consider the ...
10
votes
4answers
388 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 ...
10
votes
1answer
2k views

Add space after LaTeX command

I'd like to call a command from LaTeX, which looks like this: bash -c "\myCommand -Tpdf #2.dot > #2.pdf" \myCommand is replaced by string variable, however the space after is also removed so I ...
10
votes
3answers
727 views

Censor text spanning multiple lines

I'd like to censor or hide some text while replacing it with the appropriate amount of white-space. The replacement text cannot be searchable. The text to be hidden usually exists in the LR mode. The ...
10
votes
1answer
134 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} ...
10
votes
2answers
131 views

Expandably change letter case and use inside \csname, without a package

I want to change the letter-case of a single character argument, and use that changed letter inside a \csname. And I want to do it without an additional package. For example, I want to pass a macro ...
10
votes
1answer
156 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 ...
10
votes
2answers
240 views

Save counter value inside command?

I'm trying to automatically generate commands based on the value of a counter: \documentclass{article} \newcounter{count} \newcommand\generator[1]% {% \stepcounter{count}% ...
10
votes
1answer
123 views

Expandable, very specific keyval processing

I am having a hard time trying to come up with an fully expandable keyval parsing macro which deals only with specific keys/values. I wouldn't even attempt this in full generality, that's way beyond ...
10
votes
1answer
57 views

Reading (input) a file whose name is created with a label

I don't want to get into the details of why I want to do this, but I would like to: create a new counter called filenumber; create a file whose filename is \jobname\thefilenumber.txt and write to ...
10
votes
1answer
77 views

LaTeX3 Property lists and expansion

So, I'm trying to pass the "date" value associated with the current environment to a property list defined by a macro. It doesn't seem to work and I'm not sure why. Here's a MWE: ...
10
votes
1answer
466 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 ...
9
votes
5answers
332 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
6answers
921 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}} ...
9
votes
6answers
662 views

Is there a '\ReallyDontExpandUntilTheLastMinute' command?

There's a couple of things I want to be able to do that are quite similar and basically involve keeping back a macro expansion until the last minute. Possibly the simplest example is that I have a ...
9
votes
3answers
210 views

Command doing the same job as StrBefore but being expandable

I am looking for a command allowing me to get 3 as output if the input is 3.2. \StrBefore{3.2}{.} works fine for this purpose but is not expandable and I need to call it in another macro inside a ...
9
votes
2answers
95 views

How to expand \ifthenelse so that it can be used in \parshape?

How do I get the following MWE to work: \documentclass{article} \usepackage{xifthen} \usepackage{lipsum} \newboolean{bar} \setboolean{bar}{true} \def\foo{\parshape = 2 ...
9
votes
4answers
175 views

Apply command to list of elements separated by \and

I am trying to build a command similar to the \author command. It takes one argument with is actually a list of arguments separated by \and. The command needs to apply another command like \underline ...
9
votes
2answers
708 views

Force the expansion of a macro parameter without \edef or \xdef

Two days I am looking for a solution but I have no more idea. This is my problem. I'm trying to create a macro to automatically define new other macros to write references in a document. I want to ...
9
votes
3answers
154 views

Problem with ^^<HEX>

I have small problem with ^^<HEX>. If I have a <HEX> part of the ^^<HEX> in the macro \def\attemp{<HEX>}, I cannot write ^^<HEX> as ^^\attempt or ...
9
votes
2answers
339 views

How does this answer work?

Harald Hanche-Olsen posted some interesting code in answer to this question. Could someone explain how it works? I understand (I think) the futurelet and the expansions. I don't understand: Where ...
9
votes
3answers
630 views

Problem with nested \noexpand and \edef

I have a LaTeX problem and want to explain it with the following code snippet: \documentclass{article} \begin{document} \def\myline{A} \edef\myline{\myline \noexpand\bf B} \edef\myline{\myline ...