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
1 vote
2 answers
60 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 ...
user avatar
3 votes
2 answers
66 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\...
user avatar
  • 7,764
0 votes
1 answer
29 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 ...
user avatar
  • 5,053
0 votes
1 answer
28 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 ...
user avatar
3 votes
2 answers
75 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{...
user avatar
0 votes
0 answers
30 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{...
user avatar
10 votes
1 answer
115 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 ...
user avatar
  • 145
0 votes
2 answers
33 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 (...
user avatar
  • 117
4 votes
1 answer
48 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 ...
user avatar
  • 137
3 votes
1 answer
75 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 ...
user avatar
  • 35
1 vote
1 answer
39 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} ...
user avatar
  • 437
0 votes
1 answer
31 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 ...
user avatar
  • 35
3 votes
1 answer
62 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)}{...
user avatar
  • 33
0 votes
1 answer
99 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 ...
user avatar
  • 8,759
0 votes
1 answer
57 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?
user avatar
  • 343
3 votes
1 answer
77 views

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

I'm the author of zepinglee/citeproc-lua and which already exists \cite[⟨prenote⟩][⟨postnote⟩]{⟨key⟩} that takes optional ⟨prenote⟩ and ⟨postnote⟩ for a single cite item. I'm planning to implement a ...
user avatar
0 votes
1 answer
31 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 ...
user avatar
  • 3,429
1 vote
1 answer
54 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 ...
user avatar
0 votes
1 answer
98 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. (...
user avatar
  • 8,759
0 votes
1 answer
46 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 ...
user avatar
1 vote
3 answers
77 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 ...
user avatar
  • 240
0 votes
1 answer
79 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}{ \...
user avatar
1 vote
2 answers
83 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 ...
user avatar
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{} } { \...
user avatar
0 votes
0 answers
42 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 ...
user avatar
3 votes
1 answer
57 views

Show definition of \NewDocumentEnvironment

xparse provides \GetDocumentEnvironmentArgSpec to examine the argument specification of a defined environment (and similarly for commands and showing on the terminal). However, I would like to be able ...
user avatar
0 votes
1 answer
62 views

Create a NewDocumentEnvironment programmatically

I'd like to programmatically create a new \NewDocumentEnvironment environment to create new environments using a simple command (a bit like how one can use\newtheorem to create a new kind of ...
user avatar
  • 5,053
2 votes
2 answers
92 views

escape hashs (#) passed as argument to use them in inner macro

I am using nested macros using the xparse package, my ultimate goal being to have a custom macro factory. I have simplified my current problem here. I want to give a pattern as an argument, like in ...
user avatar
  • 123
0 votes
1 answer
51 views

Adding an optional argument to an existing command / environment

Let's say I want to make a new environment that is a copy of the beamer class' frame, but it allows one to optionally place (something) at the end to change the behaviour of the frame. I would still ...
user avatar
1 vote
0 answers
48 views

Save environment declared with \NewDocumentEnvironment to redefine it

I have some environment declared with \NewDocumentEnvironment, lets call it oldenv which I want to redefine in another package, to tweak it a little bit. However, in the redefinition I want to make ...
user avatar
1 vote
0 answers
29 views

xparse error with TexShop [closed]

This is a very strange question I encountered...so I am using the "NewDocumentCommand" from xparse. I have the following codes in my "test.sty" file (just a simple example): \...
user avatar
8 votes
1 answer
263 views

What package now provides \NewDocumentCommand?

I see that I can use the command \NewDocumentCommand without adding \usepackage{xparse} What package contains \NewDocumentCommand? Is there a package that contains the xparse package? Does any LaTeX ...
user avatar
  • 485
1 vote
1 answer
53 views

How can I correctly expand the result of \prop_item:Nn to work with my own \DoSomething function?

OK, here is the thing. I want to store property-value pairs and then later use this as a lookup table to feed the value into another function. This is what I came up with and I don't know how to fix ...
user avatar
  • 4,286
3 votes
1 answer
59 views

How does xparse's routine for looking for an optional argument do the trick of preserving space-tokens in case no optional argument is present?

(This question is not about bugs or errors or whatsoever misbehavior. I just would like to know how a pleasant trick was done.) I just encountered another subtlety in which the way of xparse's ...
user avatar
5 votes
2 answers
109 views

Merge comma separated lists from Datatool

I have tried solving this for some time now but can´t seem to find the solution. I have a document that loads data from a CSV-file using Datatool and I have been trying to combine comma separated ...
user avatar
  • 77
4 votes
2 answers
97 views

Appending a token list keeps referring to it instead of copying

I actually had some workarounds and overcame my issue. But I still cannot understand some points. I'm trying to write a command to draw a table. I started with this: \documentclass[10pt]{article} \...
user avatar
0 votes
0 answers
37 views

Update counter using xparse command with argument processing

I recently started using xparse and I want to update the value of a counter with the output of an xparse command. The xparse command uses argument processing which seems to pose a problem. Example ...
user avatar
0 votes
1 answer
46 views

Expansion while processing math in lists with xparse

I'm trying to "print" a comma-separated list of strings. The actual use case is more complex, the list being stored as a key-value, but the MWE below shows the problem: when I add math to ...
user avatar
  • 1,944
2 votes
2 answers
77 views

Split a text to a list after passing through \keys_define

I'm trying to create a command with key-value arguments with the second one is a list of items separated by commas. The list is printed normally when I passed it directly to the \DrawList command, ...
user avatar
2 votes
0 answers
60 views

xparse losing default values of optional parameters after environment

Some code that used to work has stopped working on a newly updated system (revision 61040 of l3packages, from what I can tell; I don't have a version number for which it did work), and I'm trying to ...
user avatar
  • 85
2 votes
1 answer
50 views

Columns of questions without interruptions for a test with multiple choice

I have the file sebmcq.sty created by the excellent users Florent Rougon, Enrico Gregorio to generate a multiple choice questions with answers. % sebmcq.sty --- Multiple choice questions. Can print ...
user avatar
  • 46.2k
1 vote
1 answer
36 views

@ifpackageloaded If \RenewDocumentCommand Else \NewDocumentCommand

Hello (sorry for the strange title), I wanted to know how I can define a command with \NewDocumentCommand if a package hasn't been loaded and if it has than I want to redefine it with \...
user avatar
1 vote
2 answers
54 views

pgfplots and expansion - expand a macro immediately?

I'm making a special tick command. Without *, the tick shows on the left side. With *, it should appear on the right side. The * (or lack of) should set a few macros to change the behaviour of the ...
user avatar
2 votes
1 answer
47 views

xparse - order of token-type args

I am curious if there is a technical reason that the token-type args of xparse must follow the correct order? MWE \documentclass{article} \usepackage{xparse} \NewDocumentCommand{\foo}{s t+}{--- \...
user avatar
1 vote
0 answers
73 views

xparse package safe for journal submissions?

Tldr: I'm using xparse to define commands with optional parameters. I would like to use these new commands in submissions to journals (think of Elsevier or Springer etc journals). Before doing so I ...
user avatar
6 votes
1 answer
196 views

Differences between \newcommand, \NewDocumentCommand and \DeclareRobustCommand

What are the main differences between \newcommand, \NewDocumentCommand and \DeclareRobustCommand? Could you answer me giving exhaustive examples, please? I already read this, this and this, but I'd ...
user avatar
  • 793
0 votes
1 answer
105 views

Does author of LaTeX documents need xparse or \ExplSyntaxOn?

If an "end-user" is preparing documents with LaTeX and using the current version of LaTeX(as of now, LaTeX2e <2021-06-01> patch level 1), which automatically loads L3 programming layer ...
user avatar
  • 6,382
2 votes
4 answers
125 views

How extend command defined using SplitArgument so as to allow 4 arguments not just 2?

I have a command \cont used mainly in the form \cont{X, Y} and defined using \SplitArgument, as shown in the source below. How can I redefine (that is, extend the definition of)\cont so as to allow 4 ...
user avatar
  • 6,382
1 vote
0 answers
41 views

How define starred form of command already using \SplitArgument?

I have a command \cont used mainly in the form \cont{X, Y} and defined using \SplitArgument, as shown in the source below. How can I define a starred version \cont* of this command that does two ...
user avatar
  • 6,382
2 votes
1 answer
34 views

Wrap tikz matrix/tikzcd inside vcenter

How could I create an environment that wraps a tikzcd (basically a tikz matrix) inside \vcenter{...} while keeping the syntax intact? What I tried: According to How do I wrap a macro definition in an ...
user avatar
  • 5,053

1
2 3 4 5
14