All Questions
Tagged with macros optional-arguments
210
questions
4
votes
2
answers
109
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 "\...
1
vote
2
answers
88
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. ...
3
votes
1
answer
111
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 ...
6
votes
2
answers
154
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?
...
-1
votes
1
answer
72
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 ...
4
votes
3
answers
409
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 ...
1
vote
1
answer
71
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,...
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 $...
2
votes
2
answers
224
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 ...
0
votes
2
answers
379
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{...
1
vote
1
answer
53
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 ...
0
votes
2
answers
53
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, ...
0
votes
2
answers
122
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 ...
1
vote
1
answer
93
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}...
1
vote
1
answer
590
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 ...