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
3 votes
3 answers
55 views

Nested SplitList Problem for quick expansion

I'm thinking whether I can write a new command for quick inserting any number of small groups of vectors in vector space. Here is what I want: $\basis{x; u; v}$ will automatically resolve to: $x_1, \...
Zhuoqun Chen's user avatar
0 votes
0 answers
54 views

v-type argument in \NewDocumentCommand ignores spaces

Consider the following code: \documentclass{article} \usepackage{listings} \NewDocumentCommand{\hey}{v}{\lstinline|#1|\ignorespaces} \begin{document} \hey|a |b \lstinline|a |b \end{document} Why ...
Gargantuar's user avatar
3 votes
1 answer
110 views

Add aliases for command while defining command

I'd like to have a command \NewDocumentCommands which allows for multiple commands to be defined at once using the same definition. For example: \NewDocumentCommands { \powerset, \Powerset, \PowerSet }...
steve's user avatar
  • 2,134
2 votes
2 answers
113 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,134
1 vote
1 answer
48 views

Having label and caption optional for custom tabularray environment

This is a followup question to a similar problem: I like to create a table environment and to have the option creating a label/caption. This is my MWE: \documentclass{scrbook} \usepackage{xcolor,...
lukascbossert's user avatar
1 vote
1 answer
85 views

Name of glossary entries containing command defined with \NewDocumentCommand

I defined the following latex command: \NewDocumentCommand{\invokeWithCSV}{m>{\SplitList{,}}m}{#1#2} It takes as input the name of a command and a list of comma separated arguments and invokes the ...
atti6j's user avatar
  • 11
1 vote
1 answer
40 views

Renew qtyrange with default precision value

i would like to have a default round-precision value for \qtyrange that is different from the rest of the package, im having some problem changing it MWE: \documentclass{article} \usepackage{siunitx,...
Felipe9's user avatar
  • 309
1 vote
1 answer
35 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,165
3 votes
1 answer
129 views

Parse every character and transform it into a table column

I am trying to produce an array that will output most ascii characters in a given LaTex font. Currently, I have the following awful code that works: \documentclass{standalone} \usepackage[utf8]{...
Vincent's user avatar
  • 5,165
1 vote
1 answer
86 views

Use parameters as delimiters in \NewDocumentCommand

Using \NewDocumentCommand, it's possible to specify a delimited argument (e.g. r() for a required argument in parentheses). Is it possible to use other arguments in the same command as those ...
Gravitron's user avatar
0 votes
1 answer
73 views

I can't create command with \DeclareDocumentCommand{}{omv}{}

I have to make list environment based on description that should be used to describe code functions. Here is the prototype: % !TeX program = lualatex \documentclass[11pt]{report} \usepackage{enumitem}...
Vladyslav Rehan's user avatar
1 vote
1 answer
78 views

luacode works with \newcommand but not with \NewDocumentCommand

Imagine the following code: \documentclass{book} \usepackage{luacode} \usepackage{xparse} \NewDocumentCommand{\HelloWorld}{}{Hello World} \newcommand{\DefaultHelloWorld}{Hello World} \begin{luacode}...
Dave's user avatar
  • 111
1 vote
1 answer
45 views

You cannot use \raise in vertical mode error

\documentclass{article} \usepackage{mwe} \usepackage{pdfpages} \usepackage{tikz} \NewDocumentEnvironment{Insert}{m}{% \AddToHookNext{shipout/foreground} \bgroup \put(0,-\pdfpageheight) \...
Display Name's user avatar
  • 46.9k
4 votes
2 answers
69 views

Expand conditional in the outer specification for a tabularray table

I am trying to create a custom tblr environment for a schedule which I reuse often. I want to include an optional label for cross-referencing. I'm using the xparse \NewDocumentEnvironment command ...
jw5801's user avatar
  • 147
0 votes
1 answer
44 views

Custom command in \NewDocumentCommand documentation

I'm seeing a rather unexpected result with \NewDocumentCommand. Suppose I have a custom-defined command \mybold{}, like this: \NewDocumentCommand{\mybold}{m}{\mathbf{#1}} Or \oybold[]: \...
Abhimanyu Pallavi Sudhir's user avatar
1 vote
1 answer
28 views

Skipped line in `\iftoggle` gives error: paragraph ended and too many }'s

I'm trying to make a new command that outputs the first or the second argument depending on a toggle (with a specific counter -- it's basically to output question and answer for an exam). However, if ...
Nora NICOLAS's user avatar
1 vote
1 answer
64 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
2 votes
2 answers
353 views

How to simplify the code below by using cycles?

\documentclass{article} \newcommand[3]{\mycounter}{a=#1, b=#2, c=#3} \begin{document} \mycounter{1}{2}{3} \mycounter{4}{5}{6} Too much… and the last line is \mycounter{28}{29}{30} \end{document} I ...
Axia's user avatar
  • 173
3 votes
1 answer
75 views

Redefining \input with itself leads to unexpected behaviour

I am trying to intercept calls to \input and branch of functionality for some filetypes. However, I have run into the following strange error: Consider the M(n)WE given below, where the macro \input ...
marc's user avatar
  • 679
1 vote
1 answer
75 views

expl3/xparse: expansion, comparing tokens and xparse-defined macros

What is the correct (preferred?) way to do comparisons of whether a particular token---in my examples, it's typically a single character, but it could be something like \mathcal{A} or \mathbf{b} and ...
karlh's user avatar
  • 511
1 vote
1 answer
48 views

How to extract the text typed by user in \NewDocumentCommand

In order to solve this issue, let us start from a simpler task: how could I get the text typed by the user when defining a \NewDocumentCommand, to get a result close to what I would get when typing \...
tobiasBora's user avatar
  • 8,401
0 votes
0 answers
31 views

Bottom-aligning columns with tikzposter and TexLive 2022

The script found in Bottom-aligning columns with tikzposter works fine with TexLive 2021. However, since TexLive 2022, the script raises ! Missing number, treated as zero. \xparse function is not ...
Jingbei Li's user avatar
2 votes
2 answers
43 views

Setting beamer label from xparse option

I want to write a custom environment that handles some layouts that default beamer slides aren't designed to do. I use xparse's \NewDocumentEnvironment to achieve this, but have problems passing down ...
fhred's user avatar
  • 43
0 votes
1 answer
74 views

Unexpected LaTeX cmd Errors

I have a tex-document with the scartcl class. In the preamble I redefine \it by \RenewDocumentCommand{\it}{...}{...}. Moreover, I have to different environment in which I want to comple the document ...
Franz's user avatar
  • 175
5 votes
4 answers
195 views

Grouping multiple matches with \str_case:nnF

Consider the following: \documentclass{article} \usepackage{xparse} \ExplSyntaxOn \NewDocumentCommand{\demo}{m}{ \str_case:nnF{#1} { {a} {Run case 1\\ % Actually super long code } {b} {...
Clément's user avatar
  • 5,571
2 votes
0 answers
43 views

How to put the section line into tcolorbox

The contents of chapter are put into tcolor by below code. How can we modify the code for section. My code have created the \mysectionnamebox to add a contentline of section. Thank you for help! \...
Nam Tran Le's user avatar
2 votes
1 answer
77 views

How to make verbatim option optional in my \NewDocumentEnvironment?

How to make the below \NewDocumentEnvironment 3rd argument optional verbatim (optional that escapes special LaTeX characters)? Below is the 3 ways for how to the custom style: (Keep in mind that the ...
Omar Shawky's user avatar
0 votes
1 answer
57 views

LaTeX count number of occurrences within an argument

I've been trying to count a particular character within a string (an argument of a new environment I've defined). I came across this question, where one of the answers pointed me in the right ...
coreuter's user avatar
  • 103
1 vote
0 answers
109 views

Use of xparse macro and expl3 key-value pairs [closed]

I'm trying to set up a family of key-pairs to be used in a \NewDocumentCommand. The goal is to have a function with two key-pairs. I want to be able to get the values of the two keys within the macro, ...
user1850133's user avatar
4 votes
2 answers
178 views

example of \if_true: \fi: \else \reverse_if:N

it seems expl3 language is not yet very popular, i have not found even a single example of this test. I tried it but it fails. What i understood is that \reverse_if:N <primitive conditional> ...
user1850133's user avatar
3 votes
1 answer
211 views

Answer key for multiple choice bubble sheet

Consider the following MWE: \documentclass{article} \usepackage{tikz} \usepackage{xparse} \ExplSyntaxOn \NewDocumentCommand{\answergrid}{ m m m }{ \begin{tikzpicture}[x=0.75cm,baseline] ...
azetina's user avatar
  • 28.8k
6 votes
1 answer
115 views

How to use for loops in a custom command?

I have this nice code snippet to generate a DI table for integration by parts: \documentclass{article} \usepackage{xparse} \usepackage{amsmath} \usepackage{tikz} \usepackage{pgffor} \usepackage{...
Shai Avr's user avatar
  • 685
0 votes
1 answer
41 views

Number rows of table in decimal and hexadecimal with multiple counters

TL;DR My code to automatically number a table with two running counters in decimal and zero-padded hexadecimal (using the fmtcount and array packages) is not working. I'm trying to automatically ...
Ben Zelnick's user avatar
1 vote
2 answers
59 views

Iterate over list with xparse

I have this code with xparse package \documentclass{article} \usepackage{xparse} \ExplSyntaxOn \NewDocumentCommand{\addexercise}{m m m} { \prop_gput:Nnn \g_exercise{ #1 } { {#2} {#3} } } \...
user69507's user avatar
1 vote
1 answer
48 views

Macro without arguments to define macro with arguments

I'm trying to use xparse and generic TeX/LaTeX commands to write a macro (that takes no arguments) to define another macro that does take arguments: \documentclass{minimal} \RequirePackage{xparse,...
Ben Zelnick's user avatar
0 votes
0 answers
22 views

How to get xparse to accept an argument as multiline one? [duplicate]

In xparse, the argument specifier +b in environment allows for entering multiple lines in the body of the document. Is there any equivalent when using \NewDocumentCommand. For example, the following ...
Al-Motasem Aldaoudeyeh's user avatar
0 votes
0 answers
53 views

How to pass xparse optional parameters to other commands, preserving ability to check for `-NoValue-`?

I'm running into a situation using xparse where \IfValueT{#2}{#2} yields -NoValue-. My \NewDocumentEnvironment poem omo environment is passing its three parameters up to \NewDocumentCommands for ...
Josh Hansen's user avatar
0 votes
1 answer
44 views

Creating an edge command with iteration

i intent to create the command \graphEdge to streamline drawing graphs edges, it would take a list of arguments separated by , the function would then divide the arguments and iterate on it, creating ...
Felipe9's user avatar
  • 309
6 votes
2 answers
113 views

\NewDocumentCommand: Mandatory types r / R and their “default values”

The documentation of xparse states (emphasis mine): r Given as r⟨token1⟩⟨token2⟩, this denotes a “required” delimited argument, where the delimiters are ⟨token1⟩ and ⟨token2⟩. If the opening ...
O'Neil's user avatar
  • 203
0 votes
1 answer
60 views

Using \NewDocumentCommand to redefine a table rule [duplicate]

I was trying to redefine an old command \lightrule with the new syntax from xparse. When I try to use \newlightrule unexpectedly it displays Misplaced \noalign error. Minimal Working Example and ...
Emanuele Nardi's user avatar
7 votes
2 answers
227 views

Text not respecting \text within NewDocumentCommand within align*

Within an align* environment I have lines of the form \Rightarrow &<\texttt{Program Code}, [a \mapsto 1, b \mapsto 2]> &\text{Rule Name}\\ \Rightarrow &<\texttt{Program Code 2}, [...
Harith's user avatar
  • 195
1 vote
1 answer
57 views

xparse command optional argument in \uline{} error

Sorry, but I am so bad in English. I try my best to describe my problem. Here is an example \usepackage{ulem} \usepackage{xparse} \NewDocumentCommand{\test}{o m}{ % #1#2 } \begin{document} %\...
hua's user avatar
  • 13
2 votes
1 answer
366 views

\NewDocumentEnvironment does not work somehow

Why does \newenvironment work but the same code does not work with \NewDocumentEnvironment: \documentclass{scrlttr2} \usepackage[scaled]{helvet} \renewcommand\familydefault{\sfdefault} \...
mrCarnivore's user avatar
  • 1,505
1 vote
3 answers
93 views

Using Macro Inside Description List Label

I made a macro using xparse for formatting the month with optional day and year. Except the appended optional argument doesn't work inside a description label for the description list---unless I ...
User23456234's user avatar
  • 1,727
6 votes
1 answer
87 views

NewDocumentCommand for font size and style

I would like to create a NewDocumentCommand that would take optional arguments like font color (blue, red), font size (12pt, 18pt, maybe large, huge), and font style (bold, italic, maybe bold+italic). ...
PatrickT's user avatar
  • 2,901
1 vote
1 answer
102 views

\NewDocumentCommand embellishments/tokens syntax

Edited: David Carlisle kindly provided the answer in a comment, which is the definition after \makeatletter. I'm trying to use embellishments in \NewDocumentCommand to define a macro to kern ...
John Bourke's user avatar
2 votes
1 answer
60 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,116
3 votes
2 answers
180 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,401
1 vote
2 answers
159 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
  • 897
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

1
2 3 4 5
15