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

41
votes
2answers
47k 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 ...
40
votes
7answers
10k 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 ...
39
votes
4answers
6k 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 ...
39
votes
7answers
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 ...
39
votes
2answers
663 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
2answers
3k views

Understanding \@ifnextchar

I understand the definitions of the \makeatletter and \makeatother commands and also \def and \newcommand somewhat. But, explained in a simple way, what is happening in the following line? ...
38
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} ...
37
votes
2answers
4k 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 ...
37
votes
2answers
1k views

List of higher-level LaTeX commands corresponding to TeX commands

Since LaTeX is a format built on top of TeX, it surely has several high level abstractions that perform similarly to TeX commands, with some added error-handling functionality, for example. I always ...
36
votes
8answers
3k views

Why do people use unnecessary braces?

I often see people creating new macros where the macro token is surrounded by braces. For example, \newcommand{\foo}{foo} This is unnecessary and I find the extra braces make it harder to read. Why ...
35
votes
3answers
3k views

Nicely force 66 characters per line

I would like to have "something" (a package, a trick, a macro, ...?) that makes it possible for me to nicely play with the margins (or the layout) in order to set the average or typical number of ...
35
votes
4answers
5k views

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

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 ...
34
votes
3answers
2k views

Removing the spaces between words

Is there any way to remove spaces from in between the words in a text? Something like \RemoveSpaces{This is my sentence.} which will be converted to Thisismysentence.
34
votes
3answers
67k 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 ...
34
votes
2answers
3k views

Why Different Commands for Seemingly Similar Tasks?

Take a look at the following list: \textit, \it, \emph, \itshape, \mathit \textbf, \bf, \bfseries, \mathbf ... One might say, for instance, that: \mathbf and \mathit are for math mode, while the ...
34
votes
3answers
9k views

Can I use \clap, \rlap and \llap in math mode?

The commands \clap, \llap and \rlap are useful "horizontal" analogues of \smash: they reduce the horizontal width of a box to zero, aligning the box with either the middle, left or right of the ...
34
votes
1answer
14k views

What is the difference between \vskip and \vspace?

I found myself writing: \vspace 1 \baselineskip and then when not compiling changing without thinking to: \vskip 1 \baselineskip but what is the difference? Perhaps knowing this will make me ...
33
votes
7answers
12k views

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 ...
33
votes
3answers
727 views

Do fontsize environments exist?

Without any doubt there are fontsize switches in the form of control sequences (described here for instance.) But, from time to time I ran into code examples where environment versions of those were ...
33
votes
5answers
5k views

How to automatically resize the vertical bar in a set comprehension?

I have a simple command which I use to write set comprehensions so that the braces automatically resize with respect to size of the enclosed arguments, e.g. \usepackage{amsmath} ...
33
votes
4answers
2k 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 ...
33
votes
3answers
2k 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{% ...
33
votes
2answers
483 views

What are the standards of TeX/LaTeX coding in order to obtain robust packages?

I have posted several questions ultimately involving various aspects of robustness, that have arisen in the context of other questions in risk of clouding the main point of the question in each case. ...
32
votes
5answers
4k views

Stop LaTeX compile with a command?

Is there a way to stop the compile process through the use of a command? Something like: \exception{This is a user-set exception. Compile halted.} So when performing the compile process, the ...
32
votes
3answers
2k views

Why are LaTeX macros so inconsistent?

I use LaTeX daily to write my papers, and while I find it a very nice tool to make documents in, some things about the system outright bother me; such as the very inconsistent macro system. A few ...
32
votes
6answers
2k views

Censoring Curse Words with Grawlixes

Suppose that I would like to censor a curse word <word> using grawlixes, e.g. "What the #@$! are you doing?!" How can I define a command \censor such that \censor{<word>} results in a ...
32
votes
2answers
794 views

No \makeatletter required?

In typing up some small examples that might create errors in LaTeX (for Documents with typical LaTeX errors), I tried the following: \documentclass{article} \def\my@macro#1{-#1-}% This is magic ...
32
votes
2answers
3k views

\newcommand vs \DeclareRobustCommand

I sort of understand the difference between the two. But that's not what I'm interested in—I just want to know, which one should I use? In general, when I'm creating commands in a package or class, ...
32
votes
1answer
4k views

What, if anything, is the advantage of \bigskip and friends over \vspace?

What are the advantages to using \bigskip, \medskip, and \smallskip instead of just using \vspace{somelength}?
32
votes
1answer
823 views

Macro naming best practice?

Is there a preferred or generally accepted idiom for naming user defined macros? I notice that in the change from Tufte 3.5.0 to 3.5.2, for example, the names of the debugging macros have change, for ...
32
votes
1answer
16k views

What is the purpose of \protect? [duplicate]

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?
31
votes
3answers
2k views

How to know whether or not we need \expandafter?

The following is quoted from Peter Grill's answer on question LaTeX dynamic macro definition. The \expandafter is requried as the \newcommand needs to be dealt with after the \csname. As a ...
30
votes
4answers
8k views

How to conditionally define a new command in LaTeX?

I'm trying to compile a LaTeX code with an older version of some package. Thus, I'm having a few issues due to undefined commands. How can I add conditional code so that I can define some work-around ...
30
votes
2answers
992 views

How to color the characters in LaTeX2e logo?

I want to get the LaTeX2e logo but with each character having a different color. I know that \LaTeXe produces the logo, but how do I give a color to each character?
30
votes
2answers
2k views

Please tutor the usage of patchcmd and xpatch

I understand that the patchcmd package provides a command \patchcommand that can be used to add material at the beginning and/or end of the replacement text of an existing macro. It works for macros ...
30
votes
5answers
61k views

typesetting column vector

I would like to define a command which typesets a column vector. For one vector I can have something like: \left( \begin{array}{c} a\\ b\\ \end{array} \right) I would like the command to produce ...
30
votes
2answers
476 views

How to design a command inquiring internally required packages?

How can I define a document command \FilesRequire that writes to the .log (or to the output console) a list of all packages internally required by the declared document class and by the packages that ...
29
votes
6answers
1k views

How do I typeset morse code with LaTeX

I am writing an article regarding the history of the Morse code and I am having difficulties printing the dots and dashed (they get combined when the document is printed). Is it also possible to ...
29
votes
5answers
2k views

Using indentation to automatically begin and end itemize environments

This is a question one might answer with "Why the hell would you want to do it?!", sort of an experiment. What I am looking for is a way to write lists with many levels of nestings (notes for school) ...
29
votes
7answers
2k views

How to replace a large block of text by an empty block of the same size?

I know there exists the \phantom command, but does it work on large blocks of text (containing several paragraphs or even several pages)? What I want is to have some commands, call them \hide and ...
28
votes
5answers
3k views

Macro for \left( and \right)

I know there has been discussion about this topic, but I haven't seen a working solution. Is it possible to define a macro within LaTeX, such that inside math mode, ( would produce \left( and ) would ...
28
votes
5answers
2k views

How can I use one argument as the default value for another?

I'd like to define a command that takes 1, 2 or 3 arguments, and where the 2nd gets the same value as the 1st if it is not defined. I tried \newcommand\codefrom[3][#1][Matlab]{ ... } but I get an ...
28
votes
1answer
645 views

What does “expanding” mean in (La)TeX?

You can often read about expanding a macro or when a macro does expand, sometimes about expansion. But what does this mean - in English?
28
votes
2answers
811 views

How do I debug pgfkeys?

I'm sure if you're reading this question you are already familiar with my love for pgfkeys. However, it is absolutely impossible to debug: \tracingmacros is a total mess, with every key expanding to ...
27
votes
3answers
3k views

Defining a new function with argument in LaTeX environment

I want to define a function in a LaTeX document. More precisely, I want to define a function, say \ang{x}, where x is any input, such that the output is \rangle x \langle. Is there a way to go about ...
27
votes
5answers
1k views

How to find out where a macro is defined?

Using \@ifdefined (in LaTeX), we can check whether a command is defined. Using \meaning, we can get the definition of a command. Can we also get information about where a command was defined? For ...
27
votes
3answers
8k views

When to use @ in an \if statement

I am new to LaTeX and so this question might come across as rather basic. It might also reflect my biases/assumptions from my C/C++ programming days. I was seeing the code of the 'exam' class and ...
27
votes
3answers
504 views

How to define phantoms for depth and height?

In the third "dangerous bend" on page 178 of of The TeXbook there's the following description of \vphantom: Even more useful than \phantom is \vphantom, which makes an invisible box whose height ...
27
votes
2answers
6k views

Meaning of an asterisk (*) in a macro name

What does the * in the starred version of a macro "mean"? I know for \section and \section* the * controls numbering and for \newcommand and \newcommand* the * determines if the macro is long. What I ...