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
1 answer
32 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 ...
user avatar
0 votes
0 answers
40 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: \...
user avatar
  • 1,258
0 votes
0 answers
212 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} ...
user avatar
  • 489
1 vote
1 answer
50 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}{ \...
user avatar
  • 269
4 votes
1 answer
48 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 ...
user avatar
  • 137
4 votes
2 answers
119 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? \...
user avatar
  • 141
1 vote
1 answer
28 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 ...
user avatar
1 vote
0 answers
28 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} \...
user avatar
2 votes
1 answer
29 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 ...
user avatar
  • 365
0 votes
1 answer
27 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: \...
user avatar
  • 343
3 votes
0 answers
86 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}...
user avatar
1 vote
3 answers
77 views

Is there a 'shift' instruction for \newcommand and \NewDocumentCommand macros?

I'm looking for a shift instruction which will rotate the parameters passed to a LaTeX macro. The idea is that if optional parameters are omitted, then they should be dropped from the beginning of the ...
user avatar
  • 240
1 vote
1 answer
26 views

Redefining \section outputs the equivalent of an additional \section{*} before the TOC

When I redefine the \section command, an additional section with title "*" is created before the table of contents, as if I had inserted a \section{*} before the table of content, which I ...
user avatar
0 votes
0 answers
42 views

Boolean flags with xparse, and xparse in general

I would like to define an environment whose syntax works like this \begin{myenv}{arg1,arg2}[opt_1,opt_2,...,opt_n] body, taking several lines \end{myenv} One of the optional arguments is to be a ...
user avatar
3 votes
2 answers
130 views

PGFPlots: Trying to create a non-linear axis using trafo/.code in \newcommand - how to escape the #1 argument?

I would like to make my Y axis non-linear. I have found an answer but the problem is that my code for charts is encapsulated in the \newcommand environment. When I use something like this: \...
user avatar
  • 133
6 votes
1 answer
415 views

How LaTeX "understands" optional arguments?

The most common notation for commands I have seen is the following: \command[optional]{mandatory} What I am trying to understand is how the optional arguments are understood. For example they can be ...
user avatar
  • 183
0 votes
1 answer
51 views

Adding an optional argument to an existing command / environment

Let's say I want to make a new environment that is a copy of the beamer class' frame, but it allows one to optionally place (something) at the end to change the behaviour of the frame. I would still ...
user avatar
3 votes
1 answer
96 views

Define arguments in a command

I am using the skak and xskak packages to make notes about chess. Everytime I need to print a board, I have to manually set the optional parameters, like the code below: \chessboard[ %--> ADD ...
user avatar
  • 1,174
3 votes
1 answer
59 views

How does xparse's routine for looking for an optional argument do the trick of preserving space-tokens in case no optional argument is present?

(This question is not about bugs or errors or whatsoever misbehavior. I just would like to know how a pleasant trick was done.) I just encountered another subtlety in which the way of xparse's ...
user avatar
  • 22.9k
0 votes
1 answer
62 views

Need conditional that evaluates to nothing

Resolution: The problem was with the outdated version of moderncv I was using. I put some additional details at the end of the question, but I will delete this question. Thanks to those who wrote to ...
user avatar
2 votes
0 answers
60 views

xparse losing default values of optional parameters after environment

Some code that used to work has stopped working on a newly updated system (revision 61040 of l3packages, from what I can tell; I don't have a version number for which it did work), and I'm trying to ...
user avatar
  • 85
1 vote
1 answer
74 views

Using xargs to define custom environment

I want to define a custom environment for the following LaTeX box using xargs package, but currently I am running into errors and a bit confused on how to properly make the environment. First, here's ...
user avatar
  • 133
0 votes
0 answers
37 views

XeLaTeX Awesome CV - conditionally add hyperlink to title text

I'm using font-awesome package for icons in my resume I want to add hyperlinks to few titles, examaple Link to Job Experience Certificate will be included in text if the URL is provided What I tried ...
user avatar
0 votes
0 answers
15 views

How to make listings package recognize strings of a specific form

The listing package provides literate command which allows replacing specific fragments of code with something else, like: literate={)}{{\textcolor{red}{)}}}{1} replaces the right bracket with its ...
user avatar
  • 1,510
0 votes
1 answer
17 views

Add htbp to all float environments [duplicate]

In short: How can I add the optional parameters [htbp] to all float environments? Ideally, I don't want to define a custom new environment, but add these options "with a hack" like \g@addto@...
user avatar
2 votes
1 answer
55 views

\newcommand to define shortcut with optional argument (derivative package)

The recent release (June 2021) of the derivative package includes the command \odif which can be used to typeset differentials. For instance, \odif[order={3}]{x} yields something like d^3x. Because I ...
user avatar
2 votes
1 answer
50 views

Optional argument for newcommand

Suppose we define the following macros: \newcommand*{\G}[1][G]{\mathbb #1} \newcommand*{\Cop}[1][]{\Delta_{#1}} For the first one, if we use $\G$ it produces in the pdf what $\mathbb{G}$ does and if ...
user avatar
  • 23
2 votes
0 answers
62 views

History - LaTeX2e - \newcommand - Why does the mechanism for detecting an optional argument not crank out the case of an implicit [?

[Please take this question for a moot point/an "academical" issue.] The LaTeX-kernel-command \newcommand was invented decades before expl3, xparse and \NewDocumentCommand were available. \...
user avatar
  • 22.9k
1 vote
1 answer
70 views

History - LaTeX2e - \newcommand - Why optional arguments as (]-)delimited arguments?

[Please take this question for a moot point/an "academical" issue.] The LaTeX-kernel-command \newcommand was invented decades before expl3, xparse and \NewDocumentCommand were available. \...
user avatar
  • 22.9k
4 votes
3 answers
194 views

How can I differentiate in \newcommand between an unused optional argument and an empty one?

I want to change the behavior of my macro depending on whether an optional argument is not given at all or is explicitly stated (using []) but empty. MWE could look like this (stolen from this answer):...
user avatar
4 votes
4 answers
368 views

Pass 3 optional arguments in newcommand

In a mathematical text which I write, I want to denote a certain number by $S(x;q,a)$. The number, as you may have guessed, depends on three parameters $x, q, a$. I would like to give this expression ...
user avatar
0 votes
2 answers
93 views

Why does xparse manual talk people into thinking that reliable expandable checking for optional arguments is possible? [closed]

There is no expandable method for reliably looking at the next token of the input stream. So why does xparse manual talk people into thinking that reliable expandable checking for optional arguments ...
user avatar
0 votes
1 answer
50 views

Add optional arguments before and after "Exercise"

I would like to create an exercise environment for which I can specify two optional arguments, one appearing before the "Exercise" mention and the other one appearing in brackets after the ...
user avatar
  • 13
1 vote
2 answers
84 views

Expanding command with optional arguments: \edef

I have defined a LaTeX command with an optional argument, e.g., \newcommand*{\commA}[1][opt]{A#1}, and I cannot get it to be part of an expanded command defintion with \edef, e.g., \edef\expcom{\commA}...
user avatar
1 vote
1 answer
55 views

Macro with optional parameter returning calculated length

I'm trying to define a macro returning a calculated length, but making the parameter optional breaks the macro (error Missing number, treated as zero.): \documentclass{article} \usepackage{xfp} \...
user avatar
  • 1,632
3 votes
3 answers
73 views

Using Starred Version as Optional Argument

I have been reading this page on defining commands with *-options. I have got completely stuck, though. I'd like the following. A command with an optional argument and a star option. Optional ...
user avatar
  • 1,147
1 vote
2 answers
43 views

Behavior of environment with optional argument changes when optional argument is not passed

Recently, when I've been working with environments with an optional argument, I've noticed that the behavior changes when I introduce a set of square braces, even when there is nothing inside them. ...
user avatar
1 vote
1 answer
86 views

Multiple optional arguments with tcolorbox

I would like to produce boxes from tcolorbox which can take two optional arguments, but I'm not sure where to start with. Here is my current MWE : \documentclass{article} \usepackage[utf8]{inputenc} \...
user avatar
  • 13
8 votes
1 answer
90 views

xparse's 's' argument returns \Gamma and \Delta, instead of \BooleanFalse and \BooleanTrue

The xparse documentation says, But that's not what I get when I test s. \documentclass{article} \usepackage{xparse} \NewDocumentCommand{\myfunc}{s}{#1} \begin{document} \myfunc % should return \...
user avatar
  • 715
2 votes
1 answer
74 views

Change multicolumn column spec with a star command

I am trying to make a macro that will wrap the column specification of a \multicolumn command with @{} if a * is passed to my macro. I can achieve the behaviour I want in the first definition below, ...
user avatar
1 vote
1 answer
38 views

Custom proof environment preserving optional argument

I basically want to obtain the result (replace Proof -> Solution, and mdframed around the environemnt) simply by the code: \begin{solution} Set Theory Best Theory. \begin{align*} 2 =...
user avatar
1 vote
0 answers
146 views

Any reference and tutorial on writing .cls file class? [closed]

I was trying to re-edit the report.cls file to adapt to our institution thesis presentation format. I was stuck at declaring and executing options,also with error flag on xcolor file execution. Having ...
user avatar
2 votes
2 answers
109 views

\newtcblisting with multiple optional arguments and defaults

I have a custom environment for code like this (it is a modified version of the code here): \documentclass[12pt,a4paper]{report} \usepackage[many]{tcolorbox} \tcbuselibrary{minted,skins} \definecolor{...
user avatar
  • 167
2 votes
1 answer
55 views

How to use optional arguments of the original commands in a macro?

I'd like to use sectioning commands inside macros in order to enhance them, i.e. put some kind of line before and thing after the heading. Is it possible to use/address the optional arguments of the ...
user avatar
  • 6,260
0 votes
2 answers
75 views

How to redefine a product command to add an optional argument?

I would like to redefine the product commands (\times, \cdot, \otimes, \wedge, \odot) to add an optional negative spacing argument, but I don't know how to do this in a proper way. I need the new \...
user avatar
  • 2,024
2 votes
1 answer
58 views

Changing \newcommand to have optional argument breaks command

Simply put, I have a command defined for an edge when using the tikzpicture environment. Command: \newcommand{\bendangleundiredgenodes}[6]{(#3) edge [-] [bend #2=#1] node [#5] {#6} (#4)} Usage: \...
user avatar
3 votes
3 answers
233 views

Keeping default optional argument when adding to command

TeX FAQ's "Patching existing commands" gives a method to add to existing commands that have an optional argument: \documentclass{article} \usepackage{letltxmacro} \newcommand{\rough}[2][\...
user avatar
2 votes
1 answer
32 views

Empty command with one optional argument after an equation causes an extra horizontal indentation

Consider the following minimal example: \documentclass{minimal} \newcommand{\CMDI}[1]{} \newcommand{\CMDII}[2][]{} \begin{document} \begin{equation} 3.14 \end{equation} \CMDII[...
user avatar
  • 231
2 votes
2 answers
32 views

Omit punctuation after optional argument in glossary

I'm building a glossary of German Mathematics terms. I would like to omit the comma after the optional argument #2 when #2 is empty. I tested \IfNoValueF and \IfNoValueTF. They work perfectly without \...
user avatar
  • 43
0 votes
1 answer
33 views

Adding an argument to \part macro

I want to be able to call the part macro like this: \part{Introdução Geral}{(2015)} Having the year as a kind of subtitle. I can call: \part{Introdução Geral\\\\ \Large(2015)} But this applies the ...
user avatar

1
2 3 4 5
9