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}.

461 questions
8
votes
5 answers

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 any reason to avoid commands with inverted order…
8
votes
1 answer

Defining optional parameters in \newcommand

If I have a command in the form \newcommand{\TM}[1]{\color{red} $\boldsymbol{#1}$} how can I call it with an optional parameter for color? What I want is that if it's called like \TM{\alpha} it should return a red alpha but if it's called…
Gabu
  • 995
5
votes
2 answers

Iterating over a list of optional arguments

I'm defining a new command which should take an optional list of arguments (integers or ranges): \doit[3,5-7,9]{something} What I have so far: \def\doit{\@ifnextchar[{\@with}{\@without}} \def\@with[#1]#2{ ... } \def\@without#1{ } In the with…
5
votes
1 answer

Passing more command line argument

I am new to latex. I would like to pass command line arguments (probably more) to \newcommand macro and expecting output like below. if input is 1 /include {1.tex} else if input is 2 /include {2.tex} else if input is 3 /include…
BusyBee
  • 123
  • 4
4
votes
3 answers

How can I utilize optional arguments for flexible Vector sizes?

I have created a macro to create a size of 2 x 1, but I would like to add an optional argument to make it 2 x 1, or 3 x 1 depending if you choose to a third argument. The current implementation is, \NewDocumentCommand{\Vector}{ m m}{% …
Michael
  • 43
4
votes
1 answer

Russian matryoshka doll of optional arguments

Why this not work. I suspect an expansion problem ... \documentclass{standalone} \newcommand{\foo}[1][foo]{#1} \newcommand{\Fbox}[1][bla]{\fbox{#1}} \begin{document} \Fbox[\foo[bla]] \end{document}
Tarass
  • 16,912
4
votes
4 answers

How to make a command with three optional arguments?

I'm sorry for my English, but, anyway, I'd like to know how to create a new command with three optional arguments? I wanna get what is shown on the picture. I have some other ways how to achieve that, but they are not so comfy as I want. I tried to…
MGMKLML
  • 185
3
votes
0 answers

\let, \renewcommand, and optional arguments

Possible Duplicate: When to use \LetLtxMacro? I have a problem in redefining a command with an optional argument in terms of its old definition. Here is what I did: \newcommand{\testopt}[2][optional]{opt:#1; arg:#2.} \let\oldtestopt\testopt …
Nicola
  • 123
1
vote
0 answers

Redefine an environment such that it always has a certain optional value unless told otherwise

How can I redefine an environment so that it will have a certain optional value unless told otherwise? My particular problem is: how can I redefine the itemize environment so that its beginpenalty option is always set to…
Noah J
  • 515
1
vote
2 answers

Best way to craft custom command with 4 optional arguments

I would like to make a command that produces the following…
1
vote
1 answer

how to check in the tex file an argument has been passed to a class

within a tex file, I'd like to know if a given argument has been passed to a class. E.g., suppose in my main tex file: \documentclass[optionA]{myClass} How can I check if optionA has been passed to myClass ? And is there a way to know its value /…
Sergio
  • 303
0
votes
1 answer

Introducing colour ta a separator

I am having difficulty constructing the function \celest_separ:n that can handle colour because code level functions do not have optional arguments. Quite unfortunate. How may I get out of such problem ? What is the advantage of using - versus…
Celest
  • 1
0
votes
0 answers

position of optional arguments

\documentclass[a4paper]{article} \usepackage{amsmath} \newcommand*{\price}[2][17.5]{\pounds #2 excl VAT @ #1\%} \begin{document} \setlength{\parindent}{0pt} \price{100} \\ \price[20]{30} \end{document} Works perfectly fine. For my purpose, is…
CasperYC
  • 683
-1
votes
1 answer

Passing symbol to a command

I intended to have a command to print a coloured QED using a user-defined symbol. The advice is not to make commands with two consecutive optional arguments. What is one to do, is there a neat way to accomplish this…
-1
votes
1 answer

Environment with multiple optional arguments

I have the following environment taking four arguments, the latter two being optional. Things look as expected. Would I have to test for #4 in my case ? \NewDocumentEnvironment{Statement}{mmoO{orange}} { \IfNoValueTF {#3} { \noindent…
Veak
  • 1