Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [xparse]

A high-level package from the LaTeX3 project that provides a powerful mechanism for defining new commands with various types of arguments.

0
votes
1answer
27 views

xparse: forward empty optional argument

I'd like to use tcolorbox to call a theorem environment. My tcolorbox is supposed to ask for an optional title, and a mandatory label, so in the xparse specification I chose O{}m. Then, in the ...
1
vote
1answer
109 views

How to expand a \macro (or a copy) to save in a list at end of environment in xparse (expl3)?

I am trying to encapsulate a couple of environments to pass them to lists using xparse/expl3. I have defined a one command and two environments and I have had a problem with one of them. I use the ...
1
vote
1answer
51 views

xparse: Starred commands and \IfBooleanTF

In some longer redefinition of existing code I am using a construct like \documentclass{book} \usepackage{xparse} \makeatletter \NewDocumentCommand{\mymacro}{smO{}m}{ \def\blabla{#1}% % ...
3
votes
1answer
39 views

Add parentheses if double superscript or double subscript

I've already got an answer for Add parentheses if double superscript. I want to go a step further as proposed below. However lualatex complains of “missing $” when using the e{_}-type argument… \...
1
vote
1answer
87 views

Keep a key locally passed from multicols to enumitem using xparse

I have a small problem when trying to keep a key=val locally defining using xparse to pass multicols to enumerate (enumitem package). I have redefined the environment enumerate to accept the columns=...
0
votes
0answers
54 views

Expand one more time as needed? To compose with a macro that requires a maximally expanded argument?

Consider the case below as a minimal example. But the questions concerns understanding nonfragile composition of macros each which parse using something like xparse. (code below thanks to egreg) \...
0
votes
1answer
38 views

How much negative space needed? To recognizably remove a space by letting something be added? For macros whose argument is another macro?

Suppose that one has brea + (notice the space at the end). brea + is not printed yet. A macro \m{brea +} will replace + with \added ... how then does one define added, imagine it prints a d but only ...
0
votes
0answers
24 views

Using an xparse macro inside parenthesis adds an extra space

I've defined a macro using xparse to have one or two arguments, and to use different commands depending on the number of arguments given. It's been working very well until I had to put one of the ...
3
votes
3answers
56 views

Environment with comma separated optional arguments

Using xparse, how does one get something like this to work? \documentclass{article} \usepackage{xparse} \ExplSyntaxOn \NewDocumentEnvironment{ anenvironment }{ >{\SplitArgument{1}{,}}o }{ \...
1
vote
1answer
16 views

Center quote only if it fits in one line

I wrote some code for a quote environment. I'd like the quote to be centered only if it is short enough to fit in one line, otherwise it shouldn't be centered. This is the code \documentclass{article}...
2
votes
2answers
168 views

To be or not to be - Optional arguments inside definition of macro

The version A part in the following example is to define header/footer by macros from package fancyhdr. Though this version is workable, it's a awkward achievement because the same part of code(\...
3
votes
1answer
121 views

Automatic date in personal journal

I keep a personal journal using LaTeX. I'd like to create an environment that automatically keeps track of the date of every entry, without having to manually input them myself. This is the code so ...
4
votes
3answers
225 views

Empty optional argument or Not giving optional argument at all?

I learnt that \parbox has five arguments, that is: \parbox[<align>][<height>][<inner-align>]{<width>}{<text>}. So I constrcut my own \myparbox in which I add \sloppy\...
3
votes
1answer
127 views

Automatic theorem list

In the accepted answer to Code between \begin{environment} and \end{environment} stored in an array it's shown how to create an automatic list of theorems using expl3 syntax. However the \...
10
votes
5answers
661 views

A command challenge

Here's a little challenge. The goal is to create a command that takes is two or three arguments without using square brackets for optional arguments. The first and second argument are separated by a ...
0
votes
0answers
42 views

Macro with logic and longtable

I need to create a macro, like \newcommand, but with logic. The logic has to chose the table that must be created. For this I've found an useful package that is xparse. The problem is that this ...
2
votes
1answer
29 views

Which exact versions of `xparse` changed the behavior of `k`-type and `e`-type arguments?

At some point in 2016 the xparse package changed its k-type argument to the better e-type one. Then, shortly after, the behavior of the e-type arg was changed again to improve its usability. This is ...
2
votes
1answer
40 views

Command defined with \NewDocumentCommand and specifiers {O{strict} m} not receiving all of the mandatory parameter

I defined a command using \NewDocumentCommand with specifiers {O{strict} m}. I expected #1 to default to strict when calling the command with only a parameter enclosed in {}, and to pick up all of the ...
0
votes
1answer
72 views

Automatic bold formatting of author name in bibliography

I would like to automatically boldface a single author's entries in a bibliography generated with natbib. The bio.tex file looks like this (everything has been fictionalized): \documentclass{bio} \...
1
vote
1answer
40 views

Use value from xparse key-value store in regular expressions

This is an extension of a previous question (link). I would like to include the following xparse key-value store holding a name value into the document below: % Key-value store \ExplSyntaxOn \...
1
vote
1answer
36 views

How to create a string comparison with xparse's \NewDocumentCommand?

My MWE was created with the help of these two Q&As: 1 and 2. MWE: \documentclass{article} \usepackage{xparse} \usepackage{xstring} \usepackage{pdftexcmds} % Command declaring a global ...
0
votes
1answer
97 views

How to use xparse's NewDocumentCommand for global definition?

This is re: egreg's solution to this question. Issue: I would like the \NameOne command to replicate the \NameTwo command where it outputs only when being called on like so: \NameOne. When an ...
6
votes
3answers
144 views

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} ...
5
votes
1answer
158 views

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 ...
6
votes
1answer
138 views

xparse g argument should be avoided?

In new versions of xparse the manual states the following: (in 2. Backwards Compatibility) One role of xparse is to describe existing LaTeX interfaces, including some that are rather unusual in ...
1
vote
1answer
37 views

Iterating over characters of a string during a for each loop in a Tikz picture

I am trying to make a command that renders a Tikz picture in which there is a square surrounded by a number of smaller squares on the boundary. The first parameter defines the size of the picture, the ...
5
votes
1answer
54 views

How does xparse handle nested delimited arguments?

In this answer egreg mentions that the r argument type from the xparse package handles nested delimited arguments, as shown in this small example: \documentclass{article} \usepackage{xparse} \...
1
vote
1answer
63 views

xparse - \NewDocumentCommand definition behaves different if defined in preamble [closed]

I encountered a very strange behavior for the \NewDocumentCommand command in the xparse package related to the point of definition. The following code works: \documentclass{article} \usepackage{...
2
votes
2answers
55 views

Math subscript inside ExplSyntax switches

I'd tried to rewrite @egreg answer given in this Reusing of DeclarePairedDelimiter in a foreach manner thread to solve another 'code reuse' issue, but I've got some problem with math subscript between ...
3
votes
2answers
48 views

Blank lines in argument cause failure

For some reasons, \NewDocumentCommand from xparse package other than \newcommand from Latex has to be used to construct my macro. Yet I find in some situations blank lines in arguments of my macro ...
1
vote
1answer
65 views

Add parentheses if double superscript

I'd like to set up a macro able to add parenthesis if the argument has already one superscript. It similar to this question, unfortunately the compilation of the following MWE doesn't end… \...
11
votes
1answer
1k views

Is LaTeX3 ever going standalone or has this goal been abandoned?

I recall that earlier (over 10 years ago), producing a standalone compiler of LaTeX3 code was a project's goal. Today, this goal is no more articulated. Instead, the developers stress today that LaTeX ...
2
votes
2answers
740 views

xparse/command-already-defined

Hello I am trying to use the following class (yReport.cls) from this link https://github.com/HarveySheppard/yLaTeX I am using MikTex 2.9 and I have installed the relevant packages, fonts and cls ...
5
votes
2answers
132 views

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{);}}{----...
7
votes
2answers
315 views

How to define a command with two optional arguments?

I would like to have a single command that can take either 1, 2, or 3 arguments and do something different for each number of arguments. \c{a} -> C_a \c{a}{b} -> C_{a}^{[b]} \c{a}{b}{c}...
2
votes
1answer
99 views

Configuring a section alias in LaTeX

Every week I produce a couple of A5 booklets (A4 folded) for my wife, an active colleague in church ministry, from which I am recently retired. I call the booklets a pulpit manuscript, as it includes ...
2
votes
1answer
71 views

Nested xparse Macros

I often have a macro defined with with various optional parameters such as \NewDocumentCommand{\GenericWebSite}{s O{blue} o m e_}{<code>} and want to define a small variant of this macro, ...
0
votes
1answer
56 views

Determine the relative path of a package

The general idea is that I can get the relative path of my project root by including the package mymacros.sty in my subprojects. I have the following setup: mymacros.sty myimg figure.tikz the ...
0
votes
0answers
31 views

ltablex and NewDocumentEnvironment

I'm trying to wrap long tabularx tables from ltablex into a new environment (which would do more stuff, but not in the mwe below). However, this gives me an error \begin{wraptable} on input line 15 ...
0
votes
2answers
42 views

tabularx inside \NewDocumentEnvironment (xparse package)

I am trying to set up a new environment using xparse and its \NewDocumentEnvironment including a table. My MWE looks like this: \documentclass{article} \usepackage{tabularx} \usepackage{xparse} \...
3
votes
1answer
86 views

Argument Processor for o-type Argument

I sometimes define an argument processor to (imho) simplify some code if I want to write a wrapper around another macro. For example if I write a wrapper around a macro that takes an optional * I ...
12
votes
0answers
144 views

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 ...
1
vote
1answer
104 views

How to use \exp_not:N and \exp_after:wN to prevent the expansion of \input in a expl3 list?

I have been working on the implementation of an environment (which never nests) and a command to save different parts of a document and use them within it later using a expl3 list andxparse. So far ...
1
vote
3answers
52 views

\newcommand to define a function such as \#1\colon\mathcal{#2}\rightarrow\mathcal{#3}

SX.](https://tex.stackexchange.com), I would like to define a new command, in this occasion I want to denote a function, as in the title of the question. My attempt \documentclass{memoir} \...
2
votes
1answer
118 views

How can expand a counter of auxiliary file and save in list with xparse?

I am using the modification of a macro to save to lists using expl3 and xparse. I have managed to create a small interface type [key = val] and using the environ package I have been able to achieve my ...
5
votes
1answer
117 views

Evaluating a raw expression before passing to a function

This question comes from combination of two previous questions A and B which worked properly without any problem. But it fails when I combine them. I have a result file results/measurements.txt ...
2
votes
1answer
15 views

Process first or last case differently with clist_map

I wrote this macro to transform a comma-separated list of objects into a custom-separated list of objects: \usepackage{xparse} \ExplSyntaxOn \NewDocumentCommand{\separators}{m}{% \clist_map_inline:...
1
vote
3answers
103 views

Make a macro with a different token as its argument for different actions

I'd like to make a macro named \mycmd by \NewDocumentCommand from xparse, and use it like this: \mycmd-[options1]{action1} \mycmd+[options2]{action2} \mycmd/[options3]{action3} The xparse mandatory ...
0
votes
1answer
17 views

multipurpose index command with xparse: conditionals as arguents of \index not working

I want to define a multipurpose index command, \xindex{text}[index]/parent/ with one mandatory and two optional arguments. It should (i) print 'text' in the main text, (ii) send 'index' (or 'text') ...
1
vote
1answer
92 views

Parsing function arguments and brackets

I've been trying to get a macro to work without any kind of success. I want a function \graf{} to take a list of arguments separated by a semicolon. These arguments need to be passed to the function \...