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.
751
questions
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 ...
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,...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 '\...
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\...
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{}{\...
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}
\...
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 ...
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,
...
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 ...
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 \...
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{...
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 ...
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}
\...
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 ...
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}
\...
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 ...
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 ...
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 ...
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 ...
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....
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}{}...
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}}%
...
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 ...
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}
}
...
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 ...
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{...
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 ...
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_\...
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{...
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[...
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
\...
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 ...
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 ...
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 ...
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\...
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
{ > { \...
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 ...
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 ...
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}
\...
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 ...
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 ...
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{...
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=...
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}
{...