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

282
votes
1answer
39k views

What do \makeatletter and \makeatother do?

Many TeX “hacks” begin with \makeatletter and end with \makeatother. What do these commands do?
137
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?
131
votes
3answers
8k 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 ...
32
votes
7answers
7k 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 ...
35
votes
3answers
4k 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 ...
175
votes
4answers
16k 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 ...
56
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 ...
46
votes
1answer
678 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 ...
143
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 ...
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 ...
155
votes
4answers
26k 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 ...
70
votes
3answers
8k 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.
31
votes
3answers
5k 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. ...
61
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) ...
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% ...
15
votes
3answers
378 views

How keep a running list of strings and then process them one at a time

I would like to keep track of all the \AddRef commands in a document and then process them one at a time, for instance print them in the document on one line per value. It seems that this should be ...
19
votes
5answers
2k views

No space following macro without argument

With a macro such as: \def\naive{na\"{\i}ve} I find that the space which I would hope to follow it, is absent. So, with the \naive approach I get the naïveapproach in the output. How do I ...
47
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]{}
40
votes
2answers
8k 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 ...
35
votes
7answers
6k views

LaTeX macro expander

Is it possible to have LaTeX (or another program) to expand a the macros in a .tex file, and output the expanded LaTeX source? If no such program exists: are LaTeX macros processed simply as string ...
31
votes
3answers
1k views

Why the end-of-line % in macro definitions?

I found two things peculiar in the common style of macro definitions: Ending lines in macro definitions with '%'; Not wrapping a macro name in braces. Example: \newcommand\examplemacro{% ...
19
votes
1answer
3k views

TikZ \foreach loop with macro-defined list

I have a small problem with the TikZ \foreach loop whenever the list, over which we loop, is defined my a macro. The following code example will show my problem: \documentclass{scrartcl} ...
22
votes
1answer
796 views

Tex Capacity Exceeded (if remove % after use of macro)

I don't understand why this simple (but lengthy) iteration results in TeX capacity exceeded, sorry [main memory size=3000000], if I remove the last % following the call to \DoNothing. I thought that a ...
14
votes
2answers
2k views

Command/macro name cannot include numbers and symbols

I would like put picture into table, and my idea is define new command as below> \newcommand{\EJ471}{\includegraphics[scale=0.150]{EJ_471.jpg}} But compiler reports an error. If I use the command ...
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 ...
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 ...
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 ...
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 ...
47
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 ...
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 ...
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} ...
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 ...
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, ...
36
votes
6answers
1k views

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 ...
84
votes
3answers
15k 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.
21
votes
4answers
5k views

Command to uppercase the first letter of each word in a sentence

I'm writing a textboox in latex, and I have things like \textit{some definition}\index{Some Definition} all over the place. I'd like to combine them into something like \define{some definition} ...
30
votes
4answers
1k views

What do \@firstoftwo and \@secondoftwo do?

The LaTeX kernel uses these two all over the place. For example, apparently the correct way of defining something like \ifeq{\macro 1}{\macro 2}{true}{false} is (note Martin's response: each case ...
16
votes
4answers
1k views

Is there a test for the different styles inside maths mode?

Is there a test for the different styles within maths mode? What I really want is to be able to save the current style to reinvoke it later on, but a \if along the lines of \ifmmode would work just ...
19
votes
5answers
1k views

Wrapping long lines that contain no spaces

I need to format extremely long strings of text. I would like to be able to specify their width, and have them wrap, with or without some special symbol to indicate that the line is wrapped. The ...
35
votes
2answers
3k views

Macros for common abbreviations

Common abbreviations are surprisingly tricky to format correctly. I'd like some simple macros for them, to be used like so: You should eat more fruit, \eg apples, bananas, oranges, \etc. There are ...
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 ...
27
votes
3answers
50k views

How can I manually install a LaTeX package (Debian/Ubuntu Linux)? [duplicate]

Possible Duplicate: How do I install an individual package on a Linux system? The Debian/Ubuntu archives typically include assemblies of many LaTeX packages for convenience of downloading ...
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?
37
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 ...
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? ...
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; ...
41
votes
2answers
763 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?
25
votes
5answers
1k views

onlyitems? How to select specific items from an item list

I have the following setup, I have a file with some definitions, one of which is a list of items: \newcommand{\mylist}{ \item first item \item second item \item third item } I want to use \mylist ...
14
votes
3answers
1k views

Can I change the font and colour of a letter permanently?

For my lectures, I like to colour the symbols in the equations to make it easier to follow what's going on - a bit like syntax highlighting. So all vector spaces are one colour, all sets another, e ...
22
votes
2answers
874 views

Lisp relics in LaTeXe logo

I always thought TeX's macros are very Lispy like and stumbling across the definition of the LaTeXe logo confirmed it. The macro is defined as follows: %\LaTeXe The LATEX2" logo as proposed by A-W ...