{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

4
votes
1answer
70 views

Create a package with optional mode and key values

I'm trying to create a package with three options as follows: \usepackage[swpl]{mypack} swpl option provides the environment \begin{myexample}[forced bracketed options]...\end{myexample} ...
8
votes
1answer
95 views

Automatically Insert Environment Arguments

How can I automatically insert [<+->] arguments to the itemize environment when I'm in a beamer frame so I get pretty incremental display during presentation?
13
votes
3answers
167 views

How to define a new command based on \section with its optional argument?

I've defined a new command called \mysec like the below: ‎‎‎‎‎‎ \documentclass{article} \newcommand{\mysec}[1]{\section{#1}} \begin{document} \mysec[Foo foo]{Bla bla bla} \end{document} But in the ...
0
votes
0answers
14 views

Re: LaTeX - Subfloat caption apparently can't include optional arguments for citations? [duplicate]

I would be very grateful for any help with the following problem, as a LaTeX novice. I am trying to create two subfigures, each with their own captions, to include quotations with the optional ...
5
votes
2answers
51 views

Different Behaviors Digesting \csname x\endcsname and Digesting \x (expansion issue)

This question has been significantly EDITED, as I learned more of the problem. If I was good, I would be able to create macros with multiple optional arguments, but not only can't I, but in this ...
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 ...
6
votes
2answers
64 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: ...
5
votes
1answer
47 views

How to put the character ] inside the short version of caption on list of table? [duplicate]

I'm using winedt and would like to insert something like \caption [blabla [-1, 1]V] {blabla [-1, 1]V...} in one of the tables, but I do not know how to escape the character ]. I've tried \\] ...
6
votes
2answers
79 views

Passing an if-else option to a custom sty file

I have a custom .sty file loading needed packages and defining some commands and environments. Is there an easy way to either: define an if-else option define option's default value I am using the ...
11
votes
1answer
78 views

Processing document class options with l3keys

How can I parse (that is, access) the entire option list given to the current document class with l3keys? This would obviously need some sort of \keys_define:nn { document-class-?? } { default ...
11
votes
1answer
103 views

Parsing commands with multiple optional arguments

Some LaTeX commands accept multiple optional arguments. Here are some examples: \makebox[<width>][<pos>]{<text>} \framebox[<width>][<pos>]{<text>} ...
9
votes
2answers
156 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
6answers
230 views

How to create new commands with multiple arguments?

I'd like to create a new command \add that accepts 2 arguments, called entity and title. In other words, the command should look like this: \add{entity}{title}. The output should have the following ...
6
votes
1answer
135 views

Gobble optional arguments

You can use \@gobble, for instance, to restrict the usage of a macro like: \documentclass{article} \makeatletter \newcommand*{\cmd}[1]{% #1 \global\let\cmd\@gobble } \makeatother \begin{document} ...
1
vote
1answer
78 views

Predefined enumerate settings

I have multiple enumerates across some files, for which I want a consistent style (same enumitem options): \documentclass{article} \usepackage{enumitem} \newcommand{\enumSettings}{noitemsep, ...
8
votes
1answer
86 views

Optional arguments: xparse vs. xargs

To implement a macro that takes one or more optional arguments that do not have to be placed in the first position, xargs can be used as well as xparse. The latter seems to have more recent updates ...
8
votes
1answer
53 views

Moving the optional argument

When I create macros using \newcommand, I usually provide default variants setting some of the first arguments in a sort of partial application style \newcommand\five[5]{#1,#2,#3,#4,#5} ...
11
votes
3answers
140 views

Cannot use ampersand as argument in user defined command with optional arguments

I'm trying to produce a command for an equation that may or may not be used inside an align element, and therefore sometimes needs a & next to the = to align the equation. I therefore defined the ...
3
votes
1answer
93 views

Xparse macro with optional parameter breaks value for PGF foreach

I write a document class and want to execute something a certain number of times, depending on a user-defined quantity. So I thought I'd use a foreach loop from PGF together with accessor macros: ...
2
votes
1answer
91 views

How can I pass optional arguments as optional arguments?

I have the following environments which are being used in my document. As you can see, a lot of unnecessary complexity is being added by my arcane optional argument handling using \IfValueTF. Is there ...
5
votes
1answer
58 views

Error output using \ifdefempty

I'm using TeX 3.1415926 (TeX Live 2013) and when I execute \documentclass{article} \usepackage{etoolbox} % contents \newcommand{\contentdesc}[2]{\item \ifdefempty{#2}{\textbf{#1}}{\textbf{#1}: ...
4
votes
0answers
55 views

xparse with underscore and optional argument

I need a macro which handles its input as follows: \foo A > #2 = A \foo{A} > #2 = A \foo(B) > #3 = A (round brackets) \foo_m A > #1 = m, #2 = A \foo_m{A} > #1 = m, #2 = A \foo_m(B) > #1 = m, #3 = B ...
5
votes
2answers
121 views

Setting package option from the command line

I want to compile a document that uses the tcolorbox package in two different ways: with the option /tcb/lowerbox set to visible, so that the lower part of the tcolorbox environment is typeset with ...
3
votes
0answers
66 views

Class Variables

I am exploring the use of class options, I was under the impression that optional arguments presented at the point of class declaration, were subsequently presented to all packages used thereafter. ...
8
votes
2answers
79 views

Connecting multiple arguments

I recently discovered Latex and is using TexMaker to edit my documents, in one of my university courses we will be performing a number of tests on a hydraulic rig. Since the tests will be conducted by ...
4
votes
1answer
180 views

\newcommand with optional multi-line argument and implicit itemize environment

While drafting a text, I want to subdivide and group text pieces and keywords to easily reorder them throughout the document. Examples for such a group of text pieces would be: Example 1): Two ...
9
votes
2answers
356 views

How to use a macro inside \includegraphics options?

I have to do several figures like this: \begin{figure}[h!] \centering \includegraphics[trim = 9.55cm 1.8cm 10.25cm 4.05cm, ...
5
votes
2answers
273 views

TikZ: Using optional arguments in after part of \newenvironment*

How can I pass the optional arguments to a node being drawn in the after part of a \newenvironment*? In the before part this is easy since I can simply use #1. I tried using \edef, but that ended up ...
7
votes
1answer
743 views

TikZ: \newcommand with optional TikZ options

I want to create a new command with some default TikZ options that you can override using an optional argument. If working as intended the code below would generate a red line between A and B, and a ...
12
votes
5answers
233 views

Two independent optional arguments for new commands

I'm trying to adapt the solution provided in Different command definitions with and without optional argument to change the behavior of my new command. I'd like to use basic command to avoid some non ...
5
votes
2answers
135 views

explicitly setting the a4paper option has no effect using scrreprt?

I compile the following code: \documentclass[a4paper]{scrreprt} \usepackage{lipsum} \begin{document} \lipsum \end{document} with pdflatex. If I leave out the a4paper option and compile again, the ...
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}} ...
3
votes
1answer
238 views

How to write a \newenvironment with a conditional structure and one optional parameter

I would like to define a new environment with an optional parameter. Currently, I have \theoremstyle{plain} \newtheorem{prop}{Proposition} \newenvironment{propExt}[1][]{\ifx!#1! \begin{prop} \else ...
3
votes
1answer
102 views

LyX style for command with multiple arguments

I would like to create a style for a command that takes multiple arguments: \classify{A}{B}{C} I started creating a style Style Classify Category FrontMatter LatexType Command ...
3
votes
1answer
112 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 ...
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 ...
3
votes
3answers
78 views

Environment with coordinate-like arguments

I would like to define an environment which takes coordinate like arguments (1,2). I think about two different calling schemes: \begin{myenv}(mandatory coordinate)[optional](optional coordinate) ...
7
votes
4answers
200 views

Special macro definition (2opt, 1mand)

How can you define a macro \cmd in TeX primitives using two optional arguments (and a mandatory one) that fulfills the property that calling \cmd[opt]{mand} is equivalent to \cmd[][opt]{mand}. Yet, I ...
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 ...
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 ...
0
votes
0answers
49 views

\renewenvironment optional arguments using old environment [duplicate]

I ran into a problem and haven't quite figured out how to solve it. I would like to reuse an existing environment definition with optional argument to get a new one, which should also have one ...
1
vote
0answers
64 views

What is [htbp] used for? [duplicate]

When I try to input a macro for tables or figures, I usually get [htbp] beside the command... e.g. \begin{table}[htbp] What is the use of it? Can I remove it?
5
votes
1answer
82 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: ...
5
votes
2answers
174 views

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 ...
4
votes
1answer
89 views

Problems with xparse and enumerate

I am trying to get the following document to work \documentclass[10pt]{article} \usepackage{enumitem} \newcounter{foo} \newcounter{bar}[foo] \addtocounter{foo}{1} \usepackage{xparse} ...
2
votes
2answers
92 views

Add parameter to existing command produces error

I have this command in a template given by my prof \newcommand{\homeworkProblemName}{}% \newcounter{homeworkProblemCounter}% \newenvironment{homeworkProblem}[1][Problem ...
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] ...
5
votes
1answer
122 views

Using environment argument inside a new environment doesn't work

I know it must be something trivial: \documentclass{article} \usepackage{amsmath} \usepackage{amsthm} \usepackage{thmtools} \usepackage[svgnames]{xcolor} \usepackage{framed} ...
19
votes
1answer
520 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} ...
2
votes
1answer
1k views

Create new environment with options

I'm new to creating new environments and even though I searched at the xparse*documentation I couldn't figured out how to solve my specific problem. I would like to create a new environment, say ...