{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

62
votes
5answers
6k 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) ...
21
votes
1answer
705 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} ...
9
votes
2answers
1k 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} ...
47
votes
5answers
8k 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 ...
28
votes
1answer
3k 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
2k views

Cite in theorem environment argument

When I try to cite a book in such a way \begin{theorem}[\cite[p.~90]{bibitem}] Theorem body. \end{theorem} I've got an error because of multiple use of [ and ]. Is it possible to cite in such a way ...
26
votes
5answers
1k 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 ...
12
votes
1answer
412 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} ...
13
votes
4answers
3k 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 ...
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 ...
10
votes
3answers
370 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 ...
9
votes
3answers
778 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: ...
15
votes
2answers
2k 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 ...
15
votes
3answers
9k 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 ...
4
votes
2answers
365 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 ...
13
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. ...
9
votes
2answers
192 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 ...
7
votes
2answers
395 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
5k 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
1k 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 ...
7
votes
3answers
556 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] ...
6
votes
2answers
136 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: ...
1
vote
1answer
135 views

naming argument and optional-argument for \def, \newcommand and newenvironment

I know how to create a new command or an environment. I think it will much better if I can specify name of the arguments. For example in framebox command and array environment below, we know exactly ...
8
votes
1answer
206 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 ...
14
votes
1answer
212 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 ...
3
votes
1answer
129 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
4k 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
329 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 ...
10
votes
1answer
173 views

Optional argument problem

This example works but if I try to put an optional argument changing \newcommand\TBLdiag[5]{% in \newcommand\TBLdiag[5][\tabcolsep]{% it does not work anymore. Of course I call \TBLdiag with ...
7
votes
3answers
186 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}} ...
6
votes
1answer
94 views

How to add optional arguments to a package I'm writing?

I want to build a package that can optionally typeset line in double-space. Something like this: \ProvidePackage{mypackage} % actual functional codes Then I can use the package in this way: ...
6
votes
2answers
293 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. ...
5
votes
1answer
650 views

How to expand several arguments in an environment?

I have an environment that I've defined as follows: \newenvironment{regularEnumerateEx}[2][0em] {begin{listSkeleton}[#1]{enumerate}{#2}} {\end{listSkeleton}} The problem is that I need to ...
4
votes
1answer
896 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 ...
10
votes
3answers
779 views

Are commands defined by \newcommand[.][.]{.} robust?

This question is from the comments at the foot of Abbreviations for AM, PM (small caps) for use within \textbf. Readers will get the remaining gist from there. With ...
5
votes
1answer
170 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 ...
5
votes
1answer
126 views

Is a command with an argument before and after the command possible?

I'm trying to create a LaTeX3 command that works the same whether its argument comes before or after the command. For example, I'd like to define \squared to be used as either \m\squared or \squared\m ...
4
votes
1answer
64 views

Macro for abbreviated ranges (pages, music measures)

I would like a semantic, configurable way to input ranges of pages, poetic lines, and music measure numbers. Using a macro would enable me to make sure all such ranges are formatted consistently, and ...
4
votes
1answer
93 views

mdframed: how to change the separator between the label and the title of a non-numbered thereom?

The problem There seems to be a bug in mdframed package. With the theoremseparator key, one should be able to change the text between the "label" and the title of a theorem ("Theorem" being the label ...
4
votes
3answers
175 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
106 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 ...
2
votes
2answers
76 views

Name of the proof instead of just proof

Packages I'm using: \usepackage{amsmath} \usepackage{graphicx} \usepackage[colorinlistoftodos]{todonotes} \usepackage{amsthm} \usepackage{amssymb} \newtheorem{thm}{Theorem} ...
2
votes
3answers
487 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
0answers
88 views

Tabularx moving table to next page, ignoring optional arguments [closed]

Using the tabularx and booktabs packages to include tables I have a problem in my Appendix. A table, when inserted, appears on the start of the next page, above the next appendix's designation and ...
1
vote
1answer
214 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
44 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]------\/ ...