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.

Now integrated in the LaTeX kernel as ltcmd. Formerly, xparse was high-level package from the LaTeX3 project that provided a powerful mechanism for defining new commands with various types of arguments. The current xparse package gives access to deprecated command types and its usage is not recommended.

The main interface implemented in ltcmd is the \NewDocumentCommand macro and its variants, which improve on \newcommand and its variants, allowing commands with multiple optional arguments of various formats, verbatim arguments, and so on.

754 questions
11
votes
0 answers

xparse gobbles character(s) using an optional argument

Some recent change of the xparse package or of the LaTeX3 fundament seems to yield some changed behaviour regarding parameter processing. In some situations, at least one character is gobbled where it should not. The following MWE shows a rather…
11
votes
1 answer

Is it possible to use {} as delimiter for an optional xparse argument?

I'm redefining beamer blocks to use tcolorboxes. I want to make the title optional, but want to keep the curly braces. How can I achieve this? I tried…
MaxNoe
  • 6,136
7
votes
1 answer

Syntax for `\NewDocumentCommand`

The xparse documentation gives examples of names of \NewDocumentCommands enclosed in braces, and without braces, as demonstrated in the two commands below. Is there any difference in functionality whatsoever between the two? I never use braces and…
7
votes
1 answer

Control error messages made by commands defined with \NewDocumentCommand

The \NewDocumentCommand command uses a clever trick to make better error messages -- if the arguments of \mycommand are messed up, it would be undesirable for the resulting error to be something like "File ended while scanning use of…
Hood Chatham
  • 5,467
7
votes
2 answers

How can I create an oddly-delimited macro, using xparse?

I have a partial version of this macro working, without xparse, but I needed to tweak it and it got too unwieldy, so I'm trying to use xparse instead. It's admittedly a farfetched macro, but I'm trying to learn how xparse works... Suppose I'm…
Ben Lerner
  • 7,082
6
votes
1 answer

Providing optional (unused) parameter to macro along with \tikzmark introduces spurious space

In my overkill solution to Enclose an entry in an enumerate list in parentheses there is spurious space at the beginning of some (not all) uses of \SpecialItem. I have narrowed it down to the MWE below where the macro \SpecialItem is defined with…
Peter Grill
  • 223,288
6
votes
1 answer

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 given at each occurrence of the ⟨token(s)⟩ where…
6
votes
3 answers

Prevent xparse from stripping braces?

So I'm trying to implement a COOL-style \Sum macro which is supposed to support the following syntax: \Sum{\ldots} % -> \sum \ldots \Sum[i]{\ldots} % -> \sum_{i} \ldots \Sum[i \in I]{\ldots} % -> \sum_{i \in I} \ldots \Sum[i, 0, N]{\ldots} % ->…
6
votes
2 answers

How do I create a specially delimited command in `xparse`

Using \def I can define a command as follows: \def\aecmd#1 located at (#2);{---definition---} I can recreate this with xparse as follows: \NewDocumentCommand\aecmd{ u{~located~at~(}u{);}}{----definition---} However, I have a situation where I…
A.Ellett
  • 50,533
6
votes
4 answers

\SplitList on several delimiters

How can I tell \SplitList from xparse to split the argument at any one of several delimiters, e.g. either a comma, a semi-colon, etc. The following example works with a list of items separated by commas, but I would like it to work also when the…
lotomat
  • 527
6
votes
1 answer

Could someone explain the branching in xparse's \SplitList?

I was digging through xparse.sty to better understand how \SplitList works and am confused about some branching that is happening there. \SplitList is essentially letted to be \__xparse_split_list:nn which examines the token(s) to be used in…
A.Ellett
  • 50,533
5
votes
4 answers

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} {Run case 1\\ % Actually super long code } } { …
Clément
  • 5,591
5
votes
1 answer

xparse SplitList parameter expansion

I need to split comma-separed string from variable (actually data file) for further procesing. There is MWE: \documentclass{article} \usepackage{csvsimple} \usepackage{xparse} \usepackage{filecontents} \begin{filecontents*}{sample.csv} colA; …
5
votes
1 answer

Is it possible to have optional argument and mandatory one with brace using xparse?

I am trying to stress xparse and find something I tried which is not documented anywhere. This code snippet is not compiling and I do not get why. \documentclass{article} \usepackage{xparse} \DeclareDocumentCommand\mycom{gm}{% Optional:…
5
votes
1 answer

Defining a command to define commands where the name uses the argument using xparse

Using xparse I want to create a command which defines other commands. However I want the secondary command to consist of text and then the argument to the first command. For example For example in the…
1
2 3 4 5