Questions tagged [arguments]

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

Filter by
Sorted by
Tagged with
16
votes
3answers
576 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
439 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
604 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
246 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
872 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
476 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
185 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
639 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
373 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
930 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
315 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
237 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
364 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
181 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
271 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
224 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
288 views

Issue with Expansions of Nested Macros

I am trying to incorporate membership checking macros by marmot and Phelype Oleinik (thanks to both of them for their neat solutions) into an argument of another macro: \singleBox{\...
6
votes
2answers
185 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
240 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
195 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
171 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
3answers
77 views

How to change value of an argument (e.g. #1) such that any reference to it (the argument, #1) would expand to the new value?

I was wondering how to change #1, based on its value, to something else such that any #1 that follows the change would contain the modified value, not the original value (passed to the macro from ...
5
votes
2answers
768 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
173 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
733 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
151 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
198 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
750 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
99 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
533 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
125 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
129 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
191 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
101 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
132 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
147 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
2answers
447 views

Newcommand inside foreach: multiple arguments and minipage environment

I am trying to define multiple, sophisticated newcommands within a foreach loop. This sounds so simple, but why is it so hard ? Naive attempt: \documentclass{report} \usepackage{tikz} \foreach \i ...
4
votes
1answer
70 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
679 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
508 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
162 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
616 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
2answers
42 views

Nested keyval proper parsing

I have two families of keyval arguments, and two functions, and I want them to behave like on toy MWE below. \documentclass{article} \usepackage{xkeyval} \usepackage{xparse} \makeatletter \define@...
3
votes
3answers
76 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
174 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
600 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 \...