Questions tagged [xparse]

Now integrated in the LaTeX kernel as {ltcmd}. Formerly, {xparse} was a package from the LaTeX3 project that provided a powerful mechanism for defining new commands with various types of arguments.

Filter by
Sorted by
Tagged with
2 votes
1 answer
61 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,126
3 votes
2 answers
183 views

LaTeX3: elegant way to forward arguments (tokens, star, embelishments) to another command

I struggle to define elegantly a LaTeX3 command and forward its arguments (notably stars, tokens, embellishments) to another command. I guess I might be able to make it work using \expandonce or alike,...
tobiasBora's user avatar
  • 8,537
1 vote
2 answers
166 views

Landau notation with optional argument

I would like to create a command for Landau's notations (small o for example), which would have an optional argument consisting of two elements (the variable and the point) separated by a comma. How ...
jowe_19's user avatar
  • 939
1 vote
1 answer
74 views

Can you not pass argments to commands using keys?

I use my own LaTeX preamble for university, so I am fairly used to creating macros using tools such as xparse. However, I am unsure why I cannot do something that will choose between two images on my ...
TimeTravelPenguin's user avatar
5 votes
3 answers
256 views

Define NewExpandableDocumentCommand whose name is in a macro

If a macro or an argument (say #1) contains some strings, say Mystring, I can create a macro \PrefixMystring{}{} using something like: \expandafter\newcommand\csname Prefix#1\endcsname[2]{ the ...
tobiasBora's user avatar
  • 8,537
0 votes
1 answer
41 views

Macro definition change from newcommand to NewDocumentCommand produces error for empty lines in beamer slides [duplicate]

for slides I defined my own frame command. Now I want to change from a definition with \newcommand to \NewDocumentCommand. But empty line(s) in the \xframe create an error. I could replace all empty ...
sigbert's user avatar
  • 125
4 votes
0 answers
91 views

Redefine overlay-aware beamer command using xparse

Suppose to want the \texttt command accept two optional arguments with a default value before and after the mandatory one, in order to specify anything (here spaces) that should be prepended or ...
Axel Krypton's user avatar
  • 1,083
1 vote
1 answer
58 views

How to avoid a macro with optional argument to create any token?

I was trying to use a macro inside of \cite optional argument. I expected the optional argument to be ignored if the macro expands into nothing (i.e, get something like [1]), but sometimes a ...
User9123's user avatar
  • 147
2 votes
1 answer
38 views

problem returned type of fields with expl3 and siunitx

I made a list of key-value, that I can get and set, but when i'm trying to display the stored number in engineering writing, it gives me an error : Package siunitx Error: Invalid numerical input '\...
DrStu's user avatar
  • 33
0 votes
3 answers
187 views

Parsing non-expandable commands like \small, using expl3

Using expl3 syntax, I want in my \coolgloss command to use as an optional argument one or several formatting commands such as \small and \itshape. With a command like \newcommand{\coolgloss}[3][\small\...
Vincent Krebs's user avatar
1 vote
2 answers
119 views

How can I get `\texttt` in `\href` to work with Springer Nature's sn-jnl class?

Using version 2019/11/18 of Springer's sn-jnl.cls template (archived as a gist here), I get the following: \documentclass{sn-jnl} \usepackage{xparse} \NewDocumentCommand{\githublink}{m m o}{\href{}{\...
Jason Gross's user avatar
  • 2,125
3 votes
3 answers
71 views

\clist_item and \pgfmathsetmacro causing an error

My main aim was to be able to use more than 9 arguments when defining a new command. Therefore i am using the following code: \documentclass[12pt]{article} \usepackage{pgfmath} \usepackage{xparse} \...
usuallyiamhungry's user avatar
0 votes
0 answers
72 views

Program a key/value-style optional argument (expl3 command) such that relative values must be used

Thanks to egreg's answer here I created a command involving a key/value-style splitted optional argument. The expl3 syntax allows to indicate the default value for each key. The default values in my ...
Vincent Krebs's user avatar
2 votes
1 answer
173 views

Passing arguments using IfValueT

I have seen the following usage: \NewTColorBox[]{containerbox}{o o}{ %invisible boxes for sections (now grey) boxsep=0cm, boxrule=0cm, sharp corners, left=0cm, right=0cm, ...
rosecabbagedragon's user avatar
4 votes
2 answers
228 views

Argument splitting using low-level Expl3 syntax

Using egreg's answer here I tried to create my own advanced command with key=value-style optional argument splitting, which was successful. Now how can I integrate the splitting of the mandatory ...
Vincent Krebs's user avatar
4 votes
3 answers
304 views

How to split optional arguments

With commands such as \usepackage, all options can be given within the same pair of square brackets, using only commas as delimiters. I'd like to achieve the same thing, here for example with the \...
Vincent Krebs's user avatar
1 vote
1 answer
183 views

How to use xparse for multiple optional arguments?

I am trying to create a new environment for listing some achievements as follows: \documentclass{article} \begin{document} \setlength{\tabcolsep}{0 pt} \newenvironment{twentylong}{ \begin{...
Ethan Mark's user avatar
0 votes
2 answers
48 views

Why isn't SplitArgument working as expected here?

I'm trying to define macros to set the size and position of TikZ nodes based on the text that is supposed to go into them. Because there are multiple similar but not identical nodes of varying ...
joelproko's user avatar
  • 115
0 votes
1 answer
41 views

My paper/page size stopped working once I added speech bubbles to my document

So I'm working on a project which is supposed to be in A5. I have a template for this kind of document and it has always worked just fine. This is the code I usually use: \documentclass{memoir} \...
Tiago's user avatar
  • 1
2 votes
2 answers
134 views

Macro factory, passing on star arguments

I want to define a set of macros, with similar behaviour but applied to different symbols. To avoid repetitions, I thought it would be a good idea to generate them programmatically from a template. I ...
Aubergine's user avatar
  • 252
3 votes
3 answers
118 views

canonical macro definition for conditional with discrete choices from valid set

what is the canonical way to define a macro (presumably, now xparse is preferred) that acts differently based on one of a set of discrete choices. \mymacro[a]{does one thing, e.g., print this in red} \...
ivo Welch's user avatar
  • 3,744
2 votes
2 answers
202 views

Pass xparse optional token argument from outer command to inner command

I have a document command which accepts several optional token arguments, and I'd like to implement another document command which accepts the same optional token arguments and passes them properly to ...
Null's user avatar
  • 1,525
2 votes
2 answers
98 views

Convert a macro name to pgfkey name

Let's consider a macro name of the form \first@second. I would like to write a command that would convert the name of the macro to pgfkey name of the form /first/second so that the following ...
Vincent's user avatar
  • 5,225
0 votes
0 answers
46 views

Update "How to scale a tikzpicture to \textwidth" for expl3/xparse

I am probably the thousandth person who wants to scale a tikzpicture to the size of \textwidth. There is a solution for this problem given in https://tex.stackexchange.com/a/6391/193625 however it ...
Franz's user avatar
  • 175
0 votes
1 answer
69 views

How to store Boolean values for later use

I want to define a new command for a package using xparse. My command looks like this: \NewDocumentCommand{\fancyCommand}{s o m}{ \def\@optional{#2} \def\@mandatory{#3} } This is, because I ...
Matthias's user avatar
3 votes
1 answer
87 views

NewDocumentCommand enumerate macro not working with linebreak while \newcommand does work

In the following code, I write two macros for \begin{enumerate}...\end{enumerate}. In trying to get more than one optional argument, I used the method in More than one optional argument for newcommand....
D.R's user avatar
  • 771
1 vote
1 answer
156 views

Latex Environment with named optional parameters

Is there a way to get a string options in \NewDocumentEnvironmentor \newenvironment ? i.e \begin{foo}[color=red,size=12pt] \end{foo} where the environment is defined as \NewDocumentEnvironment{foo}{}...
cdickstein's user avatar
0 votes
1 answer
101 views

Can you make boolean expressions in xparse?

I have a preamble I use on my assignments containing the following command using xparse: \ProvideDocumentCommand{\integral}{s m m e{_^}}{% \int% \IfValueT{#4}{_{#4}}% \IfValueT{#5}{^{#5}}% ...
TimeTravelPenguin's user avatar
2 votes
2 answers
73 views

Pass option to tikz node based on page parity

Story: I've recently been creating a document with Koma Script with a moderately complex page layout. There are different layers of content set with different commands declared in the preamble and it ...
TopologicalFieldTheory - TFT's user avatar
0 votes
0 answers
27 views

NewDocumentCommand inside NewDocumentEnvironment, and an illegal parameter issue [duplicate]

I am trying to write a macro like this: \usePackage{xparse} \NewDocumentEnvironment{myenv}{} { \NewDocumentCommand{\myarrow}{g}{\IfNoValueTF{#1}{\to}{\xrightarrow{#1}}} \begin{enumerate} } ...
user680089's user avatar
0 votes
1 answer
47 views

Error in a piece of code written by expl3 (correct usage of { O{} m })

Consider the following piece of code that I copied and modified it from cas-common.sty: \tl_new:N \g_stm_mydate_day_tl \tl_new:N \g_stm_mydate_year_tl \cs_new:Npn \date_parse:n #1 { \date_parse_aux:w ...
C.F.G's user avatar
  • 552
1 vote
1 answer
32 views

Expand command in pgfplots axis options

Depending on a boolean flag, I would like to set axis options like in the following example: \documentclass{article} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \usepackage{xparse} \usepackage{...
Manuel Schmidt's user avatar
2 votes
1 answer
375 views

Removing box around solution

My inital problem was finding a solution which allowed me to collect all answers in the exam document class and have them printed at the end of an document. I found this solution click, which ...
Philip's user avatar
  • 23
3 votes
1 answer
111 views

NewDocumentCommand with embellishments does not work in superscript/subscript without braces

The following example \documentclass{article} \NewDocumentCommand{\K}{e{^}}{{\exp(\IfValueT{#1}{#1}n)}} \begin{document} These work \( \K, 2^{\K^{2}}, 2_{\K}, 2^{\K}, \log(\K)\). These do not \( 2_\...
Tohiko's user avatar
  • 1,787
3 votes
1 answer
74 views

TikZ environment style options don't work inside `\ExplSyntaxOn`

I want to use a TikZ environment inside an \ExplSyntaxOn... \ExplSyntaxOff block. \documentclass{article} \usepackage[utf8]{inputenc} \usepackage{xparse} \usepackage{tikz} \usetikzlibrary{...
Mountain's user avatar
  • 199
0 votes
1 answer
77 views

How to expand a macro argument into a string, remove all the spaces, then append and prepend the string inside a \NewDocumentCommand macro definition?

I want to expand a macro argument into a string, remove all the spaces, then append and prepend the string inside a \NewDocumentCommand macro definition. Here's my MWE using LuaLaTeX. \documentclass[...
Farrel Ahmed's user avatar
1 vote
0 answers
41 views

Processing the body of an ams align math environment (to add alignment characters)

I would like to define a variant of the align* environment that aligns each column on the left and does not include anything extra in the spacing between columns. Consider the following MWE \...
Gennady Uraltsev's user avatar
0 votes
1 answer
42 views

Grab variable number of tokens – xparse macro

I'm trying to create the following macro: \adddescr{<comma separated list>}{<description 1>}...{<description n>} this macro should print element -- description \par accordingly, so ...
antshar's user avatar
  • 4,228
1 vote
1 answer
125 views

Why does this command defined with \NewDocumentCommand behave differently from \def inside tabular column specification?

On the first glance \NewDocumentCommand{\foo}{m}{#1} and \def\foo#1{#1} should be identical and in most scenarios they actually are, but when the argument is not explicitly follows \foo, the command ...
antshar's user avatar
  • 4,228
0 votes
1 answer
104 views

IfNoValueOrEmptyTF in tcolorbox

In the following MWE, I would like to remove the space associated with the title, when the argument ##1 is mentioned but the title is empty. This would mean changing IfValueTF to IfNoValueOrEmptyTF in ...
jowe_19's user avatar
  • 939
0 votes
0 answers
25 views

NewDocumentEnvironment Ignoring gdef Statement in Beamer [duplicate]

The following beamer document uses handout mode to generate two frames. \documentclass[handout]{beamer} \usepackage{xparse} \NewDocumentEnvironment{frm}{+b} \ExplSyntaxOn {% \makeatletter \gdef\...
Brian Fitzpatrick's user avatar
3 votes
1 answer
221 views

How 'experimental' is \TrimSpaces today?

The documentation of xparse dated 2022-06-22 describes the argument processor TrimSpaces which can be used to remove leading and trailing spaces with example \NewDocumentCommand \foo { > { \...
Thomas F. Sturm's user avatar
4 votes
1 answer
163 views

How can I count the number of arguments from an xparse argument specifier?

Given a token list e.g. \ArgumentSpecification containing some argument specification e.g. oom... How can I count the resulting number of arguments? For instance in this case the output would be 3 ...
user202729's user avatar
  • 7,093
6 votes
1 answer
151 views

What is the thing that \SplitList produces?

I'm reading the documentation for xparse and I'm rather interested in \SplitList. However there are some things about the description that I don't understand: This processor splits the argument ...
Sriotchilism O'Zaic's user avatar
0 votes
1 answer
50 views

incompatibility of pdftex graphics driver, expl3 and xparse in TL2022 [closed]

I am running into a strange compilation error. Consider the following MWE: % file test.tex \documentclass{article} %\usepackage{mdframed} %\usepackage{color} \makeatletter \input{pdftex.def} \...
Maximilian Keßler's user avatar
2 votes
2 answers
109 views

How do I create macros that take + (plus) or - (minus) separated arguments as inputs and stores them to variables (e.g., coefficients of polynomials)?

How do I create macros that take + (plus) or - (minus) separated arguments as inputs and store them to variables (e.g., coefficients of polynomials)? I want to define macros that can access and select ...
Farrel Ahmed's user avatar
0 votes
2 answers
42 views

Cleaner way of making rows in a table dynamically appear

So what I have works, but I am looking for a cleaner / better approach. I have a titlepage which needs a \maketitle in the form of a table (Tabular actually). However, when options are missing they ...
N3buchadnezzar's user avatar
5 votes
2 answers
231 views

\NewDocumentCommand not working in pgfplots when \newcommand does

I'm currently trying to update some LaTeX code. I want to replace \newcommand with \NewDocumentCommand. Most of the time it works fine, but I have problems with the following example: \documentclass{...
user avatar
2 votes
2 answers
65 views

Using \usepackage{tikz,xparse,xstring,fp} to create a lattice a lattice multiplication

\documentclass[tikz,border95=3mm]{article} \usepackage{tikz} \begin{document} \begin{tikzpicture}[case/.style={minimum width=2cm,minimum height=2cm,draw},line/.style={blue!10!gray,line width=...
Paul A's user avatar
  • 989
0 votes
3 answers
212 views

How to determine if an argument in tcolorbox is empty?

I'm defining a tcolorbox environment with xparse library. \documentclass{article} \usepackage{tcolorbox} \tcbuselibrary{xparse} \DeclareTColorBox[auto counter, number within=section]{mybox}{g} {...
Syvshc's user avatar
  • 1,328

1
2
3 4 5
16