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

learn more… | top users | synonyms

9
votes
1answer
222 views

Expansion inside \AtBeginDocument

I'd like to expand a macro inside \AtBeginDocument, although I guess the concrete macro does not matter. \documentclass{article} \makeatletter \@for\x:=1,2,3\do{% ...
4
votes
1answer
191 views

Are there any programs that will attempt to preprocess simple LaTeX?

I find myself in the awkward, although apparently not uncommon, position of being ordered to write, or at least end up with, documentation in the Word format. I don't have anything that fancy in my ...
6
votes
1answer
755 views

How to use \ifnum for arguments (expanding macros)?

I want to count my section's, figure's etc. using the totcount package. To get a general useable template I want to show only counters which are larger than zero. But it seems that total{counter} ...
8
votes
1answer
98 views

How do the \xx_case: functions work?

In the process of answering expl3 switch for booleans: Is there a \bool_case:Nnn?, I tried to make sense of the various \xx_case: functions Expl3 provides. Here, for example, is \tl_case:Npn: ...
8
votes
1answer
270 views

\href is not working inside \xdef

this is my first question here. I've already spent a substantial amount of time searching this before posting it here. This is my code: \documentclass[]{article} \usepackage{hyperref} ...
4
votes
2answers
105 views

Wrapper around xdef to check for conflicts

How can I write transparent wrapper around xdef that, depending on package options, report error, override or obey previous definition without sacrificing all flexibility? I have no idea how to pass ...
7
votes
3answers
144 views

Command that expands to the contents of a file

I'd like to make a macro that expands to the contents of a file. Basically something like \def{\mycommand}{\input{file.txt}} % file.txt contains "Hello%" \anothercommand{\mycommand} ...
11
votes
4answers
200 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} { ...
8
votes
1answer
78 views

A proxy command for deprecation

I'm interested in defining a macro to deprecate other macros. The system on which we are working goes through a lot of refactorings and is used by more than a couple people, so we want to be able to ...
9
votes
2answers
275 views

Expansion problems with pgfkeys

I'm using pgfkeys, and a fairly adventurous syntax in which the values for some keys contain additional key/value pairs. (For instance, the value of the nodes key is a list of pairs, and the second ...
7
votes
2answers
503 views

Expand command read from file

I have a file, that contains a list of latex commands each command per line. Now I want to read this file line per line and execute/expand the macros automatically. I tried the following but this only ...
6
votes
4answers
210 views

Expansion of commands in errmessage

When I run \documentclass{article} \def\pet{dog} \errmessage{My \pet\ is {sick}} \begin{document} My \pet\ is {sick}. \end{document} the error message is: My dog\ is {sick}. but the PDF ...
10
votes
2answers
167 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 ...
19
votes
2answers
335 views

Difficulty with macro expansion

I'm not getting the output I want from my LaTeX code, and I think the problem is that I'm not expanding things at the right times. Code \documentclass{article} \usepackage{tikz} ...
7
votes
1answer
153 views

String Comparison with a \protected\def

I am using a \protected\def as that solved an earlier issue of mine. I need to compare this value of the token to see if it is initialized to the same value as the \protected\def in different ways. ...
3
votes
2answers
358 views

Undefined control sequence \pgfmath@

Why does the following code give me this error message? Error ERROR: Undefined control sequence. --- TeX said --- \pgfmath@dimen@ ...men@@ #1=0.0pt\relax \pgfmath@ l.28 \draw ...
8
votes
2answers
389 views

Package xparse \SplitList last token

I need to create a macro to render lists with a variable number of arguments (1+), e.g. \mylist{1,2,3} should expand to $\tilde{1}$--$\tilde{2}$--$\tilde{3}$. I'm trying to use xparse and \SplitList, ...
10
votes
1answer
122 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 ...
7
votes
1answer
141 views

Modified \overline over first character of complex argument

I've been using zref to handle my references. It has allowed me to customize a reference the way I want through its property lists. In particular, I reference a variety of structures in my document ...
2
votes
1answer
199 views

Cutting string with formula or cite

I am trying to define a macro that would take a string and paint its ending, for example: \def\paintString#1{% \saveexploremode% \exploregroups% \textcolor{white}{\StrGobbleRight{#1}{5}}% ...
3
votes
2answers
105 views

How to append commands to a macro without expanding them

I'm working on building an expenses package. The intention is to be able to write \expense{someone}{something}{something a bit longer}{10}{GBP} \expense{someone else }{something else}{something a bit ...
22
votes
3answers
317 views

Why the \expandafter\@firstoftwo idiom?

I see a lot of macros which are conditional tests followed by a {true}{false} pair defined so that they result in either: \expandafter\@firstoftwo or \expandafter\@secondoftwo Why are these ...
3
votes
2answers
152 views

How to use a TeX macro with a CSV list to filter an external file

The code below produces the results I desire, which is a list of the lines with XXX={<value>} with a <value> which is not one of the allowed list of values: However, this solution ...
5
votes
1answer
483 views

Preprocessing Latex: What is your workflow? Your tools?

I know, for various reason, some users preprocess their latex file using Perl or sed, say. I'm considering doing this to, so I would like to seek your guidance, to smooth my entry in this area. My ...
6
votes
2answers
182 views

Delaying command expansion that appears in \begin handler until \end handler executes

I have a custom environment for handling a code interface declaration that is specified as: \begin{decl}{FOO} \param{in}{bar} the bar input parameter \param{out}{baz} the baz input parameter ...
16
votes
2answers
2k views

Expanding arguments before macro call

I've been banging my head against this for days. I have a macro which takes a macro name and its arguments. It then re-arranges the arguments a bit and then calls the passed macro with the re-arranged ...
4
votes
2answers
129 views

List of tokens from TeX mouth

Is it possible to get list of tokens which comes from TeX "mouth"? If I understand correctly: in mouth all macros, conditionals and special operations (like \the and \input) are expanded and then goes ...
1
vote
1answer
104 views

How to expand keyval options immediately

I am trying to build up a macro that creates other macros depending on kvoptions' options. But then, the outcoming macros are dependent on the actual state of the options instead of their state at the ...
3
votes
1answer
420 views

How to use commands in table specs, and still support array package?

For a package, I want to write code that creates tables, where the exact type of table is configurable (tabular, longtable, tabularx, ... [Update: David rightly remarked that formats like tabularx ...
6
votes
1answer
431 views

At which point does \immediate\write write to file?

Assume I have opened a file myfile and write to it with \immediate\write\myfile{My cat is too old} I have multiple such statements in my document and do calculations in between which influence the ...
4
votes
0answers
271 views

\ref, \autoref and hyperref expansion

I'm trying to write section numbers to a file with the newfile package. In details, this MWE basically tries to write to a .ref file with lines like A-B. The A and B are generated by \label and \ref ...
10
votes
5answers
501 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)} ...
2
votes
1answer
81 views

Specify file name shell access via \@@input

Background: I need to perform a conditional branch based on the first three characters of a file. I found a rather simple solution (on a Unix system, or PC with cygwin installed): head -1 ...
14
votes
2answers
343 views

LaTeX3: How to get reliable control over the level of expansion?

Say you want to write LaTeX3 code that manages user data. Sometimes you want to process that data, but other times you just want to store it, move it around and return it unchanged (when developing a ...
15
votes
3answers
321 views

Parsing strings containing diacritical marks (macros?)

I apologize that this question may seem very much like several other recent ones I have asked (Parsing leading hardspaces, Parsing a \$ as part of an improved \getargs command). They are all related ...
6
votes
1answer
125 views

\def variables with xparse and other questions about variables

I'm writing a documentation for a REST API. So there's very much information that has to get repeated. So I'm trying to figure out a few things: Consider the following code: ...
4
votes
1answer
320 views

Expand macro immediately in \pagenote

I'm trying to use the contents of a macro in a \pagenote, using the memoir class: \documentclass{memoir} \makepagenote \def\myvar{Good morning.} \begin{document} In the morning\pagenote{\myvar} ...
5
votes
2answers
232 views

Variadic arguments macro

I am trying to make macro with variadic arguments, iterating over them. The final result is supposed to be: \foreach[x]((var = \x )){foo}{bar}{baz}\null evals to var = foo var = bar var = baz My ...
7
votes
3answers
830 views

\uline within a pgfmath expression produces an error

Why does using \uline within a pgfmath expression result in an error? \documentclass{article} \usepackage[normalem]{ulem} \usepackage{tikz} \begin{document} \pgfmathparse{width("\uline{blabla}")} ...
7
votes
1answer
155 views

Forcing macro expansion with keyval

While trying to provide an answer to this question, I've run into a stumbling block that I can't seem to get over. The listings package (like many others) uses keyval to handle configuration. What ...
7
votes
2answers
120 views

Is there a way of defining a command \nullifyifmoved{arg} that will normally act like its argument but act like a no-op if the macro is “moved”?

I'm interested in a macro \nullifyifmoved that takes one argument arg and acts like arg in normal contexts, except it acts like a no-op wherever it is written to a file. Some background: Martin ...
3
votes
1answer
72 views

List Version of \str_if_eq

I am using \str_if_eq:xxTF{\A}{\Target}{<true>}{<false} to execute the <true> or <false> code if \A=\Target. What is the list version equivalent of this? So I am looking for ...
9
votes
1answer
156 views

Is there a way of defining a command which is automatically converted to a no-op after its first execution?

Is there a way of defining a command that can be executed only once and is then redefined to be a no-op? Related: Is there a way of defining a command \nullifyifmoved{arg} that will normally act ...
4
votes
3answers
138 views

Macro to be used in a \section command that has no effect in the table of contents

I need a macro that is executed only in the main document (within a section title) and then disappears (for the table of contents). A minimal example where this occurs is this: ...
5
votes
3answers
149 views

Metacommand for commands that dynamically select a parameter?

Original question I would like to create a metacommand for creating new projection commands. Specifically, \newproj{\cmd}{<n>}{<m>} should create \cmd as a new command of <n> ...
5
votes
2answers
120 views

passing current content of commands to a macro

I am sorry for this is probably a current question with a well known answer, but I was not able to google it out. I am trying to build a macro adding content step by step; at every step I need to ...
4
votes
1answer
138 views

Expanded StrSubstitute

I am trying to use \StrSubstitute, but what I want is to expand it all the way to get the result string. \StrSubstitute{Řepa}{Ř}{Rzzz} then i use it with % somehow define \a as the result string ...
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 ...
25
votes
3answers
684 views

A guide to understanding expandability: when to write protected functions and when not to

I'm having difficulty understanding (and appreciating) the concept of expandability. I'm very murky about understanding when and how expandability impacts me in writing code for my documents. I've ...
2
votes
1answer
139 views

Passing name ending with number to \csname does not work [duplicate]

Possible Duplicate: macro names with special characters When I use \yyy defined bellow it does not print yyy, but if I use \xxx it prints xxx. How can I make \yyy work? \def\P1{yyy} ...