{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

12
votes
4answers
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 ...
6
votes
6answers
188 views

How to write macro with variable amount of text variables

I am trying to make a signature block macro that accepts a variable number of text variables so that I can add or subtract the text without using empty fields "{}" as arguments. \sigblock{0}{2}{...
3
votes
3answers
46 views

Creating \newcommand from existing command

So I have been using the nomencl package with the following \newcommand, to save having to type the abbreviation and then the \nomenclature command: \newcommand*{\nom}[2]{#1\nomenclature{#1}{#2}} %...
5
votes
2answers
131 views

Square brackets for \section and \chapter. What is the difference between \section{Section Name} and \section[ something here]{Section Name}?

I recently solved a problem for adding footnotes in a chapter title by changing \chapter{Title\footnote{text}} to \chapter[Title]{Title\footnote{text}}. However, I don't understand why this works. ...
3
votes
1answer
22 views

Setting frame options for a frame at runtime

I am designing a custom theme. What I want to achieve is I want to construct an if statement that take cares of options of the frame. For an examples you can see the following code: \documentclass{...
4
votes
2answers
175 views

Table with unknown number of rows

I (a LaTeX noob) am trying to create a command that I will call as follows: $\machine{a_1}{a_2}{\vdots}{a_n}$ with a variable number of arguments, which will output $\begin{array}{|c|} \hline ...
4
votes
1answer
130 views

How to create a colour option in custom beamer theme?

I have used this answer from the question about how to design a beamer theme from scratch to design a Beamer theme to look like a university presentation (Powerpoint) template. There are 3 colour ...
5
votes
2answers
127 views

How do I nest a command with an optional argument?

I'm having problems making a normalizer command that can nest. Here is my code so far: \documentclass{article} \newcommand{\nrml}[2][]{N_{#1}(#2)} \begin{document} $\nrml[\nrml{H}]{J}$ \end{document}...
5
votes
7answers
306 views

newcommand with comma separated argument, and optional arguments

I want to define a command (not with \def) the simplest possible way that it takes arguments separated by a comma, supports an optional argument (the first one). maybe another solution with extra ...
5
votes
0answers
67 views

How to tell LaTeX to throw a warning if argument is not being used?

In this question the given argument wasn't used, because #1 was missing.. One would actually assume an error or a warning be thrown. A little MWE based on 1: \documentclass{article} \usepackage{...
4
votes
1answer
256 views

Latest xparse/amsmath update doesn't work well in align

The following minimal example doesn't compile when the optional argument to \macro is used: \documentclass{article} \usepackage{xparse,amsmath} \NewDocumentCommand{\macro}{o}{A\IfValueT{#1}{(#1)}}% ...
3
votes
1answer
38 views

Different command definitions with and without optional argument renders incorrectly

I used answers given to this question (in particular, this answer by egreg) to come up with the following code: \documentclass{article} \makeatletter \def\ifemptyarg#1{% \if\relax\detokenize{#1}\...
5
votes
4answers
138 views

How can I define a number parameter for this own align environment?

I'm "trying to change the "0.5" as needed. It would be perfect if this command could have an default value of 0.5. Unfortunately it seems to be very difficult to create a new environment with the "...
4
votes
1answer
43 views

Gettting rid of ntheorem's limitation concerning footnotes in theorem's notes

As shown by the following MWE, footnotes in theorems' notes work well for amsthm's theorems: \documentclass{article} \usepackage{amsthm} \newtheorem{theorem}{Theorem} \begin{document} \begin{theorem}[...
3
votes
1answer
47 views

Passing a newcommand with one argument to another newcommand

I am wondering how to define a new command A with another new command B (which has one argument x) as the argument of A. Here is a simple example: \documentclass[english]{article} \usepackage[T1]{...
3
votes
1answer
41 views

Ignoring optional argument in bibliography entries

I have a long list of references that are of the form, for example: \bibitem[optionalarg]{label} Text of the reference When I compile the source, this makes the cited reference to appears as [...
1
vote
1answer
51 views

Styling \Blindtext and \blindtext (aka renewcommand with optional arguments)

I am using blindtext package to draw out how the layout of the document will look like and then swapping the "dummy" parts with real text. Problem is that I would like to give some style to these text ...
4
votes
2answers
67 views

Newcommand inside foreach: multiple arguments and minipage environment

I am trying to define multiple, sophisticated newcommands within a foreach loop. This sounds so simple, but why is it so hard ? Naive attempt: \documentclass{report} \usepackage{tikz} \foreach \i ...
0
votes
2answers
56 views

reverse expansion order with optional parameters

Trying to implement a command with more than nine parameters (that also reverses things about) when there are, e.g., 8 of them, the first invocation is temporarily saved with \def\mytemp{\mycommandtwo{...
5
votes
4answers
115 views

Define newcommand with multiple sorted mandatory arguments that can be empty

I'm trying to define a command that will take 3 arguments each one possibly empty. An empty argument will slightly modify the output. Let me give a non-working example : \newcommand{\foo}[3]{ \...
2
votes
1answer
82 views

Beamer template with different style options for frame Sidebars

After looking at this post I'm sure something similar--having a different template style applied to particular frames--could be done with sidebars rather than with headers. As such I adapted the code, ...
19
votes
1answer
3k views

Define same command with different amount of parameters

I want to define two versions of the command \Set, depending if I provide one or two parameters. I.e. like this: \newcommand{\Set}[1]{\bigl\{ #1 \bigr\}} \newcommand{\Set}[2]{\bigl\{ #1 \bigm| #2 \...
1
vote
1answer
36 views

Default behaviour when missing argument in \newcommand

I'll try to be clear because this is not what I am looking for. What I'm trying to do is to define a new command that takes one argument but has a different behaviour whether that argument is or is ...
2
votes
1answer
19 views

Issue Passing an Optional Argument through Theorem Name with thmtools [duplicate]

I am using thmtools to create theorems, and I sometimes want the theorem name to include math symbols. In this particular project, I have used xargs to create a command that uses an optional argument, ...
2
votes
2answers
85 views

How to switch macro expansion by giving optional arguments?

Popular ways to define a macro with optional arguments is using TeX's \def with the aid of \@ifnextchar[ and/or LaTeX's \newcommand. In both cases, macro's definition usually contains its optional ...
15
votes
3answers
1k 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 ...
5
votes
1answer
36 views

Passing arguments to class in a key=boolean value manner

Assume I have a bunch of flags which I want to pass to my class, how do I do this? If you see the example below, I am looking for passing flags in the form: key=<boolean value from flag> to ...
10
votes
6answers
18k 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 ...
2
votes
1answer
113 views

Macro to emulate \SI macro of siunitx package

I am using pandoc to convert a .tex document into a .docx. The tex document uses the siunitx package. As pandoc can not interpret the macros in the package, I have to write dummies for the macros I ...
6
votes
2answers
371 views

Square brackets [ ] as first text inside environment

I had a case where I wanted do start a text with a square bracket inside an environment. It was interpreted as an optional argument. My workaround was to insert a {} to separate that. Is that the way ...
1
vote
3answers
140 views

Optional parameter in newcommand

I have made a command \newcommand{\mysec}[2]{% \textbf{#1} \\ #2 } I use it with \mysec{A}{B}. But sometimes I also want a third parameter. I could make a whole new command for those situations ...
1
vote
1answer
94 views

Enumerate with enumitem and \newcommand macro

% !TeX spellcheck = he_IL \documentclass[titlepage=false,12pt,titlepage]{scrreprt} %\pagenumbering{roman} \usepackage{ucs} % unicode support \usepackage[utf8x]{inputenc} \usepackage[T1]{fontenc} %...
5
votes
1answer
94 views

Optional argument breaks command with multicolumn

I have a command to make a formatted header entry in a table. Most table header entries span 1 column, but others span multiple columns, so I defined the command as follows with an optional width ...
18
votes
2answers
5k views

How do you define your environment such as to use […] for some parameter(s)?

In an environment, say \newenvironment{whatever}[3]{...}{...} you instantiante it (if that's the word for it in LaTeX) by \begin{whatever}{first}{second}{third} ... \end{whatever} But how do ...
3
votes
1answer
48 views

Redefine optional argument to item

Similarly to this question, I would like the optional argument of the \item command to print the number of points. Since I don't want to define a new list environment or a custom \item command I tried ...
5
votes
1answer
52 views

How do I pass through options when defining a new environment?

I'm trying to define a new environment that's a customized version of the itemize environment, where any options that I pass to the new environment get passed through to the underlying itemize. For ...
1
vote
1answer
118 views

How can I specify a short caption for a listing?

One of my listings has a very long name. In the \lstlistoflistings table of contents, I would just like to have a shortened version of it. How can I specify an abbreviated name for my listing? \...
1
vote
1answer
43 views

float placement options appearing in pdf document

I have a latex document that contains lots of floats, and so I want to place them all at the end of the pdf. I have done this using: \usepackage[nomarkers, nolists]{endfloat} Above all of my ...
6
votes
2answers
202 views

Pass a command as optional argument of environment

Sorry for the beginner question, but I'd like to know if there is a robust way to do what the title says. The following MWE \documentclass{book} \usepackage[demo]{graphicx} \newcommand{\myoptions}{h!...
4
votes
1answer
63 views

Patching a command with an optional argument or declared with \DeclareRobustCommand

To re-define a command to contain itself (patching in TeX parlance) you usually use \let. This answer by @egreg says: Never use \let on commands defined with \DeclareRobustCommand or commands ...
1
vote
0answers
39 views

Passing optional arguments to a listing environment based on conditionals

I am trying to make a presentation which can optionally compiled for handouts. This presentation also contains highlighted code snippets. For highlighting I use the code from this question. (Which ...
2
votes
0answers
79 views

Autocomplete in TeXstudio for macro with optional argument

I have a macro, such as \newcommand*{\example}[2][]{#1.#2} defined. TeXstudio adds this to its autocomplete list, which is great, but when I actually autocomplete it shows up as \example{arg1}{...
2
votes
2answers
130 views

PGF keys passing arguments to multiple environments

I'd like to combine both tcolorbox and textpos to place boxes to a specific position in a page. Here is a MWE: \documentclass[]{article} \usepackage{pgfkeys} \usepackage{tcolorbox} \usepackage[...
3
votes
2answers
441 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
107 views

newcommand with two arguments, one optional

I'm struggling with a command that doesn't do what I expect. This is my code \newcommand{\expectation}[2][]{\mathrm{E}_{#1}\left[#2\right]} \begin{document} I get $\expectation{A}{B}$, but I expect $...
6
votes
4answers
142 views

macros with multiple arguments in absence of some arguments

I would like to define a command with two arguments, say \mycommand{arg1}{arg2} in such a way that if the second argument is absent, then it takes the first argument in place of the second one, in ...
4
votes
1answer
69 views

How to condense environments and options to one environment?

In order to make grey boxes around code in my document I am using: \usepackage{listings} \usepackage{xcolor} %custom colours \usepackage{mdframed} %nice frames \definecolor{light-gray}{gray}{0.95} %...
8
votes
1answer
322 views

Gobble optional arguments

You can use \@gobble, for instance, to restrict the usage of a macro like: \documentclass{article} \makeatletter \newcommand*{\cmd}[1]{% \textbf{#1} \let\cmd\@gobble } \makeatother \begin{...
2
votes
0answers
49 views

titlesec extra arguments to sections

Is it possible to add extra arguments to a modified section environment using the titleformat command of the titlesec package? For example, that the section color appears as red when doing \section[...
4
votes
1answer
67 views

Russian matryoshka doll of optional arguments [duplicate]

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