Skip to main content

Questions tagged [expandafter]

The tag has no usage guidance.

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

Expanding Variables to Input as Arguments for Macro

I have an issue when trying to use variables in a command (\ResearchModule). I read up to 8 lines from a text file and have them set to elements of an array (using code thanks to egreg!), with \...
MrOakPlanks's user avatar
3 votes
1 answer
43 views

Generate \charge arguments with a macro

I'm trying to use a macro to generate arguments that should be passed to \charge. I'm trying this: \documentclass{minimal} \usepackage{chemfig} \begin{document} \charge{-135:1pt=5}{C} \...
ttsc's user avatar
  • 415
6 votes
3 answers
242 views

How to expand a command with \csname and \expandafter

I get it when I write: \expandafter\def\agent{Hello} \expandafter\def\expandafter\agent\expandafter{\agent World} \agent result: Hello World It doesn't work for me when I write: \expandafter\def\...
Juli's user avatar
  • 121
3 votes
3 answers
167 views

Define a new command as a loop of existing Latex commands

I want to define a new command, which is a composition of commands already defined within the \csvsimple package. Therefore I've written the following code, which correctly works for my purpose: \...
MattiaP's user avatar
  • 43
1 vote
2 answers
61 views

Table csvreader: loop over columns

I have a csv file called "data.csv" containing the following data: 1,2,3 4,5,6 I am writing the following table in Latex by using \csvreader: \begin{table} \centering \begin{tabular}{|c|c|c|}...
MattiaP's user avatar
  • 43
4 votes
2 answers
269 views

How to use \foreach and \newtheorem together?

I want to use \foreach and newtheorem together, so I've assigned an array with the package listofitems \setsepchar{;/,}\ignoreemptyitems \readlist\baz { theorem, lemma, definition, corollary, ...
Axia's user avatar
  • 514
2 votes
1 answer
110 views

Understanding `\expandafter` when checking nested `\csname…\endcsname`

Please consider the following MWE, which is an excerpt from a much larger project. The scenario is to define a conditional \IfComp{<number>}{<defined>}{<undefined>} that queries, ...
Lupino's user avatar
  • 2,762
1 vote
1 answer
42 views

amsart problem with typsetting title

I tried to implement a metalevel for the author and title commands, because most style files want them to be a little bit different and I want to be able to easily change the style file. Long story ...
Nathanael Skrepek's user avatar
5 votes
1 answer
148 views

Question in Stephan's TUGboat article about \expandafter

In the first page of Stephan Bechtolshein's TUGboat article about \expandafter, he described the rules of the execution of \expandafter. I think the case iii should not be listed here since the ...
Stephen's user avatar
  • 4,299
0 votes
3 answers
131 views

How to understand "\appendroman#1#2#3" on page 41 of The TeXbook?

At the bottom of page 41 of The TeXbook, there is a question: Define a control sequence \appendroman with three parameters such that \appendroman#1#2#3 defines control sequence #1 to expand to a ...
Y. zeng's user avatar
  • 2,105
6 votes
2 answers
1k views

Doesn't "\romannumeral1986" equal "mcmlxxxvi" in TeX?

In TeX, \uppercase{\romannumeral1986}\par %\catcode`\m=12 \uppercase{mcmlxxxvi} \bye produces So, doesn't mcmlxxxvi equal \romannumeral1986? What the difference between them? \expandafter can bypass ...
Y. zeng's user avatar
  • 2,105
0 votes
1 answer
50 views

How to expand from DLTforeach prior to function call

Apologies if this is a trivial problem, I've seen a lot of similar posts, but i have not been able to solve this. Setup: I have created a table based on this answer. I have created a function for ...
Malle's user avatar
  • 3
0 votes
1 answer
62 views

Trying to expand items within a newglossaryentry in a generic function without causing the Improper alphabetic constant

I've looked at both these related topics, but my situation is a little bit different. improper alphabetic constant with-glossaries improper alphabetic constant The first thing I found in the ...
Miraino Hikari's user avatar
5 votes
2 answers
101 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
4 votes
3 answers
155 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
  • 5,317
1 vote
2 answers
50 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
1 vote
1 answer
73 views

Macro to conditionally generate tikz-cd diagrams

I'm trying to define a macro that will generate a tikz-cd diagram with small changes in it based on the arguments I pass to the macro call. I'm using xstring package to express conditions. My first ...
Ivan's user avatar
  • 33
1 vote
1 answer
26 views

ifcase command that changes color does not work

I am creating a handout with a command that hides the answers for students and reveals the answers for instructors. I defined a new command invisible that takes a bool and text. If 0, the text should ...
om94266's user avatar
  • 11
0 votes
0 answers
53 views

How to underline text from a macro when using Alex Chan's implementation of 'a really nice underline'

Following David Carlisle's answer in How to underline text from a macro including a line break?, I am attempting to adapt David Carlisle's use of \expandafter to allow linebreaks (when underlining ...
RosesBouquet's user avatar
2 votes
1 answer
92 views

How to use correctly \expandafter? (real example with \uppercase)

(This question is not related to LaTeX 3). At https://www.alanshawn.com/latex3-tutorial/, I read this code: \newcommand{\cmda}{abcd} \uppercase{abcd\cmda} This give "ABCDabcd". The target ...
quark67's user avatar
  • 4,221
2 votes
1 answer
68 views

(expl3) Expand the result of a function in a definition

If I do that: \ExplSyntaxOn \NewDocumentCommand{\foo}{m} { [ \fp_eval:n { #1 } ] } \ExplSyntaxOff ... \edef\bar{\foo{#1} } \edef\baz{\foo{#1+1} } if the argument #1 is 42, and if I write: \...
Pierre Dufays's user avatar
4 votes
4 answers
179 views

Delaying a sequence of tokens via \expandafter

Use case: define a command that loops over a list of input names, defining a command from each name. In the working code below, note the \expandafter\definput\expandafter{\x} within a loop with \x as ...
David Fink's user avatar
7 votes
2 answers
286 views

Why does \expandafter work with \uppercase, but not with \textbf for instance?

Why does \expandafter work with \uppercase, but not with \textbf? Consider the following MWE: \documentclass{article} \begin{document} \def\name{hello world} \textbf\expandafter{\name} \uppercase\...
Daniel Huff's user avatar
2 votes
1 answer
99 views

translator vs. translations

What's the point of having two packages translations and translator with roughly the same main functionality? Let's consider the following example: \documentclass[USenglish,french,ngerman]{article} \...
user avatar
5 votes
2 answers
110 views

Redefine a definition with itself, without evaluate its content

I have this MWE : \documentclass{article} \usepackage[TS1,T1]{fontenc} \usepackage[french]{babel} \newcounter{nbrefpage} \newcommand\setindex[1] {% \stepcounter{nbrefpage}% ...
Pierre Dufays's user avatar
1 vote
1 answer
81 views

Expand command argument twice before passing to lua function (like \luastringO)

I would like to make a helper macro like luacode's \luastringO, but instead expand the arg twice instead of once. There is a bunch of \expandafter/\unexapnded\noexpand hackery that always seems to go ...
likethevegetable's user avatar
3 votes
1 answer
165 views

expandafter and ifx

I try set color for only first letter, (aaa or bbb) in relation with test \ifx. I have more complicated task in original, but I want to understand how it work on this simple example. My MWE: \...
Elisey's user avatar
  • 401
5 votes
2 answers
245 views

How can I expand or detokenize a macro before using it in a hyperlink?

So I have some information stored in a macro that is used already elsewhere and can contain formatting macros like \small or similar and I want to expand or detokenize those commands before also using ...
TobiBS's user avatar
  • 5,260
2 votes
3 answers
152 views

How to expand a newcommand where it is called?

I need to gather things that will be presented at the end of the document, as shown bellow \documentclass{article} \usepackage{collect} \definecollection{somethings} \newcommand{\collectthing}[1]{ ...
bmello's user avatar
  • 133
0 votes
1 answer
299 views

How to reduce one counter

In the MWE below, the excoutP is added to store the value of excout. How can we only use the counter excout? \documentclass{article} \usepackage{etoolbox} \usepackage{xcolor} \...
Nam Tran Le's user avatar
6 votes
4 answers
331 views

Wrapping a command (parametrically) - csname woes

I would like to "wrap" an existing command with another command. For example, suppose that there is one command \cmda I would like that each time this is called we end up executing: \...
Andrea Censi's user avatar
5 votes
3 answers
188 views

Testing "sequentiality" of \expandafter (plain Tex) - weird results

Trying to have a better understanding/controlling over \expandafter, I wrote this code. \count100 = 0 \count101 = 1 \def\c{% \the \count100 \advance \count100 by \count101\relax}% % \everypar{\...
Daniel Bandeira's user avatar