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

learn more… | top users | synonyms

54
votes
5answers
5k views

Different command definitions with and without optional argument

I want to define a command that expands to two completely different things depending on whether I supply, or not, an optional argument. For example, \mycmd{normal} -> something(normal) ...
19
votes
1answer
519 views

] inside an optional argument

I accidentally discovered (here) that a closing square bracket within an optional argument delimited by [ ] can cause problems. Here is example code illustrating the issue: \documentclass{article} ...
8
votes
2answers
911 views

LaTeX: optional arguments with square brackets

LaTeX is trying to add a missing $ that I don't want to the following code: EDIT: replaced stricken lines from original question with minimal working example: \documentclass[letter,12pt]{article} ...
36
votes
5answers
6k views

More than one optional argument for newcommand

The \newcommand macro allows to use an optional argument for the first parameter #1 with: \newcommand{\mycommand}[3][defaultfor1]{blah blah blah} Is it possible to have more than one option with ...
26
votes
1answer
2k views

How can I make a package that accepts an optional argument?

I am writing a package that has a bunch of values that are going to be the same most of the time, but that I might want to change in select cases. I want to do this by giving this package an optional ...
11
votes
1answer
318 views

Bug? LaTeX misparses nested optional arguments

LaTeX seems to be having problems handling nested optional arguments. I've included a minimal code example that generates the error: \documentclass[12pt,oneside]{book} \begin{document} ...
23
votes
5answers
910 views

How can I use one argument as the default value for another?

I'd like to define a command that takes 1, 2 or 3 arguments, and where the 2nd gets the same value as the 1st if it is not defined. I tried \newcommand\codefrom[3][#1][Matlab]{ ... } but I get an ...
24
votes
3answers
2k views

How can I use \patchcmd with commands with optional arguments?

This question led to a new package: xpatch This is likely a simple question, but I'm getting stuck on the small details. I have an internal command, defined by a package as ...
12
votes
4answers
2k views

Optional arguments in \def

I want to re-define the \sqrt command (as detailed in Nice-looking p-th roots), and so far I have the following: \documentclass{article} \usepackage{fouriernc} % use the New Century Schoolbook font ...
8
votes
3answers
711 views

Optional arguments in pgfkeys?

I need an optional argument in a pgfkey? Something like the following: \pgfkeys{example/.code = (Argument: #2, optional argument: #1)} \pgfkeys{example=[other]{some}} should result in (Argument: ...
13
votes
2answers
1k views

New command with optional argument being first argument [duplicate]

I know I can create a new command with an optional parameter with \newcommand{\mycommand}[2][Hello]{\textbf{#1} #2} I would like to have the command such that there is an optional parameter which ...
4
votes
2answers
248 views

Different macro behavior when supplied an argument

I want to define a macro, call it \func, so that \func will output\phi, and \func[i] will output \phi(i). what is the easiest way to achieve this? I know there are other questions that address this ...
9
votes
2answers
155 views

Defining a macro with three optional arguments in the form \newmacro{a}{b}[c]{d}[e][f] and \newmacro{a}{b}[c]{d}*[f]

I am defining a macro in LaTeX2e for writing function declarations. I want that the macro has tree compulsory arguments: the name of the function (v.g f), a depiction of the type of variable it takes ...
5
votes
2answers
3k views

Beamer allowframebreaks default option

How do I tell beamer that I want allowframebreaks allowed by default? Something like noitemsep for itemize: \setlist[itemize]{noitemsep} So that I don't have to do: \begin{frame}[allowframebreaks] ...
11
votes
3answers
928 views

How to pass an optional argument to an environment with verbatim content?

This is an attempt to make clear what happened in this question of xport (now deleted, sorry). The now deleted question included code that tried to make my answer to this question of xport work for ...
10
votes
3answers
274 views

Defining a list environment with multiple optional arguments

I'm trying to define a list environment with multiple optional arguments and with a default values for those arguments. For example, creating a new environment with a name newenv, which accepts two ...
6
votes
2answers
63 views

Use of optional argument stretch in \parbox

I'm having some difficulty on how to use the "stretch" optional argument of \parbox. Is it supposed to equally interspace lines of text inside a box of determined size? If I code it like: ...
10
votes
3answers
5k views

Creating a new environment with one optional argument

I want to create a new environment with one optional argument in LaTeX. Here is what I used: \newenvironment{argument}[1][]{% \par \noindent \textbf{Argument#1:} \noindent} {} When there is no ...
14
votes
1answer
184 views

How to read a stream of tokens up to one of two different delimiters

The core question How can I process text delimited by one of two terminators? For instance, if I want to process text up to the next \A, I can just write \def\CmdA#1\A{...} But suppose that \A ...
8
votes
1answer
164 views

How can I make a custom theorem for a definition?

Looking at the wikibooks article on theorems has me wondering... I'd like to do something, if possible, similar to the default "proof" theorem style, whereby I can add a custom name to each theorem as ...
3
votes
1answer
111 views

Passing arguments to a .sty-file - a specific case

After having plowed through (i.e. read and trimmed down the given examples in an attempt to apply them to my case) these documentations and guides: Implementing key-value input: An introduction The ...
2
votes
2answers
3k views

\newcommand gives errors in math mode (with or without arguments)

I'm trying to define a custom command for use in math mode, defined as \newcommand{\deriv2}[2]{\ensuremath{\frac{\partial^2 {#1}}{\partial {#2}^2}}} Other non-math mode \newcommands work in my ...
13
votes
2answers
292 views

TeX Parameter Processing imitating key-value pairs

I am thoroughly confused by this answer to How to generate n points on a circumference and connect all of them while having constraints on the image size as I don't understand how the parameter ...
12
votes
2answers
5k views

A macro with either one or two arguments

I am trying to define a macro with variable number of arguments. For example I want to define a macro with two arguments that can work with one argument as well. So the same macro works in two ways. ...
7
votes
3answers
170 views

Adjusting command behavior based on argument type

I have a following command in my latex document: \newcommand{\ApplyGradient}[1]{ \pgfmathsetmacro{\PercentColor}{100.0*(#1+0.2)/1.3} \textcolor{black!\PercentColor}{#1}} ...
7
votes
2answers
327 views

A macro for optimization problems

This question is an extension of Using an array environment inside an xparse command. I was advised to make a separate question for the extension. I would like to thank egreg very much for his help. I ...
6
votes
2answers
269 views

How to extend a macro for e-mail addresses to support multiple arguments?

I prepared the following macros to format e-mail adresses in a e-mail header. \usepackage{xifthen}% Provides \ifthenelse and \isempty % E-Mail header strings with format. ...
6
votes
3answers
403 views

xparse empty arguments

I have defined a command using xparse as \DeclareDocumentCommand\mymacro{o o o} and I want to call it with various numbers of arguments (up to 3) \mymacro, \mymacro[test][two], \mymacro[][][test] ...
5
votes
1answer
133 views

verbatim-like environment with optional arguments poorly behaved

[EDITED to show where I actually want to use the optional argument] This question may be answered at How to pass an optional argument to an environment with verbatim content?, but I'm having a hard ...
4
votes
3answers
162 views

Arguments to Commands: […] vs {…}

Perhaps this is something that has been answered before, but a cursory search didn't turn anything up. Is there any logic to how commands take arguments? Some things want the arguments to the ...
4
votes
1answer
71 views

Optional arguments in verbatim environments

This question is a follow up to verbatim-like environment with optional arguments poorly behaved. Based on David Carlisle's suggestion, I manually looked for an optional argument and employed ...
3
votes
1answer
475 views

Creating a custom environment

I'm using the following syntax for my code snippets \begin{minipage}{\textwidth} \begin{lstlisting}[caption=<something>, label=<something>] The REST Endpoint URL is ...
2
votes
3answers
348 views

Itemize - set default option

I have plenty of lists, all with the [noitemsep] option: \begin{itemize}[noitemsep] \item foo \item bar \end{itemize} Is it possible, to setup itemize to use this option by default? Or do I ...
1
vote
1answer
95 views

Using variables to draw a tikz diagram

I am defind my own command to plat a diagram with tikz. Instead of constant values I rather want to pass numbers to my command which determine the height of the bars in my diagram. Problem: I am ...
1
vote
1answer
39 views

kprefix in \krddefinekeys seems to be not optional

Maybe I misunderstood something but the following example doesn’t compile with out a optional argument defining the kprefix \documentclass{article} \usepackage{keyreader} % [KV]------\/ ...