Questions tagged [optional-arguments]

{optional-arguments} concerns commands and environments that accept optional arguments. For example the \sqrt command can be used as \sqrt[3]{x}.

Filter by
Sorted by
Tagged with
0 votes
1 answer
34 views

Latex Environment with named optional parameters

Is there a way to get a string options in \NewDocumentEnvironmentor \newenvironment ? i.e \begin{foo}[color=red,size=12pt] \end{foo} where the environment is defined as \NewDocumentEnvironment{foo}{}...
0 votes
0 answers
24 views

Commands with optional arguments [closed]

I want to make a latex command that takes optional arguments \newcommand{\vamt}{1.5cm} \newcommand{\vspc}[1][\vamt]{\vspace{#1}} I define a variable \vamt that stores the amount of vertical skip. The ...
  • 195
1 vote
1 answer
24 views

Syntax: use second argument leaving the first argument as default in a macro

I use this command to abbreviate my notation \NewDocumentCommand{\Lp}{O{p}O{\mathbb{R}^d}O{[- \infty, \infty]}}% {L^{#1}(#2, #3)} I've set one default for each argument, in most cases I need just ...
  • 37
0 votes
0 answers
24 views

How do I check if a list item is blank when it is passed as a parameter in LaTex?

I'm trying to create a command that accepts two lists using the \listofitems package where the first list is optional. In the command I want to check if the first entry in the optional list is "...
  • 1
3 votes
1 answer
31 views

behaviour of the option multicols in listings

I think the following two codes saying the same thing. However, the second code causes error. My question is: how to make the second code workable same as what the first code does. That is to say, how ...
  • 2,619
2 votes
1 answer
63 views

How to avoid typing \leavevmode before a citation macro that already starts with \leavevmode?

Control sequences with optional arguments inside optional arguments must be "hidden" with braces. Using the abntex2cite package to handle my citations, I often want to write: \begin{teor}[{\...
0 votes
2 answers
31 views

Conditionally specify an optional argument to a command

I have these two new commands defined: \usepackage{tcolorbox} \newcommand{\mycommand}[1]{ \begin{tcolorbox}[ center, colback=black!20!white, width=.75\textwidth, boxrule=0pt, ...
0 votes
2 answers
59 views

Taking in optional boolean flags in a macro without expl3

I want to create a macro \verticalStep which will produce a vertical skip of fixed length, and take two optional arguments, negative and small. So for you could use \verticalStep for a standard ...
1 vote
1 answer
32 views

NewDocumentEnvironment optional argument changes behaviour with \obeylines

I notice that the behaviour of environments with an optional argument that use \obeylines changes based on whether the optional argument is present or not. I would have expected all the environments ...
  • 23.9k
1 vote
1 answer
81 views

How to define a wrapper around the xparse \NewDocumentCommand command?

I often want to define a command (using xparse) like the following \NewDocumentCommand{\Comon}{oo}{ \IfNoValueTF{#1}{ \mathsf{Mod} }{ \IfNoValueTF{#2}{ \mathsf{Mod}...
  • 11
1 vote
1 answer
39 views

Include page numbers in a \cite argument?

I'm quoting the same book quite often, it's just different page numbers. So what I want to do is putting the page numbers in an argument while citing, so I don't have to create a new bib entry for the ...
  • 13
1 vote
1 answer
153 views

Meaning of square brackets, optional arguments

I'm a bit confused as to how LaTeX parses square brackets/optional macro arguments. I'll try to explain what I understood by means of the macro \section which has one optional and one mandatory ...
0 votes
0 answers
47 views

Unable to show the macro/command definition, when the macro/command defined with optional argument

For example, I define two commands. \mytesta with optional argument, \mytestb without optional argument. Now using \cs_meaning:N to show the command definition. The result is like this: \...
  • 4,778
0 votes
0 answers
221 views

a verb=xxx_== problem with newcommand - missing $ inserted

\documentclass[12pt,a4paper,UTF8, scheme = plain]{ctexrep} \usepackage{amsmath,enumerate} \usepackage{geometry} \usepackage{adjustbox} \usepackage{booktabs} \usepackage{fancyhdr} \usepackage{lastpage} ...
  • 515
1 vote
1 answer
55 views

Is there an empty value for the counter in `\newtheorem{xxxx}{xxxx}[empty]`?

I'm trying to set an optional counter in the \newtheorem command based on some input given to a .sty file. Something like \DeclareOption{empty}{ \edef\counter{} } \DeclareOption{section}{ \...
  • 269
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
4 votes
2 answers
147 views

How to pass optional empty arguments in a newcommand down to another command with optional empty arguments in LaTeX?

I would like to define a newcommand with two optional arguments, which in turn, calls on another command with two optional arguments. Something like the following (\B calls \A). How do I do it? \...
  • 141
1 vote
1 answer
42 views

Extend Beamer frame and inherit arguments (and overlays)

I intend to extend a beamer frame to save some overhead when making slides. I've followed an answer here after another answer involving NewEnviron didn't work for me. The beamer user guide has some ...
1 vote
0 answers
31 views

Constrain \@ifnextchar to the same line

I need an environment that takes an optional argument between square brackets, but only when provided on the same line as the \begin{...} command. \documentclass{article} \begin{document} \...
2 votes
1 answer
35 views

new command with multiple optional arguments, one of which is bracket size

Building on this question and this one and this one, I'd like to make a new command that has a default behavior for a single primary argument but has two additional arguments that specify (i) bracket ...
  • 389
0 votes
1 answer
31 views

environment with an optional argument relating to counter

This question is on the basis of my last question: Define own class options relating to counter. With the help of egreg, here is a class file in which there is an environment named exercise: \...
  • 411
3 votes
0 answers
97 views

How to write a multiple argument environment within a newcommand?

In my custom class file, I have a command that generates a new environment: \newcommand{\MakeThEnv}[4]{ \DefaultFrame{#1}{#2} \theoremstyle{#3} \newtheorem{#2T}{#4} \newenvironment{#2}{\begin{#2Box}...
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
1 vote
1 answer
26 views

Redefining \section outputs the equivalent of an additional \section{*} before the TOC

When I redefine the \section command, an additional section with title "*" is created before the table of contents, as if I had inserted a \section{*} before the table of content, which I ...
0 votes
0 answers
61 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 ...
3 votes
2 answers
141 views

PGFPlots: Trying to create a non-linear axis using trafo/.code in \newcommand - how to escape the #1 argument?

I would like to make my Y axis non-linear. I have found an answer but the problem is that my code for charts is encapsulated in the \newcommand environment. When I use something like this: \...
  • 133
6 votes
1 answer
513 views

How LaTeX "understands" optional arguments?

The most common notation for commands I have seen is the following: \command[optional]{mandatory} What I am trying to understand is how the optional arguments are understood. For example they can be ...
  • 203
0 votes
1 answer
65 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 ...
3 votes
1 answer
103 views

Define arguments in a command

I am using the skak and xskak packages to make notes about chess. Everytime I need to print a board, I have to manually set the optional parameters, like the code below: \chessboard[ %--> ADD ...
  • 1,224
3 votes
1 answer
66 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 ...
  • 24.5k
0 votes
1 answer
73 views

Need conditional that evaluates to nothing

Resolution: The problem was with the outdated version of moderncv I was using. I put some additional details at the end of the question, but I will delete this question. Thanks to those who wrote to ...
2 votes
0 answers
72 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 ...
  • 85
1 vote
1 answer
116 views

Using xargs to define custom environment

I want to define a custom environment for the following LaTeX box using xargs package, but currently I am running into errors and a bit confused on how to properly make the environment. First, here's ...
  • 175
0 votes
0 answers
62 views

XeLaTeX Awesome CV - conditionally add hyperlink to title text

I'm using font-awesome package for icons in my resume I want to add hyperlinks to few titles, examaple Link to Job Experience Certificate will be included in text if the URL is provided What I tried ...
0 votes
0 answers
16 views

How to make listings package recognize strings of a specific form

The listing package provides literate command which allows replacing specific fragments of code with something else, like: literate={)}{{\textcolor{red}{)}}}{1} replaces the right bracket with its ...
  • 1,510
0 votes
1 answer
19 views

Add htbp to all float environments [duplicate]

In short: How can I add the optional parameters [htbp] to all float environments? Ideally, I don't want to define a custom new environment, but add these options "with a hack" like \g@addto@...
2 votes
1 answer
80 views

\newcommand to define shortcut with optional argument (derivative package)

The recent release (June 2021) of the derivative package includes the command \odif which can be used to typeset differentials. For instance, \odif[order={3}]{x} yields something like d^3x. Because I ...
2 votes
1 answer
75 views

Optional argument for newcommand

Suppose we define the following macros: \newcommand*{\G}[1][G]{\mathbb #1} \newcommand*{\Cop}[1][]{\Delta_{#1}} For the first one, if we use $\G$ it produces in the pdf what $\mathbb{G}$ does and if ...
  • 23
2 votes
0 answers
66 views

History - LaTeX2e - \newcommand - Why does the mechanism for detecting an optional argument not crank out the case of an implicit [?

[Please take this question for a moot point/an "academical" issue.] The LaTeX-kernel-command \newcommand was invented decades before expl3, xparse and \NewDocumentCommand were available. \...
  • 24.5k
1 vote
1 answer
72 views

History - LaTeX2e - \newcommand - Why optional arguments as (]-)delimited arguments?

[Please take this question for a moot point/an "academical" issue.] The LaTeX-kernel-command \newcommand was invented decades before expl3, xparse and \NewDocumentCommand were available. \...
  • 24.5k
5 votes
3 answers
203 views

How can I differentiate in \newcommand between an unused optional argument and an empty one?

I want to change the behavior of my macro depending on whether an optional argument is not given at all or is explicitly stated (using []) but empty. MWE could look like this (stolen from this answer):...
5 votes
4 answers
581 views

Pass 3 optional arguments in newcommand

In a mathematical text which I write, I want to denote a certain number by $S(x;q,a)$. The number, as you may have guessed, depends on three parameters $x, q, a$. I would like to give this expression ...
0 votes
2 answers
102 views

Why does xparse manual talk people into thinking that reliable expandable checking for optional arguments is possible? [closed]

There is no expandable method for reliably looking at the next token of the input stream. So why does xparse manual talk people into thinking that reliable expandable checking for optional arguments ...
0 votes
1 answer
56 views

Add optional arguments before and after "Exercise"

I would like to create an exercise environment for which I can specify two optional arguments, one appearing before the "Exercise" mention and the other one appearing in brackets after the ...
  • 15
1 vote
2 answers
129 views

Expanding command with optional arguments: \edef

I have defined a LaTeX command with an optional argument, e.g., \newcommand*{\commA}[1][opt]{A#1}, and I cannot get it to be part of an expanded command defintion with \edef, e.g., \edef\expcom{\commA}...
1 vote
1 answer
57 views

Macro with optional parameter returning calculated length

I'm trying to define a macro returning a calculated length, but making the parameter optional breaks the macro (error Missing number, treated as zero.): \documentclass{article} \usepackage{xfp} \...
  • 1,630
3 votes
3 answers
92 views

Using Starred Version as Optional Argument

I have been reading this page on defining commands with *-options. I have got completely stuck, though. I'd like the following. A command with an optional argument and a star option. Optional ...
  • 1,169
1 vote
2 answers
50 views

Behavior of environment with optional argument changes when optional argument is not passed

Recently, when I've been working with environments with an optional argument, I've noticed that the behavior changes when I introduce a set of square braces, even when there is nothing inside them. ...
1 vote
1 answer
117 views

Multiple optional arguments with tcolorbox

I would like to produce boxes from tcolorbox which can take two optional arguments, but I'm not sure where to start with. Here is my current MWE : \documentclass{article} \usepackage[utf8]{inputenc} \...
  • 13
8 votes
1 answer
100 views

xparse's 's' argument returns \Gamma and \Delta, instead of \BooleanFalse and \BooleanTrue

The xparse documentation says, But that's not what I get when I test s. \documentclass{article} \usepackage{xparse} \NewDocumentCommand{\myfunc}{s}{#1} \begin{document} \myfunc % should return \...
  • 715

1
2 3 4 5
9