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

learn more… | top users | synonyms

0
votes
1answer
30 views

Using \MakeUppercase on expanded macro with argument

I would like to have the first letter in an expanded macro shifted to upper case but I can not seem to manage this. In the minimal example below, I would like the two rows to produce the same output, ...
1
vote
3answers
86 views

How to expand macro in a macro call

How can I expand a macro inside an optional argument list \newcommand{\sss}{% label={$\bullet$},topsep=0mm, parsep=0mm,% leftmargin=3mm,rightmargin=0cm,labelwidth=5mm,labelsep=3mm% } ...
1
vote
1answer
32 views

How can I use \foreach to place nodes in a pgfplots axis?

I am trying to foreach over some coordinates to place nodes at whilst inside an axis environment. I followed the advice here, but I am getting nowhere; the following fails with error ! Argument of ...
2
votes
1answer
40 views

Using a macro for table alignment

I am trying to use a macro to define the alignment of a table as shown below: \documentclass{article} \begin{document} \def\align{|l|c|} \begin{tabular}{\align} 1 & 2 \\ \end{tabular} ...
12
votes
3answers
198 views

Useful applications of \edef with macro arguments

Well, it's been in my head for some time, but I haven't got anything out of it, so I ask here. At what places could be useful to have \edef\foo#1{..}? What applications could it have? Is it useful at ...
3
votes
1answer
60 views

Lualatex : how to avoid this “unnatural” \\

I have a lua function to withch I want to pass some extra optional latex code (basycally a macro with a parameter, macro can change, parameter too). I have to double backslash the name of the macro, I ...
4
votes
4answers
455 views

One-liner for removing characters from a string

I have a predefined command \mycommand which, for some reason, outputs {"/home/user/di rect ory/"/}. (Yes, there's a slash after the quotation mark, and there are curly braces.) Could one think of a ...
6
votes
3answers
69 views

Why does \def fail inside \edef?

An answer to one of my previous questions provided this code for referencing a range of lines in which a line labels were placed at the beginning and end of the line range. \makeatletter ...
2
votes
0answers
16 views

Robust handler of arguments with conditionals and complex elements

Context This question is a follow up of the answer of this question Spurious space on moderncv \cventry using \if Problem The problem is that complex content (for example, itemize on the content of ...
11
votes
3answers
251 views

How to delay expansion

Consider the following document: \documentclass{article} \usepackage{polynomial} \begin{document} \def\a{-3} \def\b{-2} \def\c{-4} \[ \polynomial{\a,\b,\c}\quad\polynomial{-3,-2,-4} \] ...
1
vote
0answers
40 views

how to expand some macros in latex file [duplicate]

I have a latex file that uses some of my own macros (a mix of tex & latex macros). I need to post the latex source, but don't want to expose the macros (some of which are nasty hacks that just get ...
5
votes
3answers
106 views

Check occurrence of a macro inside another macro

With the substr (or xstring) package you can, of course, identify whether a control sequence contains some text string: \documentclass{article} \usepackage{substr} \def\somecontrolseq{some silly ...
1
vote
0answers
69 views

what is the change in macro expansion when using environ and newenviron as compared to the standard environment

The packages environ and newenviron both provide an alternative to the standard environment macros included with LaTeX. The main difference is that they make it possible to refer to the environment ...
3
votes
1answer
44 views

Undefined control sequence at definition

Why would I be getting an error that the control sequence is undefined while I'm trying to define it? ! Undefined control sequence. <argument> * \cs_set:Nn \obj_this:n ...
4
votes
1answer
68 views

How to expand control sequence in argument of a macro

Consider the following: \def\foo#1#2 {% \if#1a% \message{#2} \fi} \def\x{abc} \edef\y{\foo\x} \y The result: ! Argument of \foo has an extra }. The expected result: bc
3
votes
1answer
91 views

HowTo make beamer's \insertauthor all uppercase?

So I was finally able to create a MWE for this one: I am creating my own beamer style which has some areas, where all text is supposed to be all caps. Using \MakeUppercase with the beamer class' ...
0
votes
0answers
14 views

\edef together with microtype generates an error [duplicate]

In a previous question, I asked why \edef produced an error when trying to expand commands that takes an argument in the belief that this was the cause of it. But in actuality, I've realized that the ...
3
votes
1answer
39 views

How can I use \noexpand and \unexpanded without appending a space to the unexpanded tokens?

One of my current tasks involves composing an auxiliary file with extra commands to be loaded at a separate compilation. Here's an MWE: \documentclass{memoir} \newwrite\testaux ...
28
votes
1answer
646 views

What does “expanding” mean in (La)TeX?

You can often read about expanding a macro or when a macro does expand, sometimes about expansion. But what does this mean - in English?
6
votes
1answer
84 views

How can I \typeout a percent sign?

I want to \typeout a message containing a percent sign. I know that if I want to \typeout a macro followed by a space, as in: The name Name is unknown. I have to use \space, not \␣, because \space ...
1
vote
0answers
31 views

Passing background color to \lstinputlisting

In question Passing parameter in presence of an xkeyval value I received two ideas for dealing with passing an option to a macro. Namely, \expandafter\lstset\expandafter{\ME@options} and ...
1
vote
1answer
15 views

error when using expandafter for databib command in indexing command in foreach loop

I'm trying to create an author index using the databib package (datatool) bundle. I can loop over the entries in a BibTeX database and for each entry, loop over the authors using the \foreach command ...
1
vote
2answers
51 views

Pre-expansion of moving macro argument

I am using databib package (datatool bundle) to get information out of a BibTeX database for arbitrary use in a LaTeX file. It provides a command to loop over the BibTeX entries. Within such a loop, ...
8
votes
5answers
226 views

How do I expand exactly once a macro which takes an argument

I thought I was finally understanding expansion, but then I wrote something along the following lines, and it has me a bit stumped. \documentclass{article} \usepackage{xcolor} \usepackage{etoolbox} ...
4
votes
2answers
80 views

Expansion in forest

I am trying to expand a macro as part of a style within a forest tree. Here's an MWE: \documentclass[tikz,border=5pt]{standalone} \usepackage{forest,ifthen} \begin{document} \bracketset{action ...
0
votes
1answer
34 views

Using fully expanded result as a simple string (with citet and \IfSubStr)

I am breaking my head with that problem, without finding anything that could help on Internet : The initial problem is that I write an essay in French but I need to include some articles written in ...
3
votes
1answer
45 views

index, acronym and sorting, macro expansion

I want to use index together with acro: Whenever I use an acronym, I want it automatically in the index. However, not the abbreviation but the long name! What I did: I created a new command: ...
9
votes
2answers
120 views

What is the preferred way of expanding twice in expl3?

expl3 includes the o, f, and x argument specifiers for one-level and the two kinds of full expansion, respectively, before passing the argument to the base function. What is the preferred way of ...
4
votes
1answer
57 views

Setting a counter to a value obtained by expansion

I use the glossaries and minitoc packages. Minitocs are generated for all glossaries printed in the table of content, eg with the toc option for the glossaries package. When one prints the glossaries ...
1
vote
1answer
62 views

Expansion problem in a grid-like tikz figure

My goal is to automate a process where I have many pictures from a movie sequence and I would like them to be typeset in descending rows. For that, all my images rest in a folder and of course, they ...
5
votes
2answers
139 views

Use \foreach loop to execute macro with parameters of macro provided in a list

I have to execute a macro a number of times, and would like to provide a list of the parameters to be executed. So, instead of \FormatLinks*[Main Search Site]{Google}{http://www.google.com} ...
4
votes
1answer
32 views

How can I set a style in `\forestset` which requires delayed calculations with the results of node walks?

What is the correct way to wrap the specification for the tree below into the my binomial style defined in \forestset and why? The following code works fine: ...
2
votes
1answer
73 views

newcommand that does not expand at all

How do I define a command that exactly inserts its contents back into the source file without any reinterpretation, expansion, etcetera? In other words, I want there never to be a difference ...
2
votes
1answer
44 views

How can I use a variable from xstring with the text along path decoration from tikz?

Issue How can I get proper text expansion for text=\somevariable in a tikz text decoration. I think I have an expansion problem here. Set \releasedate Extract year from \releasedate in ...
4
votes
2answers
136 views

How to get LaTeX to expand at the correct position?

I have a latex document which in the main part lists a number of "tasks" (for students to solve); to each task belongs a "script", however, all scripts are supposed to be printed in an appendix at the ...
11
votes
5answers
500 views

Basics of scanning

I'm trying to master the art of scanning text one character at a time. The following is what I've discovered so far. Is this as good as it gets? I would really prefer not to do all those \edefs as ...
19
votes
2answers
441 views

\expandafter and \aftergroup: where do the 2n+1 and n^2-1 rules come from?

Both TeX primitives \expandafter and \aftergroup have "rules of thumb" stating that \expandafter should be used 2n+1 times to look n tokens ahead (is this correct?). A similar "rule of thumb" holds ...
3
votes
1answer
40 views

Problem with expansion of \@ifnextchar inside tabular environment

I'd like to define a macro that expands to \hline and \cline inside the tabular environment depending on the next character: \documentclass{standalone} \makeatletter ...
11
votes
1answer
166 views

Why this output using \string on the empty csname

How does this exactly work? \expandafter\string\csname\endcsname I don't know what I would expect to come from there, but definitely not \csname\endcsname_ where _ is a space. I thought ...
2
votes
1answer
85 views

Define an expandable function for comparing a token list to a string in LaTeX3

In LaTeX3, I could define a function for comparing a token list to a string \cs_generate_variant:Nn \tl_if_eq:nnTF { V } \cs_new_nopar:Npn \module_compare:n #1 { \tl_if_eq:VnTF \g_some_tl { #1 ...
8
votes
3answers
118 views

Appending active and expansion sensitive characters to a macro

This question comes up pretty often when people want to build tables with empty columns or similarly building up some active characters inside a macro hoping to expand them at the right time right ...
2
votes
1answer
56 views

Command containing babel shorthand not expanding [duplicate]

Greetings to the distinguished gathering of TeXperts! My problem is: if a macro is defined with a babel shorthand containing the quote mark (") as an active character, it does not expand when ...
6
votes
1answer
76 views

Delimited \def's and expansion

I try to understand how work the macro named \separator in MWE . \documentclass[]{article} \def\separator#1\separator#2{% \unexpanded{#1}% \ifx*#2% \else , \expandafter\separator\expandafter#2% \fi ...
8
votes
2answers
255 views

Could someone explain the tokenization process that's leading the whitespace creeping in here?

Here's a MWE that creates spurious whitespace: \documentclass{article} \usepackage[T1]{fontenc} \usepackage{lmodern} \newcommand\aetest[2][\relax]{%% \def\aejunk{<#2>}%% \ifx\relax#1 ...
4
votes
2answers
121 views

loop in tabular that uses \the\count to access current line number

I would like to generate an autmatic table using loop. As suggested here before, it is best to first generate the lines in a toks and then pass them to tabular. However, I have problems with accessing ...
3
votes
2answers
83 views

Expand \def value from optional default argument? - Bug in \oldacronym (glossaries v4.02) - first use not respected and funny effects?

Edit: Bug only in glossaries v4.02. -> Update! \edef\args{[#4]{#1}{#2}{#3}}% \expandafter\newacronym\args% may be a way to expand unexpaned args. Is there a bug in the glossaries ...
6
votes
2answers
193 views

TeX/LaTeX: Macro for getting a length as number

I would like to write a macro getlengthin to get a length or dimen as floating point number in a specified unit. Here is what I have created so far: \documentclass{article} ...
6
votes
4answers
117 views

How to expand a macro into viewport= arguments(includegraphics)

How do I properly expand a macro \myviewport so that it is parsed as the viewport=0pt 10pt 100pt 200pt argument of \includegraphics[clip, \myviewport]{somepdf.pdf}? \documentclass{article} ...
5
votes
2answers
104 views

Inserting Macros in argument of \sindex[]{} aren't expanded

I've to build an individual register with \sindex[]{} from the splitxdx package from an outside generated TeX code. The call name of people with two firstnames is sometimes put in braces, sometimes ...
4
votes
1answer
63 views

Macro expansion and href with hyperlink

I have very simple question I hope! I am writing a book on MPASM (PIC) assembler and there will be very many similar links to programs, hex files, videos etc. These will be enclosed in a standard ...