Questions tagged [macros]

{macros} is for questions specifically concerning TeX's macro processor. Note that, because TeX uses macros ubiquitously, most questions about code that uses macros are not looking for information about how macros work, and so are not appropriate for this tag.

{macros} is for questions specifically concerning TeX's macro processor.

Questions about the peculiarities of such TeX commands as \def, \edef, \expandafter, \noexpand, or \futurelet are appropriate, or LaTeX commands such as \newcommand.

Note that, because TeX uses macros ubiquitously, most questions about code that uses macros are not looking for information about how macros work, and so are not appropriate for this tag.

8234 questions
388
votes
5 answers

What is the difference between \def and \newcommand?

Inspired by a question about \let and \def, I have some that essentially all boil down to asking What are the differences between \def and \newcommand? In particular, I wonder Is it possible to have parameters passed to \defed commands, both…
Michael Underwood
  • 21,356
  • 13
  • 52
  • 41
206
votes
3 answers

What do newcommand, renewcommand, and providecommand do, and how do they differ?

What do newcommand, renewcommand, and providecommand do, and how do they differ? I think \newcommand overwrites any previously existing command, while \providecommand creates the command only if it does not already exists. Does \renewcommand only…
keflavich
  • 4,613
140
votes
2 answers

The \the command

I wanted to know if someone could point me to a reference where I could learn more about the \the command. Searching for "the" has been, without surprise, entirely unproductive. Even consulting "comprehensive" LaTeX command/macro lists has been…
user001
  • 7,964
105
votes
4 answers

\newcommand argument confusion

I'm trying to work through LaTeX Beginner's Guide by Stefan Kottwitz. Here's where I got stumped: \documentclass{article} \newcommand{\keyword}[2][\bfseries]{{#1#2}} \begin{document} \keyword{Grouping} by curly braces limits the \keyword{scope} of…
147pm
  • 1,369
102
votes
1 answer

What is the purpose of \protect?

Possible Duplicate: What is the difference between Fragile and Robust commands? I've never understood the purpose of the command \protect? When and why should it be used?
gablin
  • 17,006
90
votes
5 answers

Why do LaTeX internal commands have an @ in them?

Does the @ mean anything specific? For example, is it substituted? Does it split the command into parts, like \s@foo could internally mean "foo of type s"? Is the purpose of the @ only to make internal commands break when used outside a class…
eje211
  • 1,201
89
votes
1 answer

When to use \LetLtxMacro?

Frequently I see users redefine macros using (for example) \let\oldmacro\macro% Store \macro in \oldmacro \renewcommand{\macro}{% % ...redefined \macro \oldmacro% } and other times they use \usepackage{letltxmacro}%…
Werner
  • 603,163
84
votes
10 answers

How to define a command that takes more than 9 arguments

I have a mathematical transformation that takes 16 parameters (grouped into 3+8+5) and would like to make a latex command for it, so that I can easily change the notation for it if the need arises. As far as I know, both \def and \newcommand take a…
Simon
  • 4,262
77
votes
3 answers

When is it harmful to add percent character at end of lines in a \newcommand, or similar

Since egreg has graciously agreed to not comment at least for a day to When not to use \ensuremath for math macro? :-), I thought I would take advantage of that and post a question about another (non-offical) campaign of egreg: additional % at the…
Peter Grill
  • 223,288
70
votes
3 answers

Display source for a command

When using renewcommand, sometimes I wish to first check what the original source code for a particular command, such as chapter was before I change it, so that I can be certain that I do not make unintended changes. When I have a lot of packages…
Village
  • 13,603
  • 23
  • 116
  • 219
61
votes
8 answers

What is the recommended way to assign a value to a variable and retrieve it for later use?

What is the recommended way to define a variable inside a document and retrieve its value later? I've googled several different solutions, usually about ~10 lines long. I was wondering, that there must be a shorter way of doing something like this…
citronas
  • 1,085
  • 2
  • 11
  • 17
60
votes
8 answers

Short names for macros

Often it happens that I would like to define macros that I would use very frequently throughout the document – for example, a special symbol that I use repeatedly in many equations. Ideally, in such situations, I would like to keep the name of the…
Jukka Suomela
  • 20,795
  • 13
  • 74
  • 91
50
votes
5 answers

TeX macro idioms, or: understanding advanced macros

I often find that when I look at solutions from the experts here, the macro definitions are completely inscrutable to me. Trying to use standard techniques one would use to understand code in most programming languages often isn't helpful; for…
Mohan
  • 15,906
49
votes
3 answers

undefining custom commands

After you define a command using \newcommand, is it possible to undefine it? My motivation is that I'm writing a thesis, where each chapter is in a separate source file. Some chapters define their own commands that are used nowhere else, so I'd like…
49
votes
6 answers

Macros with # as the last parameter

Knuth hid a special rule for delimited arguments in exercise 20.5 of the TeXbook. If the very last character of the parameter text is #, so that this # is immediately followed by {, TeX will behave as if the { had been inserted at the right…
yannisl
  • 117,160
1
2 3
81 82