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

34
votes
8answers
2k 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 ...
34
votes
3answers
3k 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 ...
34
votes
2answers
2k 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 ...
33
votes
2answers
2k 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? ...
32
votes
4answers
3k 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 ...
32
votes
7answers
5k 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
2answers
710 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 ...
31
votes
7answers
8k 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 ...
30
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 ...
30
votes
2answers
803 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
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{% ...
30
votes
2answers
9k 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 ...
30
votes
2answers
369 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. ...
29
votes
5answers
1k 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 ...
29
votes
7answers
6k 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 ...
29
votes
5answers
3k 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} ...
29
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. ...
29
votes
1answer
2k 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}?
29
votes
2answers
417 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
1answer
8k 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 ...
28
votes
3answers
2k 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 ...
28
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 ...
28
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 ...
28
votes
5answers
1k 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) ...
28
votes
7answers
1k 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
1answer
2k 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 ...
28
votes
1answer
627 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 ...
27
votes
3answers
1k 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
4answers
6k 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 ...
27
votes
3answers
44k 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 ...
27
votes
3answers
7k 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 ...
27
votes
3answers
558 views

Set up a system to alternate between genders per paragraph

In RPG writing it has become traditional to swap he and she on a per paragraph basis. Something like "He can use the smite evil ability one a day at first level. (Blah blah blah, paragraph break) when ...
26
votes
4answers
3k 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. ...
26
votes
9answers
702 views

When is it appropriate to use \outer?

\outer is a strange beast. Any control sequence declared \outer cannot be used as either the parameter text or replacement text of a macro, at least if the control sequence is declared \outer at the ...
26
votes
3answers
1k views

Does TeX always insert the macro \par?

When the input processor encounters two characters with category code 5 in a row (in other words, a blank line), it inserts the \par macro. When \vbox{Abc.} ends, TeX ends the current paragraph, but ...
26
votes
4answers
483 views

A macro that passes each word of its argument to another macro as an argument?

I'd like a command that works like this: \dothings{Takes several words as argument} and have this expand to: \@dothings{Takes} \@dothings{several} \@dothings{words}... I know how to define a ...
26
votes
1answer
25k 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 ...
26
votes
3answers
845 views

Always use \NewDocumentCommand instead of \newcommand?

Are compelling reasons to stick with \newcommand or should one always use \NewDocumentCommand instead, even when not using any of the additional features offered by xparse? In addition and more ...
26
votes
2answers
701 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 ...
26
votes
2answers
714 views

Create a “List of Effective Pages”

I am considering learning Latex in order to more easily maintain a bunch of manuals for my company. One of the requirements is to have a "List of Effective Pages" towards the beginning of the ...
25
votes
3answers
641 views

When is it better to use \par than \endgraf?

Just yesterday I had to patch a package file (changing the description to indicate that the file had changed) to replace some \par to \endgraf because the code had bad interactions with non-\long ...
25
votes
3answers
776 views

@tempdima, reserved@a, @tempcnta, what else?

I'm aware that some "temporary" LaTeX dimensions etc. exist. I would, however, like to know all of them. I know \reserved@a (macro), \@tempdima (dimension) and \@tempcnta (counter).
25
votes
4answers
931 views

Why does the LaTeX kernel define \usepackage *and* \RequirePackage?

The ubiquitous \usepackage command is used to load packages in the preamble of a document; the command syntax is \usepackage[<package-option-list>]{<package-list>}[<version>] ...
25
votes
3answers
7k 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 ...
25
votes
4answers
1k views

Alternate he / she in text

This question led to a new package: he-she I have seen a book that instead of using the masculine pronoun (he, his, etc.) alternates the gender ('he' then 'she' then next time 'he' again). Is ...
25
votes
5answers
895 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 ...
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 ...
25
votes
2answers
600 views

Programming TeX macros so that they output instructions to rerun the compilation

This question is motivated by the behavior of the tikzmark macro created by Andrew Stacey, and a recent discussion with David Carlisle on chat. I have noticed that LaTeX code using tikzmark typically ...
25
votes
5answers
1k 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 ...
25
votes
4answers
2k views

Can I have a flexible partial derivative macro?

I was thinking about writing a partial derivative macro that has a similar syntax to the Mathematica D function. (example) The syntax could be like this: \D{f}{x} expands to \frac{\partial ...