{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

2
votes
1answer
16 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
72 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 ...
5
votes
1answer
24 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 ...
2
votes
1answer
69 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
119 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
104 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
70 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
75 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 ...
3
votes
1answer
43 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
40 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
66 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
28 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
187 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} ...
4
votes
1answer
52 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
27 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
2answers
84 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} ...
2
votes
0answers
55 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 ...
6
votes
4answers
129 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
66 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} ...
2
votes
0answers
43 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 ...
3
votes
1answer
94 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 ...
4
votes
1answer
64 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]] ...
2
votes
2answers
59 views

Custom label in enumerate prints “label” before the items

I followed the demo in Customizing enumerated lists Using packages in LaTeX/List Structures. The code is \documentclass{article} \usepackage{enumerate} \begin{document} ...
4
votes
1answer
70 views

Defining multicolum by macro with optional argument

I try to define macro for shortcut form \multiline{1}{<pcolumn type>}{\textbf{text}}: \documentclass[12pt,border=1mm,preview]{standalone} \newcommand\mcbf[2]{\multicolumn{1}{#1}{\textbf{#2}}} ...
3
votes
4answers
110 views

How to make a command with three optional arguments?

I'm sorry for my English, but, anyway, I'd like to know how to create a new command with three optional arguments? I wanna get what is shown on the picture. I have some other ways how to achieve ...
0
votes
1answer
78 views

Passing arguments to custom frame option

Follow up to http://tex.stackexchange.com/a/174213/36296 Long story short: I wondered how to pass arguments to custom frame options. For example add an image to the frametitle.
6
votes
1answer
74 views

Is it possible to consider a single optional parameter among three in node declaration?

Please consider the following dummy MWE: \documentclass[border=3mm,tikz,preview]{standalone} \usetikzlibrary{arrows,positioning,shadows,shapes} \tikzset{test/.style = {% > = ...
3
votes
1answer
76 views

Conditional section title [ifthenelse] not working

I have the following code: \documentclass{article} \usepackage{ifthen} \usepackage{amsmath,amsfonts,amsthm,amssymb} \newcommand{\probName}{}% \newcounter{probCounter}% \setcounter{probCounter}{1} ...
2
votes
2answers
121 views

Check options in \newcommand or \NewDocumentCommand?

I'm trying to implement a custom command that is called like this: \mycommand[hello][world]{mandatory1}{mandatory2} OR: \mycommand[hello,world]{mandatory1}{mandatory2} However, I can't figure ...
3
votes
1answer
127 views

TikZ Pics with optional/default parameters

I am trying to set up a small TikZ library or package with pics I can reuse. Thus, I create a file called "tikzlibraryBES.code.tex" with the following content: \tikzset{ % House ...
4
votes
1answer
48 views

Pass options in verbatim environment inside another environment

I want to define a new environment (here testenv), which is going to include text in verbatim mode. So, I have the code: \documentclass{article} \usepackage[english,greek]{babel} ...
2
votes
1answer
55 views

commands with optional arguments in \write

To extract text from huge LaTeX-files in a safe and controllable manner, I am having LaTeX itself write to a textfile. To retain and adapt some formatting informations and structural elements I have ...
4
votes
2answers
103 views

Howto: if argument is numerical … else

I'm trying to create a differentiation command. At the moment I have the following: \newcommand{\diff}[1][]{% \def\ArgI{{#1}}% \diffRelay% } \newcommand{\diffRelay}[2][]{% ...
3
votes
1answer
71 views

Extending xparse for new arguments

I was looking for a way of grabbing sub and superscripts as optional arguments to a command in xparse. That is, \foo_{a}^{b} would receive a as an optional argument and b as another optional argument. ...
3
votes
1answer
93 views

How to configure complex options for graphics groups in LyX

I have a document with several images from a few different sources. I'd like to indicate different formatting options for each source. I understand I can use graphics groups for this, but I don't know ...
4
votes
1answer
65 views

\edef\x trick and pgfmath

With the MWE below, I find the following trouble: within the figure* environment, I have three different \lstset instructions. The first and 3rd (commented out) work, the 2nd (as is) presents with ...
6
votes
1answer
84 views

Forward command arguments to another command

How can I define a command that forwards arguments to another command? Specifically, I'd like to create a command that forwards arguments to \pdfcomment and adds the author optional argument with a ...
5
votes
2answers
159 views

Using macro with optional argument inside macro with optional argument

I am trying to define a macro that has an optional argument that can take a macro with an optional argument as an argument. A minimal example to explain the problem more clearly: ...
11
votes
3answers
277 views

3n arguments in a macro (n is an even number) for curves whose thicknesses increase or decrease

For some mathematical figures it's nice to be able to vary curve thickness smoothly along a path, to reproduce hand drawn mathematical figures made with inking liners for instance. One way to do it ...
3
votes
2answers
129 views

Passing complicated argument patterns to a new command

I am using the nice changes package. Which basically provides three commands \added, \deleted and \replaced. Because of the structure and the fact that the optional arguments it takes, I think it is ...
1
vote
2answers
73 views

How to test whether report has been called with “draft” option

How can I test within a document, whether or not the initial \documentclass[a4paper,11pt,twoside,fleqn,draft]{report} includes the "draft" option? My naive attempt \newif\ifmydraft \mydraftfalse ...
3
votes
1answer
87 views

tikz/pgf upgrade and decorations

Since a major upgrade in pgf, my code does not compile any more. I am trying to make "decorated" source listing, where the decorations can be like highlighting some lines (see the MWE), balls on some ...
8
votes
1answer
64 views

TeX quotation marks short-circuit optional argument with \ifx

In a command with an optional argument, if I put a string beginning with TeX quotes (e.g., ``quote'') in the optional argument, something goes wrong. See the bottom entry in the example below. The ...
3
votes
1answer
128 views

Listings: syntax for literate

In the documentation for the listings package it says: literate = [*]<replacement item>. . .<replacement item> First note that there are no commas between the items. Each item ...
8
votes
7answers
383 views

How to define optional second argument for macro?

I've defined a command which lets me quickly reference to the number (of figure or table) AND page at the same time: Command \newcommand{\kplref}[2]{~\ref{#1}, S.~\pageref{#1}{#2}\xspace} The ...
5
votes
2answers
57 views

Adding optional arguments to environment

I'm trying to understand and modify this code: \newtheorem*{nonamethm}{\nonamethmname} \newcommand{\nonamethmname}{} \newenvironment{genthm}[1] {\renewcommand{\nonamethmname}{#1}\nonamethm} ...
5
votes
2answers
120 views

Defining a command and its starred version with different number of arguments

I want to create the commands: $\vecbi*{A}{s}$ and $\vecbi{A}$ To write bold vectors in my text. However, I have tried the following code, but I am still stucked without a solution. \makeatletter ...
12
votes
1answer
123 views

Add another optional argument for an environment

I have defined an Example environment that I use as follows to produce a numbered example and send the example title to an example index: \begin{Example}[one]{Cooking eggs} To cook an egg, ... ...
2
votes
1answer
38 views

Manually resize a grouping macro

I know there's a braket package that will probably do all this for me but I've defined my own macro for matrix elements in Dirac notation: \makeatletter \def\me{\@ifstar\@me\@@me} ...
4
votes
2answers
112 views

Optional argument to \item

I am typesetting an ordered list where the entries may appear out of order, but should be assumed in order otherwise. I don't want to have to jump through \setcounter hoops to do this. That is, I want ...