Skip to main content
18 votes
Accepted

TeX jargon - Difference between "argument" and "parameter" in TeX?

With this answer the phrase "⟨replacement text⟩" (in angles) denotes the ⟨replacement  text⟩ of a macro's ⟨definition⟩ at the time of defining that macro. Such ⟨replacement text⟩ may ...
Ulrich Diez's user avatar
  • 29.6k
17 votes
Accepted

Several arguments in tikzset pic

You can switch to the alternative definition of the pic style family such that style 2 args or style n args, style args stuff from the regular pgfkeys syntax can be used for arguments. \...
percusse's user avatar
  • 158k
17 votes
Accepted

Using the compulsory argument for the optional argument?

The classical approach for this is to use \@dblarg: \documentclass{article} \makeatletter \newcommand{\foo}{\@dblarg\ah@foo} \def\ah@foo[#1]#2{#1 foo(#2)} \makeatother \begin{document} No optional ...
egreg's user avatar
  • 1.1m
17 votes

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

Let's consider a simpler example: \documentclass{article} \usepackage{xparse} \NewDocumentCommand\TestArg{mO{x}}{% 1: #1, 2: #2 } \begin{document} \TestArg{a}[b] \TestArg{a} [b] \end{document} ...
egreg's user avatar
  • 1.1m
17 votes
Accepted

About the definition of textcolor

This is primitive tex syntax that really shouldn't be used in a latex package. It's used here as in 1993 fitting this all into a 640K machine we were really short of space and saving a few dozen bytes ...
David Carlisle's user avatar
15 votes
Accepted

Can \cref be made to ignore spaces?

Normalization with removal of spaces before and after label names and removing of empty entries. The following example uses the comma parser of package kvsetkeys for parsing the label name list of ...
Heiko Oberdiek's user avatar
14 votes
Accepted

Use of named arguments instead of numbers in LaTeX

I wrote something like that some time ago to assist in another project of mine. Some internal macros started to have too many arguments and I was changing their order too often, so keeping track of ...
Phelype Oleinik's user avatar
14 votes

argc argv in LaTeX

The command line design for running TeX is very old, so you can find it very atypical. The command switchers (like -ini, -jobname) are read first. If next object is not - nor \ then it is assumed that ...
wipet's user avatar
  • 75.5k
13 votes
Accepted

How do you write a macro that takes arguments containing paragraphs?

At the time TeX was written, one page of a document would take several minutes to be processed, and syntax highlighting was not a thing, so it was a good thing to have some mechanism to detect if you ...
Phelype Oleinik's user avatar
13 votes
Accepted

Is it allowed to put spaces after macro parameter?

When you do \def\foo#1#2{(#1,#2)} then #1 and #2 are undelimited arguments. An undelimited argument is either a single token (except { or }) or a braced group {...}. TeX ignores spaces when looking ...
campa's user avatar
  • 31.7k
12 votes
Accepted

\verb illegal in command argument in task

Use this: \usepackage{fancyvrb} \newcommand\Cpp{C\Verb!++!} But why not a simple C{}\texttt{++}?
Bernard's user avatar
  • 272k
12 votes
Accepted

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

It's easy with expl3: \documentclass{article} \usepackage{xparse} % loads expl3 \ExplSyntaxOn \NewDocumentCommand{\mathvar}{m} { \int_compare:nTF { \tl_count:n { #1 } > 1 } { \mathrm{#...
egreg's user avatar
  • 1.1m
12 votes
Accepted

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

tex macros have two kinds of argument, delimited and non delimited, for a non delimited argument the argument is either a single token, or if the token is an explicit brace (a character of catcode 1) ...
David Carlisle's user avatar
12 votes
Accepted

Trying to understand the definition of \newcommand (complex handling of parameter tokens)

Your reasoning is correct except for what the #{ parameter does. When TeX sees a # in the <parameter text> of a macro (as in \def\macro<parameter text>{<replacement text>}), the ...
Phelype Oleinik's user avatar
12 votes
Accepted

What are some examples of LaTeX commands which accept three or more arguments?

As of version 2022-11-01, patch level 1, the LaTeX "kernel" contains 10 instances of #9 30 instances of #8 40 instances of #7 86 instances of #6 172 instances of #5 407 instances of #4 892 ...
Mico's user avatar
  • 513k
11 votes

Biggest depth of a character in a string

I don't know about your approach using a loop, but to get the depth, just use \settodepth See : https://tex.stackexchange.com/a/37294/116936 You can also use the calc package \depthof \...
marsupilam's user avatar
  • 6,393
11 votes
Accepted

Biggest depth of a character in a string

The answer by marsupilam covers how one would normally achieve the task: typeset the content and get the box depth. There are two issues with the code you've got. First, the TeX primitive \dimen has ...
Joseph Wright's user avatar
  • 261k
11 votes
Accepted

How to define a comma separated list of arguments for includegraphics

Just define new keys: \documentclass{article} \usepackage{graphicx} \makeatletter \define@key{Gin}{settingsA}[]{\setkeys{Gin}{width=\textwidth, angle=90}} \define@key{Gin}{settingsB}[]{\setkeys{Gin}{...
egreg's user avatar
  • 1.1m
10 votes

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

Parameter tokens #1 to #9 are only relevant at macro definition time, so you're being misled when thinking to them. The macro \setarray has two undelimited arguments (because the parameter token are ...
egreg's user avatar
  • 1.1m
10 votes

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

Here's a LuaLaTeX-based solution. It defines a macro called \numchars, which returns the number of characters in its argument, and an implementation of \mathvar. Care is taken not to count whitespace ...
Mico's user avatar
  • 513k
10 votes
Accepted

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

Remember that with \renewcommand{<cmd>}{<stuff>}, any subsequent use of <cmd> is replaced with <stuff>. Viewed differently, using a more practical example, \renewcommand{\mB}{\...
Werner's user avatar
  • 606k
10 votes
Accepted

Is there a way to add optional and/or named argument to command

Classically the LaTeX2e solution was the keyval package (as used by \includegraphics[height=2cm, scale=3]{...}) but recent LaTeX releases include a keyval parser built in, based on l3keys. @Campa's ...
David Carlisle's user avatar
9 votes

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

Of course, the syntax uses the standard LaTeX convention of optional arguments in square brackets, in this case for both optional arguments. Also, the OP implied that the command should be used not ...
Steven B. Segletes's user avatar
9 votes
Accepted

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

You can use \detokenize; but if you want a printed underscore, you need to load fontenc with the T1 option. \documentclass{article} \usepackage[T1]{fontenc} \usepackage{etoolbox} \usepackage{hyperref}...
egreg's user avatar
  • 1.1m
9 votes

Omitting argument in command definition

TeX is a macro expansion language. If we look at some random definitions in plain.tex, we find some that only appear to have an argument. For instance \def\line{\hbox to\hsize} that should be called ...
egreg's user avatar
  • 1.1m
9 votes

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

you can not have white space before optional arguments that follow the last mandatory argument so this works. \documentclass{article} \usepackage{xparse} % 12 3 4 ...
David Carlisle's user avatar
9 votes
Accepted

Variable argument macro to define splitting polynomial

I streamline the syntax by putting all the term data in a comma separated list in the 2nd argument. I use listofitems to parse the list (the default list separtor is a comma, but that could be ...
Steven B. Segletes's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible