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

learn more… | top users | synonyms

5
votes
2answers
91 views

Build table in new command results in too long vertical lines

I am trying to build a table inside a LaTeX 3 command. A MWE: \documentclass{article} \usepackage{xparse} \ExplSyntaxOn \NewDocumentCommand{\createTable}{ m m }{ \begin{tabular}{|c*{#2}{|c}|} ...
5
votes
2answers
177 views

Manually expanding a macro within a definition

When defining macros using \edef (which by default expands every macro within the definition as much as possible), I can declare some macro within that definition to not expand by using \noexpand ...
4
votes
2answers
77 views

Trouble with expansion

I am trying to create an easier way to write math-formulas in tex for multiple assignments. At the current time, I am almost there. This example might not seem very intuitive, but I had to leave out a ...
3
votes
1answer
29 views

Efficiently applying the same patch to several bibdrivers

In this answer to a question about getting Biblatex to print the ISSN field for books, I suggest a solution which uses the \xpatchbibdriver command of the xpatch package: \xpatchbibdriver{book}{% {\...
8
votes
2answers
279 views

Recursive use of \renewcommand: How to make it work?

I am trying to define a command that is able to store the content of a section and accumulate it as new sections are created. My current attempt is the following: \documentclass{article} \newcommand{...
6
votes
3answers
257 views

Define macro for sequence/list/tuple macros

I would like to define a macro for defining further macros to display sequences/lists/tuples of elements by specifying the following parameters: The name of the new command. What to display for an ...
9
votes
1answer
154 views

Getting to grips with Expansion

I've been trying to read through some examples and text about how expansion works, but I seem to be unable to understand how it really works. The code I am trying to get to work, is the following: \...
1
vote
0answers
21 views

Macros in \ref or \pageref etc [duplicate]

I am trying to create labels using macros. I have seen somewhat related pages, but honestly nothing that solves my problem. Below follows a relatively simple minimum working example. I thought that ...
2
votes
1answer
49 views

How to compare and see if an expanded command is equal to another

Okay, I'm processing a CSV file using datatool: "TRANSID","DATE","QUANTITY" "141f8b4a-e83e-4222-911a-5a977b4d0afca","11/9/2015","10" "88cdad7e-eb21-4010-94c5-acca8ac2e559a","11/9/2015","5" "f15c1ef0-...
3
votes
1answer
68 views

Producing expandable environments with only optional arguments with LaTeX3 syntax

I am trying to create a new document environment to complete the assembly of a table (simplified for MWE) but I am having a problem combining an expandable environment with an optional only argument. ...
10
votes
2answers
148 views

Ignore expansion in edef

I would like to populate a tabular environment programmatically using an edef. For simplicity, I brought a simple example: \let\\=\relax \let\hline=\relax \edef\mmm{\hline A & B\\} \edef\mmm{\...
1
vote
1answer
83 views

Use path replacement command inside tikzpicture/pgfplots table

After using the answer of Using \nameref within \path I tried to use that command inside a 'pgfplots' table as file name. Here's the (shortened) code: \newcommand*{\expath}[1]{/Users/jo/{#1}} \...
6
votes
1answer
60 views

Command that outputs at the end of the document the pages and line numbers where it was used

I need to a command that outputs at the end of the document the pages and line numbers where it was used. I've tried different variants of the following code but my knowledge of latex is limited. I'm ...
2
votes
2answers
27 views

Manipulating arguments to a macro inside an argument

In LaTeX, I have a macro \p (okay, it's \paragraph, but perhaps the specific macro is not relevant?) with one argument. Sometimes I use it as \p{plain text} and sometimes as \p{\t{alternate 1}{...
4
votes
1answer
53 views

Is it possible to defer expansion of an object's contents until all content has been created?

I want to provide author-usable macros in my package to store data that will later appear in a table, but it would be nice to allow authors to define the data in that table at any time, even after the ...
6
votes
2answers
137 views

How to extend existing macro with \edef?

\edef does expansion, but does not execute the commands. How in the following example make so that \foo will do assignment to \tmp at the moment of its call, not when it is defined? Why \foo produces ...
6
votes
3answers
144 views

How should I /protect this command for use in \csname?

In the process of learning how to use \csname, I'm trying to create a macro that allows one to specify integers as arguments and then will yield some content specific to the arguments, like this: \...
3
votes
1answer
47 views

Changing content of variables in toc (in ConTeXt): nested \def s

I try to define a "variable" for a category. Using it for the first time, the value should be reset until it is set again. This is the desired output: Fruit: Apricot (also in category) Banana (also ...
5
votes
1answer
94 views

Trouble nesting multiple commands using \newcommandx

First Question in this forum, so go easy on me :) I made a few meeting minutes documents for my business and I wanted a custom command for adding a note in a document. I wanted the color of the text ...
25
votes
4answers
489 views

Expandable (quick) sort array macro?

I'm trying to implement a (quick) sort algorithm. Here is what I can do : \documentclass[preview, border=7mm]{standalone} \usepackage{pgffor} % \push{xs}{\i} add \i in the array \xs \def\push#1#2{...
3
votes
1answer
74 views

Defining and expanding macros In loops

I want to define and expand macros in a \foreach loop. The names of the macros depend on the iteration step. The macros I define are interpreted as strings rather than sets of numbers that I actually ...
6
votes
3answers
163 views

Write to file: using a macro as the filename

I'm setting a complex user manual, made of several independant documents. For the overall TOC, I want each document to write some data into a file which is then parsed by the TOC file later. Here's ...
2
votes
1answer
27 views

Loading data from csv into arrays [arrayjobx]: problems retrieving values

As a follow-up to several questions, I've come up with the following MWE, with the aim of filling an array (via arrayjobx) with values loaded from a CSV file. The desired output is to print something ...
5
votes
1answer
40 views

The Environ package misbehaviour on empty content

I have encountered a problem with the environ package. It returns a wrong \BODY value when the content of an environment is empty. Here is an example: \documentclass[12pt]{article} \usepackage{...
5
votes
1answer
188 views

\edef, \xdef and \ifmmode

I don't understand the difference between \edef and \xdef in the following code. Clearly, the \xdef does what I'm expecting but why? AFAIK, $ does not start a group. \documentclass[varwidth]{...
6
votes
2answers
106 views

new command is expanding as blank

So I'm trying to import a large list of values that are used throughout my report. However when i do this the results are always blank... \documentclass{scrreprt} \usepackage{csvsimple} % \csvloop{...
0
votes
1answer
64 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
2answers
166 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% } \begin{itemize}[...
1
vote
1answer
92 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
84 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} \end{...
12
votes
4answers
295 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
79 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
574 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
98 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 \newcommand{\...
3
votes
1answer
107 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
316 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} \] \end{document}...
1
vote
0answers
44 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 ...
6
votes
3answers
145 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
75 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
59 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
89 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
413 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' ...
3
votes
1answer
117 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 \immediate\openout\...
29
votes
1answer
771 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?
7
votes
1answer
138 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
38 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
20 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
79 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, ...
9
votes
5answers
348 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
144 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 ...