{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.

learn more… | top users | synonyms (4)

287
votes
1answer
40k views

What do \makeatletter and \makeatother do?

Many TeX “hacks” begin with \makeatletter and end with \makeatother. What do these commands do?
181
votes
4answers
17k views

What's the difference between \newcommand and \newcommand*?

I just spotted someone use \newcommand* in an answer and realised that I'd never quite sorted out in my head what the star (asterisk) was there for. (This one is practically impossible to search for ...
156
votes
4answers
27k views

Space after LaTeX commands

I have a definition \newcommand{\arnold}{Arnold Schwarzenegger} when I refer to it by \arnold is a it is rendered as Arnold Schwarzeneggeris a In order to have a space in front of "is" I ...
146
votes
5answers
27k views

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 ...
138
votes
4answers
6k views

What is the use of percent signs (%) at the end of lines?

I see that the code in many packages and examples contains percent signs % at the end of (many) lines. What are they used for? Do they affect the parsing of those lines?
133
votes
3answers
9k views

What is the difference between Fragile and Robust commands?

So I've read a few times about this, the “moving arguments” and all that. But what does it really mean? Could someone explain in a few words what is going on at the TeX level, what is the difference ...
99
votes
4answers
18k views

When to use \edef, \noexpand, and \expandafter?

I'm quite happy hacking TeX macros and cobbling together bits and pieces from different style files to suit my own ends, but I have a suspicion that my resulting hacks are not quite as elegant as they ...
85
votes
3answers
16k views

What is the difference between \let and \def?

What is the difference between the \let and \def commands in TeX/LaTeX? Ideally please provide a simple example that will illustrate the difference between them.
84
votes
2answers
47k views

How do I create an invisible character?

I cannot remember how to create an invisible character in LaTeX, i.e. I want to put a space the that has the width of a particular character, say `M'. I know there is a command for this, and this is ...
73
votes
5answers
12k views

What exactly do \csname and \endcsname do?

What exactly do \csname and \endcsname do? What are their job? I have glanced at the Texbook and some other books, but none of them was clear enough to me. Can anyone please give a simple example to ...
73
votes
3answers
66k views

\vspace vs. \vskip

What is the difference between \vspace{-1em} and \vskip -1em, for example? I guess the first is LaTeX, and the latter is TeX. When is the proper time to use one and not the other, and why?
70
votes
3answers
9k views

How to write (La)TeX (with parentheses) [or any other TeX-related logo]

I'm looking after a macro to write the (La)TeX logo (with parentheses), i.e. something similar to \TeX, \LaTeX, but where the output includes ()'s.
62
votes
5answers
6k views

Different command definitions with and without optional argument

I want to define a command that expands to two completely different things depending on whether I supply, or not, an optional argument. For example, \mycmd{normal} -> something(normal) ...
60
votes
3answers
2k views

What is the difference between \relax and {}?

As I understand it, the point of \relax is to stop a macro from swallowing up subsequent material (such as whitespace). But {} (\bgroup\egroup) serves the same function. Why do we need both?
60
votes
3answers
3k views

Defining starred versions of commands (* macro)

I would like to define a *'d version of a command, something like \newcommand{\foo}{blah} \newcommand{\foo*}{blahblah} If I try to do this, LaTeX complains that I'm trying to redefine \foo, so I ...
60
votes
1answer
2k views

A LaTeX log analyzer application (visualizing TeX expansion)

Consider the following MWE, test.tex: \documentclass[12pt]{article} \begin{document} \tracingassigns=1 \tracingmacros=1 \def\aaa{something} \def\bbb{else \aaa, else} \edef\ccc{third \bbb, level} ...
57
votes
4answers
13k views

When not to use \ensuremath for math macro?

I have gotten into the habit of using \ensuremath around math components in every macro that I define, so that I can use the same macro inside and outside of math mode. But egreg's comments in ...
57
votes
3answers
1k views

Why isn't everything expandable?

TeX's macro processor does its work in a process called expansion. For an input stream of tokens, the macro processor repeatedly expands them until non-expandable tokens remain. The resulting stream ...
56
votes
2answers
5k views

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 ...
54
votes
4answers
3k views

Defining custom commands is bad style?

I recently received this in a e-mail from my professor Good LaTeX style would preclude creating any of your own commands, counters, etc. (Most journals would reject submissions with user-defined ...
54
votes
2answers
1k views

If LaTeX is only a macro package, why does it have its own executable?

From other answers on this site and the FAQ of the TeX User Group my understanding is that: TeX is the original typesetting program, written by Knuth Omega, eTeX, pdfTeX, XeTeX, LuaTeX are engines. ...
53
votes
3answers
17k views

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 ...
53
votes
1answer
13k views

\dots versus \ldots - is there a difference?

Is there a difference between \dots and \ldots, the ellipsis? If yes: Which? When to use \dots and when to use \ldots? If no: Why are there both at all?
52
votes
6answers
2k views

Which document class is being used?

Is there a way to programmatically determine which document class is in effect? I'd like to be able to write conditional macros that behave differently depending on which document class is currently ...
52
votes
5answers
11k views

What's the difference between \RequirePackage and \usepackage?

I understand that "the convention is to use \RequirePackage in a package or class and \usepackage in a document", but apart from that, is there any practical difference between the two commands? (I ...
50
votes
3answers
1k views

Advantages and disadvantages of fully expandable macros

As I currently understand them, fully-expandable macros are analogous to pure/effect-free functions in functional programming. Correspondingly, things that are not expandable, such as \def, are ...
50
votes
2answers
3k views

Documentation reference for LaTeX internal commands?

This question led to a new package: macros2e Is there a place where I can find a reference of LaTeX internal commands? For example, just a few months ago I saw an answer using \@for and today I ...
49
votes
4answers
3k views

How to create a command with key values?

I am trying to create a command that the user can enter keys for values. How can I create one, for example: \myparbox[width=50,height=10,color=blue, align=left -10px]{}
48
votes
5answers
6k views

How can I see the “implementation” of the \LaTeX command?

After reading another question relating to how to see definitions of commands, I tried: \documentclass{article} \begin{document} \show\LaTeX \end{document} But this shows me in my logfile: ...
48
votes
3answers
1k views

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 ...
47
votes
5answers
8k views

More than one optional argument for newcommand

The \newcommand macro allows to use an optional argument for the first parameter #1 with: \newcommand{\mycommand}[3][defaultfor1]{blah blah blah} Is it possible to have more than one option with ...
46
votes
1answer
697 views

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 ...
44
votes
4answers
2k views

What is “expansion”?

I'm relatively new to (La)TeX, but I have a reasonable amount of experience with computational programming languages. Until I began learning (La)TeX, I'd never heard of "expansion"... So, what is ...
44
votes
7answers
13k views

Isn't there any other way of doing double quotes in LaTeX besides `` + ''?

The standard way of writing quotes and double quotes in LaTeX is with `` and '', but I find them quite ugly. Isn't there something similar to \emph{}, but for quotes? I mean something like ...
43
votes
9answers
2k views

Where do I find out how a command/environment is defined?

Say I want to redefine the itemize environment, or make a modified version of it. I want to know how it is currently defined. Where do I find this information? If it's some particular package command, ...
43
votes
3answers
3k views

What is the difference between \let and \edef?

When you write \edef\a{\b} \let\a\b the results are often identical. What is the difference between these two commands? When do they behave the same? When do they not? (The question isn't for me; ...
43
votes
2answers
4k views

\newcommand and spacing

How can I define my own shorthand command, but making sure that the spacing afterwards is correct? \newcommand{\abc}{\textsc{abc}} produces 'ABC,' but has the problem 'ABCmoretexthere' (i.e. no space ...
43
votes
1answer
2k views

What is the meaning of double pound symbol (##1) in an argument?

I've seen sometimes that people use a double pound sign (##) when defining/using arguments. What is the difference between the normal argument, #1, and the double sign one, ##1? Are there any ...
42
votes
4answers
2k views

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 ...
42
votes
3answers
1k views

Where are the necessary places to be appended with % to remove unwanted spaces?

I have experience where empty spaces cause unwanted effects. It is not easy to trace the cause of these unwanted effects. In order to eliminate any doubt, I often overuse % as follows. \usepackage% ...
41
votes
7answers
2k views

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 ...
41
votes
2answers
766 views

How can I contribute to CTAN?

I have create a template and some macros I would like to share. How can I contribute them to CTAN?
41
votes
3answers
5k views

Why are some LaTeX macros defined using \newcommand and some using \def?

We have seen this excellent discussion on the differences between \def and \newcommand. From the answers the relatives merits of using \newcommand over \def are obvious. Why are some LaTeX macros ...
40
votes
2answers
9k views

“Closed” (square) root symbol

I found a cool trick in the LaTeX wikibook which allows the square root sign to be altered such that it "closes" over its contents. Here's an example: ("closed" root on the left, normal one on the ...
40
votes
2answers
7k views

What does \ifx\\#1\\ stand for?

The following usage of \ifx can be found in several packages and also in answers on this site. What does this syntax exactly mean? Are there any alternatives and drawbacks? ...
39
votes
2answers
3k views

What does \z@ do?

in parcolumns it has \z@ all over the space. I don't see it define it anywhere so I assume it is some internal command or something? I can't really make heads or tails of it though and I can't really ...
39
votes
2answers
536 views

How to implement (low-level) arrays in TeX

Update: I have revised my question based on the comment by Bruno Le Floch and some further research. As some may know, I'm implementing a huge TeX macro package which has to do a lot of internal ...
38
votes
4answers
4k views

Can I redefine a command to contain itself?

I'd like to "add to" an existing command by writing something like \renewcommand{\somecommand}{\begin{something}\somecommand\end{something}} but (not surprisingly) I get errors about being "too ...
38
votes
2answers
12k views

newcommand vs. DeclareMathOperator

As far as I understand, whatever can be done using DeclareMathOperator can also be achieved using newcommand, but not the other way around. If this is the case, what are the circumstances where ...
37
votes
8answers
2k views

How can I specify a long list of math operators?

The preambles of my LaTeX documents often include many many lines of \DeclareMathOperator instructions, e.g. \DeclareMathOperator{\Rep}{Rep} \DeclareMathOperator{\Tet}{Tet} ...