{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

3
votes
2answers
72 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][]{% ...
2
votes
1answer
43 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
27 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
43 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 ...
5
votes
1answer
43 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
126 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
248 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 ...
2
votes
1answer
42 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
48 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
63 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
46 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
67 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
306 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
45 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
111 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
106 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
37 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
72 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
55 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
59 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
73 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
125 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
160 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 ...
8
votes
3answers
199 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
39 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
38 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
123 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
91 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
99 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
90 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
107 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
112 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
130 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
107 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
123 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
81 views

specifying line width globally

\documentclass[11pt]{article} \usepackage{tikz} \usetikzlibrary{arrows,shapes,positioning} \usetikzlibrary{decorations.markings} \usetikzlibrary{decorations.pathmorphing} \tikzstyle ...
4
votes
1answer
112 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
270 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
179 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
159 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
245 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
179 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
47 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
142 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
97 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
124 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 ...