8
votes
1answer
106 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
69 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
94 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
78 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
217 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.
5
votes
1answer
139 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 ...
0
votes
1answer
22 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 ...
4
votes
1answer
72 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 ...
1
vote
1answer
114 views

naming argument and optional-argument for \def, \newcommand and newenvironment

I know how to create a new command or an environment. I think it will much better if I can specify name of the arguments. For example in framebox command and array environment below, we know exactly ...
14
votes
3answers
223 views

How to define a new command based on \section with its optional argument?

I've defined a new command called \mysec like the below: ‎‎‎‎‎‎ \documentclass{article} \newcommand{\mysec}[1]{\section{#1}} \begin{document} \mysec[Foo foo]{Bla bla bla} \end{document} But in the ...
1
vote
1answer
156 views

Using variables to draw a tikz diagram

I am defind my own command to plat a diagram with tikz. Instead of constant values I rather want to pass numbers to my command which determine the height of the bars in my diagram. Problem: I am ...
9
votes
2answers
180 views

Defining a macro with three optional arguments in the form \newmacro{a}{b}[c]{d}[e][f] and \newmacro{a}{b}[c]{d}*[f]

I am defining a macro in LaTeX2e for writing function declarations. I want that the macro has tree compulsory arguments: the name of the function (v.g f), a depiction of the type of variable it takes ...
5
votes
6answers
660 views

How to create new commands with multiple arguments?

I'd like to create a new command \add that accepts 2 arguments, called entity and title. In other words, the command should look like this: \add{entity}{title}. The output should have the following ...
7
votes
1answer
163 views

Gobble optional arguments

You can use \@gobble, for instance, to restrict the usage of a macro like: \documentclass{article} \makeatletter \newcommand*{\cmd}[1]{% #1 \global\let\cmd\@gobble } \makeatother \begin{document} ...
9
votes
1answer
109 views

Optional arguments: xparse vs. xargs

To implement a macro that takes one or more optional arguments that do not have to be placed in the first position, xargs can be used as well as xparse. The latter seems to have more recent updates ...
8
votes
1answer
66 views

Moving the optional argument

When I create macros using \newcommand, I usually provide default variants setting some of the first arguments in a sort of partial application style \newcommand\five[5]{#1,#2,#3,#4,#5} ...
3
votes
1answer
108 views

Xparse macro with optional parameter breaks value for PGF foreach

I write a document class and want to execute something a certain number of times, depending on a user-defined quantity. So I thought I'd use a foreach loop from PGF together with accessor macros: ...
4
votes
0answers
65 views

xparse with underscore and optional argument [closed]

I need a macro which handles its input as follows: \foo A > #2 = A \foo{A} > #2 = A \foo(B) > #3 = A (round brackets) \foo_m A > #1 = m, #2 = A \foo_m{A} > #1 = m, #2 = A \foo_m(B) > #1 = m, #3 = B ...
8
votes
2answers
104 views

Connecting multiple arguments

I recently discovered Latex and is using TexMaker to edit my documents, in one of my university courses we will be performing a number of tests on a hydraulic rig. Since the tests will be conducted by ...
4
votes
1answer
275 views

\newcommand with optional multi-line argument and implicit itemize environment

While drafting a text, I want to subdivide and group text pieces and keywords to easily reorder them throughout the document. Examples for such a group of text pieces would be: Example 1): Two ...
9
votes
2answers
521 views

How to use a macro inside \includegraphics options?

I have to do several figures like this: \begin{figure}[h!] \centering \includegraphics[trim = 9.55cm 1.8cm 10.25cm 4.05cm, ...
5
votes
2answers
319 views

TikZ: Using optional arguments in after part of \newenvironment*

How can I pass the optional arguments to a node being drawn in the after part of a \newenvironment*? In the before part this is easy since I can simply use #1. I tried using \edef, but that ended up ...
9
votes
1answer
1k views

TikZ: \newcommand with optional TikZ options

I want to create a new command with some default TikZ options that you can override using an optional argument. If working as intended the code below would generate a red line between A and B, and a ...
13
votes
5answers
251 views

Two independent optional arguments for new commands

I'm trying to adapt the solution provided in Different command definitions with and without optional argument to change the behavior of my new command. I'd like to use basic command to avoid some non ...
7
votes
3answers
178 views

Adjusting command behavior based on argument type

I have a following command in my latex document: \newcommand{\ApplyGradient}[1]{ \pgfmathsetmacro{\PercentColor}{100.0*(#1+0.2)/1.3} \textcolor{black!\PercentColor}{#1}} ...
4
votes
3answers
171 views

Arguments to Commands: […] vs {…}

Perhaps this is something that has been answered before, but a cursory search didn't turn anything up. Is there any logic to how commands take arguments? Some things want the arguments to the ...
3
votes
3answers
81 views

Environment with coordinate-like arguments

I would like to define an environment which takes coordinate like arguments (1,2). I think about two different calling schemes: \begin{myenv}(mandatory coordinate)[optional](optional coordinate) ...
8
votes
4answers
214 views

Special macro definition (2opt, 1mand)

How can you define a macro \cmd in TeX primitives using two optional arguments (and a mandatory one) that fulfills the property that calling \cmd[opt]{mand} is equivalent to \cmd[][opt]{mand}. Yet, I ...
2
votes
2answers
98 views

Add parameter to existing command produces error

I have this command in a template given by my prof \newcommand{\homeworkProblemName}{}% \newcounter{homeworkProblemCounter}% \newenvironment{homeworkProblem}[1][Problem ...
6
votes
2answers
4k views

Beamer allowframebreaks default option

How do I tell beamer that I want allowframebreaks allowed by default? Something like noitemsep for itemize: \setlist[itemize]{noitemsep} So that I don't have to do: \begin{frame}[allowframebreaks] ...
4
votes
2answers
609 views

Line break (continuation) for commands (options, arguments)

How to do proper line breaking (continuation) for commands, i.e. their options and/or their arguments? For example, in order to transform this: \usepackage[top=1.0cm, bottom=1.0cm, left=1.0cm, ...
10
votes
2answers
176 views

Flexible parenthesing command

I would like to create a smart parenthesing command without using the xparse package. \p(1) prints (1) \p[1] [1] \p{1} {1} \p(1|2) (1|2) I tried this code but it ...
7
votes
2answers
135 views

Using a required argument as a default for an optional one in \newcommand

I'd like to create a new subsection command with the same calling structure like the original one, but I have no idea on how to handle the case when the optional argument is omitted. Basically I want ...
13
votes
2answers
312 views

TeX Parameter Processing imitating key-value pairs

I am thoroughly confused by this answer to How to generate n points on a circumference and connect all of them while having constraints on the image size as I don't understand how the parameter ...
14
votes
1answer
199 views

How to read a stream of tokens up to one of two different delimiters

The core question How can I process text delimited by one of two terminators? For instance, if I want to process text up to the next \A, I can just write \def\CmdA#1\A{...} But suppose that \A ...
9
votes
3answers
300 views

Create macro with several options

I struggle to create a macro that can take several options. What I want to create is for \mycommand[up,middle]{Macro} to output Macro with 'up' and 'middle' specified. Using etoolbox in the MWE below ...
4
votes
2answers
314 views

Different macro behavior when supplied an argument

I want to define a macro, call it \func, so that \func will output\phi, and \func[i] will output \phi(i). what is the easiest way to achieve this? I know there are other questions that address this ...
0
votes
1answer
442 views

Pass multiple options to \newcommand

I have defined a new command for each of the team members in my project group to add individual todo-notes with different color and name. Now I would like to add another option, but is having trouble ...
5
votes
2answers
332 views

Redefinition problem with \maketitle from KOMA class (with optional argument)

I try to redefine the \maketitle command as shown below. If I use an optional argument in the redefinition I get the TeX capacity exceeded error. Any suggestion why? MNWE: \documentclass{scrreprt} ...
10
votes
1answer
240 views

New command with default does not work

Hello I have the following new command (a bit simplified for readability): \newcommand{\xz}[1][0]{x_{#1}} I'm expecting the following behavior: $\xz$ outputs as $x_0$ $\xz{1}$ outputs as $x_1$ ...
6
votes
2answers
278 views

How to extend a macro for e-mail addresses to support multiple arguments?

I prepared the following macros to format e-mail adresses in a e-mail header. \usepackage{xifthen}% Provides \ifthenelse and \isempty % E-Mail header strings with format. ...
15
votes
2answers
2k views

New command with optional argument being first argument [duplicate]

I know I can create a new command with an optional parameter with \newcommand{\mycommand}[2][Hello]{\textbf{#1} #2} I would like to have the command such that there is an optional parameter which ...
9
votes
3answers
667 views

Are commands defined by \newcommand[.][.]{.} robust?

This question is from the comments at the foot of Abbreviations for AM, PM (small caps) for use within \textbf. Readers will get the remaining gist from there. With ...
5
votes
1answer
3k views

a “… doesn't match its definition” problem, that I don't understand

I managed to extract from my code the following MnWE which shows the problem i encounter : Example 1 \begin{document} \newcommand{\createDATA}[1]{ \xdef\DATA{} \newcommand{\test}[2][]{ ...
1
vote
1answer
6k views

Optional argument for newcommand? [duplicate]

Possible Duplicate: Different command definitions with and without optional argument I would like to define a macro which takes an optional argument, and behaves in different ways depending ...
13
votes
4answers
3k views

Optional arguments in \def

I want to re-define the \sqrt command (as detailed in Nice-looking p-th roots), and so far I have the following: \documentclass{article} \usepackage{fouriernc} % use the New Century Schoolbook font ...
4
votes
4answers
446 views

Writing a multiple option command for a package

I am a newbie at LaTeX programming, so please be patient. :-) I am writing a .sty file which I want to include a command \dan which is overloaded with three separate versions depending on whether ...
6
votes
4answers
420 views

List parsing with special input/optional arguments

I’d like to parse a list where the elements can be given as either [<pre>]<text>[<post>], where <pre> and <post> are optional, or (<special text>). I found a ...
2
votes
2answers
3k views

\newcommand gives errors in math mode (with or without arguments)

I'm trying to define a custom command for use in math mode, defined as \newcommand{\deriv2}[2]{\ensuremath{\frac{\partial^2 {#1}}{\partial {#2}^2}}} Other non-math mode \newcommands work in my ...
0
votes
0answers
127 views

how to define a newcommand with several optional arguments? [duplicate]

Possible Duplicate: More than one optional argument for newcommand Is it easy to define a new command with several optional arguments, that one would call as follows : ...