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

learn more… | top users | synonyms

55
votes
4answers
2k views

What is “expansion”?

I'm relatively new to (La)TeX, but I have a reasonable amount of experience with computational programming languages. Until I began learning (La)TeX, I'd never heard of "expansion"... So, what is ...
6
votes
3answers
373 views

Expansion? dirty tricks?

Consider \documentclass{article} \usepackage{titlesec} \def\bl#1 #2 {#1\textsuperscript{#2}\,} \titleformat{\section}[runin]{}{}{0pt}{}[. ] %\titleformat{\section}[runin]{}{}{0pt}{\bl}[. ] ...
3
votes
0answers
23 views

\ThisStyle \SavedStyle painfully slow … alternatives?

While working with customised hat glyphs using the first version of this solution, pdflatex started taking a long time compiling a document. That linked answer notes that it's a slower solution, but ...
4
votes
4answers
155 views

Expandable macro with loops and advanced string functions?

This might be a very basic problem (as a follow-up to this question) but I cannot figure out how to do it: I need a macro \mycmd{sometext} that yields a string depending on the first character of its ...
5
votes
1answer
62 views

How can I use a tl variable in TikZ options

Im setting up a command with some options via l3keys. One of the options is tikz-options and it should take a list of TikZ options and pass them to a {tikzpicture}. \documentclass{article} ...
4
votes
4answers
181 views

Identifying and writing the font size

I am trying to identify whether the current font size is small. So here is a MWE of what I am trying to do \documentclass{article} \usepackage{ifthen} \begin{document} \makeatletter ...
5
votes
3answers
151 views

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

I would like to generate an automatic 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 ...
3
votes
2answers
71 views

Using redefined \c and Turkish characters in citation

I once redefined the command \c since I need a shortcut for some formula that I use quite frequently. Unfortunately, I now need to cite a turkish author that has a \c{C} in his name. So, what I did is ...
2
votes
0answers
21 views

How to make \tl_upper_case:n in section's argument bookmark compliant?

Thanks to recent revision of the coverage of UTF-8 input for pdfTeX and accents with the expl3 (see updated answer of http://tex.stackexchange.com/a/286703/18401), the following code works nicely: ...
3
votes
1answer
104 views

How can I expand the font size within a heading (section, subsection, etc.)?

I'd like to make a list of headings with their font sizes: I envision something like the following: \documentclass{article} \begin{document} \section{{\textbackslash}section \makeatletter\f@size ...
2
votes
1answer
95 views

Need help with macro-driven tables and expantion

This is a project I have been working on for a while now and I am stuck on implementing this new function, cell coloring. My function works by taking in an unknown amount of data called 'weapons' and ...
1
vote
0answers
28 views

Expansion control in “isEmpty” condition

There is a known method of testing if an argument is empty or not. \def\isEmpty#1{% \if\relax\detokenize{#1}\relax empty% \else NOT empty% \fi } I used this trick to ...
4
votes
2answers
78 views

How to force-expand a \def for \in@?

Take the following code as an example: \documentclass{standalone} \def\myvar{foobar} \begin{document} \makeatletter \in@{foo}{foobar}\ifin@ Yes\else No\fi, \in@{foo}{\myvar}\ifin@ Yes\else No\fi ...
4
votes
1answer
56 views

How to make \tl_upper_case:n applied to diacritics work in section argument?

The LaTeX3 Interfaces' documentation claims, page 224: In package mode, the case change system will also convert text stored using the LaTeX 2ε “LICR” approach. This will upper/lower case tokens ...
24
votes
2answers
3k views

What does \begingroup\expandafter…\endgroup do?

I often see code of the following form in package implementations (this example is from the LaTeX3 sources): \begingroup\expandafter\expandafter\expandafter\endgroup \expandafter\ifx\csname ...
9
votes
3answers
119 views

Problems getting \expandafter\<controlsequence>\endgroup to work as expected

I have a scenario where I'm testing for a condition within a group which will then trigger inputting a corresponding outside file. The problem is that the outside file may contain control sequences ...
5
votes
2answers
60 views

\lowercase with \IfSubStr and \StrDel

I'm trying convert an argument to lowercase, strip out the spaces, and then search for the resulting string in a list. Thus far, I've had no luck. Here's the code I would instinctively expect to ...
9
votes
3answers
585 views

Command that changes its definition the nth time it's used

I need a command to behave differently the first time than the next times it's called. Right now I use \newcommand\foo{First\gdef\foo{Next}}, that is, it redefines itself the first time. Moreover, I ...
5
votes
2answers
65 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}|} ...
21
votes
2answers
222 views

\( \) don't work with TOC?

If I write this line of code \subsection{Ranger \( n \) boules distinguables dans \( M \) boîtes} I obtain an error over the second \) (./Probabilité.toc ./Probabilité.toc:8: LaTeX Error: Bad ...
4
votes
2answers
76 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 ...
4
votes
2answers
104 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 ...
3
votes
1answer
17 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}{% ...
6
votes
3answers
195 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 ...
8
votes
2answers
223 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} ...
10
votes
2answers
138 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\\} ...
25
votes
4answers
460 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 ...
9
votes
1answer
152 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
45 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" ...
3
votes
1answer
59 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. ...
1
vote
1answer
60 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
55 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
19 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 ...
4
votes
1answer
47 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
125 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
134 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
39 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
74 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 ...
3
votes
2answers
101 views

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

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 ...
10
votes
1answer
2k 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 ...
6
votes
3answers
122 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
0answers
51 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 ...
12
votes
4answers
248 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 ...
0
votes
0answers
100 views

Ignoring parts of text inside macro

Consider the following code: \documentclass{book} \usepackage{pgffor} \begin{document} \newcommand\containers{ \cont{aaa{\bf don't xstring me}aaa} \cont{bbb\large bbb} ...
2
votes
1answer
25 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
34 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} ...
5
votes
1answer
161 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. ...
6
votes
2answers
86 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} % ...
1
vote
3answers
128 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% } ...