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 [optional-arguments]

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

5
votes
2answers
173 views

Use second argument for optional first argument if not provided in macro

I'm trying to construct a command with one optional and one mandatory argument and I'd like the default if the optional argument is not provided to be #2. Why does this not work? (error: Illegal ...
0
votes
0answers
23 views

Add multiple arguments to figure

I am placing a figure in my document using the following code: \begin{figure}[H] \centering \includegraphics{AlgorithmFlow.png} \caption{Caption} \label{fig:myLabel} \end{figure} I ...
0
votes
2answers
17 views

How to detect whether the option citecounter was enabled on biblatex?

I think this is the definition of the citecounter option on the biblatex package: \DeclareBibliographyOption[boolean]{citecounter}[true]{% \ifcsdef{blx@opt@citecounter@#1} {\csuse{blx@opt@...
1
vote
1answer
17 views

How to detect whether \PassOptionsToPackage was already called?

If I call: \PassOptionsToPackage{backend=biber,style=numeric,backref=false}{biblatex} % And later someone else call again \PassOptionsToPackage{style=abnt,backend=biber}{biblatex} What will happen? ...
10
votes
3answers
217 views

\newcommand: Using one parameter as the default for the other

I would like to define a macro that takes two arguments, one of which is optional. If it is not given, then it should take the other one as default value. Unfortunately, \newcommand{\mycommand}[2][#...
0
votes
0answers
26 views

How to pass argument for `\includegraphics[width=..]..` without causing “Runaway argument?”? [duplicate]

I'm going to despair: It seems nobody has a problem when passing an argument for the width of \includegraphics, but I always get Runaway argument?. Whenever I remove the [#2\textwidth] from my command ...
10
votes
2answers
409 views

Euler and minus sign

I'm trying to define a macro to typeset Eulers complex e-power with or without a minus sign in its argument. I would like the macro to automatically detect if its argument starts with a -. I have the ...
17
votes
2answers
745 views

Why do people specify date as an option for \usepackage?

In LaTeX code written by other people, I sometimes see a date specified as an optional argument for \usepackage: \usepackage{iftex}[2013/04/04] Intuition tells me that this is some way to ensure ...
0
votes
0answers
21 views

Using optional argument in closing statement of new environment

The answer 969/29410 showed that it is possible to use optional arguments in environment definitions: \documentclass{article} \newenvironment{hello}[1][world]{\noindent Hello #1, }{Bye now!\\} \begin{...
1
vote
1answer
34 views

Creating a custom definition environment, with an optional argument and non default punctuation

This seems like it should be the most basic question, but I can't find a comprehensible answer on the site, I'm afraid. I'm trying to define a definition environment that 1) replaces the ...
3
votes
3answers
94 views

Different behavior if no arguments

This is similar, but not a duplicate of Special behavior if optional argument is not passed and Different macro behavior when supplied an argument. I want to define a macro \XXX such that \XXX{1} and ...
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 ...
1
vote
1answer
55 views

Pass option to each occurence of command (especially \printbibliography with biblatex)

In a large book with many sub-bibliographies, I want to ensure that crucial bibchecks are executed at every call to \printbibliography. Normally, one would simply call \printbibliography[check=...] ...
5
votes
1answer
79 views

Fail to pass arguments to orbital module of chemmacros when used inside chemfig

While illustrating atomic orbitals for 1,3-butadiene guided by examples in chemmacros' manual, I receive the following error: Argument of \orbital has an extra }. } MWE: \documentclass{article} \...
1
vote
2answers
40 views

Arrival atom numbering doesn't work with \chemabove

Consider the following MWE: \documentclass{article} \usepackage{chemfig} \begin{document} \chemfig{ X -[:30,,,2]^{18}\chemabove{O}{H} -[:-30]X } \end{document} This code returns an ...
0
votes
1answer
25 views

Using command with optional arguments inside tikzcd arrows

I have defined a command for the jacobian matrix, such as follows \newcommand{\Jacobian}[2][]{\operatorname{J}_{#1}{#2}} The problem comes if I try to use it inside a tikzcd arrow, probably because ...
2
votes
1answer
23 views

How to correctly convert size passed as argument to an environment?

I am trying and failing to adapt diagrams-latex.sty to do what I want. It takes optional parameters width and height that are passed on to an external script, but wants them as a dimensionless value ...
1
vote
1answer
74 views

How do I draw an optionally colored circle/square/ellipse around a symbol

In this thread, @HenriMenke showed how to put a circle around a symbol. It's easy to modify his code to color the circle, see below, but I don't understand how to make the color an optional ...
7
votes
2answers
174 views

How to define a comma separated list of arguments for includegraphics

I have a large set of pictures, and I want to apply predefined settings to each using the optional argument of the \includegraphics macro from the graphicx package. I would like to define the ...
1
vote
1answer
105 views

Add optional argument to new environment template

I'm attempting to create two new environments, one for writing exercises and another for its solutions, with the following characteristics: The Exercise environment should have: By default, have no ...
0
votes
2answers
153 views

AUCTeX prompting for optional arguments

My general question: is there a way to get AUCTeX to prompt me automatically for an optional argument of a command when I invoke it with TeX-insert-macro (i.e. C-cRET)? (like it does when you invoke, ...
1
vote
1answer
95 views

LaTeX Grammar and Nesting Rule

Is there any grammar and rule describing the allowed nestings and combinations and the allowed format of the arguments in LaTeX? E.g. \section{\verb|mySec|} \section{\begin{huge}mySec\end{huge}} \...
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}...
4
votes
1answer
57 views

Tikzcd: set description option in labels of arrows as default

I want all arrows in my tikzcd diagrams to have labels over them, as in the example below. \documentclass{article} \usepackage{tikz-cd} \begin{document} \begin{tikzcd}[sep = large] T \arrow[drr, ...
3
votes
1answer
67 views

How to pass tikz code as an argument?

I want to prepare an environment to show a view of a display and use some tikz code as an optional argument to mark some things on it. The first "screen" shows result with hardcoded nodes but I need ...
2
votes
1answer
101 views

LaTeX Nesting \verb in \section

Why is \section{\verb|mySec|} invalid LaTeX code.
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, ...
6
votes
2answers
213 views

Optional Arguments for Macros Called within Tikz Matrix

I am trying to set up a tikz matrix (actually, in this case, a tikz-cd) where I call different macros within the cells, which will determine the content that appears. This all works fine provided I ...
3
votes
1answer
41 views

Access optional item label when defining label style with enumitem

I want to define a personalized description environment, which adds a boldface and brackets around the label name, so I'm using enumitem: \newlist{named}{description}{1} \setlist[named]{label=\textbf{...
1
vote
2answers
75 views

Best way to craft custom command with 4 optional arguments

I would like to make a command that produces the following results \myquantity[Q] \myquantity[Q][i] \myquantity[Q][][j] \myquantity[Q][i][j] \myquantity[Q][i][j][\bar] \myquantity[Q][][][\bar] \...
5
votes
2answers
92 views

Odd custom theorem behavior when trying to set default value of optional argument

MWE: \documentclass{book} \usepackage{amsthm} \usepackage{enumitem} \usepackage{xparse} \usepackage{hyperref} \usepackage{lipsum} \newtheoremstyle{fctaylor}% name {\topsep}% Space above {\...
2
votes
1answer
66 views

optional argument

I want a macro that takes an optional argument. If nothing is passed, it produces G. If i is passed, it produces G_{p_i}. The following code however is facing some error "Can't use '\spacefactor' ...
6
votes
5answers
664 views

Is there a LaTeX recommended standard for commands with optional arguments?

According to LaTeX standards, the optional arguments of a command come before the mandatory ones. For example: \command[optional]{mandatory} Is it recommended to always follow this scheme? Is there ...
4
votes
2answers
61 views

Not using optional argument makes environment break

I'm defining a wrapper environment for filecontents so that I can modify its behaviour. Everything works fine for most of the test cases. For example, I define an environment testenv which takes one ...
1
vote
1answer
27 views

Input length sensitive optional argument macro

I wrote the following macro, that prints C_0^*. But I wanted to push the position of * little high, hence used strut. I also wanted optional argument i.e. C^* and C_0^* can be handled by same macro. ...
1
vote
0answers
28 views

Combining mhchem and chemnum with an optional argument? [duplicate]

I am trying to combine two packages in to a new command. The problem I have come across is when trying to add an optional parameter. I want to be able to have 2 parameters with the second parameter ...
13
votes
2answers
278 views

Tabular ignoring optional parameter to \\

In a basic tabular environment it seems that the optional parameter to \\ sometime has no effect. For instance, why is there no additional vertical spacing following the highlighted lines even though ...
2
votes
3answers
58 views

Custom command with addressable arguments

I know about \newcommand[<arg_num>]{#1 ... #n} to define a simple macro with up to nine arguments. (More if you link multiple newcommands together) I recently started to look at xparse for ...
2
votes
1answer
141 views

Modifying argument in macro

I need to modify an argument of macro. For example #4 equals to 1.1 Optimal solution of RNASP When I write Figure #4, output is this: Figure 1.1 Optimal solution of RNASP But I need this: Figure 1....
1
vote
0answers
79 views

LuaTeX: matrix in equation trows “missing number, treaded as zero” Error [closed]

Solved: I had declared an algorithm just before this equation, in it I did set \SetKwArray{array}{array}. I changed it to \SetKwArray{arraq}{array}, works fine now. This is my document. It throws ...
3
votes
1answer
52 views

newcommand says missing number

I plan to write a command which rounds a number with n digits. n is an optional argument and it is 2 by default. However, I keep receiving error message: Missing number, treated as zero. Let's see ...
0
votes
1answer
43 views

Different command definitions with more than one optional arguments arguments

I was reading the following post Different command definitions with and without optional argument on how to implement Different command definitions with and without optional argument. The example ...
1
vote
1answer
147 views

How to change fontspec’s default options

How can I change the default font features for the fontspec package? For example, I have a lot of definitions like: \setromanfont{FontName}[ Path = ../fonts/, Extension = .otf, ItalicFont ...
2
votes
1answer
215 views

LuaTeX: Call a Lua function with two optional arguments

I've read More than one optional argument for newcommand and I chose the answer with xargs. I would like to pass a second optional argument to the Lua function. But the first of the two commented \...
2
votes
1answer
39 views

empty options [] in pgfplots

I am curious why specifying empty options ([]) is different from not specifying options at all. Eg consider the MWE which produces \documentclass[tikz]{standalone} \usepackage{pgfplots} \pgfplotsset{...
2
votes
2answers
51 views

Use includegraphics with optional argument in environment end

I am trying to define an environment that calls an external command to draw pdfs based on the contents of the environment, and include the output. Now I also want to be able to pass on the width and ...
0
votes
1answer
47 views

Autoref with optional argument text *in generated link*

Related to Autoref with optional argument, I would like to define an (optional) argument to \autoref that appears after the regular autoref printout, but within the actual link that is generated by \...
1
vote
1answer
38 views

\let on macro defined by \newcommand with optional argument [duplicate]

Suppose we have \newcommand{\foo}[2][optional]{#1 #2} defined somewhere (e.g. some package) and want to redefine it and re-use the original definition. This usually works with \let like described in ...
2
votes
1answer
86 views

Autoref with optional argument

Something I have always wanted to do is use \autoref with an optional argument, similarly to the use that is often made of \cite: I would like to be able to write \autoref[comment]{label}, to obtain [...
2
votes
2answers
145 views

! Package keyval Error: language={bash},numbers=left undefined

The following M(n)WE gives me the message: ! Package keyval Error: language={bash},numbers=left undefined. Seems like the Key-Values are not being defined in my variable properly? \documentclass{...