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

learn more… | top users | synonyms

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 ...
6
votes
1answer
75 views

Macro expanding to comma separated list

I'm trying to use a macro for pgfplotstable labels but the macro is treated as a single entry of a csl rather than a csl. The Question asked in Using a macro as value of addtotoc in \includepdf ...
5
votes
3answers
150 views

How can I remove outer brackets without expanding content?

I'm trying to use pgfkeys to collect information that will be passed to a clist. But, I'm not able to get this to work correctly. It seems that I'm getting brackets around the list and is prevent ...
5
votes
2answers
397 views

On unprotecting (expanding) \protected macros (or, “the space after command name”)

I quite often come into a situation, where I need to obtain some text produced by a package macro as a string, like in say: Expanding (edef) a lipsum command? How do I "unprotect" an ...
5
votes
2answers
164 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 ...
5
votes
3answers
209 views

Expanding an argument of code added by \g@addto@macro

I would like to have the following (it's a part of a large code block): \def\C{foobar} \def\A{} \g@addto@macro\A{\B{\C}} Now \show\A outputs \B{\C} I would like to modify the 3rd line so that ...
5
votes
2answers
169 views

Latex3 input/output and expansion of macros

I have a package that formats a course outline and have a macro that reads a formatted user file and turns it into a section. \documentclass{article} \usepackage{xparse} \ExplSyntaxOn \tl_new:N ...
5
votes
2answers
143 views

Color Management with a Family of Curves

I am struggling with following fairly simple looking problem of plotting a family of curves. \documentclass[border=1mm]{standalone} \usepackage{pgfplotstable} \pgfplotsset{compat=1.8} ...
5
votes
2answers
102 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 ...
5
votes
2answers
216 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} ...
5
votes
2answers
65 views

Comparing the arguments passed to a macro

I want to write a command which makes a norm of a vector, with following syntax: \xnorm{v}. I want the norm delimiters to adapt to the size of the expression contained in \xnorm{}, BUT I want also an ...
5
votes
1answer
109 views

How can I define a macro with literal square brackets in the body?

The following macro works correctly for enclosing an expression in parenthesis. \def\group#1{\left ( #1 \right )} I want to write the equivalent macro for enclosing an expression in square ...
5
votes
3answers
135 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
250 views

\@startsection, hyperref and newunicodechar; protection needed?

When working with custom defined environments using \@startsection I found, after switching to newunicodechar for defining my unicode characters, that the sectioning headings give this peculiar ...
5
votes
1answer
85 views

String lowercase equality (newbie question)

i'd like to test if a string, once transformed into lowercase is equal to a given string. Here a MWE of what i'm talking about : \documentclass[a4paper,10pt]{report} \usepackage[francais]{babel} ...
5
votes
1answer
182 views

Print the counter given as an argument

I have a counterA and a counterB. I want to define a command \PrintCounter, which gets either A or B as argument, and then prints the value of the corresponding counter. I wrote the following code: ...
5
votes
1answer
587 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 ...
5
votes
1answer
52 views

Using xstring macros in edef

I've tried to use \protect to make the following \edef work but no luck. Can it be done somehow? \documentclass{article} \usepackage{xstring} \begin{document} \def\abc{a,b,c} ...
5
votes
1answer
69 views

newsavebox named after counter

I am trying to write a macro creting automatically a certain number of saveboxes. Therefore I would like to use the concatination of the value of a string and a counter to name the saveboxes. I tried ...
5
votes
2answers
328 views

Expand command and put result into a macro: Use of \value doesn't match its definition

I still struggle with the expansion of Latex. I try to calculate the a real number from a date format and put this into a macro \value. I need to expand the command with \edef because I plan to use ...
5
votes
1answer
738 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 ...
5
votes
2answers
71 views

How to get character code defined with \let (! Improper alphabetic constant)

Here's a example with the "! Improper alphabetic constant" error: %% this is ok \newcount\mychar \mychar=\number`a\relax \showthe a % shows You can't use `the letter a' after \the ...
5
votes
1answer
395 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 ...
5
votes
1answer
18 views

Selectively apply \global to some tokens set via an \input file

This should be simple, but I can't quite guess the correct combination of \expandafter needed. The value of \MyTokenGlobal should not be changed via the \input, but the value of \MyTokenLocal should ...
5
votes
1answer
79 views

\begingroup, \endgroup expansion problem “Undefined control sequence.”

I just created an answer that uses a temporary variable with \write\@auxout and thought it would be good idea to scope with \begingroup, \endgroup. For some Reason this results in: ! Undefined ...
5
votes
1answer
56 views

Clarification about how TeX/LaTeX decides it's fully read in a number

I started off a bit confused about how \romannumeral works. Then I tried several experiments testing various ways of incorportating numbers into LaTeX and got even more confused. The following table ...
5
votes
1answer
117 views

Capitalization of datetime format

In languages like dutch, the first letter of the names of days and months are not capitalized unless they occur as the first character of a sentence. So I added the following code in the preamble of ...
5
votes
1answer
103 views

Amsmath and tikz - conflict?

I have a problem with: \documentclass{minimal} \usepackage[T1]{fontenc} \usepackage[french]{babel} \usepackage{amsmath} \usepackage{tikz} \begin{document} \pgfmathparse{ifthenelse(1<0, ...
5
votes
1answer
268 views

How to use macros in command \dirtree of package dirtree?

I want to print a tree structure and started using the package dirtree (v0.32, see Making a (simple) directory tree). Following calls work smooth: \dirtree{.1 root. .2 child1. .2 child2. .3 ...
5
votes
1answer
192 views

Use macro to draw inside pgfplot/axis

I would like to implement a gantt chart function inside pgfplots. To draw the tasks, I have a macro that calculates the start and finish time of a task. However, when I use multiple tasks, the values ...
5
votes
2answers
244 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}{ , ...
5
votes
2answers
390 views

Using \input vs. \scantokens in section title (with package hyperref)

I meet the following issue when trying to use \scantokens in section titles, together with the hyperref package (whithout this package, all is fine). \protect\input... can appear in a section title. ...
5
votes
1answer
108 views

“Flatten” macros prior to sharing LaTeX file

Is there a way/an existing tool to process a LaTeX source document such that for a given list of macro definitions (using \newcommand), calls to those macros are replaced by their expanded version? ...
5
votes
1answer
314 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} ...
4
votes
4answers
213 views

How to repeat text

I get interesting errors with the following macro. Mostly it works, but I get extra spaces after \noindent (but not after \newline). I tried using \loop or \whiledo (from ifthen) but get stack ...
4
votes
2answers
260 views

Define command either with or without \csname

I'm trying to do the same as this one, but with \def, \gdef or \xdef instead. Very quick summary of the other question: I wanted to print the command (not the contents of the command) regardless of ...
4
votes
2answers
187 views

Some misunderstanding about macro expansion

I have the following code which doesn't work: \documentclass[12pt]{article} \tracingcommands=2 \tracingmacros=2 \tracingall \makeatletter \let\sep\relax \def\put@stack@#1#2{\edef#2{#1\sep#2}} ...
4
votes
2answers
93 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 ...
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
3answers
130 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: ...
4
votes
2answers
79 views

expl3: \cs_generate_variant broke with the last update: undefined control sequence \::T [closed]

The last expl3 update broke my "continue" detection for the index. Here is a MWE: (EDIT: I realized it is possible to reduce it even further) \documentclass{minimal} \usepackage{expl3,xparse} ...
4
votes
2answers
118 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 ...
4
votes
2answers
44 views

How to write \StrGobbleLeft output to an external file?

I have not learnt how the TeX expansion works behind the scene. Shortly speaking, how to write \StrGobbleLeft output to an external file? \documentclass{article} \usepackage{filecontents} ...
4
votes
2answers
323 views

expand macro in single byte encoded code

In this minimal (not) working example, I try to use single-byte latin10-encoded source file, and expand a command-macro containing a character with \catcode254: % -*- mode: latex; unibyte: t; ...
4
votes
3answers
192 views

Using a macro evaluating to a set of xkeyval arguments as argument to another command

I am trying to code a macro that adds xkeyval arguments contained in a macro to a list of default xkeyval arguments. The following minimal example explains better what I want to do. ...
4
votes
2answers
108 views

Concatenate macro with string

I try to expand a macro containing a string with another string. It is in the document and thus I want to avoid using @. I tried the following using etoolbox ...
4
votes
2answers
63 views

How to deal with macro expansion and 'TeX capacity exceeded' when using write18?

this thing is driving me nuts. ever since the friendly and knowledgeable people here on tex SE have guided me to doing multiple string replacements the proper way, i've been trying to incorporate that ...
4
votes
3answers
233 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 ...
4
votes
2answers
74 views

Creating a new array column type dynamically

I am evaluating toks registers for various uses - they are still fairly new to me. I'm using them to construct a table column-wise. During this, I have come across an issue I have failed to find a ...
4
votes
1answer
59 views

Can I expand a macro argument once without using a scratch register?

I'm still trying to get my head around how expansion works in TeX. One thing I can't figure out is how to expand a macro argument once without having to use a scratch register as an intermediate. As ...