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.

5
votes
3answers
166 views

Calculating the partial sum of a expl3 sequence

How can I compute the partial sum of a sequence of integers? This is what I have so far \documentclass{article} \usepackage{calc, forloop, xparse} \ExplSyntaxOn \seq_new:N \g_tmp_seq \seq_new:N \...
2
votes
1answer
65 views

Counting days and years in personal journal

The code below is taken from this post. Is it possible to create a sequence/array that contains all the different years, and another that contains how many entries per year there are? \documentclass{...
1
vote
1answer
27 views

How to avoid (xparse) environment box from breaking interline-spacing and getting inside space of preceding environment's box?

Interline spacing of the last line of the first environment is being infringed upon by the first line of the following environment. How do I retain proper interline spacing in such case? \...
0
votes
0answers
60 views

key={v,a,l} argument separated by commas in xparse [duplicate]

I'm trying to create a command to show the distributive property of multiplication (for school effects) using tikzmarks and xparse. So far so good, the code is a bit long and I would like to know if I ...
6
votes
1answer
99 views

How to stop macros from processing arguments?

Disclaimer: I don't know how to word this properly so the title might be misleading - edits and comments of advice or correction are very welcome! I use the minted package to add code to my documents,...
0
votes
3answers
51 views

How to automatically place number of occurrences of a certain command inside xparse environment at every occurence of that command?

There is an (xparse) environment \myEnv, and there is unspecified number of \myCo commands provided by the user inside that environment. I need to write a code for the environment which would count ...
2
votes
1answer
74 views

How to automatically capture \prevgraf value (inside xparse environment) every time text ends with \par?

I need to declare an environment with \NewDocumentEnvironment such that every \par provided by the user inside that environment would automatically set an integer variable (inside environment-...
3
votes
3answers
73 views

Allow Optional Delimited Params To Appear In Any Order (EASILY) (e.g. \REset[s](X){e}=\REset(X)[s]{e})

My package rec-thy has a number of macros that allow the optional specification of both a stage (as part of a stagewise approximation) as well as a relativization. I've adopted the convention that ...
2
votes
3answers
128 views

Why \NewDocumentEnvironment within \ExplSyntaxOn/Off removes spaces from content passed to it outside of \ExplSyntaxOn/Off?

I thought turning syntax on/off at appropriate places would make everything work, but I can't use \ExplSyntaxOn/Off inside \NewDocumentEnvironment so the following code sample doesn't work: \...
2
votes
1answer
65 views

ocgx2, xparse, expl3: splitting comma separated OCMD/OCGs lists of arguments for references automation

On an applicative level, this question follows a previous one about quizzes (MCQs) with OCGs. But it seems (I suspect) that the issue might come from expansion concept and/or LaTeX3 syntax on how to ...
2
votes
1answer
91 views

Making an environment to draw over a picture with TikZ

Following up on this answer, I've decided to just make this a new environment. Below is my MWE using packages xparse and tikz: \documentclass[10pt,a4paper]{article} \usepackage{xparse,tikz} \...
4
votes
2answers
49 views

Implementing a keyword / token / tag system

I want to have a keyword / tag / label / token system for my documents. There will be a hard coded list of allowed keywords and all theorems/examples/exercises will (optionally) be tagged with one of ...
0
votes
2answers
76 views

How to call a command accepting 2 optional args defined with `\NewDocumentCommand` and pass only 2nd optional arg to it (skipping the 1st)?

If \myB accepts two optional arguments, \myB sets both of them to default values, \myB[5] sets first to 5 and second to default value, \myB[5][10] sets first to 5 and second to 10. But how do we set #...
4
votes
2answers
147 views

Expl3 and recent xparse on overleaf: No expl3 loader detected

I'm currently writting a library that requires a recent xparse (to have the +b option for environments). Unfortunately, my computer does not have such recent xparse, so I downloaded the package here, ...
0
votes
1answer
28 views

Use environment into (new) xparse environment

I'm writing a small library, and for some reasons, it seems that I can't nest environments with xparse's new way of defining environments. It's quite annoying as my users may want to nest environments....
3
votes
3answers
82 views

Summing the values of a sequence using expl3

In the code below, what should the definition of \sumcounters be to make it sum the current values of the counters thm and lemma? \documentclass{book} \usepackage{amsthm} \usepackage{xparse} \...
2
votes
1answer
96 views

Define double environments

TLDR; How can I define a "double" environment like in theorems/proofs (with an optional proof)? I'm defining a small library that is supposed to behave more or less like theorems/proof environments (...
0
votes
0answers
47 views

How to update a specific package from ctan

In the answer to this thread it is advised to use the package xparse released 05/03/2019 or later. I've been trying to update this specific package, but without success. First I updated all the ...
1
vote
0answers
18 views

Problems with an automatic theorem list

I took the code from this thread and modified it a little to fit my personal needs. Everything works fine until I add a second theorem environment, which in the MWE I'm posting is the lemma ...
3
votes
1answer
149 views

Avoid passing an empty [optional argument] an environment (with verbatim content) using xparse?

this query is related to How to pass an optional argument to an environment with verbatim content? (whose solution did not work in my case) and with Emulating @ifnextchar in expl3 (which is the one I'...
0
votes
1answer
43 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
138 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
68 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
46 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
95 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
1answer
41 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
27 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
68 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
177 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
132 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
241 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
148 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
668 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
44 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
33 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
42 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
98 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
43 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
42 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
121 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
147 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
179 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
155 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
40 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
93 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
78 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
64 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
53 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
69 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… \...