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

learn more… | top users | synonyms

2
votes
1answer
233 views

How to add \hline to macro expansion?

I want to add one \hline to the macro expansion of this code, that is minimally modified version of David Carlisle's answer to Generating LaTeX tabular code during compilation. Compiling this with ...
5
votes
1answer
329 views

\unexpanded fails with undefined LaTeX symbols?

I'm actually not sure if the title of this post is correct. However, what is happening is that the following MWE \documentclass{article} \begin{document} \unexpanded{$\undefsym{x}$} \end{document} ...
10
votes
2answers
189 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: ...
15
votes
3answers
1k views

Expandable version of \InputIfFileExists or \IfFileExists

From this question: Cannot use \toprule when doing \input inside tabular -- why? I know that everything inside the tabular environment should better be expandable. The MWE below suggests that ...
8
votes
2answers
2k views

Cannot use \toprule when doing \input inside tabular — why?

Using \input inside a tabular environment does not seem to work in all cases, but I don't see why. The MWE below gives the following error message: ! Misplaced \noalign. \toprule ->\noalign ...
9
votes
2answers
594 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 ...
4
votes
1answer
89 views

How to use a counter in a \bookmark dest name within \BookmarkAtEnd?

I'm trying to do something similar as in this question. I would like to use the value of a counter in the name of a \hypertarget and in addition, I want to be able to refer to this name in a ...
7
votes
2answers
348 views

Convert string to file name and use in \href

I have a bunch of individual .tex files and want to be able to click on a link in one PDF file and have the appropriate PDF file open. These are small files, so don't really need to index into them, ...
12
votes
2answers
615 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 ...
13
votes
2answers
474 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: ...
6
votes
1answer
169 views

How to extend the \romannumeral-based \fullyexpand to handle empty/all-space arguments?

In Expandable full expansion of tokens that preserves catcodes, Joseph Wright presents the following code: \long\def\fullyexpand#1{% \csname donothing\fullyexpandauxi{#1}{}% } ...
3
votes
2answers
135 views

Can Texinfo's @value macro be made to work in the filename argument to @xref and friends?

Given a file xref-and-value.texi with contents: \input texinfo @c -*- TeX-PDF-mode: t; -*- @setfilename xref-and-value.info @settitle @code{@@xref} and @code{@@value} in \pdftex @set fngccint ...
7
votes
1answer
230 views

Why do some arguments in a macro need to be preceded by \noexpand?

I keep on studying the use of nested tikzpicture environments (sorry) and I discover the next problem. I'm not sure but it sounds like a problem with "fragile" commands. Perhaps, the problem is the ...
7
votes
5answers
2k views

\includegraphics: a command in the optional argument

I want to pass some arguments to \includegraphics via a command, but I can't get it working as I would expect. My M(n)WE: \documentclass{article} \usepackage{graphicx} \begin{document} ...
6
votes
1answer
424 views

How to expand values stored in a token defined by newtoks

In this project, the directory structure and file names are based on three parameters, with there being one exception to both. Directory Path: \GetTexFilePath{}{}{} The directory path is based on ...
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 ...
18
votes
2answers
306 views

Get the lion to run in loops. Tersely

Various constructions can cause TeX (aka the lion) to go into an infinite loop. The simplest example is \def~{~}~, which defines ~ to expand to itself, then expands it. Now, if we exclude macro ...
15
votes
4answers
605 views

Detokenizing without extra spaces?

I have a need to pass through potentially arbitrary characters untouched and found this macro: \def\test#1{\expandafter\zap@space\detokenize{#1} \@empty} The problem is that \detokenize inserts ...
3
votes
3answers
407 views

Problem with expansion of \BODY

In the following MWE, the command \testStringNotEmpty tests if the argument is empty. This test is robust in the sense that the argument can contain a command or an environment... The environment ...
7
votes
2answers
259 views

Hyperref to expand macro in argument

I am confused as to why the edef below does not get expanded in the link? The \GetTexFilePath is from Text being output when none should be, which is expandable, and the \GetTexFilePathOld is the ...
13
votes
1answer
502 views

Why is \input not expandable?

In latex.ltx I found \def\input{\@ifnextchar\bgroup\@iinput\@@input} where \@@inputis expandable. I would like to know if there is an expandable version of \input. The problem comes from an example ...
12
votes
1answer
292 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? ...
8
votes
1answer
155 views

Feeding a macro with the expansion of an other defined “by” \csname

I have a macro \mymacro@i that I want to "feed" with the expansion of another \test. With \expandafter\mymacro@i\test, it works. Now, the \test macro can be defined by using \csname, say a /test ...
7
votes
2answers
301 views

Why does this protection not work?

The answers to this question explain in detail what protection is so I'm not wondering about that. My question is why a certain command definition with expl3 does not give a protected command. ...
7
votes
1answer
303 views

Replacement for \unexpanded without eTeX extension

As comment on Can the extended register pool be used for \newinsert?, there is a reference to Dealing with tons of floats. It is interesting but uses \unexpanded: \edef\@freelist{% ...
6
votes
2answers
1k views

Save current value of counter in a command

I would like to define kind of an own index, that collects certain information and one counter value - in the following small example the \addstuff-command that may get the value of a counter as its ...
3
votes
3answers
325 views

Arguments expansion in IfSubStr

EDIT: Simplified question How can I make the following code print "Yes"? \IfSubStr{\textbf{AAA}}{AAA}{Yes}{No} Full question I'm playing with xstring's IfSubStr, but I don't really understand ...
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 ...
9
votes
3answers
577 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 ...
9
votes
1answer
1k views

Expansion in \numexpr…\relax versus \pdfstrcmp

The \numexpr...\relax construction in eTeX allows to evaluate numerical expressions, and it expands tokens fully as it goes. The \pdfstrcmp{...}{...} construction in pdfTeX lets us compare two lists ...
3
votes
2answers
172 views

Command representing an expansion of a summation

I am very new to using LaTeX to write equation. And I am now learning how to create my own command. I am going to write a command \Listn to help me to do this: \Listn{\sumup}{(#1)}{+} $\sumup{n}$\\ ...
7
votes
1answer
847 views

\newif conditional causing problem in \typeout or \edef

The following code produces result as expected, i.e., False True on the typeset document. \documentclass{minimal} \newif\iftest \newcommand{\test}[2]{ \iftest #1 \else #2 \fi } ...
56
votes
3answers
1k views

Why isn't everything expandable?

TeX's macro processor does its work in a process called expansion. For an input stream of tokens, the macro processor repeatedly expands them until non-expandable tokens remain. The resulting stream ...
7
votes
1answer
185 views

expansion of loop macro

I have a macro that contains a loop using \@for and it works until I try to write its output to a file. The following document shows the problem. \documentclass{article} \makeatletter ...
8
votes
3answers
459 views

colortbl: new environments and how to apply \expandafter

This is a followup question from one asked by Andrew Howard. After some discussion, it became clear that colortbl has some issues with the names that can be used for a \newcolumntype. The result of ...
21
votes
4answers
497 views

Can one define an expandable command that removes control sequences from its argument?

I am trying to create an expandable command that accepts a single argument that may contain control sequences, and expands to that same argument with all control sequences and braces removed. That is: ...
6
votes
2answers
226 views

\StrMid and \MakeUppercase problem

What's wrong with this: \documentclass{minimal} \usepackage{xstring} \begin{document} \newcommand{\cim}{c1095} \StrMid{\MakeUppercase{\cim}}{1}{1} \StrMid{\cim}{2}{100} \end{document} ...
7
votes
2answers
155 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
440 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
257 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
415 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
772 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
243 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
481 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
530 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
284 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
289 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
618 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
549 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]{% ...