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.
8,303
questions
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?
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 ...
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 ...
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?
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 ...
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 ...
322
votes
3
answers
353k
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 that has the width of a particular character, say `M'. I know there is a command for this, and this is a ...
270
votes
3
answers
76k
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.
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 ...
213
votes
4
answers
171k
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 ...
211
votes
3
answers
382k
views
How to color math symbols?
One can use the command such as \textcolor[rgb]{1.00,0.00,0.00}{boundary} to color the word "boundary" in a document.
Here is my question:
How to color the math symbols in $$? For example, can one ...
206
votes
3
answers
136k
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 ...
198
votes
6
answers
58k
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 ...
186
votes
4
answers
632k
views
\vspace vs. \vskip [duplicate]
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?
176
votes
5
answers
65k
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 ...