Questions tagged [expansion]

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

Filter by
Sorted by
Tagged with
1
vote
1answer
23 views

Immediately expand \thepage (custom TOC)

I want to define a command to add a line to a TOC with the page number where the command is called. The first try was: \def\mytoc{} \def\addlinetomytoc#1{ \g@addto@macro\mytoc{ #1\dotfill\...
5
votes
2answers
258 views

Microtype expansion gets disabled when fontsize is changed! (lualatex)

It seems like microtype's expansion gets disabled when fontsize is changed from default fontsize. Here are two pieces of code, in the first one expansion does work, in the second one it does not (as ...
5
votes
1answer
173 views

Question about exercise 21.10 in The TeXbook

This exercise asks how to store expansion of \chapno at the moment when \write is processed, but \the\count0 must be expanded at the moment of \shipout. Here is a full example: \def\chapno{5} \...
2
votes
1answer
33 views

Why can't the name of a `totcounter` be defined with a variable

I want to print the sum of some counter per subject at the beginning of that subject and I want it to be done automatically. I decided to use the totcount-package. I then define a counter like: \...
1
vote
3answers
60 views

\def, math, and order of operations, expansion?

I have what looks like a simple task but I cannot seem to get it to work. take the following: \def\varlength{1in}%has units \def\varscalar{0.2}%does not have units \raisebox{\varscalar\varlength}[...
4
votes
3answers
98 views

How to iterate through a token list to make characters uppercase, while preserving spaces?

The following (classical, I assume) "iterator" definition would be examined here: \def\zEnd{\zEnd} \def\zzIterator#1{% \ifx#1\zEnd \else #1% \expandafter\zzIterator \fi } \...
4
votes
3answers
401 views

How to capitalize letter (using \uppercase) that has been assigned to \let (or to \def)?

I don't seem to be able to capitalize a letter that has been assigned to \let. \let\zTest=t \uppercase{\zTest} % still small ADDENDUM: I've tried \def\zTest{t} just now and it didn't work either (...
10
votes
4answers
267 views

Conversion of space characters into space tokens

I'm trying to understand how the input, the expansion, and the execution processors work together. Running TeX on \def\foo#1{(#1)\baz}% \def\baz{baz}% \foo{bla} Bar \bye yields "(bla)baz Bar" with a ...
0
votes
1answer
44 views

What `\cs_new_protected` and `\cs_generate_variant` do?

After my question Undefined control sequence while adding a new parameter to a existing \ExplSyntaxOn code, I trying to fully understand the code behind it. So far, so good, with: The expl3 package ...
2
votes
1answer
26 views

How to pass custom commands to LetLtxMacro?

I think it's fairly common to redefine macros. And I'm creating two functions to help storing and restoring these redefined macros. And so I tried using the following: \documentclass{article} \...
1
vote
1answer
67 views

Writing expanded macro with space to file

I'm trying to write an expanded macro to a file without the expansion eating the space after it. I could replace the {} empty group with an explicit \space, but I want this to be fairly robust. Is ...
2
votes
1answer
29 views

Build a shortcut for string to be used as an argument later

I need to pass the result of a macro as a string to another macro (I'm using xparse). Here is a minimum working example: \documentclass{minimal} \usepackage{xparse} \NewDocumentCommand{\...
6
votes
3answers
234 views

Questions about `\cs_new:…` and friends and their TeX relatives regarding global, local, long, nopar, protected, expandable and naming

This question is two-fold. Unfortunately, one side is opinionated, i.e. something to close-vote, so I put that part at the end and hope no one notices... The other side (coming first) are serious ...
0
votes
0answers
12 views

How to use macro as a `foreach` range? [duplicate]

These two loops do not produce the same result: \documentclass{article} \usepackage{tikz} \begin{document} \foreach \i in {a,b,c} {% \i+ } \def\Index{a,b,c} \foreach \i in {\Index} {% \i+ ...
0
votes
0answers
33 views

Expanding user defined macros for compatibility

I have an annoying reoccurring problem. I often use user-defined macros with for example \newcommand in my LaTeX code. I also use LaTeX a lot in for example Jupyter Notebooks. Often Some things render ...
0
votes
1answer
30 views

Math in lwarp (via controlled expansion?)

Here is the issue I am thinking about, and some possible approaches. When writing a latex/html document using lwarp, the math code is left embedded directly into the resulting HTML file and left up to ...
2
votes
1answer
33 views

Why does an index entry generated from a listings' token preceeding a comma get rejected?

I'm trying to index the tokens in a listing, but they always get rejected if they are followed by a comma. Here's mwe.tex: \documentclass{article} \usepackage{listings} \lstset{index={foobar}} \...
1
vote
1answer
49 views

Using xstring to generate index keys

I have a document containing many instances of an environment with a mandatory argument providing a short "tag." These tags are something like "M04", and I've written a macro using xstring which ...
7
votes
2answers
226 views

How to have hashes doubled _and_ things expanded?

I'd like to learn some TeX programming technique which I can always apply for handling the same type of situation: The code \newtoks\mytokenregister \def\five{\four5} \def\four{\three4} \def\three{\...
1
vote
0answers
88 views

String check against a sage command, issue of expansion order? [closed]

I am trying to write a macro to do a conditional check against two strings. The problem I'm having is that I want to check the output of a \sage command and do a string comparison without expanding ...
5
votes
1answer
62 views

How can I use \expandafter the expand the definition of this control sequence?

I define a command \test that does nothing but define a control sequence \c[count], where [count] is the current text value of the counter count at the time \test is executed. I want \c[count] to ...
0
votes
1answer
76 views

Is there a command, macro or tool that can get the string result (as in other languages) of any macro in an easy to use way? [closed]

I don't want to go down into the depths of expandable and not expandable. I doubt that I will be able to understand my self-developed designs a few weeks later. Therefore I am looking for a universal ...
2
votes
2answers
57 views

How to pass the contents of a newcommand to answers package?

I've got the following code, which uses the exam document class and the answers package. I'd like to pass the point value of the question into a separate file so that I can make use of the question's ...
8
votes
3answers
332 views

Is there a way to retrieve the “source code” and the argument pattern from a macro for reuse (i.e. what \show shows)?

I want to concatenate the “source code” of two macros which share the same argument signature. How do I grab (i.e. expand once) the macro without TeX searching for the arguments which the macro ...
0
votes
0answers
61 views

ConTeXt: Cross reference expansion and processing with Lua

I want to process cross-references in ConTeXt/LuaTeX, that is, to do some calculations in Lua with the page and line numbers returned by the \at and \inlinerange commands. But this does not work, as ...
0
votes
1answer
26 views

define \label and \ref with shortcuts

Is there a way define \label and \pageref with shortcuts depending of context. In the mwe neither work. \documentclass[a4paper]{article} \newcommand\phasevie[2]{\section{#1-#2}\def\cod{#2}} \...
2
votes
1answer
31 views

Defining a command with star argument to be used in pdf strings (e.g. via \section)

I want to define a command with an optional star argument and be able to use it inside pdf strings, e.g. via \section. With the MWE below, I get a Token not allowed in a PDF string warning and \foo is ...
3
votes
2answers
64 views

Expand \def in \write18

I have defined the following command: \newcommand{\formatcommand}[1]{ \def\temp{#1} \def\s{\ifx\temp\empty empty\else not empty\fi} echo "\s" } This works correctly: \formatcommand{} \...
0
votes
1answer
50 views

Expandable contact information

Introduction I am sorry for the long MWE, but I was not able to make it shorter and still illustrate my problem. Again I am working on streamlining the creation of exams for my university. In the ...
1
vote
2answers
46 views

How can I avoid to copy and paste this code (similar newcommand definitions using different functions) :

I've been improving my code thanks to you guys, but this still looks improvable as it looks like an ugly copy/paste : \newcommand*{\LegendFlecheInf}[5]{ \coordinate (C2) at (axis cs:#2, { \...
0
votes
1answer
49 views

How to define a macro with digits in its name using \def and a counter value?

I need a \def whose name involves a number, with that number being value of a counter. \documentclass[varwidth,border=5mm]{standalone} \begin{document} % COUNTER \newcounter{myC} \addtocounter{myC}{...
6
votes
2answers
334 views

Issue with Expansions of Nested Macros

I am trying to incorporate membership checking macros by marmot and Phelype Oleinik (thanks to both of them for their neat solutions) into an argument of another macro: \singleBox{\...
1
vote
1answer
41 views

Problem with expansion in xparse

I am trying to use function from this answer \documentclass{article} \usepackage{xparse} \ExplSyntaxOn \NewExpandableDocumentCommand{\switchcondition}{ O{string} m m m } { \use:c { ...
0
votes
0answers
37 views

Writing into a file, strange behavior with expansion

I want to write some data into a file, but I need to replace a subtring in these data beforehand. For some reason, the expansion through the \write macro does not give the expected result. Instead, a ...
2
votes
1answer
67 views

\protect'ing a token list

To prevent expansion of a macro in expansion contexts we can define the macro as \protected. I'm wondering if there's a way to do the same for an arbitrary token list. So is it possible to define a ...
0
votes
1answer
56 views

Passing arguments using pgfkeys to a macro for including PDF files, using pdfpages

This is a slightly simplified version of a macro I've been writing (using pgfkeys and pdfpages) to include PDF files. This seems to be working. I ran into one bump. includepdf does not like it when ...
4
votes
2answers
127 views

pgfkeys: .store in constructed macro

I'm trying to store a value in a macro that is constructed from the arguments of another macro, but I must be missing something because the macro is not created. MWE: \documentclass{article} \...
4
votes
3answers
117 views

fully expand toks and save for later (appendix with exact copies of tables from the main text)

I have a document with some complex tables, defined by a command called \Rule with named parameters (using the keyval package). The individual rows of the table are first stored into a token list ...
1
vote
1answer
68 views

Is \scalebox guaranteed to fully expand its first two arguments?

In this answer, I've been conservative and used the following code: \expandafter\scalebox\expandafter{\my@scale}{\usebox{\my@box}} to make sure not to rely on undocumented (?) behavior of \scalebox ...
5
votes
1answer
65 views

Why is \unexpanded not respected after an \if?

I was surprised to find that the argument of an \unexpanded is expanded if the \unexpanded is within the first two tokens after an \if. Using Knuth TeX's \noexpand instead works but I am curious where ...
3
votes
2answers
79 views

Expansion of an optional parameter for an environment

I want to define a custom environment, which takes an optional parameter, and I want be able to link to the environment using nameref. To this end, I tried something similar to the following MWE: \...
1
vote
1answer
42 views

Expanding a command when assigning values to an array

I'll explain what I mean with an example. \documentclass{article} \usepackage{arrayjobx} \newcounter{foo} \setcounter{foo}{0} \renewcommand{\bar}{\addtocounter{foo}{1}Some text} \newarray\baz % ------...
3
votes
0answers
110 views

How do use {<setup>} in \tl_set_rescan:Nnn to replace \scantokens?

This question is related to (Changing escape character in \tl_set_rescan:Nnn) and (https://tex.stackexchange.com/a/496258/7832) but is not the same. I've tried to change this: \exp_args:NNx \...
0
votes
3answers
75 views

Package soul underline problem with macro text

I have been slowly learning LaTeX over the past few years. I have been mostly successful in these efforts. Recently, I stumbled across a problem, I know is probably quite simple to fix, but it has me ...
2
votes
2answers
69 views

Definition-time expansiton of command line input

I'm trying to make the following code work correctly. I'm using command line call to python to check whether a number is in a list (no clue how to do this in pure LaTeX(?)). I then want to check ...
1
vote
1answer
127 views

How do you compact a code that expands \macro and store it in an expl3 sequence?

I'm trying to rewrite some of the codes I have by following the correct expl3 rules. With the following code I define the scontents environment that encapsulates the filecontentsdefmacro environment ...
0
votes
1answer
48 views

newcommand counter expansion problem

I am trying to write a macro to support producing a sequence of storyboards for an appendix in a two column IEEE paper. Can the value of a counter be expanded immediately for a macro? Currently the ...
2
votes
3answers
171 views

Expand command in an argument before the main command

Related to my problem for xsim here. I want to use commands \ExOption and \ExPart to implement more easily my collection in xsim package. But i'm facing the problem that my commands do not expand in \...
10
votes
1answer
121 views

\ifnum expanding too much - what is happening?

Consider the following example: \documentclass{article} \makeatletter \newcommand\fail[1]{% \ifnum1=#1% <- here a space is missing \expandafter \@firstoftwo \else \...
5
votes
3answers
132 views

Indirectly defined macros: Undefined macro with “@” does not trigger compile error

I defined two macros \newfoo{#1}{#2} and \foo{#1}. The first parameter is used as a key and must be a valid LaTeX macro name (without the backslash). The second parameter is a short piece of text. ...