Stack Exchange Network

Stack Exchange network consists of 174 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}.

1
vote
2answers
26 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
17 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
21 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
68 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
155 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
58 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
145 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
90 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
189 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}...
3
votes
1answer
34 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
58 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
61 views

LaTeX Nesting \verb in \section

Why is \section{\verb|mySec|} invalid LaTeX code.
2
votes
1answer
59 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
191 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
37 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
68 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
79 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
57 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' ...
5
votes
5answers
607 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
57 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
25 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
26 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 ...
12
votes
2answers
242 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
53 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 ...
1
vote
1answer
119 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
67 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
44 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
80 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
162 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
33 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
45 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
37 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
25 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 ...
0
votes
0answers
52 views

How to create named variables in Latex [duplicate]

I just came across this example command: \newcommand{\tstar}[5]{% inner radius, outer radius, tips, rot angle, options \pgfmathsetmacro{\starangle}{360/#3} \draw[#5] (#4:#1) \foreach \x in {1,.....
2
votes
1answer
61 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
94 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{...
4
votes
4answers
225 views

Macro for open balls similar to mathool's DeclarePairedDelimiterX

I would like to create a macro \openball[<optional size>]{<radius>}{<center>} producing \mathrm{B}_{<radius>}^\circ \lparen <center> \rparen if no optional argument is ...
1
vote
2answers
24 views

Simplify setting the same properties multiple times

I just found myself having figures that include multiple image files with the exact same options. Is there a way to avoid this repetition? (That would also make it less cumbersome to change these ...
0
votes
0answers
22 views

commandx optional arguments

I have a custom command for the package todonotes \newcommandx{\custom}[3][1=]{\todo[#1,author=#2]{#3}} which is supposed to be used like: \custom[inline]{author1,some comments} Instead, it raises ...
1
vote
1answer
44 views

Add Rows to Table With Macro (calc fields result the same for each row)

I use as template macro from this articale: Add Rows to Table With Macro. All work fine if values in cells not to calculate. But othewise results of calculation is the same for each row. How to avoid ...
3
votes
1answer
32 views

Colouring text doen't work in newcommand definition

I am trying to define a new \note command based on todonotes and changes packages but I'm having troubles with the optional selected text styling. I want it to be coloured based on the changes ID ...
4
votes
4answers
367 views

Detect no argument in \newcommand

I wonder if there is a way to create a command which can discriminate when there is an argument or not. I don't mean empty argument, I mean no argument at all. Here an example \newcommand{\mycommand}...
0
votes
1answer
93 views

How to know all the optional arguments of Latex commands\environments? [duplicate]

For external packages CTAN provides the needed documentation, however, for built-in Latex commands I am not aware of any proper documentation except for The (not so) short introduction to Latex which ...
0
votes
0answers
25 views

Macro with optional argument inside \input

I'm currently facing the problem that I don't know how to properly put a macro with an optional argument as an argument inside \input. If I use something like this \newcommand{\test}[1][Hi]{#1} \...
1
vote
2answers
65 views

Nested newcommand and expanding \@nil

I'm creating a command to generate a series of macros all with equivalent styling. i.e. something along the lines of 1 \newcommand{\newcustommacro}[2]{\newcommand{#1}[1][Default]{#2{##1}}} \...
1
vote
1answer
48 views

Option clash for package tkz-tab

Here is the code: \documentclass[11pt,a4paper]{article} \usepackage{fontspec} \usepackage[french]{babel} \usepackage{tikz} \usepackage{tkz-tab} \usepackage[inline]{tkz-tab} \begin{document} test \...
1
vote
1answer
57 views

Bugs in conditional structure in a newcommand definition with optional arguments

I am trying to create a new command for add a caption and/or the label to an equation. The not optional parameter is for the text of the equation and first optional parameter is for the label, the ...
6
votes
3answers
218 views

Second optional argument for newcommand to be the same of the first in case it is not specified

I want to define a \newcommand with two argument, of which one is optional, which allow me to have the same output of the first input in the case I do not specify the second argument, while being the ...
2
votes
1answer
47 views

Problem with the optional value of the first argument of a newcommand

\documentclass[12pt,a4paper]{article} \usepackage[utf8]{inputenc} %définition de variable texte pour compilation conditionnelle \def\ChoixDeVersion{AB} %AB=Avec Barème, SB ou autre = sans bareme \...