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
0 votes
0 answers
27 views

\textbf, \emph and \titlecap with \NewDocumentCommand

This is a follow-up to this question. I have implemented egreg's solution. It works with regular font, but it does not work as intended with \textbf, \emph or \titlecap. \documentclass{article} \...
  • 463
0 votes
1 answer
23 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
49 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 ...
-1 votes
0 answers
62 views

Why is an environment ended by \end{document}

In the following Example 2, the star version of \cmton make the codes between \cmton and \cmtoff run in normal way. The non-star version wrap the codes into a environment named cmtblk. However, it ...
  • 2,619
0 votes
0 answers
24 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
42 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 ...
  • 263
1 vote
1 answer
22 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{...
1 vote
1 answer
40 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 ...
  • 13
2 votes
1 answer
62 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_\...
  • 1,609
2 votes
0 answers
50 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{...
  • 187
0 votes
1 answer
48 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
31 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
35 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 ...
  • 3,737
1 vote
1 answer
94 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 ...
  • 3,737
0 votes
1 answer
48 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 ...
  • 749
0 votes
0 answers
23 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
198 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
98 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 ...
  • 3,116
4 votes
1 answer
42 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
35 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
88 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
39 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
131 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{...
  • 3,043
2 votes
2 answers
59 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=...
  • 505
0 votes
3 answers
77 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} {...
  • 1,228
1 vote
2 answers
67 views

write to file full expansion of command

I have an issue I want to resolve, maybe you can help me. When I compile the mwe the following happens: In the PDF you can see: (X/A)(Up/Down) In the file.txt write: (\frac {a}{x})(\frac {u}{d}) How ...
3 votes
2 answers
72 views

Can xparse distinguish arguments inside braces and single-token arguments without braces?

The \foreach command from pgffor package has a good feature that it can distinguish arguments inside braces and single-token arguments without braces: \foreach \i in {1,2,3} {do some thing} \def\...
  • 8,933
0 votes
2 answers
81 views

Synctex: make it work with environment accessing its content (e.g. environ or xparse +b option)

If I create an environment using environ and \BODY or xparse and +b, the synctex functionality breaks: instead of going to the appropriate line, it goes at the end of the environment. I guess that the ...
  • 5,265
0 votes
1 answer
48 views

Passing string containing "special" catcodes (especially `_`) to custom NewDocumentCommand command

How can I pass underscore to \newcommand properly? suggests the solution is to use a zero-argument command that changes the catcode of _, before expanding to the actual command. That's kind of the ...
3 votes
2 answers
81 views

list of macros as arguments to another macro

I would like to use some macros as arguments with xparse. I need it because I use siunitx. Here is a simplified code which compiles: \documentclass[a4paper]{article} \usepackage{xparse} \usepackage{...
0 votes
0 answers
32 views

Repeating a string in xparse

Is it possible to repeat a string using xparse? I have the following snippet \usepackage[ISO]{diffcoeff} \usepackage{amsmath} \usepackage{amssymb} \newcommand{\lagrange}{\mathcal{L}} \usepackage{...
10 votes
1 answer
125 views

\NewDocumentEnvironment eats the first non-letter token when used for verbatim environment

I was messing around with creating verbatim environment saving its contents to a file like the one described in verbatim package documentation (end of section 2.2), but using latex3 features. It ...
  • 315
0 votes
2 answers
40 views

Command inside tabular with automatic \hline placement

I am trying to define a command that simplifies building tables. I want the last entry to be automatically preceded by a horizontal line. I tried to do a minimal working example, and it worked (...
  • 117
4 votes
1 answer
50 views

Unknown spacing after using command in optional argument

Context I am trying to paste multiple images in one row within a tabularx environment. Using optional commands with the \NewDocumentCommand from the xparse package I tried to implement this. It ...
  • 137
3 votes
1 answer
84 views

How can I parse a clist into a keyval prop?

I'm trying to store a comma-separated list into a key-value property to use it later, but I can't get it to work properly. I don't really understand how latex parses a keyval parameter but my guess is ...
  • 35
1 vote
1 answer
41 views

Why can't insert "\textrm" in "xparse"?

I tested these codes in Texworks with Xelatex: \documentclass{article} \usepackage{siunitx} \usepackage{xparse} \ProvideDocumentCommand\pH{\textrm{pH}} \begin{document} \pH~\num{5}. \end{document} ...
  • 731
0 votes
1 answer
42 views

XeLaTeX error when using nested tcolorbox listing environment inside custom xparse environment

I want to start by saying I don't fully understand how environments work, so I apologize if this is turns out to be a bit out of topic. Desired behaviour I'm trying to create a wrapper environment for ...
  • 35
3 votes
1 answer
74 views

Using math commands inside \ExplSyntaxOn

I am trying to define new commands using xparse package. To be specific I am trying to abbreviate integrals from this \int\limits_{a}^{b}\ f(x)\ \mathrm{d}x to a more reader friendly \dint[a,b]{f(x)}{...
  • 33
0 votes
1 answer
173 views

How to correctly parse a CSV file row-by-row with different number of commas/columns from each row to another?

Following up this answer, with this csv file \begin{filecontents*}[overwrite]{mydata.csv} TeMaxPartLoad,163.0576,,,, MaxSpeedTR,1065.9,,,,, coeffs, 3, 5, 9 , 8, 6 , \end{filecontents*} I ...
  • 8,839
1 vote
1 answer
68 views

Usage of `e` and `E` argument types in `xparse`?

What are the argument types e and E described in xparse package used for? Can someone give me a simple example to show the usage of them?
  • 411
3 votes
1 answer
94 views

How to implement biblatex's \cites command with LaTeX3?

I'm the author of zepinglee/citeproc-lua and which already has \cite[⟨prenote⟩][⟨postnote⟩]{⟨key⟩} that takes optional ⟨prenote⟩ and ⟨postnote⟩ for a single cite item. I'm planning to implement a ...
0 votes
1 answer
51 views

Process list of list stored in a macro

My case is very similar to this problem: I've got a list of pairs (first name, last name), and I want to process it to make last name in \scshape. It works fine with @egreg's solution. But when I want ...
  • 3,651
1 vote
1 answer
55 views

Separate declaration and placement of listings, figures, etc. Capturing and storing verbatim content in a token list

I'm trying to separate the definition and placement of figures, tables, listings, etc. I find them highly disruptive when editing the prose of my document. They often take up a large number of lines ...
0 votes
1 answer
109 views

expl3: Print a polynomial out of coefficients stored in a row of CSV file

Following up this answer, how to robustly use the values stored in \getRow as coefficients of a polynomial to be printed? Also, I need to have an argument of the symbol to be used in the polynomial. (...
  • 8,839
0 votes
1 answer
52 views

Environment with a mandatory or optional argument behind the \end{env}

I would like to create a custom environment, let's say foo, with an optional and a mandatory argument. This could be an approach: \NewDocumentEnvironment{foo}{O{default} m}{start #1 #2}{end} This ...
1 vote
3 answers
81 views

Is there a 'shift' instruction for \newcommand and \NewDocumentCommand macros?

I'm looking for a shift instruction which will rotate the parameters passed to a LaTeX macro. The idea is that if optional parameters are omitted, then they should be dropped from the beginning of the ...
  • 240
0 votes
1 answer
130 views

LaTeX3 Error: Command '\sc' already defined!

Please can someone explain to me why I'm getting the following compiling error LaTeX3 Error: Command '\sc' already defined! \documentclass[10pt]{book} \NewDocumentCommand{\ch}{om}{ \...
1 vote
2 answers
99 views

Saving the body of an environment to a file verbatim using xparse

Variations of this question have been asked before, but those answers don't seem to work when used within \NewDocumentEnvironment from xparse. For example, see Write environment body verbatim to a ...
0 votes
2 answers
36 views

Where is -No Value- coming from in \NewCommandEnvironment?

The code below produces -No Value- as the initial output. Why? \documentclass[10pt]{article} \ExplSyntaxOn \NewDocumentEnvironment{intfig} { > { \SplitArgument { 2 } { , } } m O{} } { \...
0 votes
0 answers
59 views

Boolean flags with xparse, and xparse in general

I would like to define an environment whose syntax works like this \begin{myenv}{arg1,arg2}[opt_1,opt_2,...,opt_n] body, taking several lines \end{myenv} One of the optional arguments is to be a ...

1
2 3 4 5
14