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

learn more… | top users | synonyms

7
votes
2answers
161 views

How to put a conditional construct in \edef

\ifthenelse works fine normally, but when used in \edef: \documentclass{article} \usepackage{ifthen} \newcommand\testing[1][]{% \edef\tmp{\ifthenelse{\equal{#1}{}}{Blank}{#1}}% } \begin{document} ...
3
votes
1answer
462 views

meta-command - need help with expansion

To enforce labeling regulations in a document to be edited by ~50 users (imported subdocuments) i have to re-redine the existing document structuring commands part, chapter, etc to follow a predefined ...
8
votes
1answer
277 views

Expansion of macros and box contents

I don't understand the following behavior. Intro First, here is a simplified version of a macro I am using (which is itself a hacked version of a macro found in gloss.tex). If you have a string ...
8
votes
2answers
440 views

How can I allow a command to be used without braces around its argument, when the argument has an argument?

I've defined a couple simple macros to make my life a little easier: \newcommand{\curl}[1]{\ensuremath{\nabla\times #1}} \renewcommand{\v}[1]{{\ensuremath{\vec{#1}}}} This way, in text mode I can ...
9
votes
1answer
813 views

Highlighting line ranges in a lstlisting: partial solution, but expansion issues

In my quest for a better solution for How to change appearance of a particular line when using \lstincludelisting, I came across the linebackground= option Martin Scharrer added to the listings ...
8
votes
0answers
98 views

Can I detect (from within a macro) if I'm in an \edef (or similar)? [duplicate]

Possible Duplicate: Are we inside an edef? I've defined a macro that changes its behaviour depending on the next character, so it uses \@ifnextchar. This makes it behave badly inside ...
8
votes
2answers
252 views

How to control whether and when a macro gets expanded during another definition?

I wish to define a meta-command that, whenever invoked, will define an instance of another command; but this inner command must include a progressive number (somewhat similar to what happens with ...
7
votes
1answer
503 views

Is there a robust \renewcommand replacement?

Replacing \newcommand by \DeclareRobustCommand makes a new command robust. But what about \renewcommand? Is there a command to robustly renew a command? It would be possible to first use ...
6
votes
2answers
549 views

Expanding (edef) a lipsum command?

Just trying to debug some stuff, and I thought about 'expanding' a \lipsum[1-2] statement using \edef into a new command (that would contain the "raw" text); strangely I cannot get it to work; this ...
6
votes
1answer
300 views

Why am I processing a comma-separated list incorrectly when using etoolbox and kvoptions?

I'm trying to pick something out of a list that has been passed from some package options by kvoptions, but docsvlist doesn't appear to be recognising the commas. I suspect this may be something to ...
10
votes
2answers
311 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
3answers
670 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 ...
7
votes
2answers
562 views

Expansion issue with \begingroup and \foreach

This question led to a new package: nowidow I'm trying to define a dynamic \begingroup command to get rid of widows: \usepackage{pgffor} \newcommand{\nowidow}[1][2]{% ...
5
votes
1answer
632 views

How to expand several arguments in an environment?

I have an environment that I've defined as follows: \newenvironment{regularEnumerateEx}[2][0em] {begin{listSkeleton}[#1]{enumerate}{#2}} {\end{listSkeleton}} The problem is that I need to ...
6
votes
1answer
372 views

Use \csname … \endcsname to compute the starred-version of some command

I want to define some commands declaring paired delimiters using the mathtools package in LaTeX. For example, \paren{...} should result in \left(...\right), whereas \paren[Big]{...} should give ...
14
votes
3answers
615 views

TeX macro and command expansion?

I have implemented couple of macros that should remove commas from numbers. It's nasty dirty stuff, but it works when input is number: \removecommas{12,34,56.7} % => 123456.7 But it stop working ...
8
votes
4answers
1k views

How to write a command to file

I am trying to write to a auxillary file using \newwrite\tempfile [...] \immediate\openout\tempfile=list.tex \immediate\write\tempfile{Text to write to file} \immediate\closeout\tempfile It works ...
20
votes
2answers
2k views

What does \begingroup\expandafter…\endgroup do?

I often see code of the following form in package implementations (this example is from the LaTeX3 sources): \begingroup\expandafter\expandafter\expandafter\endgroup \expandafter\ifx\csname ...
8
votes
2answers
272 views

Preparing macro content in a loop (calling \foreach from \edef)

I need to do something like \def\MyArray{{1, 2, 3, 4}} but with a dynamical number of elements. The following command makes the string: \newcommand{\MakeArray}[1]{\{ 1 \foreach \x in {2, ..., #1}{ , ...
4
votes
3answers
240 views

Saving the value of a text macro at the start of the page.

I have a macro that stores some text. I'd like to print the text of that macro as it was at the start of the page in the header, and as it is at the end of the page in the footer. I can do this for ...
7
votes
1answer
242 views

\forcsvlist and expansion

I've got an expansion issue with the following code: \def\sizes{huge, LARGE, Large, large, normalsize, small, footnotesize, scriptsize, tiny} \forcsvlist\sampletext{\sizes} My problem is that ...
3
votes
1answer
464 views

\rule doesn't work inside an \xdef command

This code: \documentclass{article} \begin{document} \def\a{} \newcounter{mycounter} \def\b#1{ \def\p{#1} \ifnum\value{mycounter}=0 \long\xdef\a{\a\rule{3mm}{3mm}\par #1} ...
6
votes
1answer
2k views

Is there a LaTeX/TeX preprocessor/inliner that replaces only selected macros with their definitions?

I have the following situation: Like most LaTeX users that write much, I have my own header files where the packages I use normally are required and the macros I use often are defined. So if I write ...
15
votes
3answers
1k views

Expand after all that stuff?

Often I find myself in the need of expanding some macro, whose contents should be given as an argument to another command. The usual solution is to invoke some \expandafter concoctions to somehow ...
8
votes
4answers
269 views

Does macros get applied to the source code before compilation?

I wonder if this is true. The latex compiler first run though the document, and search for all the macro declarations. the compiler then go though the document, apply each macro as a string ...
25
votes
4answers
606 views

Why isn't a command defined by \newcommand with an optional argument expandable?

In trying to fix a problem with a nested macro repeatedly calling itself, I tried expanding the inner call before passing it as an argument to the outer one. This failed miserably because the macro ...
10
votes
2answers
545 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 ...
16
votes
3answers
843 views

Why does \dimexpr swallow \relax?

Following the comments at Doing maths with distance values in LaTeX source code: +1 for teaching me that \dimexpr can optionally swallow a \relax. Yesterday I tried to use \relax as a delimiter ...
4
votes
1answer
451 views

pgfmath expansion - call a command from within a pgfmath environment

I am trying to define a newcommand using pgfmath. This commands calls a previously defined command but it fails. It propably has to do something with expansion. I've read this question about ...
3
votes
1answer
265 views

Converting command to result

Consider this example: \documentclass{article} \newcommand{\foo}{} \newcommand{\currentbar}{\thebar} \newcounter{bar} \setcounter{bar}{0} \makeatletter ...
3
votes
1answer
1k views

Expanding macro arguments in newcommand

I'd like to use datetime's \monthname as part of a command; consider this snippet of command line pdflatex use: $ pdflatex This is pdfTeX, Version 3.1415926-1.40.11 (TeX Live 2010) restricted ...
6
votes
2answers
564 views

Forcing tikz/pgf to expand macros within commands

I would like to use simple macros within tikz commands, but it seems tikz doesn't expand them in the ways I would expect. For instance, the code ...
2
votes
2answers
268 views

Macro behaviour different inside tabular environment

I have a lot of problems lately with macros expanding (or not expanding) at unexpected times, so thought I was having a related problem here. But, in this case, things are working as I want outside of ...
6
votes
4answers
390 views

Signalling error in “expandable context”

I'm reviewing a few old macros of mine to make them fully expandable. One of the macros takes one argument, which should either be a two-digit or a four-digit integer (>1955). The macro then converts ...
5
votes
1answer
455 views

Evaluation order during macro expansion.

From this question Creating PDF bookmarks in custom order arose another. (I hope it is correct to create a new question instead of commenting or editing/answering my old question.) Using this macro ...
4
votes
3answers
2k views

Can (pdf)LaTeX recognize text strings and replace (expand) them?

I'd like LaTeX to replace e^ with \mathrm{e}^. I know I could just make a macro \e that does this, but I know I'll forget using it.. Can LaTeX find and replace and replace letter combinations (I ...
4
votes
2answers
244 views

Expand within \label

Is there any way to use a macro within a \label tag? \edef\num{1} \label{test\num} \ref{test1}
8
votes
1answer
819 views

Problem with environment expansion and the Tikz external library.

I've created my own environment mytikz, which basically looks like this (full MWE): \documentclass[a4paper]{article} \usepackage{tikz} \usetikzlibrary{external} \newenvironment{mytikz}{%begin code ...
76
votes
3answers
4k views

Showing the bibliographic entry in a popup when you hover over the citation key

I thought it would be useful to have bibliographic entries displayed as a tooltip so readers are not interrupted by following hyperlinks or trying to find the Bibliography, so I created the following ...
0
votes
2answers
2k views

The argument of foo has an extra }.

I'm trying to write a command that does, effectively, an \fbox in something like an align environment. The following code works: \usepackage{etextools} \makeatletter ...
6
votes
1answer
204 views

Expansion of command for language in otherlanguage environment

I wish to keep the language in a command \newcommand{\testlang}{english} \begin{otherlanguage}{\testlang} ... \end{otherlangauge} However, \testlang is not expanded, and i get the error ! ...
4
votes
1answer
266 views

LaTeX3: expansion of argument to function

I would like to define functions which extract the PDF object number from a PDF object reference, such as 12 from 12 0 R. I defined two versions of such a function, a low level one and a high level ...
6
votes
1answer
824 views

How do I examine a token?

... let me count the ways. I can test it with \if and \ifx and \show its \meaning And there I stop, both in my knowledge and my poetic ability (though some might argue that the latter never ...
5
votes
1answer
805 views

Jobname of inputted file?

\begin{filecontents}{foo.tex} \def\foo{\jobname} \end{filecontents} \documentclass{article} \begin{document} \input{foo} \foo \end{document} This outputs the jobname of the main file not "foo". How ...
8
votes
1answer
285 views

How do I store the upper case counterpart of a string?

I have a string stored in a variable \word, and I want to store its upper case counterpart in another variable \WORD. If I try \def\WORD{\MakeUppercase{\word}} \show\WORD then the message ...
4
votes
2answers
421 views

Strange expansion of a macro inside an environment

I'm, I should confess, a total newbie. I'm trying to generate invoices with LaTeX, so I'm using the fp package. But the strange thing is that calculations occur many times when they should only ...
16
votes
3answers
909 views

Does `\noexpand` have to be a primitive?

Background: I'm trying to deepen my understanding of TeX and how the intricacies work (spurred a little by this place, I should say, and hoping one day to not be a "Cargo Cult Programmer" - see When ...
12
votes
3answers
332 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 ...
8
votes
2answers
271 views

reversing the order of expansion

Is there a non-expl3 expandable function for reversing the order of expansion of an arbitrary number of tokens or macros? For example, \reverseexpansion<n>\a\b ...
17
votes
5answers
1k views

Are there purely expandable variants of \MakeUppercase?

\MakeUppercase and \uppercase use TeX's uccode, and they are not purely expandable. Say, \edef\temp{\MakeUppercase{abc}} will fail. Sometimes purely expandable macros are very useful. They are ...