{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

1
vote
2answers
38 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 ...
2
votes
1answer
42 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
41 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
64 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
290 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
43 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
104 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
101 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
36 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
70 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 ...
3
votes
1answer
49 views

Redefine optional argument of \item in enumitem

I am using the enumitem package, and I would like to redefine the optional argument of the \item command. By default, the optional argument accepts text to replace the default label. I never ...
4
votes
1answer
57 views

Conditional code based on token

This is a follow-up question to Xparse Adding backslash after each command. xparse allows for conditional tokens to be inserted into the parameter text for a macro using the t<token> directive ...
7
votes
1answer
70 views

Remember an class option with newcommand and CurrentOption

I'm trying to make a class but it needs to remember its arguments I'm using the file \documentclass[x]{test} \begin{document} \end{document} With the class \NeedsTeXFormat{LaTeX2e} ...
6
votes
2answers
118 views

Enhanced fill-in-the-blank document

I am about to improve my lecture slides from last semester. Specifically, I would like to add a fill-in-the-blank option. I found this code suggestion (from here): \documentclass{article} ...
4
votes
2answers
146 views

How is beamer's {frame} title optional, yet in braces (not brackets)?

It dawned on me that the title in beamer, which is provided for in curly braces, is optional! Help me to understand this. Normally, optional arguments are supplied in square brackets. As I show on ...
7
votes
3answers
184 views

Special behavior if optional argument is not passed

I am looking to define a command (actually, an environment, but that shouldn't matter for the purposes of this question) that does some default behavior, and if an optional argument is passed, does ...
3
votes
1answer
36 views

Use Variable as optional input in enumerate

Can anyone tell me how to fix the following problem: The following code produces the error Package enumitem Error: topsep=0em,partopsep=0em undefined \documentclass[11pt]{amsart} ...
2
votes
1answer
37 views

If used insdide \cs_new(_protected), \IfNoValue(TF) doesn't detect -NoValue- at document-level

I guess my problem is related to Commands from xparse inside functions created by \cs_new:Npn? but I still don't understand what's going on: in the following WE (not minimal, sorry for this), why ...
4
votes
2answers
119 views

Processing “List” of “List”

I implemented a short macro that processes a comma separated argument list to format them. So by calling \macroa{ABC, DEF} it will format the text to ABC DEF Now what I would like to have is ...
1
vote
1answer
34 views

Inserting command with optional argument as optional argument Problem

If I define the following two commands: \newcommand{\TestA}[1][]{a^{#1} aaa} \newcommand{\TestB}[1][]{#1} and then call it by $\TestA[\TestB[111]]$ I get the error: "Argument of \\TestB has an ...
4
votes
1answer
87 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 ...
7
votes
3answers
98 views

Defining default arguments for a macro?

Quick question, is there a way to define default arguments for a macro? For example, I have a page filled with these: \TextField[width=2cm,height=10pt,bordercolor=stuff]{Question 1} ...
1
vote
1answer
85 views

pgfplots: Optional graph range arguments in a macro

I defined a macro that inserts a plot that I can re-use the same graph style in multiple places. Mine actually loads data from a file, but a similar MWE looks like: \newcommand{\drawGraph}[1]{ ...
2
votes
1answer
102 views

Can't use command with square brackets in matrix environment

I've defined a command that uses square brackets, and when I use it within a matrix environment, the command is not parsed. I stumbled upon a solution to my problem here: "[" Square bracket ...
5
votes
1answer
109 views

Optional arguments and &

I defined a simple diagram environment with \usepackage{tikz-cd} \newenvironment{diagram} { \begin{equation}\begin{tikzcd} } { \end{tikzcd}\end{equation} } and it worked fine. In particular ...
6
votes
1answer
86 views

Loading a package as an option in a personal style file?

I'm sure this has been answered many times before, but all my reading has just got me more confused. Anyway, I'm trying to create a little style file containing all my personal definitions and ...
8
votes
1answer
129 views

Defining a command that scans every arguments' macro “looking for” a token

Knowing that every command declaration with conditionally optional arguments, as \foo{...} expanding into \foo[default]{...} can be defined by \newcommand\foo[1][default]{...} or the safer version of: ...
4
votes
2answers
103 views

Defining a macro with combine many options to one bracket

I am beginner in writing macros with multi options. What I want to do, is to combine many options to one pair of brackets. \documentclass{article} \usepackage{tikz} \usetikzlibrary{calc} ...
4
votes
1answer
122 views

Providing optional key without value

I would like to prepare a macro with an optional argument like [wide], using xkeyval. (something whether to use \figure or \figure* inside) My test program below presents the output test0=false ...
4
votes
1answer
78 views

specifying line width globally

\documentclass[11pt]{article} \usepackage{tikz} \usetikzlibrary{arrows,shapes,positioning} \usetikzlibrary{decorations.markings} \usetikzlibrary{decorations.pathmorphing} \tikzstyle ...
4
votes
1answer
108 views

What is the difference between passing optional and mandatory arguments?

I wanted to define a macro which makes a program listing, and finds out a program language from an optional argument. The output I receive from the MWE below is Language set = 'Verilog' Passed ...
10
votes
2answers
262 views

Can I define a command with optional argument coming after the mandatory ones?

Is it possible to define new commands having the following form: \command{<marg>}[<oarg>] I have seen commands of this form in the fontspec package. But not sure how to achieve this.
0
votes
0answers
56 views

Prepend and append options to options list in environment

I need to define a macro superenv that expands to the usage of an environment which accepts key-value options. superenv should have three arguments: the environment name, the list of options, and the ...
4
votes
2answers
158 views

In \DeclareDocumentCommand signaling first optional argument is missing

In \DeclareDocumentCommand if I have two successive optional arguments how can I signal the first one is missing? For example: \documentclass{article} \usepackage{xparse} \begin{document} ...
2
votes
2answers
132 views

keyval error on passing macro as an optional argument to includegraphics [duplicate]

I am trying to include an image in my document: \documentclass[a4paper,10pt,twoside]{book} \usepackage{graphicx} \begin{document} \def\foo{scale=0.1} \includegraphics[\foo]{fig1.eps} ...
6
votes
1answer
239 views

Defining a LaTeX macro with optional arguments as keywords inside square brackets

I want to define a macro to insert pictures in figures, called \centeredfigure, which I am hoping to use the same way as \includegraphics. In \includegraphics, all optional arguments are given in the ...
2
votes
1answer
167 views

Adding an argument/variable in `sequencediagram` (pgf-umlsd)

My aim is to have the possiblity to configure in the figure tex either if the vertical bar of a sequence diagram is dotted, plain, thick, etc. Depending on the diagram, I wish I could have the choice ...
0
votes
1answer
40 views

\newcommand to create a command with optional arguments

In Latex, I always use \mathbb{something0}_{something1}^{something2}, wheres sometimes 'something1' or 'something2' can be empty. So I had the idea to create a newcommand using the \newcommand. So I ...
1
vote
0answers
120 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 ...
4
votes
1answer
83 views

Define a macro with an optional argument that is a space

I'm trying to define a macro replaces a phrase by a single latex expression, e.g., I want \myPhrase to return the phrase "this is the dog". The trouble is that when you do this in the obvious way ...
2
votes
2answers
92 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} ...
4
votes
1answer
119 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 ...
2
votes
2answers
165 views

mdframed: how to put the optional argument of a theorem-like environment between brackets?

The classical case With the classical \newtheorem command of amsthm, one gets the following result for optional arguments: from this code \documentclass{article} \usepackage{amsthm} ...
1
vote
1answer
176 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 ...
10
votes
1answer
194 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
1answer
329 views

How do I remove parentheses from theorem optional argument?

This is a MWE: \documentclass[12pt]{article} \usepackage{amsfonts, amsthm, amsmath, amssymb} \theoremstyle{definition} \newtheorem{Theorem}{Theorem}[section] \newtheorem*{Pythagorean ...
6
votes
1answer
100 views

Problem in using comment line in tcolorbox in a bash code

I am recently introduced to tcolorbox, which is a great package. I am trying to use it to highlight computer codes such as bash, python, and c++ in my document. When I run the following MWE, I get the ...
2
votes
1answer
407 views

Beamer template with different style options for frames

I am working on a beamer template which tries to mimick an existing .ppt-template from my institute. My problem now is, that the beamer template should be able to have frames with different styles for ...
4
votes
1answer
93 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
101 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?