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
0
votes
0answers
30 views

Writing to custom ouput file with lualatex: Hook to start of the writing process and substitute not-fully expandable macros

I am working on writing document with informations, that are at the end of each part summarized in summary. To prevent writing them twice, I am using datatool to create "buffers" in runtime, from ...
0
votes
1answer
21 views

Storing my 'standard float alignment' in a macro

While writing a few macros to wrap around float environments, I stumbled upon failure of macro-expansion (at least I think so) when it comes to storing float specifiers. main.tex: \documentclass{...
1
vote
1answer
55 views

TeX Conditional in Lua

Why can I use \startluacode context.mymacro("\noexpand\\iftrue") \stopluacode But not \startluacode context.mymacro([[\noexpand\iftrue]]) \stopluacode Or not \startluacode context.mymacro([[\...
3
votes
2answers
100 views

Checking a function's expansion against a string

I have a function \Foo that I test against what I think it should expand to for given arguments. Two problems: 1/ I can't 'log' the fully expanded version of \Foo{arg}. 2/ even when the expansion ...
0
votes
1answer
56 views

Expansion problem when redefining some footnote fonctions

I am currently trying to redefine some aspect of the footnote, footnotemark and footnotetext command to allow the use of these command in diverses situation (like in float) with things like hyperlink ...
2
votes
2answers
36 views

I want to load data from a file and use it in a figure caption. I have a solution that works in some environments

I want to load data from a file and use it in a figure caption. Found this code (that I've modified slightly to demonstrate it's limitations) which does exactly what I want it to do when it works, for ...
5
votes
2answers
175 views

Macro argument expansion and edef

I created a macro to recognize between two patterns #1 - #2 or #1 - #2 - #3 and assure an output on the form # - # - # (for dates). \def\cal@ymd#1:#2:#3:{#1-#2-#3} \def\cal@md#1:#2:#3:{\cal@Year-#...
2
votes
1answer
43 views

When do curly braces disappear in macro definitions? (e.g. \documentclass expansion)

I've been looking into how \documentclass and friends are actually defined, and I noticed something peculiar which I'd like to understand. Let's say I have \documentclass[11pt, titlepage]{article}. ...
2
votes
1answer
32 views

Controlled expansion applied to l3prop

In the example below, Hook 1 and Hook 4 compile, not Hook 2 and Hook 3. Why? \documentclass{report} \usepackage{xparse} \ExplSyntaxOn \prop_set_from_keyval:Nn \__erw_foo_prop{key=a} \cs_set:Nn \...
0
votes
1answer
17 views

Index entry with nameref content leads to emergency stop

Good evening, everybody. After having read lots of your formidable Q&A's (thank you for the insights) I am struggling hard with this problem and would like to pose a question: What I intend to do ...
3
votes
1answer
63 views

Lualatex luaescapestring and variable expansion

I am trying to write the contents of \foo to a file using LuaLatex. Consider the following example: \newcommand{\abcd}{test} \newcommand{\foo}{XXX \abcd} \directlua{ local f = {} f.foo = token....
3
votes
3answers
121 views

Expanding a parameter token argument to \g@addto@macro

Consider the following example. By default \g@addto@macro doesn't expand its arguments, which can have unexpected results when passing a macro as an argument, if the macro value is changed later. ...
0
votes
2answers
100 views

Pass and run a TeX macro from Lua

\starttext \startluacode userdata = userdata or {} function userdata.simple(c) context("\\%s{%s}{%s}",c,1,4) context.par() context[c](1,4) end \stopluacode \...
0
votes
0answers
35 views

What is * doing for these commands and how to replicate?

I'm trying to get a project's root folder path for usage later on in the preamble. My latex knowledge is... limited... but I've gotten a solution working using a combination of the currfile, and ...
8
votes
4answers
162 views

How to safely check by means of expansion-methods whether a list of tokens contains a token which is defined in terms of \outer?

I take the following question for a moot thing. Nonetheless it makes me sick that I don't see a good and robust solution myself. ;-) Assume something like this: \def\unfold{\umbrella My bald head ...
0
votes
1answer
33 views

fp and macro question

I try to feed macros doing FP calculations into other macros doing the same, and face problems with macro expansion. The usual "protect" trick didn't work for me. Any hints? An example is below. \...
0
votes
1answer
69 views

Why does \ifdim work here but \if doesn't?

I'm very new to LaTeX, and need to compare a length I've defined with a default value (and set another length accordingly). Consequently, I'm exploring the murky (to me anyway) world of LaTeX ...
0
votes
1answer
42 views

Metapost: replace variables with values before being consumed by a macro

I am trying to use the metaflow macro set for metapost. It and its documentation can be obtained from: https://personal.utdallas.edu/~hamlen/projects.html The relevant definition that I'm having ...
3
votes
2answers
72 views

\tl_set:Nf deletes beginning spaces in its #2

In syntax \tl_set:Nf <tl var> {<tokens>} if <tokens> begins with a space (input as ~), then this space does not appear in the definition of <tl var>. If a space appears in ...
5
votes
3answers
290 views

Dynamic variable name gets overwritten

I'm writing a class and thus storing a bunch of data into variables. Those variable needs to be access, and rely on a counter value. However, when accessing the values of previously-defined variable, ...
0
votes
2answers
35 views

construct \externaldocument command's argument for programmable cross referencing

My ver12.tex and ver12_SM.tex documents cross reference each other using the xr package. How could I program them such that when going over to ver13 the two \externaldocument commands do their job ...
0
votes
1answer
36 views

Bind a label to newwatermark / refactoring macros defined with newcommand

I trying to make a kind of a refactor of, and added feature to, newwatermark (and siblings). That feature is binding a label to the watermark, such that the page on which it is applied is ...
1
vote
1answer
27 views

Removing leading comma of a comma separated list generated by a macro

The goal of the program below is to apply certain modification to the values of certain keys within a cs list. It works fine, except for removing the leading comma. Try with/out lines A and B. \...
5
votes
1answer
80 views

Purpose of \expandafter in a particular macro

Consider the following set of definitions... \documentclass[12pt]{article} \def\foreach{% \begingroup \catcode`\^^M=12 \xforeach} {\catcode`\^^M=12 \gdef\xforeach #1^^M{% \first #1,,\...
3
votes
4answers
185 views

Prevent hash doubling with \message

Assume a token sequence: Token 1: Explicit hash character of category code 6. Token 2: Explicit 1 of category code 12. Token 3: Explicit hash character of category code 6. Token 4: Control word token ...
1
vote
2answers
62 views

Why parameter whose tokens are being iterated through should be ended with a non-empty macro, and what should that macro actually contain?

I've asked this question more than once here, but all I could get is that "it's safer" to use a non-empty macro. I was never told why, and (more importantly) it was never clarified what exactly the ...
0
votes
2answers
54 views

Expand variable name before writing to aux file

How can I have a variable in variable name while writing to aux file in the answer on this link: https://tex.stackexchange.com/a/416272/192717 For example, from the above link: \edef\mysuffix{...
1
vote
1answer
27 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
315 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
242 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
44 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
73 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
123 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
473 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
310 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
83 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
30 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
76 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
33 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
253 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
46 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
42 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
38 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
55 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
242 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
89 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
67 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
78 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
68 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 ...

1
2 3 4 5
17