Skip to main content

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
136 views

design a \Command that allows a Dual-parameter \Command passing its return into another \Command as one (which might be a label) of its inputs

Design: a (La)TeX command (maybe look like this \passresult{\outercommand}{\innercommand}{param1}{param2}), which pass the return of a dual-parameter \innercommand{param1}{param2} into another \...
谢尘竹's user avatar
1 vote
1 answer
65 views

How does one fully expand a macro between \csname and \encsname?

The best way to ask this question is to present two MWEs, one of which works and one of which does not. Naturally, I would like to get this into the second form, but I am at a loss as to what is ...
Mike Pugh's user avatar
  • 319
1 vote
1 answer
51 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
2 votes
2 answers
109 views

hyperref warning: Token not allowed in a PDF string - macro Refactoring as a fix

I have a macro that takes a comma-separated list of lists and applies some formatting to it. The list consists of the first and last names of the document's authors. I managed to create a macro - \...
Mycroft_47's user avatar
4 votes
2 answers
171 views

Anonymous macro with #1 argument specifier

\def\foo#1{a#1b} creates \foo that expects for a mandatory argument when used. I'm trying to create so called "anonymous" or "lambda" macro that is essentially a token list with a ...
antshar's user avatar
  • 4,632
2 votes
1 answer
51 views

How to trim spaces without expanding what is inside in expl3?

Consider the following pattern: \NewDocumentCommand{\mycommand}{m}{ \myinternalcommand:n{#1} } \cs_new:Nn \myinternalcommand:n{ \tl_if_single:nTF{#1}{TRUE}{FALSE} } and let's say that I want ...
Vincent's user avatar
  • 5,327
4 votes
5 answers
314 views

Convert control sequence with a variable number of undelimited parameters into a token list

In expl3, I can translate a token list \l_greet_tl into a control sequence \greet that takes two parameters as follows: \tl_new:N \l_greet_tl \tl_set:Nn \l_greet_tl { Hello,~#1!~How~is~#2~doing? ...
Witiko's user avatar
  • 1,006
3 votes
1 answer
84 views

How to know for certain in expansion-contexts the moment when the result of a fully expandable expl3-function is there?

There are a lot of functions provided by the expl3 programming environment that in interface3.pdf are marked with a black asterisk (fully expandable) or with a white asterisk (restricted expandable). ...
user avatar
1 vote
0 answers
30 views

Record the content of an environment as a property

I came up with this question since I saw copy and reuse the content of an environment and thought that this might be solved using ltproperties. I want to record the content of an environment as a ...
NemoYuan2008's user avatar
0 votes
0 answers
35 views

How to mask \begin and \end in the versions package?

With the versions package, a version switch foo can be created to turn on/off the text that is written within the foo environment. My goal is to create new commands \mybegin and \myend, which mask the ...
cero's user avatar
  • 221
0 votes
2 answers
59 views

def inside def gives an error when used with ref

I want to define a command that returns a label to use with \ref, but it requires using \edef to expand another command. However, I am getting several errors starting with Missing \endcsname inserted. ...
Tohiko's user avatar
  • 1,833
4 votes
2 answers
116 views

Memoir pagenote (endnote) id's all coming out the same

I am creating a document using the memoir package and specifically memoir's endnote facility (which is called pagenote to avoid naming conflicts). The document, when complete, will have an entry for ...
Paul Dulaney's user avatar
  • 5,350
4 votes
2 answers
154 views

Get the string return by \namecref to use in another command

Suppose I have a theorem with \label{thm}, and I want to create a theorem of the same type as thm, here's what I want it ideally behaves: \documentclass{article} \usepackage{lipsum} \usepackage{...
NemoYuan2008's user avatar
4 votes
1 answer
143 views

What is the regurgitation process?

After a long time fighting with an \uppercase in a \csname ... \endcsname, I came across this post that mentions the argument being “regurgitated,” which means that to capitalize a control sequence, ...
Sébastien Le Callonnec's user avatar
1 vote
4 answers
87 views

expansion of a macro defined with \csname

I have a problem with expanding and not expanding macros together with \csname. Please look at the following code: % Save content of a macro via \csname \def\LetCsVar#1#2{\expandafter\let\csname#1\...
coonlight's user avatar
  • 137
3 votes
3 answers
136 views

\def and \edef: Expansion for one level, not more

I want to save the content of a macro (which may contain text and other macros) for later use and without full expansion. \def\mcr{a} \def\textandmacro{sampletext \mcr} % this content i want to recall ...
coonlight's user avatar
  • 137
3 votes
5 answers
445 views

Usefulness of using an expandable command

I would like to see how I can show the advantage of using an expandable command. I made the command \myDimensionCommand but I do not see it is the best way to show the advantages to use fully ...
Veak's user avatar
  • 1
0 votes
1 answer
65 views

Demonstrating expansion in using l3

One of the pleasures, when using the l3 layer, is one does not have to deal with \expandafter commands (well almost). A good understanding of expansion though and how the variants deal with it, is ...
yannisl's user avatar
  • 118k
0 votes
3 answers
91 views

Unexpected behavior of \g@addto@macro in class definition

I am implementing a new class for a journal. Withi this class, I defined the command to insert the authors of an article. I anticipate that everything works perfectly in the basic form, that is, if ...
TrAmA's user avatar
  • 17
3 votes
4 answers
135 views

Compare first token after expanding macro once and discard the rest

How does one write an if clause that checks whether the first element of the immediate expansion is \mymacro, without fully expanding the input? \documentclass{minimal} \def\mymacro#1{Does something ...
Hyperplane's user avatar
5 votes
3 answers
134 views

Fallback if def failed to parse the arguments?

I love the way \def can be (ab)used to parse very efficiently a string (another option would be to loop over all chars in LaTeX3 style or use LaTeX3 regexp, but it's faaaar slower, and often harder to ...
tobiasBora's user avatar
  • 8,944
8 votes
3 answers
536 views

Get third argument from string?

So here is a way to get the first, second, and remaining elements (characters) of a given string: \makeatletter \newcommand{\firstof}[1]{\@car#1\@nil} \newcommand{\secondof}[1]{\expandafter\@car\@cdr#...
wmnorth's user avatar
  • 657
0 votes
0 answers
42 views

Try-Except on performing an expansion

Is it possible to write a function that essentially does: function \tryexpand (\foo): try: expand(\foo) except (Argument of \@following has an extra }): store "\relax&...
Hyperplane's user avatar
2 votes
1 answer
109 views

How to parse a `key[value]` string with the package listofitems

Through two previous answers by @StevenB.Segletes (1 and 2), I'm 99% able to parse the 4 most important fields in SGF files/strings: B and W for Black and White moves, respectively; AB and AW for ...
psygo's user avatar
  • 438
2 votes
1 answer
82 views

Problems expanding a variable inside a `\foreachitem` using the package `listofitems` and a macro

Following this answer by @StevenB.Segletes, who's also one of the creators of the package listofitems, I'm now trying to use what that package was able to parse from a single-branch SGF string inside ...
psygo's user avatar
  • 438
0 votes
0 answers
67 views

How to expand a macro so that it can be used as an input to another macro

I use datatool to get key-value pairs from a data file into a database. I then retrieve values using a custom command, \varConfig{}. One of these values is the number 1, saved as a string in the data ...
Andy Clifton's user avatar
  • 3,709
5 votes
3 answers
236 views

Counting the number of occurences of specific characters in a string in an expandable way

This question shows how to count the number of occurrences of a specific character in a string. I would like to do it in an expandable way, and for a list (not only one) of specific characters. \...
Vincent's user avatar
  • 5,327
0 votes
2 answers
113 views

A macro to check command expandability

I would like to create a command that checks whether an expression is fully expandable, and crashes if not (ideally printing an error message). I would like to do that without a specific TeX engine in ...
Vincent's user avatar
  • 5,327
0 votes
1 answer
97 views

In expl3, how to test if something, once fully expanded, contains any character belonging to classes 11 or 12?

I am wondering in expl3 syntax (not using the most recent additions, let's say additions posteriors to 2018 [nothing special about 2018, it's just an arbitrary date to say not too recent]) how to test ...
Vincent's user avatar
  • 5,327
1 vote
0 answers
91 views

Design a generic numeric comparator function using expl3 working for strings, counters, numexpr, dimexpr

I would like to design a generic compare function between numbers, ideally expandable with the following signature: \NewExpandableDocumentCommand{\compare}{r[] m m m m m}{%CODE HERE%} that would be ...
Vincent's user avatar
  • 5,327
4 votes
3 answers
148 views

Problem with a command that prefixes words only if needed when the arguments are provided through macros

Consider the following code coming from this answer, where it adds a prefix to a word, only if the prefix is missing. \documentclass[border=6pt,varwidth]{standalone} \ExplSyntaxOn \...
Vincent's user avatar
  • 5,327
5 votes
4 answers
322 views

An expandable command that adds a string to an argument if the string is missing

I would like to write and expandable command which adds a string S1 at the beginning of another string S2 if S2 does not start with S1 in order to ensure that my string always start by S1. I currently ...
Vincent's user avatar
  • 5,327
5 votes
1 answer
136 views

trouble with expansion in ltproperties

I am struggling to control expansion in code recorded with ltproperties. In the following example, I am trying to record the body of an environment as stated, without expansion (so as if with \exp_not:...
mbert's user avatar
  • 4,506
0 votes
1 answer
73 views

How to select a command based on the expansion of \Cref*?

(This is a somewhat of a continuation of this question of mine, which @egreg provided an easy solution to.) In the following (slight variation of egreg's) MWE, three commands are defined. \mylabel ...
Atom's user avatar
  • 665
2 votes
2 answers
118 views

Command that expands to `{ <output> }` instead of `<output>`

I'd like to define a command which expands to { <output> } instead of <output>. I've tried wrapping the command contents with additional { / } \bgroup / \egroup \begingroup / \endgroup \...
steve's user avatar
  • 2,256
2 votes
2 answers
119 views

Understanding expansion in \addtocontents

I am confused about how expansion works in \addtocontents, or more precisely in \protected@write. As I understand it, \addtocontents should essentially expand its second argument with \protected@edef ...
mbert's user avatar
  • 4,506
1 vote
0 answers
41 views

"Merge" subsequent counter-based commands

I'm trying to implement two simple paragraph numbering commands \verse and \subverse. When a \verse command is followed by a \subverse (irrespective of spaces and new lines), only the subverse counter ...
P. Price's user avatar
1 vote
3 answers
93 views

Problem with command expansion in xstring macro? "Incomplete \iffalse"

I have written the following commands which first chunk the input text by ; and then make "fractions" out of text that is separated by /. My intention with this is to display genotypes with ...
tired63194's user avatar
1 vote
1 answer
38 views

Command color not working with the name of a color built through macros

Consider the following code and especially the command \nicecolorname which builds the name of a color following the pattern ["nice"][shade][hue]. In its current name, the command \color is ...
Vincent's user avatar
  • 5,327
0 votes
1 answer
39 views

Compound glossaries command with proper sub- and superscripts and custom arguments

I would like to create a macro which helps in combining gls-symbols. Each compound symbol should consist of a body and (optionally) a super and subscript (which are itself gls symbols and get listed ...
Wulle's user avatar
  • 1,204
0 votes
0 answers
35 views

Escape grouping as macro + feedback

I am currently trying my hand at latex3 to get a deeper understanding of programming with latex. For this I have created a simple settings system. It works as follows: You create a setting via \...
Dave's user avatar
  • 327
2 votes
2 answers
86 views

Expanding a l3 variable to split it

I need to expand the variable \pmbc_bounds_tl to split it. I've tried playing around with exp_args without success. Which version of exp_args should I use? \documentclass{article} \ExplSyntaxOn \...
projetmbc's user avatar
  • 13.4k
0 votes
1 answer
80 views

Print message in expandable macro

Is it possible to print a message like \message{…} in an expandable macro for debugging purposes? I tried to create expandable functions with \message{}, but I can't plug them into siunit \num{…} that ...
tobiasBora's user avatar
  • 8,944
1 vote
1 answer
50 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
89 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
  • 4,506
3 votes
4 answers
147 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
67 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
72 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
30 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
  • 158
1 vote
1 answer
63 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
  • 523

1
2 3 4 5
23