{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

11
votes
3answers
196 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
114 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
123 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
75 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
69 views

xparse with underscore and optional argument [closed]

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 ...
6
votes
2answers
205 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
70 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
123 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
343 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 ...
10
votes
2answers
692 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
340 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 ...
9
votes
1answer
2k 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 ...
13
votes
5answers
267 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
184 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
184 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
386 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
156 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
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 ...
4
votes
3answers
174 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
81 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) ...
8
votes
4answers
225 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
103 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
169 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
50 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
65 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?
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: ...
5
votes
1answer
220 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
117 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
104 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 ...
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] ...
5
votes
1answer
131 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} ...
21
votes
1answer
698 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
2k 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 ...
2
votes
3answers
480 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 ...
5
votes
1answer
146 views

Switch on number of arguments given to a macro

I want to define a macro that does different things depending on the number of (optional) arguments given to it. Is this possible? How? \documentclass{standalone} \usepackage{xparse} ...
10
votes
3answers
365 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 ...
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 ...
4
votes
2answers
794 views

Line break (continuation) for commands (options, arguments)

How to do proper line breaking (continuation) for commands, i.e. their options and/or their arguments? For example, in order to transform this: \usepackage[top=1.0cm, bottom=1.0cm, left=1.0cm, ...
10
votes
2answers
178 views

Flexible parenthesing command

I would like to create a smart parenthesing command without using the xparse package. \p(1) prints (1) \p[1] [1] \p{1} {1} \p(1|2) (1|2) I tried this code but it ...
5
votes
1answer
471 views

Optional argument within another optional argument in biblatex \cite

What is the right way to define a macro with an optional argument that can be called within the <postnote> optional argument to biblatex \cite? The last two \cite below don't work. (Unless ...
11
votes
2answers
1k views

A new environment based on enumerate

I have defined the following simple environment: \newenvironment{renumerate}{\begin{enumerate}\raggedright}{\end{enumerate}} I wonder how the above can be modified to use with, say, the following: ...
7
votes
2answers
142 views

Using a required argument as a default for an optional one in \newcommand

I'd like to create a new subsection command with the same calling structure like the original one, but I have no idea on how to handle the case when the optional argument is omitted. Basically I want ...
2
votes
0answers
76 views

\let, \renewcommand, and optional arguments [duplicate]

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: ...
5
votes
1answer
114 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 ...
13
votes
2answers
327 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 ...
14
votes
1answer
209 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 ...
4
votes
1answer
892 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 ...
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} ...
8
votes
1answer
205 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 ...
9
votes
3answers
330 views

Create macro with several options

I struggle to create a macro that can take several options. What I want to create is for \mycommand[up,middle]{Macro} to output Macro with 'up' and 'middle' specified. Using etoolbox in the MWE below ...