Skip to main content

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.

403 votes
6 answers
44k views

What is the use of percent signs (%) at the end of lines? (Why is my macro creating extra space?)

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?
Federico Poloni's user avatar
971 votes
1 answer
258k views

What do \makeatletter and \makeatother do?

Many LaTeX “hacks” begin with \makeatletter and end with \makeatother. What do these commands do?
Caramdir's user avatar
  • 89.8k
640 votes
12 answers
223k 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 ...
Kaarel's user avatar
  • 6,501
346 votes
5 answers
41k views

What is the difference between Fragile and Robust commands? When and why do we need \protect?

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 ...
Juan A. Navarro's user avatar
62 votes
6 answers
19k views

Will two-letter font style commands (\bf , \it , …) ever be resurrected in LaTeX?

I understand that \bf and \it are now obsolete in LaTeX and that \textbf and \textit are proper, as they produce more sophisticated (in particular, cumulative and properly kerned) changes to font ...
brannerchinese's user avatar
89 votes
1 answer
4k 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 \...
Werner's user avatar
  • 607k
141 votes
4 answers
66k 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 \...
Peter Grill's user avatar
568 votes
4 answers
88k 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 ...
Andrew Stacey's user avatar
94 votes
1 answer
11k views

What is the meaning of double pound symbol (number sign, hash character) ##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 ...
adn's user avatar
  • 11.4k
98 votes
10 answers
15k 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, ...
Seamus's user avatar
  • 73.7k
392 votes
5 answers
153k 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 ...
Michael Underwood's user avatar
107 votes
7 answers
48k views

Conditional typesetting / build

Let's say I have .tex file which is a set of problems and solutions, of which I want to make two pdf files, one which includes the solutions and one which doesn't. so I need to build the .tex file ...
behzad.nouri's user avatar
  • 1,655
119 votes
10 answers
46k views

Defining commands/abbreviations that contain numbers

I tend to use \newcommand to define macros for symbols I use often, e.g. \newcommand{\hankel}{H^{(1)}_0}. One inconvenience of this approach is the fact that command names cannot include numbers. ...
Leo Alekseyev's user avatar
34 votes
2 answers
29k views

How to draw commutative diagrams?

Can anyone help me in giving commands for commutative diagrams in LaTeX ? It doesn't seem to appear properly in the LaTeX guides that I have. A command for a simple triangular diagram with arrows ...
smiley06's user avatar
  • 637
221 votes
5 answers
70k 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 ...
Andrew Stacey's user avatar

15 30 50 per page
1
2 3 4 5
151