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
0answers
33 views

commandx optional arguments

I have a custom command for the package todonotes \newcommandx{\custom}[3][1=]{\todo[#1,author=#2]{#3}} which is supposed to be used like: \custom[inline]{author1,some comments} Instead, it raises ...
1
vote
1answer
62 views

Add Rows to Table With Macro (calc fields result the same for each row)

I use as template macro from this articale: Add Rows to Table With Macro. All work fine if values in cells not to calculate. But othewise results of calculation is the same for each row. How to avoid ...
4
votes
1answer
47 views

Colouring text doen't work in newcommand definition

I am trying to define a new \note command based on todonotes and changes packages but I'm having troubles with the optional selected text styling. I want it to be coloured based on the changes ID ...
4
votes
4answers
835 views

Detect no argument in \newcommand

I wonder if there is a way to create a command which can discriminate when there is an argument or not. I don't mean empty argument, I mean no argument at all. Here an example \newcommand{\mycommand}...
0
votes
1answer
118 views

How to know all the optional arguments of Latex commands\environments? [duplicate]

For external packages CTAN provides the needed documentation, however, for built-in Latex commands I am not aware of any proper documentation except for The (not so) short introduction to Latex which ...
0
votes
0answers
51 views

Macro with optional argument inside \input

I'm currently facing the problem that I don't know how to properly put a macro with an optional argument as an argument inside \input. If I use something like this \newcommand{\test}[1][Hi]{#1} \...
1
vote
2answers
143 views

Nested newcommand and expanding \@nil

I'm creating a command to generate a series of macros all with equivalent styling. i.e. something along the lines of 1 \newcommand{\newcustommacro}[2]{\newcommand{#1}[1][Default]{#2{##1}}} \...
1
vote
1answer
72 views

Option clash for package tkz-tab

Here is the code: \documentclass[11pt,a4paper]{article} \usepackage{fontspec} \usepackage[french]{babel} \usepackage{tikz} \usepackage{tkz-tab} \usepackage[inline]{tkz-tab} \begin{document} test \...
1
vote
1answer
82 views

Bugs in conditional structure in a newcommand definition with optional arguments

I am trying to create a new command for add a caption and/or the label to an equation. The not optional parameter is for the text of the equation and first optional parameter is for the label, the ...
6
votes
3answers
260 views

Second optional argument for newcommand to be the same of the first in case it is not specified

I want to define a \newcommand with two argument, of which one is optional, which allow me to have the same output of the first input in the case I do not specify the second argument, while being the ...
2
votes
1answer
56 views

Problem with the optional value of the first argument of a newcommand

\documentclass[12pt,a4paper]{article} \usepackage[utf8]{inputenc} %définition de variable texte pour compilation conditionnelle \def\ChoixDeVersion{AB} %AB=Avec Barème, SB ou autre = sans bareme \...
2
votes
2answers
775 views

How can I make a list with variable parameter size inside of a custom environment?

I have a custom environment that I am using as part of a template. Right now this is the code for the template file. %----------------------------------------------------------- % customtemplate....
2
votes
1answer
420 views

\IfNoValueTF - How to force “no value” if there (are brackets but there) is no value for an argument

This code uses LaTeX3, the xparse-package and in particular the \IfNoValueTF command as explained in Will Robertson's answer to the OP "Different command definitions with and without optional argument"...
1
vote
2answers
108 views

How to reference a node's anchor by optional parameter (#2) inside a style when that node is referenced by parameter (#1) itself?

I have a style (POSITION) that references a node by parameter \documentclass{standalone} \usepackage{tikz} \usetikzlibrary {% positioning, shapes.geometric } \tikzset {% ...
0
votes
2answers
247 views

How to check if optional argument has its default value?

Is it possible to check whether some macro's optional argument has its default value and generate different output based on this condition? For instance, say I defined: \documentclass{article} \...
1
vote
1answer
42 views

Hiding/commenting out a nested table

Continuing the question File ended while scanning use of \next, while using \begin{comment} on macro definition another example would be when there is a table inside the redefined command redefined by:...
1
vote
0answers
54 views

File ended while scanning use of \next, while using \begin{comment} on macro definition [duplicate]

On the question How to replace a command with a dummy one? I learned to do: \documentclass[10pt,a5paper,twoside]{memoir} \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage[brazil]{...
3
votes
2answers
419 views

How to replace a command with a dummy one?

On the question How to create a dummy generic environment replacement? I learned how to replace an generic envinronment with a dummy one. Until now I had success replacing then as replacing \...
0
votes
2answers
208 views

How to create a dummy generic environment replacement?

I am trying to create a debug mode where I can comment out most things on the document. For now I was able to replace commands like \currenttime from datetime package with \def\currenttime{Current ...
3
votes
1answer
83 views

gobble optional argument in edef

for some improvement of reledmac/reledpar (https://github.com/maieul/ledmac/issues/668), I need to gobble any argument of a macro before using it in a \edef. But I get an error. See this MWE \...
3
votes
2answers
386 views

Using \foreach with \SplitArgument

Why does the \test command not split the argument when called from a foreach loop? \NewDocumentCommand{\test}{ >{\SplitArgument{3}{|}} m }{\printtest#1} \NewDocumentCommand{\printtest}{mmmm}{ (...
3
votes
2answers
1k views

Indent in itemize/enumerate with different width for body and for item

I'm having some troubles with the customisation of the indent of itemize environment. My MWE is: \documentclass{article} \usepackage{lipsum} \usepackage[utf8]{inputenc} \usepackage{...
1
vote
3answers
175 views

\newcommand with two options: omit vs. leave empty

I am re-writing our template for exams, and I would like to create a command \questionpart{Q}{A} which I can set up in a way, so that I can turn the solutions on and off, and also format und number ...
3
votes
1answer
45 views

Index duplication error caused by tokenizing an optional argument in a macro

I'm trying to create a command \term for printing a definition and then indexing it. It has one optional argument and one mandatory argument; if the optional argument is absent, the mandatory argument ...
5
votes
1answer
135 views

A transparent optional agrument macro

Is there a way to define a macro that takes one optional argument and behaves transparently? The traditional Latex way (\newcommand{\foo}[1][]{foo}) has the following shortcome: writing $T_\foo$ ...
6
votes
3answers
1k views

\def macro with multiple parameters

I'm trying to tweak a style file, I have a 'def' as follows: \def\logo#1{\gdef\@logo{#1}} \gdef\@logo{} Inside of a custom 'make title': \includegraphics[scale=0.1]{\@logo} I'm new to Tex/Macros, ...
2
votes
1answer
356 views

Reformatting TexMemo into Spanish

So I dowloaded a memo template from ShareLatex, the TexMemo. Essentially, I want to reformat the entire template into Spanish. Additionally, I want the fields at the top to be written in spanish. For ...
1
vote
1answer
575 views

How to globally define different task bar colors in a gantt chart?

I've been working with this gantt chart example here. I would like to add user specific colore bars. Essentially, I don't want to have to type bar/.append style={fill=green} into every new bar command....
9
votes
4answers
679 views

How to write a macro that takes a variable number of arguments

I am trying to make a new command called \com which can do the following: If no argument is provided to \com, $\com$ produces the symbol $\lambda$. If one argument is provided, e.g. $\com{f}$, the ...
6
votes
2answers
1k views

One `\newcommand` for inserting figures differentiating two cases with/without captions

I have written the following two \newcommand for inserting figures with or without a caption, respectively. % for fig with caption: #1: width/size; #2: fig file; #3: fig caption \newcommand{\...
4
votes
1answer
2k views

Defining optional parameters in \newcommand

If I have a command in the form \newcommand{\TM}[1]{\color{red} $\boldsymbol{#1}$} how can I call it with an optional parameter for color? What I want is that if it's called like \TM{\alpha} it ...
9
votes
2answers
314 views

Patch 2016 xparse to support k-type argument

As per Xparse's new e-type argument (replacement for k-type argument), support for xparse's k_ argument type is no longer available as of TeXLive 2016 and thus have stuck to TeXLive 2015 so far. ...
1
vote
0answers
47 views

Bug with optional arguments in sagetex?

I can't seem to find where to report this bug, and I wanted to see if it was either known about, or repeatable by others. When you compile sage code using the sagetex package it is suppose to ...
3
votes
2answers
809 views

How to pass optional arguments to command?

I'm trying to write my own command that wraps the \VerbatimInput command. I'd like my command to take optional arguments (those given inside [...]) and pass those directly to \VerbatimInput[...]. Of ...
13
votes
4answers
1k views

Using the compulsory argument for the optional argument?

I am trying to define a command that takes two arguments, where one is optional. If the optional argument isn't given I would like the compulsory argument to be used for the optional argument. For ...
16
votes
1answer
470 views

Any difference between \newcommand{\foo}{foo} and \newcommand{\foo}[0]{foo}?

I have a co-author who defines many macros as e.g. \newcommand{\foo}[0]{foo}, explicitly giving the number of arguments even when it’s zero, where I have always previously used and seen \newcommand{\...
1
vote
1answer
444 views

Two boxes wanted for a theorem environment based on tikz

Okay, so I want to make an enviroment, preferably using tikz, that looks like this, which I made with paint (and I like to use black squares for my qed symbol): Okay, that qed symbol and last line ...
15
votes
2answers
818 views

Xparse's new e-type argument (replacement for k-type argument)

Accoring to Joseph Wright's answer at Optional Parameters in xparse: \IfBooleanTF vs \IfNoValueTF The k-type argument has recently been adjusted: you now want e-type Questions: What is the ...
9
votes
1answer
2k views

Optional Parameters in xparse: \IfBooleanTF vs \IfNoValueTF

I tend to get \IfBooleanTF and \IfNoValueTF (and the other similar macros) mixed up and wondering which is the correct ones to use for the following optional parameters: s, o, d, g, k_ (and k^) and t_ ...
6
votes
2answers
146 views

Newcommand with different definitions depending on the value of one argument

I am writing some stats notes, and I have to type null and alternative Hypothesis quite often, so I thought having a command that does it for me would be nice Basically I want to get something that ...
1
vote
1answer
37 views

how to check in the tex file an argument has been passed to a class

within a tex file, I'd like to know if a given argument has been passed to a class. E.g., suppose in my main tex file: \documentclass[optionA]{myClass} How can I check if optionA has been passed ...
2
votes
1answer
666 views

csvsimple - import only certain columns

\begin{figure} \csvautobooktabular[]{csvs/some-ttests.csv} \end{figure} This produces way too large a table (cut off on the left side), so I want to split it up into multiple tabulars, one for ...
1
vote
0answers
24 views

newenvironment not taking input arguments [duplicate]

This should be a simple thing, but everywhere I've looked says what I have should work I think. After doing this for a few hours I'm calling it and asking for someone to point out the stupid mistake. ...
2
votes
1answer
608 views

Error using a command with argument in brackets in listing caption

\documentclass{article} \usepackage{listings} \usepackage{hyperref} \begin{document} \lstlistoflistings \section{Section}\label{section} \begin{lstlisting}[caption={Sample from \hyperref[section]{...
4
votes
1answer
200 views

Coding a *short* newcommand with a variable number of arguments for a very specific use-case

Is it possible to create a simple, robust command with a variable number of arguments for the following specific use-case ? Consider \newcommand{\bigmap}[7]{% #1\!\begin{pmatrix}#2\\ #3\\ #4 \end{...
3
votes
1answer
3k views

The default value of \newcommand is not as documented

The documentation of \newcommand in latex2e.pdf claims that if the optional parameter is specified as [] and is not given in the call, the value will be the string def. Instead, the command is getting ...
2
votes
2answers
907 views

How define LaTeX command with 2 or 3 arguments in comma-separated list

To avoid typing subscripts and extra parentheses and brackets, I want to define a command, say \disk, that may be used with a comma-separated list of either 2 or 3 arguments, like this: $\disk{r,x}$ $...
1
vote
1answer
112 views

How beamer notices an empty line between title and subtitle?

Referrring back to my question Finding out the number of needed macro arguments : how Beamer can find out whether a {} term is subtitle or not? I see that an empty line makes the difference; my ...
3
votes
2answers
415 views

How to make properly macro with the use of pic?

I'd like do make a picture that consists of few blocks. One of these blocks I called \elementsymbol (in MWE below) - it consists of an arrow surrounded by a circle. I have the problem with scaling of ...
13
votes
2answers
660 views

Xparse k argument to parse options at end of environment

I am trying to combine the solutions from How to properly use \collect@body within align environment Xparse t argument type (underscore with optional parameter) to parse optional parameters ...

1 2
3
4 5
8