Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [arguments]

The {argument} tag is used for specific questions about macro parameters and arguments.

16
votes
3answers
552 views

\NewDocumentCommand: Why can't I put args on an own line?

I encountered a peculiarity concerning \NewDocumentCommand arguments. In a case where I had real long names in the arguments, I wanted to put them each on its own line. The first ones are OK, the 2 ...
12
votes
3answers
432 views

how to determine the number of characters in the argument of a command

I want to define a command that behaves differently for single-character arguments than it does for longer arguments. How do I retrieve the number of characters in, e.g., #1? The specific application ...
12
votes
2answers
574 views

How are parameter tokens (#1,#2,…,#9) processed?

I wonder how the TeX token muncher processes parameter arguments. It seems that parameter arguments are sent token by token. Is this true? Consider the following code based on wipet's answer used to ...
12
votes
1answer
203 views

About the definition of textcolor

I was curious and found the following definition for the macro textcolor defined in the package xcolor: \def\textcolor#1#{\@textcolor{#1}} \def\@textcolor#1#2#3{\protect\leavevmode{\color#1{#2}#3}} ...
11
votes
4answers
814 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 ...
11
votes
3answers
458 views

Can \cref be made to ignore spaces?

I think this MWE says it all. \cite can ignore spaces in its argument, while \cref cannot. I wonder if \cref could be improved that way. \documentclass{article} \usepackage{cleveref} \usepackage{...
10
votes
1answer
183 views

Omitting argument in command definition

Sometimes I define model commands (\foo in the example below) and then particular commands based on that model (\fool in the example below). However, I am not entirely sure I am using the correct ...
9
votes
4answers
635 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 ...
8
votes
4answers
365 views

Runaway argument? with \newcommand[2]

I have a date (in the format YYYY.MM.DD) and a time (format HH:MM). From these, I want to compute a kind of TimeStamp/Total of minutes. \documentclass{article} \makeatletter % Timestamp \...
7
votes
3answers
922 views

Biggest depth of a character in a string

I need to find depth of a string, for this end i would like to loop over the string and ask for depth of every character. I ask for depth like this: \dimen=\fontchardp\expandafter\font`\a And loop ...
7
votes
7answers
2k views

newcommand with comma separated argument, and optional arguments

I want to define a command (not with \def) the simplest possible way that it takes arguments separated by a comma, supports an optional argument (the first one). maybe another solution with extra ...
7
votes
2answers
300 views

Understanding \@firstofone

I was looking over this answer and trying to understand the code, I am a super newbie (my second day) in LaTeX and I stuck at the following part of the code that i could not make it work in a not ...
7
votes
3answers
229 views

Macro that takes any latex code as an argument

So I am thinking of creating a macro that takes any latex code as an argument. For example, \newcommand\purp[1]{\color{purple} #1} I hoped that this macro would make any latex code inside of \purp ...
7
votes
2answers
350 views

Handling _ (underscores) in a macro's comma-separated list of arguments

Context: I created a "\citep-like" macro. I use it in the body of my document to refer to some code found in appendix. My macro takes a comma-separated list as input, and prints each element of the ...
7
votes
2answers
179 views

How to define a comma separated list of arguments for includegraphics

I have a large set of pictures, and I want to apply predefined settings to each using the optional argument of the \includegraphics macro from the graphicx package. I would like to define the ...
7
votes
3answers
267 views

How to test if argument is a single space?

I am currently writing a document, that sometimes requires me to alternate the colors of the letters in a sentence. I thought it would be easy to find a way to create a macro that does that, but I've ...
7
votes
1answer
200 views

Optional args for TikZ style

I have a defined a TikZ style "midcircle" that decorates a path with, say, a small circle in the middle (with the decorations.markings library, setting "pos=0.5"). E.g. \draw (0,0)edge[midcircle](1,0)...
6
votes
2answers
182 views

Variable argument macro to define splitting polynomial

I need a macro that behaves the following: \mpoly{x}{1}{2} outputs (x+1)(x+2) \mpoly{x}{1}{2}{3} outputs (x+1)(x+2)(x+3) \mpoly{x}{1}{2}{3}{5} outputs (x+1)(x+2)(x+3)(x+5) and so on. I am not at ...
6
votes
3answers
239 views

Strange argument absorption, using \color

I just noted a strange behavior, when ending a macro with a \color{<color>} invocation, the net effect of which seems to absorb the subsequent space. I realize the easy thing to do is just ...
6
votes
1answer
184 views

Why does \renewcommand{\A}{\B} change the value of \C? when \A, \B, and \C are arguments?

I'm very puzzled by the effect of a \renewcommand with two macros as arguments that appears to affect the value of a third macro. This all occurs within a command to which all three macros are passed ...
6
votes
2answers
170 views

Anonymous commands with Expl3

The following code allows me to produce series easily (see examples below the code): \documentclass{article} \ExplSyntaxOn \NewDocumentCommand \simpleseq { m m m } { \seq_set_split:Nnn \...
5
votes
2answers
744 views

Remove extra curly braces

In this MWE, I demonstrate my problem: \documentclass{article} \usepackage{seqsplit} \newcommand{\dosomething}[1]{\uppercase{#1}} \newcommand{\dosomethingelse}[1]{\seqsplit{#1}} \begin{document} \...
5
votes
2answers
171 views

Reading the arguments of my command and using them in the command

My question is about reading and using the arguments of a custom created command using \def. Let's say I have the command \mytestcommand and I want to read and use it's arguments (optional and ...
5
votes
3answers
713 views

Variable number of arguments in a command

Code \documentclass{article} \newcommand*\test[2]{#1\textsuperscript{#2}} \begin{document} The player ended as no.~\test{1}{} and her friend came in \test{2}{nd}. \end{document} Output Question ...
5
votes
2answers
147 views

Plain LuaTeX: Detecting if displaymath is ended by $$ or \Ustopdisplaymath

In the TeX Book (chapter dirty tricks) there is mentioned a way to left align displaymaths. https://arxiv.org/macros/cp-aa.tex A macro \displaysetup whose argument is delimited by $$ is used. So it ...
5
votes
2answers
188 views

Use second argument for optional first argument if not provided in macro

I'm trying to construct a command with one optional and one mandatory argument and I'd like the default if the optional argument is not provided to be #2. Why does this not work? (error: Illegal ...
5
votes
2answers
717 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{\...
5
votes
1answer
1k views

Several arguments in tikzset pic

I want to pass more than one argument to a pic defined with \tikzset. I tried this and it works: \tikzset{ Piece/.pic={ \draw (0:1) -- (120:1) -- (240:1) -- cycle; \draw (0,0) ...
5
votes
1answer
91 views

Strange error for passing parameter to forestset to draw tree

I am trying to draw a simple probability tree, where the probabilites could sometimes be fraction or decimals., this means, I will have to adjust the spacing. So I tried the below code. This produces ...
5
votes
1answer
208 views

Why do braces around a single-letter argument of a macro affect its output?

I thought \ul 8, \ul8, and \ul{8} are identical ways of passing an argument 8 to a command \ul. However, they produce different output. Why? MWE: \documentclass{article} \usepackage{soul} \...
4
votes
4answers
514 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}...
4
votes
2answers
120 views

Use N type for own macros

Background In LaTeX3 I’m programming some macros to store and read contents from a variable like \tl_set:Nn does. An thus I’m generating variants using the N type, which causes a warning. The warning ...
4
votes
2answers
126 views

Formatting phonenumbers with phonenumber-package and macros as argument (expand-problem)

I try to use the phonenumbers-package to format phonenumbers. As argument I want to use a macro (in the actual document the macro will be defined with pgfkeys!) What I tried so far: \documentclass{...
4
votes
1answer
189 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{...
4
votes
2answers
135 views

In TeX how can I define a list of data such that I can use a numerical argument to call for one entry out of the list

I would like to be able to have a defined macro something like this: \def\testmacro[1]{[54.7],[74.1],[98.5]} Such that when I call \testmacro{2}, in a document, 74.1 is printed. Is this ...
4
votes
2answers
100 views

Define macro whose argument is a word

I need to define a macro whose argument is the next word (the first character after the word should be a blank space, the end of the line, or a punctuation mark from . , : ; ! ?. For example, let's ...
4
votes
1answer
127 views

Arguments to macros in mathmode lose their mathmode typesetting

I'm writing a little semantics package(I know that there already exists some good packages for this) in latex to help me and my friends out with our assignments. but im having a broblem that ...
4
votes
2answers
143 views

\def'ed plain-text argument behaves differently from plain text

So this is my example, closely related to Remove extra curly braces. Apart from my application, trying to line-break the labels in the margin even if they do not have spaces in them, I am trying to ...
4
votes
1answer
61 views

tikz : Specify a percent parameter in a path

I am trying to define a style to draw a bend line from one shape's south to another shape's west \documentclass[border=5mm, convert, usenames, dvipsnames]{standalone} \usepackage{tikz, pifont, xcolor}...
4
votes
1answer
655 views

Arithmetic operation between command arguments and latex parameters

I'm defining a new command that places two images one next to the other and I want to add an horizontal space between the two images which corresponds to one third of the space that remains blank. The ...
4
votes
1answer
491 views

Passing arguments to class in a key=boolean value manner

Assume I have a bunch of flags which I want to pass to my class, how do I do this? If you see the example below, I am looking for passing flags in the form: key=<boolean value from flag> to ...
4
votes
1answer
159 views

Robust handler of arguments with conditionals and complex elements

Context This question is a follow up of the answer of this question Spurious space on moderncv \cventry using \if Problem The problem is that complex content (for example, itemize on the content of ...
3
votes
2answers
538 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 ...
3
votes
3answers
73 views

Allow Optional Delimited Params To Appear In Any Order (EASILY) (e.g. \REset[s](X){e}=\REset(X)[s]{e})

My package rec-thy has a number of macros that allow the optional specification of both a stage (as part of a stagewise approximation) as well as a relativization. I've adopted the convention that ...
3
votes
2answers
168 views

For the life of me I can't find the runaway argument here — but then I'm very new to all this

\documentclass[11pt, oneside]{article} \usepackage{geometry} \geometry{a4paper} \usepackage{graphicx} \usepackage{amssymb} \usepackage{arydshln} \usepackage[table]{xcolor} \usepackage{pifont} \begin{...
3
votes
2answers
566 views

How to patch with \xpretocmd and \xapptocmd a command by applying to it a macro with argument?

Suppose I'd like to patch a very complicated macro, say \autocite. For this, xpatch package is my friend. If the patch consists in applying a modal command which doesn't take arguments, such as \...
3
votes
2answers
199 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
1answer
962 views

\verb illegal in command argument in task

Following this: Make two-columned list start at same line as its section, I did: \documentclass{article} \usepackage{cprotect} \usepackage{tasks} \begin{document} \section{Languages} \...
3
votes
1answer
81 views

TikZ PGF - Minus sign being interpreted as a unit of measure

I'm trying to write a macro that draws a number line given a number of tick marks to use. However, there are a couple of spots in the code where I try to do arithmetic using the argument of the ...
3
votes
1answer
90 views

Raw postscript (!ps) do not expand in argument of \psaxes

The (!ps) syntax is supposed to expand to a pair of coordinates by executing some raw postscript code. In the following example it works well in argument to \rput but not with \psaxes; why is it so? \...