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
2 answers
95 views

How to check that something starts with * (or how to build your own exercise sheet from a moodle database)

I would like to check if something starts with an asterisk (*) My attempt: \def\testast#1{\ifx*#1\relax YES\else NO\fi} But the output of \testast{*Word} is WordYES while I would expect just YES The ...
user avatar
0 votes
1 answer
30 views

How to check that the double expansion of something is empty?

I'm using the listofitems package, which produce a list whose elements are accessable by \LIST[n] but in the manual I read that I need a double expansion. In particular how do I chek that (the double ...
user avatar
0 votes
1 answer
38 views

Expand argument before using it

This question is my attempt to solve the main problem (MWE there). I realized that using macro \newcommand{\veca}{|_{\vec{a}}} next to \bigg is being treated as a single token, so those two queries ...
user avatar
  • 1,824
0 votes
1 answer
35 views

How to store current counter in collect file

I want to store the number of Exam in collect environment. The counter is alway store with final value. PLease help me correct my code with collect package. Thank you in advance! \documentclass{...
user avatar
3 votes
3 answers
78 views

Usage of \greadlist* from package 'listofitems'

I'm trying to define a LIST using \greadlist from the listofitems package. I would like to give a dynamic name to that list, something like LISTN, where N depends on a counter. I tried something like \...
user avatar
2 votes
3 answers
104 views

I need to expand a macro defined in listofitems package

I'm building an exercise database. The exercises are stored in the form \begin{Exer} Text of the exercice \item first answer \item* second answer \end{Exer} where the * denotes the correct ...
user avatar
1 vote
1 answer
60 views

Using a macro to pass parameters to a command

I am trying to pass some tags to the command \iftagged from the package tagging. See the MWE below. From what I understand, my macro \mytags does not get expanded. I found a lot of similar questions ...
user avatar
  • 129
2 votes
2 answers
48 views

Write definition of command with arguments to file [duplicate]

I am trying to create a command that can write command definitions into a file, while also defining them. So I want a command \teecommand that takes one argument. This argument should be written to a ...
user avatar
1 vote
0 answers
31 views

What is the right way of cascading styles using nested environments/macros, while each environment/macro might partially stylize its embedded content?

I have asked similar to this question before, but I think I have to describe it in another way. Need What is the right way of cascading styles using nested environments/macros (much like the way CSS ...
user avatar
  • 365
1 vote
0 answers
54 views

Can you map arbitrary token sequences expandably and unambiguously to numbers or to strings of explicit character tokens of category 12?

How to map arbitrary brace-balanced sequences of non-outer tokens expandably and unambiguously to numbers or to strings consisting exclusively of explicit character tokens of category 12, if possible ...
user avatar
  • 22.9k
5 votes
3 answers
316 views

LaTeX3 - Expand nested argument

MWE: \tl_set:Nn \l_tmpa_tl {a} \tl_set:Nn \l_tmpb_tl {\mathbf{\l_tmpa_tl}} \tl_set:Nn \l_tmpa_tl {b} \(\l_tmpb_tl\) The code snippet above actually produce \(\mathbf{b}\). What I want to achieve is ...
user avatar
9 votes
1 answer
119 views

Expl3 - \cs_generate_variant:Nn / \exp_args:N... - Which method is preferable under which conditions?

If you need arguments preprocessed/expanded before TeX passes them to a macro, you can do two things in expl3: Use \cs_generate_variant:Nn for generating a variant of the macro where the arguments ...
user avatar
  • 22.9k
1 vote
1 answer
32 views

Expanding glossaries abbreviations/acronyms in commands

I want to implement \usepackage{glossaries-extra} for handling abbreviations and auto-expanding them. I've also created a math command that makes use of an acronym and am having some difficulty ...
user avatar
  • 135
0 votes
0 answers
53 views

Make \exp_not:V and \exp_args:NV work for fp variables too?

In interface3 the description of \exp_not:V command is the following: \exp_not:V ⟨variable⟩ Recovers the content of the ⟨variable⟩, then prevents expansion of this material in x-type or e-type ...
user avatar
  • 7,604
3 votes
1 answer
58 views

How do I move a macro expansion outside of the current semi-group, without defining the macro globally?

I've written a macro \measureHbox{} which calculates the height and width of a breaking \hbox where the lines are separated with \breaks: \long\def\measureHbox#1{% \begingroup \def\break{\...
user avatar
  • 2,315
1 vote
1 answer
32 views

luatex: token.set_macro() issue

In the MWE below, I first define \command(A|B|C|D) which expands to \cmd(A|B|C|D) which all expand to THE COMMAND. None of these use \edef, so I should have no issue with defining \commandX first. But ...
user avatar
1 vote
1 answer
59 views

LaTeX3 expansion in a coffin box

I am stranded with my attempts to set up a coffin box, which expands some variables, which are typeset in it. EDIT Background info: I am trying to write a package, which will allow the user to write, ...
user avatar
  • 5,050
1 vote
1 answer
61 views

Upper-case programmatic data with expl3 in TeX Live 2019

I use the following expl3 code to upper-case the first character of a programmatic string. The code is from the body of a control sequence definition and is not supposed to be fully expandable. \...
user avatar
  • 1,017
1 vote
2 answers
74 views

Getting the absolute page number with zref and latex3

Within a larger project, I want to set a string equal to the current absolute page number, like this \documentclass[10pt]{article} \usepackage{zref-abspage} \usepackage{zref-user} \ExplSyntaxOn \...
user avatar
2 votes
1 answer
58 views

variable defined with a command (for exemple a random value) is not correctly stored in a lua list

I am writing random exercices for all students in a class, and i want to store the solutions to print them all at the end of the document (in final versions, each question will be printed in a ...
user avatar
4 votes
2 answers
148 views

Can we safely use o expansion when V expansion is not available?

For example \exp_args:Nxo is available but not \exp_args:NxV. Can we safely use the former instead of the latter?
user avatar
1 vote
0 answers
49 views

How to know what variant expl3 functions to provide in a package?

This question stems from a bug report to my package, pdfoverlay. The function in question is: \cs_new_protected:Nn \pdfoverlay_set_pdf:n { \file_if_exist:nTF { #1 } { \str_gset:Nn \...
user avatar
  • 23.6k
3 votes
1 answer
69 views

expl3 - Is it safe to apply f/o/e-type-expansion to argument in situations where the argument in question might be empty?

Is it safe to apply f-type-expansion or o-type-expansion or e-type-expansion to a macro-argument in situations where the argument in question might be empty or where expansion of the argument in ...
user avatar
  • 22.9k
1 vote
1 answer
71 views

How to write and expand \gls command to a text file?

Is it possible to expand the \gls command in order to print it's "output" in a text file? Here a 'MWE.tex' file content: \documentclass{article} \usepackage{glossaries-extra} \...
user avatar
3 votes
3 answers
248 views

How to reliably obtain a control sequence token which is undefined?

How to reliably obtain a control sequence token which is undefined in the current scope? E.g., is there a sequence of tokens ⟨stuff⟩ with which you can do \begingroup\expandafter\endgroup\expandafter\...
user avatar
  • 22.9k
0 votes
1 answer
88 views

LaTeX 3 / expl3 help understanding \cs:w and expansion order

I've been trying to learn the L3 programming layer while writing a simple package to set and use text "styles". The background is that I added key--value arguments to my class that are ...
user avatar
2 votes
2 answers
156 views

display full macro expansion

Intrigued by a strange question (how to produce a [La]TeX representation of a Texinfo source file, under the assumption that the Texinfo source file would yield somehow a lower level document in "...
user avatar
  • 3,983
2 votes
2 answers
51 views

fAlternate colors for tikz node frame

Initial Question I may be asking the wrong question, or phrasing it incorrectly, but here is my goal: I would like to have the color of a tikz rectangle alternate between 2 different colors. The ...
user avatar
  • 23
0 votes
0 answers
48 views

How to extract year from date in iso 8601 format?

I want to extract the year (or day or month) of a date which is stored as ISO 8601 in a database. My MWE looks like: \documentclass{article} \usepackage{xstring} \usepackage{datatool} \newcommand{\...
user avatar
0 votes
2 answers
54 views

Passing nested argument specifier to hook

Consider a macro that declares some other document command, but by accepting their body as an own argument (simple indirection) also adds the invocation of itself to some hook as in \...
user avatar
0 votes
0 answers
76 views

How get the result of a macro that uses xstring functions before writing to a file

I encountered the need to write last name with initials (extracted from the full author's string based on first chars of first and middle name) into an external file. I use the xstring package to ...
user avatar
0 votes
1 answer
30 views

How to tweak expansion of acro entry in section/chapter title and ToC?

Same question as this one but regarding the acro package. How shall I prevent expansion in section, title and ToC? MWE %\documentclass{book} \documentclass{article} \usepackage{acro} \...
user avatar
  • 2,447
1 vote
2 answers
41 views

Macros for section name affects nameref

I have a LaTeX environment which manipulates a section name through the macro \sectionname before eventually creating the section by \section{\sectionname}}. The issue is that as this macro is ...
user avatar
  • 135
1 vote
1 answer
46 views

Expl3 - Can you outline the trick applied with \file_parse_full_name:nNNN for preventing expansion only with active characters?

This question is not about something not working. This question is about how a nice trick is accomplished. interface3.pdf, section "12.2 File operation functions" says about the function \...
user avatar
  • 22.9k
2 votes
1 answer
45 views

Using expansion in toggleocgs argument

I want to use ocg-p to define an environment step which has an Optional Content Group (OCG / "layer") with a "+" character in the margin that allows you to toggle the group. I use \...
user avatar
  • 4,865
4 votes
3 answers
146 views

Process and save macro result

I'm trying to create a command \placeDate to print something on the first call and then print nothing and generate an error if I call it once again. The idea is to print the macro as usual and at the ...
user avatar
  • 43
2 votes
1 answer
101 views

Get \string-ification of first opening brace in argument?/Get \string-ification of first opening brace's matching closing brace in argument?

Can you write a LaTeX macro where the output is the result of applying \string to the argument's first character token with category code 1 which is not a control-sequence-token and not an active ...
user avatar
5 votes
1 answer
89 views

Cases of different tokens having same meaning and same \string-representation that can occur in the stage of expansion

Please take this question for a moot point: I'd like to know about edge cases where different tokens which TeX might encounter during expansion without delivering error-messages have the same meaning ...
user avatar
  • 22.9k
2 votes
0 answers
32 views

Add rows to a table with a macro after the table is shown [duplicate]

I'm trying to have a command to be executed at the begining of the document in order to append a value to a variable after it is being used. The idea is to combine it with Add Rows to Table With Macro ...
user avatar
  • 51
0 votes
1 answer
46 views

Expansion while processing math in lists with xparse

I'm trying to "print" a comma-separated list of strings. The actual use case is more complex, the list being stored as a key-value, but the MWE below shows the problem: when I add math to ...
user avatar
  • 1,944
2 votes
1 answer
48 views

\index{\protect\foo{#1}} gets sorted wrong

When I build the following, the index ends up with two of the ZZZ item and one of them sorts before the AAA item. How do I make the index see and operate on the expanded value of the macro rather than ...
user avatar
  • 157
0 votes
1 answer
76 views

tabulararray: can't use def to set cell properties?

in order to keep a coherant look in my tabular, I wanted to define a command like \def\YES{\SetCell{bg=green9} YES} to automatically add a green background when I type \YES. Unfortunately, it does not ...
user avatar
  • 5,043
1 vote
2 answers
54 views

pgfplots and expansion - expand a macro immediately?

I'm making a special tick command. Without *, the tick shows on the left side. With *, it should appear on the right side. The * (or lack of) should set a few macros to change the behaviour of the ...
user avatar
5 votes
2 answers
225 views

Recursion with counters not resetting counters

I'm trying to use recursion to draw Sierpinski's triangle in TikZ. I have something that's partially working, but not quite. At each step, I draw something. Then, if the counter is positive, I call my ...
user avatar
  • 489
2 votes
1 answer
40 views

Fixing macro for siunitx backwards compatibility

I am encountering errors with my below code (contained in a loaded .sty file; packages appropriately loaded beforehand), which is part of my attempt to ensure siunitx3 compatibility for older code, ...
user avatar
  • 1,449
1 vote
2 answers
45 views

How does \protected deal with arguments? Is it different than \protect?

According to this answer \protect\foo expands to something like \noexpand\protect\noexpand\foo when it gets saved to a macro (e.g. in a context like a beamer frame). I think \protected\def basically ...
user avatar
1 vote
1 answer
52 views

expl3: partially expand an argument

I wish to assign a \crefname with dynamical strings. With \exp_args_generate:n { xVV }, I ended up with something like: \exp_args:NxVV \crefname {\__my_countername: } {\csname ...
user avatar
  • 4,515
1 vote
1 answer
92 views

expl3: fully expand two more arguments

I wish to assign the \crefname of a counter \__my_countername: according to two related string, and for this I wrote something like: \exp_args:Nx \crefname { \__my_countername: }{ \csname my@cref@\...
user avatar
  • 4,515
4 votes
2 answers
74 views

smuggling macro out of a group in tex core results in undefined control sequence

I am trying to re-apply changes done in a group directly afterwards with the following code similar to the approach in here \def\smuggle#1\endgroup{% \expandafter\endgroup\expandafter\edef\...
user avatar
1 vote
3 answers
182 views

Reconstructing a macro from its \meaning in tex-core

In order to gain a deeper understanding of TeX I am following this guide on TeX Programming. It contains examples on macro expansion like this one \def\point(#1,#2){we do something with #1 and #2} \...
user avatar

1
2 3 4 5
20