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
1 answer
34 views

Dynamic tabular preamble string

I would like to provide a wrapper around tabularx in way to let users define the overall content alignment without defining tabular border style. Something along lines below. Users can still define ...
Agodie A's user avatar
3 votes
1 answer
50 views

Test if "name" key of label is empty

I'd like to test if the "name" key attached to a label when nameref is loaded is empty. The value can be retrieved expandably with refcount's \getrefbykeydefault and tested as follows. \...
mbert's user avatar
  • 3,460
3 votes
4 answers
120 views

How to pass a \def coordinate to macros

I am trying to pass a \def coordinate to a macro and got an error. Below is the code. The macro with direct passing works, but the two commented out lines don't. \documentclass[border=1cm]{standalone} ...
Leon Chang's user avatar
0 votes
3 answers
59 views

Defining a command that applies an inline function to each element in a list and saves the result to multiple commads

I would like to modify/extend a collection of pre-existing macros with an inline code that the user provides as an argument. Consider we have multiple variables, for instance: \def\mon{Monday} \def\...
user3250177's user avatar
1 vote
1 answer
62 views

Expanding an xparse \NewDocumentCommand before \bar

I would like vector variables to be bold faced, and scalar variables to be in plain font. The components of vector variables should then follow the scalar (nonbold) convention. To this end, using the ...
AndreasT's user avatar
  • 815
0 votes
1 answer
23 views

How to \immediate\write multiple lines produced using \newline and \StrSubstitute

Why this does not work when the lines are produced using \newline (instead of ^^J) and \StrSubstitute as follows? Thanks \documentclass{article} \usepackage{xstring} \begin{document} \def\mystrings{\...
Krantz's user avatar
  • 159
1 vote
1 answer
56 views

Write pageref to a file

How to write \pageref to a file. I've tried also with and without \unexpanded\expandafter with no success. And with \immediate as well. I'd expect 19. But I get \pageref {mylabel} or \__cmd_start:...
wolfrevo's user avatar
  • 503
4 votes
1 answer
105 views

Count number of occurrences of a character in the content of a macro string output

How to generalize this macro to make it print the number of times the string occurs and allow arbitrary separator including blank space? Thanks. Outputs could be: 0 if FALSE; 1,2,3... number of times ...
Krantz's user avatar
  • 159
4 votes
1 answer
110 views

Understanding expansion in tblr environment

I'm trying to understand how tokens and expansion work in the context of the following problem. I'd like to create a tblr environment from the tabularray package via a command that does some of the ...
Yossarian's user avatar
1 vote
3 answers
127 views

Storing a series of tokens for later evaluation

Is it possible to expand the tokens in a string as though they were typed at that point in the source file? I'm trying to do something like this: \begin{vmatrix} \@for\tmpone:=a,b,c\do{% \def\...
karlh's user avatar
  • 456
2 votes
4 answers
295 views

`{` in the definition of a macro?

I know that using article to obtain chapters is idiotic, but the code to improve is long and depends on this. In the following code I define a new macro \Section*, but I must remove curly braces from ...
Przemysław Scherwentke's user avatar
5 votes
2 answers
98 views

Problem expanding math in arguments of en environment

I want to redefine by hand a "restatable" environment for theorems. I have to do so because for some obscure reason the jloganal class (for the Journal of Logic and Analysis) mess it up: ...
Quentin G's user avatar
11 votes
1 answer
610 views

How to create an active tilde in LaTeX 3

I have some LaTeX3 code that generates matrices and uses the hhline package internally. In LaTeX3 the ~ character is a special character, used for inserting spaces in strings, and using \c_tilde_str ...
314159265358979323's user avatar
6 votes
1 answer
84 views

Expansion in precompiled l3keys

I'm having some issues with expansion in precompiled l3keys. I'd like to define a command \NewThm{<name>}[<options>] that sets the displayed theorem name to be a titlecased version of the ...
mbert's user avatar
  • 3,460
3 votes
1 answer
113 views

Using lthooks to locally hook into command

Following a previous question of mine, as an exercise I'm trying to mimic the behavior of thmtools with amsthm using l3keys and lthooks. Now I am stuck on the hooks part. thmtools defines prehead, ...
mbert's user avatar
  • 3,460
0 votes
1 answer
50 views

Fully expand an argument of a newenvironment created with expl3

In this answer, I was provided with the following code that solves my original problem. \ExplSyntaxOn \NewDocumentEnvironment{withalignment}{m} { \begin{\vincent_alignment:n { #1 }} } { \end{\...
Vincent's user avatar
  • 4,703
4 votes
3 answers
152 views

Command gobbling extra letters not working when passed another command

On another topic, I was given the following command as an answer: it takes either a two letter font shape (sc, it...) or a full version (scshape, itshape...) to set the corresponding font shape. \...
Vincent's user avatar
  • 4,703
1 vote
3 answers
52 views

Expansion in stored csname of restatable theorem

Thinking about this question, I'd like to use thmtools' restatable environment to store theorems with a number in the csname. That way one can loop through them at the end of the document to restate ...
mbert's user avatar
  • 3,460
2 votes
0 answers
53 views

pgf key style with no argument, or how to avoid escaping hashes

I expect a user to write something like: \pgfkeys{ latex/.append style={ add to preamble={ \def\sayhello#1{Hello #1.} } }, } but this does not work, as #1 is understood as the first ...
tobiasBora's user avatar
  • 7,803
7 votes
2 answers
210 views

Expansion issues again

I seem to keep encountering the same issue. In my attempt to learn more about expansions I have written a program that starts with a sequence of 1s and then after each step increments it to generate a ...
Ted Black's user avatar
  • 453
2 votes
2 answers
66 views

Generating tensor expression with macro

I am trying to create a command that given a comma separated list of subscript indices, subscript values, superscript indices, superscript values and then name of the tensor generates the following ...
Ted Black's user avatar
  • 453
3 votes
2 answers
44 views

String expansion: spaces are removed

I have a LaTeX3 string containing something like Hello \macro, and I’d like to expand it into another string, so that if \macro is defined as Alice, then the resulting should be Hello Alice. I tried ...
tobiasBora's user avatar
  • 7,803
6 votes
1 answer
95 views

How can I disable shadows (and similar preaction/postaction effects) in TikZ or PGF?

Is there a general way to disable preactions/postactions in TikZ on which effects such as shadows depend? If not, is there a straightforward way to enable users to add options to an existing style so ...
cfr's user avatar
  • 194k
1 vote
0 answers
32 views

typesetting equations based on external text file gone wrong [duplicate]

This example reads n lines and prints them out as addition problems. $ cat equations.txt 8 1 2 3 4 5 9 6 7 13 18 7 25 34 66 100 94 21 115 0 31 31 27 18 45 84 51 135 64 9 73 $ cat equations.tex \...
tzr381's user avatar
  • 11
5 votes
4 answers
184 views

Trouble with nested macros containing ifnum

I have problems with macros containing ifnum. After using the command \noexpand one macro works fine, nesting two of them does not compile but causes the error message Extra \fi. \fi as in the ...
gschaaf's user avatar
  • 147
1 vote
2 answers
45 views

How to control expansion order to define variables from a prefix and a command?

The following is a command that does basic arithmetic with nine variables. \documentclass{article} \usepackage{xfp} \newcommand\functesta[9]{ \edef\myvara{#1} \edef\myvarb{#2} \edef\...
rdx73735's user avatar
0 votes
1 answer
62 views

Is it possible to define commands that accept different argument types?

This is actually a more general question, but since a MWE is almost universally called for, consider David Carlisle's code \documentclass{article} \usepackage{fontspec} \usepackage{nopageno} \...
Mike Pugh's user avatar
0 votes
1 answer
68 views

Convert key-value argument into \str_case comparison

This was the underlying motivation for a previous question of mine. However, after several hours of failure, I decide to ask this problem directly. The goal In order to support the four declensions ...
Jinwen's user avatar
  • 8,092
3 votes
2 answers
188 views

LaTeX3 how to use content/value of predefined command in token list/string?

First of all, I guess that will be a very easy answer for people who are experienced in expl3. But for me its new and I'm very willing to learn that stuff to understand Latex3 better. So I hope for ...
lukeflo's user avatar
  • 1,483
0 votes
1 answer
23 views

How to measure height of expected output from \listoffigures

I defined a new command \sectiontest{<text part>} to measure the height of a particular part of text in relation to the \textheight. If the height of the test part transcends half the textheight,...
lukeflo's user avatar
  • 1,483
0 votes
1 answer
125 views

Macro to define color within SetCell

I'm using a macro to build a table dynamically, but I can't manage to color the cell with SetCell dynamically using a counter. The colors are defined like color@1, color@2, ... and I'm using a counter ...
3isenHeim's user avatar
  • 2,097
2 votes
2 answers
168 views

How to use loop for creating defined number of newcommands counting authors

For my template I want to create possibility to define a number of authors and automatically create a respective number of variables/commands which save the name of any author and make it able to ...
lukeflo's user avatar
  • 1,483
11 votes
3 answers
479 views

\NewDocumentCommand vs \newcommand vs \NewExpandableDocumentCommand (to define a container for a text)

In his answer to a recent question of mine, @egreg advised \newcommand instead of \NewDocumentCommand to define a container for a text. And I'm aware of this (10 years old!) question where: Joseph ...
Denis Bitouzé's user avatar
0 votes
0 answers
76 views

Force full expansion of a token

I have an aliased verbatim command (specifically lstinline) e.g. \def\verbalias{\lstinline[morekeywords={thing}]} Next I have a few commands that I want to use both in text and in my verbatim command ...
AltF4's user avatar
  • 75
2 votes
1 answer
63 views

Missing endcsname when passing command to hypersetup

I'm trying to manually process a list of authors. The logic works in the document, but not it does not seem to work when I pass it to hypersetup. \documentclass{article} \usepackage{authblk} \...
dikdirk's user avatar
  • 73
1 vote
1 answer
55 views

xparse command optional argument in \uline{} error

Sorry, but I am so bad in English. I try my best to describe my problem. Here is an example \usepackage{ulem} \usepackage{xparse} \NewDocumentCommand{\test}{o m}{ % #1#2 } \begin{document} %\...
hua's user avatar
  • 13
4 votes
2 answers
61 views

Problem with macro expansion when making a custom queue container

I'm trying to make a simple queue using the etoolbox package by making my own custom macros \listfront and \listfrontpop. This is my very first time using TeX code to this level, so my understanding ...
daedsidog's user avatar
  • 154
1 vote
0 answers
45 views

How to define a colorbox command which can treat other user-defined commands in its argument?

I would like to highlight text including user-defined commands with linebreaks. I found a solution for linebreaks (Colorbox does not linebreak), but the \ctext{} command cannot treat other commands in ...
TobiR's user avatar
  • 574
3 votes
2 answers
78 views

How to pass the content of a macro to a command?

For the development of a class file I am trying to perform some basic checking on strings (which can contain latex commands). For this I use the tokcycle package. When I pass a string directly ...
jwbos's user avatar
  • 55
2 votes
1 answer
51 views

How to add rows to a table via a command

I'd like to do something very similar to this question here: Add Rows to Table With Macro However, I cannot get it to work with my case of a version log table created with the tabularray package and ...
MaxNoe's user avatar
  • 6,106
3 votes
0 answers
76 views

How to treat the output of a command as an "ordinary text"?

In the following example, how can I treat the output of \cite as it was a simple string of text? \documentclass{article} \usepackage[style=numeric-comp]{biblatex} \begin{filecontents*}{\jobname.bib} @...
CarLaTeX's user avatar
  • 61.3k
0 votes
1 answer
61 views

Expl3: Expansion of mappings over lists

The package xcolor can "prepare" color definitions in such a way that they're only loaded if they're actually needed, which may be indicated by a later call to e.g. \providecolors{<id-...
steve's user avatar
  • 2,060
1 vote
0 answers
39 views

understanding edef [duplicate]

My command \angles defined with \def will not give the same result. I would like to define this command with expansion at definition time, so using \edef. The MWE shows that \def only compiles, but \...
mathteacher's user avatar
2 votes
1 answer
53 views

How to use edef to defines an item from a l3 sequence?

I would like to defines one element from a list with \edef. I wrote the following MWE, which shows that only \def gives a result. However, as i use the result in many complex ways, \def is not an ...
mathteacher's user avatar
1 vote
1 answer
72 views

Find string in expl3 case function and store result in integer variable

If I pass a time zone (e.g. CEST) to the function \__mildate_parse_timezone:n, the function \__mildate_timezone_abbrev:n should find the associated time zone in UTC as an integer (for future ...
alexBer's user avatar
  • 33
0 votes
1 answer
59 views

Forcing numbering expansion before moving solutions in exam class to endnotes

I am trying to adapt the amazingly useful answer here and its followup here about how to occasionally display the solutions after each section and numbering them in exam documentclass. The last link ...
yPNia's user avatar
  • 15
6 votes
1 answer
124 views

Macro to create entries in tabularray in user defined environment

I need a macro to create entries (rows) in a table. As proposed here I was successfully using the environ package together with the tabu one. Since tabu is not maintained, I decided to switch to ...
Tobard's user avatar
  • 1,189
1 vote
0 answers
67 views

Expansion in latex3 within sub-command

Starting from here, I want a function that add a superscript depending on the number of elements passed as arguments. As depicted below. As you can see, when there already is a superscript in the set,...
NBur's user avatar
  • 4,066
4 votes
1 answer
120 views

Macro in `\section` names expand in context of `\nameref`

If I have a \section where its name includes a macro, if I try to reference that section via \nameref the included macro seems to be expanded at the point of the \nameref rather than the point of the \...
BCS's user avatar
  • 251
3 votes
1 answer
49 views

Scantokens and balanced text, what options exist for curly braces?

\scantokens takes balanced text as its argument, and braces have to be explicit, as far as I can tell. I'm puzzled by the following, where the first line is okay and the second line results in a &...
Dan Levin's user avatar
  • 351

1
2 3 4 5
22