{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.
25
votes
2answers
924 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?
...
25
votes
3answers
841 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 ...
25
votes
3answers
1k 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]{}
25
votes
6answers
4k 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 ...
25
votes
3answers
975 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 ...
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
2answers
469 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
3answers
671 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) ...
25
votes
1answer
762 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? Is there any ...
24
votes
7answers
739 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 ...
24
votes
4answers
432 views
Why isn't a command defined by \newcommand with an optional argument expandable?
In trying to fix a problem with a nested macro repeatedly calling itself, I tried expanding the inner call before passing it as an argument to the outer one. This failed miserably because the macro ...
24
votes
1answer
1k 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}?
23
votes
7answers
2k 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 ...
23
votes
4answers
542 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>]
...
23
votes
3answers
453 views
Is it possible to define an acronym-command which behaves differently on the first invocation than on the rest?
Most technical writers will immediately see how I'd like to use this. I'm writing a paper about something I'll call That Which Will Be Abbreviated (TWWBA). I'd like to have a macro, \TWWBA{}, that ...
23
votes
3answers
4k 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 ...
23
votes
3answers
601 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{%
...
23
votes
1answer
390 views
Is there a \die command?
Is there a command that generates the error or warning of my choice? I'm planning to put it in an \ifthenelse, so it can't be a syntax error.
23
votes
2answers
594 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 ...
22
votes
3answers
520 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 ...
22
votes
3answers
425 views
A list of newcommand objects
I often have a whole bunch of definitions such as
\newcommand{\R}{\ensuremath{\mathbb{R}}}
with R replaced by R,Z,C, etc.
I might also have a bunch of math operators or category definitions, ...
22
votes
5answers
730 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 ...
22
votes
4answers
352 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 ...
22
votes
5answers
973 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 ...
22
votes
5answers
608 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 ...
22
votes
2answers
493 views
What is “\\” called?
I’ve seen it take arguments, and apparently there’s a starred version, but I can’t find any documentation because it is ungooglable!
21
votes
6answers
1k views
“For loop” in newcommand
I have this command
\newcommand{\pdfappendix}[1]{
\includegraphics[scale=0.6]{pdf/#1.pdf}
}
It works well when I have 1 page pdf but is not including the other pages. Now I decided to change ...
21
votes
2answers
804 views
What does \z@ do?
in parcolumns it has \z@ all over the space. I don't see it define it anywhere so I assume it is some internal command or something? I can't really make heads or tails of it though and I can't really ...
21
votes
7answers
341 views
Fully robust way to access the first item in a token list (expandably)
Given a token list such as \a\b\c or {ab}c, I define the first item to be what \@gobble would get as its argument (recall the definition \long\def\@gobble#1{}). It is not hard to devise a macro which ...
21
votes
7answers
1k views
How to split text into characters
I would like to define a function which splits an input text into its constituent letters, so I can process each letter individually (the background to this question is that I would like to put each ...
21
votes
8answers
729 views
What is the best way to scan over a list of somethings?
It seems that a common operation needed when defining new commands is to scan over a list of arguments (separated e.g. by a comma, but maybe by something else) and do something with each argument in ...
21
votes
5answers
341 views
Test if a given control sequence is a length register
I'm in need of a macro which receives a control sequence as argument and needs to branch if this macro is actually a length (of any kind, e.g. dimen, skip etc.) or "just" a normal macro (including one ...
21
votes
5answers
354 views
Easier way to make permutation diagrams?
I prefer using figures created inside TeX, but I only know very labor-intensive methods. The following creates a permutation diagram for (6,3,2,4,1,5) with some colors and additional symbols.
I'm ...
21
votes
4answers
670 views
Do all starred commands have anything in common?
\section* produces an unnumbered section, align* makes the environment unnumbered, which is comparable in a way. \newcommand* doesn't accept \par in its argument, which is different.
Stefan Kottwitz ...
21
votes
2answers
1k views
What’s behind \over?
Typically a TeX command have arguments coming after it. But the command \over, which is used to produce fractions, can access the token before it. How exactly is it implemented and can I define a ...
21
votes
7answers
505 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 ...
21
votes
4answers
496 views
Can one define a '\superexpandafter{n}' that would expand to 2^n-1 '\expandafter's?'
This question was inspired by comment banter in this question. See title.
21
votes
2answers
764 views
Why don't we always use \long\def instead of \def?
Why don't we always use \long\def instead of \def? It seems that \long\def is more complete than \def.
By the way, I know the difference between these two commands.
21
votes
4answers
350 views
Can one define an expandable command that removes control sequences from its argument?
I am trying to create an expandable command that accepts a single argument that may contain control sequences, and expands to that same argument with all control sequences and braces removed. That is:
...
21
votes
1answer
1k 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 ...
21
votes
2answers
273 views
Lifespan lines in TeX
I'm writing a document (written in plainTeX) about the lives of important mathematicians and physicists in human history.
Now I have a problem I'd like to tackle. I need to be able to visualize their ...
21
votes
3answers
4k 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 ...
21
votes
1answer
5k 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 ...
20
votes
5answers
513 views
Ways to grab and store larger amount of text
A standard way to grab and store a short text (say, a title of a document) is to use something like
\def\title#1{\def\@title{#1}}.
But if the content to be stored is longer (say, an abstract}, I ...
20
votes
3answers
312 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).
20
votes
4answers
1k 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}
...
20
votes
3answers
728 views
Why does TeX remove braces around delimited arguments?
On pp. 203–204 of the TeXbook, Knuth describes how TeX absorbs macros' arguments: delimited go until the first appearance of the delimiter, and undelimited go until the next token, in both cases ...
20
votes
4answers
953 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 ...
20
votes
3answers
2k views
Definining 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. ...
20
votes
2answers
525 views
Which is better: a dimension or a macro?
When messing around with TikZ/PGF then I frequently find myself wanting to store a length for later use. By "length" here, I mean the word in its non-TeX meaning. As I'm doing stuff in TikZ/PGF then ...
