Skip to main content

Questions tagged [optional-arguments]

{optional-arguments} concerns commands and environments that accept optional arguments. For example the \sqrt command can be used as \sqrt[3]{x}.

Filter by
Sorted by
Tagged with
0 votes
0 answers
19 views

Customizing numbering on environment with optional argument

I am not sure if this is considered bad practice so please let me know if it is. I have an environment I use form homework problems \newtheoremstyle{mystyle} {\topsep}{\topsep}{\normalfont}{}{\...
4u9ust's user avatar
  • 23
2 votes
1 answer
48 views

Merging two commands for left and right alignment

I have the following two commands. Have can I conveniently merge the two into a single command ? The unstarred version clears previously set keys, whereas the starred will keep the values. And using ...
Bulldrive's user avatar
  • 153
4 votes
2 answers
106 views

Redefine the command \cite to be able to use an additional syntax

Background The package amsrefs redefines the command \cite so that one can use the syntax "\cite{book-name}*{optional-argument}" to produce (essentially) the same output as the usual "\...
Lorenzo Pompili's user avatar
1 vote
1 answer
41 views

tcolorbox and ifmtarg: bad argument specification when checking for empty argument using @ifmtarg

Problem I am trying to put a bunch of optional arguments in a new tcolorbox definition, and trying to use the ifmtarg so I can skip some optional arguments like in the following syntax: Example 1: A ...
BrightBulb123's user avatar
0 votes
1 answer
72 views

Printing by matching argument with a string

I want to 1) print Robert when the argument is not present, and 2) print Alice when the argument matches some string or print Robert when the argument does not match it. \documentclass[a4paper,10pt]{...
Veak's user avatar
  • 1
3 votes
2 answers
95 views

Custom proof environment: spacing issue with when optional argument given

Consider the following code, the purpose of which is to have a proof environment in which the "Proof." bit is bold. \documentclass{article} \usepackage{amsthm} \renewenvironment{proof}[1][...
Oxonon's user avatar
  • 147
1 vote
2 answers
87 views

Is it possible to name macro (`\newcommand`) parameters and do math with them?

I'm new to creating commands in LaTeX, and I would like to do something like adding a more helpful name inside my command, as I do calculations with it; while also doing some math with said parameter. ...
psygo's user avatar
  • 438
3 votes
1 answer
105 views

"unexpected $ after $$" and "unclosed $$ found at $" errors with inline math inside display mode

I am trying to define a new command for different types of homomorphisms. The command is: \newcommand{\Hom}[2][]{% \operatorname{Hom}_{\textnormal{#1}}\left({#2}\right)% } The outputs of this ...
Lorenzo Carozzo's user avatar
6 votes
2 answers
151 views

Why do optional arguments of commands affect spacing of \mathcolor

I am very surprised that simply adding an optional argument to the definition of my command changes the spacing in formulas in combination with \mathcolor. Why does this happen? How can this be fixed? ...
Jakob's user avatar
  • 1,003
-1 votes
1 answer
100 views

Passing symbol to a command [closed]

I intended to have a command to print a coloured QED using a user-defined symbol. The advice is not to make commands with two consecutive optional arguments. What is one to do, is there a neat way ...
Lestine's user avatar
0 votes
1 answer
60 views

Introducing colour ta a separator

I am having difficulty constructing the function \celest_separ:n that can handle colour because code level functions do not have optional arguments. Quite unfortunate. How may I get out of such ...
Celest's user avatar
  • 1
-1 votes
1 answer
71 views

Referring to arguments in newcommand not working in math mode [closed]

I would like to create a command given the arguments $g,n,d,X$, generates the output $\overline{M}_{g,n,d}(X)$. If no $g$ is given, I would like the default to be 0. What I thought was correct was to ...
Irit's user avatar
  • 1
-1 votes
1 answer
58 views

Environment with multiple optional arguments

I have the following environment taking four arguments, the latter two being optional. Things look as expected. Would I have to test for #4 in my case ? \NewDocumentEnvironment{Statement}{mmoO{...
Veak's user avatar
  • 1
4 votes
3 answers
406 views

Is there a way to add optional and/or named argument to command

I'm writing a handbook for my students and I want to create a command which should draw a task definition, its type and possible features, like source and link to the solution on YouTube. In my plan ...
Nikita Vasiliev's user avatar
2 votes
1 answer
80 views

How to properly set optional boolean parameter for pic in tikz?

I try to draw beam on tikz with the possibility to hide its axis. I created the following: \documentclass{article} \usepackage{tikz} \usetikzlibrary{math, shadings} \usepackage{ifthen} \tikzset{ ...
Sindzicat's user avatar
  • 143
1 vote
1 answer
66 views

Macro without arguments to define macro with arguments

I'm trying to use xparse and generic TeX/LaTeX commands to write a macro (that takes no arguments) to define another macro that does take arguments: \documentclass{minimal} \RequirePackage{xparse,...
Ben Zelnick's user avatar
0 votes
1 answer
252 views

renewenvironment to change default color of tcolorbox

I want to change the default background color of the \tcolorbox environment. I really like /.append style but I know that's a TiKZ thing. When you uncomment the \renewenvironment in the header, ...
user26305's user avatar
  • 142
1 vote
0 answers
22 views

Redefine an environment such that it always has a certain optional value unless told otherwise

How can I redefine an environment so that it will have a certain optional value unless told otherwise? My particular problem is: how can I redefine the itemize environment so that its beginpenalty ...
Noah J's user avatar
  • 515
2 votes
1 answer
49 views

Adding optional argument (as exponent) to custom math expressions

I want to define a command \bigO where if I type something like \bigO[3]{\epsilon} it gives $\mathcal{O}(\epsilon^3)$, and if I leave out the optional argument and have \bigO{\epsilon} it defaults to $...
Physicist's user avatar
  • 187
1 vote
0 answers
101 views

How to add the [pifont] option to the spacingtricks package documentation

For the novice TeX programmer such as I, package documentation such as that for the spacingtricks package is akin to the Bible, particularly when it comes to specifying all package options. I recently ...
RosesBouquet's user avatar
1 vote
1 answer
61 views

How to avoid a macro with optional argument to create any token?

I was trying to use a macro inside of \cite optional argument. I expected the optional argument to be ignored if the macro expands into nothing (i.e, get something like [1]), but sometimes a ...
User9123's user avatar
  • 147
0 votes
3 answers
202 views

Parsing non-expandable commands like \small, using expl3

Using expl3 syntax, I want in my \coolgloss command to use as an optional argument one or several formatting commands such as \small and \itshape. With a command like \newcommand{\coolgloss}[3][\small\...
Vincent Krebs's user avatar
0 votes
1 answer
98 views

How do I create a generic environment template with optional arguments declared inside the environment?

I am posting this as a general question prior to introducing the specific use case. Apologies if this has already been posted and I am using the incorrect terms for what I want, my searches have been ...
WesH's user avatar
  • 427
0 votes
1 answer
316 views

Passing parameters and arguments to a \documentclass without adding them directly to the \documentclass[ HERE ]{article}

I would like to pass several arguments to \documentclass[HERE]{beamer}. I have several arguments so I don't want to write them all in there. I would like to pass a file or write them down in the ...
Yi Qiang Ji's user avatar
2 votes
2 answers
222 views

Pass xparse optional token argument from outer command to inner command

I have a document command which accepts several optional token arguments, and I'd like to implement another document command which accepts the same optional token arguments and passes them properly to ...
Null's user avatar
  • 1,525
4 votes
3 answers
190 views

How can I utilize optional arguments for flexible Vector sizes?

I have created a macro to create a size of 2 x 1, but I would like to add an optional argument to make it 2 x 1, or 3 x 1 depending if you choose to a third argument. The current implementation is, \...
Michael's user avatar
  • 43
0 votes
2 answers
364 views

Optional parameters for NewDocumentCommand with if cases

I have this command, which I would like to take two optional parameters: \pubtitle[title][symbol]{custom}. Here is the command (MWE): \documentclass{article} \usepackage{xcolor} \usepackage{...
Vebjorn's user avatar
  • 1,854
8 votes
1 answer
532 views

argc argv in LaTeX

Can the LaTeX executable receive arguments from the command line to be used as internal variables? That is, can a command like ./latex document.tex a=3 b=rational c=-17.2 d=true be used to pass values ...
sood7600's user avatar
1 vote
0 answers
16 views

How can I add text influenced by an option after the body of an environment? [duplicate]

I want to add text after the body of a \newenvironment after the main body of the environment. So the pseudocode would look like this: \newenvironment{example}[2]{#1 \newline}{\newline #2} \begin{...
grepgrok's user avatar
1 vote
1 answer
197 views

Latex Environment with named optional parameters

Is there a way to get a string options in \NewDocumentEnvironmentor \newenvironment ? i.e \begin{foo}[color=red,size=12pt] \end{foo} where the environment is defined as \NewDocumentEnvironment{foo}{}...
cdickstein's user avatar
1 vote
1 answer
52 views

Syntax: use second argument leaving the first argument as default in a macro

I use this command to abbreviate my notation \NewDocumentCommand{\Lp}{O{p}O{\mathbb{R}^d}O{[- \infty, \infty]}}% {L^{#1}(#2, #3)} I've set one default for each argument, in most cases I need just ...
Fral's user avatar
  • 79
0 votes
0 answers
163 views

How do I check if a list item is blank when it is passed as a parameter in LaTex?

I'm trying to create a command that accepts two lists using the \listofitems package where the first list is optional. In the command I want to check if the first entry in the optional list is "...
Rhys's user avatar
  • 1
3 votes
1 answer
64 views

behaviour of the option multicols in listings

I think the following two codes saying the same thing. However, the second code causes error. My question is: how to make the second code workable same as what the first code does. That is to say, how ...
lyl's user avatar
  • 2,747
2 votes
1 answer
76 views

How to avoid typing \leavevmode before a citation macro that already starts with \leavevmode?

Control sequences with optional arguments inside optional arguments must be "hidden" with braces. Using the abntex2cite package to handle my citations, I often want to write: \begin{teor}[{\...
Daniel Diniz's user avatar
0 votes
2 answers
51 views

Conditionally specify an optional argument to a command

I have these two new commands defined: \usepackage{tcolorbox} \newcommand{\mycommand}[1]{ \begin{tcolorbox}[ center, colback=black!20!white, width=.75\textwidth, boxrule=0pt, ...
sampathsris's user avatar
0 votes
2 answers
120 views

Taking in optional boolean flags in a macro without expl3

I want to create a macro \verticalStep which will produce a vertical skip of fixed length, and take two optional arguments, negative and small. So for you could use \verticalStep for a standard ...
Atai Ambus's user avatar
1 vote
1 answer
75 views

NewDocumentEnvironment optional argument changes behaviour with \obeylines

I notice that the behaviour of environments with an optional argument that use \obeylines changes based on whether the optional argument is present or not. I would have expected all the environments ...
David Purton's user avatar
  • 26.4k
1 vote
1 answer
92 views

How to define a wrapper around the xparse \NewDocumentCommand command?

I often want to define a command (using xparse) like the following \NewDocumentCommand{\Comon}{oo}{ \IfNoValueTF{#1}{ \mathsf{Mod} }{ \IfNoValueTF{#2}{ \mathsf{Mod}...
Matt's user avatar
  • 11
1 vote
1 answer
123 views

Include page numbers in a \cite argument?

I'm quoting the same book quite often, it's just different page numbers. So what I want to do is putting the page numbers in an argument while citing, so I don't have to create a new bib entry for the ...
maur1ce's user avatar
  • 13
1 vote
1 answer
584 views

Meaning of square brackets, optional arguments

I'm a bit confused as to how LaTeX parses square brackets/optional macro arguments. I'll try to explain what I understood by means of the macro \section which has one optional and one mandatory ...
Nico Schlömer's user avatar
0 votes
0 answers
58 views

Unable to show the macro/command definition, when the macro/command defined with optional argument

For example, I define two commands. \mytesta with optional argument, \mytestb without optional argument. Now using \cs_meaning:N to show the command definition. The result is like this: \...
Tom's user avatar
  • 7,703
0 votes
0 answers
238 views

a verb=xxx_== problem with newcommand - missing $ inserted

\documentclass[12pt,a4paper,UTF8, scheme = plain]{ctexrep} \usepackage{amsmath,enumerate} \usepackage{geometry} \usepackage{adjustbox} \usepackage{booktabs} \usepackage{fancyhdr} \usepackage{lastpage} ...
CasperYC's user avatar
  • 705
1 vote
1 answer
115 views

Is there an empty value for the counter in `\newtheorem{xxxx}{xxxx}[empty]`?

I'm trying to set an optional counter in the \newtheorem command based on some input given to a .sty file. Something like \DeclareOption{empty}{ \edef\counter{} } \DeclareOption{section}{ \...
user40276's user avatar
  • 279
4 votes
1 answer
85 views

Unknown spacing after using command in optional argument

Context I am trying to paste multiple images in one row within a tabularx environment. Using optional commands with the \NewDocumentCommand from the xparse package I tried to implement this. It ...
PLY's user avatar
  • 149
4 votes
2 answers
637 views

How to pass optional empty arguments in a newcommand down to another command with optional empty arguments in LaTeX?

I would like to define a newcommand with two optional arguments, which in turn, calls on another command with two optional arguments. Something like the following (\B calls \A). How do I do it? \...
CypherX's user avatar
  • 143
2 votes
1 answer
118 views

Extend Beamer frame and inherit arguments (and overlays)

I intend to extend a beamer frame to save some overhead when making slides. I've followed an answer here after another answer involving NewEnviron didn't work for me. The beamer user guide has some ...
Frederick Nord's user avatar
1 vote
0 answers
43 views

Constrain \@ifnextchar to the same line

I need an environment that takes an optional argument between square brackets, but only when provided on the same line as the \begin{...} command. \documentclass{article} \begin{document} \...
Jérôme LAURENS's user avatar
2 votes
1 answer
71 views

new command with multiple optional arguments, one of which is bracket size

Building on this question and this one and this one, I'd like to make a new command that has a default behavior for a single primary argument but has two additional arguments that specify (i) bracket ...
rrrrr's user avatar
  • 503
0 votes
1 answer
57 views

environment with an optional argument relating to counter

This question is on the basis of my last question: Define own class options relating to counter. With the help of egreg, here is a class file in which there is an environment named exercise: \...
Stephen's user avatar
  • 4,269
4 votes
1 answer
144 views

How to write a multiple argument environment within a newcommand?

In my custom class file, I have a command that generates a new environment: \newcommand{\MakeThEnv}[4]{ \DefaultFrame{#1}{#2} \theoremstyle{#3} \newtheorem{#2T}{#4} \newenvironment{#2}{\begin{#2Box}...
Strumff.'s user avatar

1
2 3 4 5
10