Linked Questions

392 votes
5 answers
152k 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 ...
Michael Underwood's user avatar
345 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 ...
Juan A. Navarro's user avatar
215 votes
6 answers
44k views

Where do I start LaTeX programming?

I'm interested in writing packages for TeX/LaTeX/XeLaTeX. I googled around, but all I found was guides or tutorials about how to prepare documents using LaTeX. I want to know how LaTeX works and how ...
sorush-r's user avatar
  • 2,697
17 votes
6 answers
3k views

Defining new commands inside a for loop

I would like to define a number of related commands by using the counter in a for-loop. For example, I want to define 26 commands like this: \newcommand{\calA}{{\cal A}} \newcommand{\calB}{{\cal B}} ...
mhelvens's user avatar
  • 6,126
36 votes
1 answer
21k views

What are the differences between \def, \edef, \gdef and \xdef?

I am a LaTeX guy, slowly working into the miracles of TeX. Can anybody tell me the differences between \def, \edef, \gdef and \xdef? Where shall I use which, what are the pros and cons? Or is it ...
Jan's user avatar
  • 5,323
15 votes
2 answers
2k views

\foreach with \newcommand how to use them together?

What I want to do is to shorten this \newcommand with a \foreach since this is just a very little part of what I will use. \newcommand{\CC}{{\mathbb C}} % the set of complex numbers \newcommand{\NN}{...
Oguzhan Yoruk's user avatar
7 votes
2 answers
670 views

Why can't I use <some macro> inside the argument of <some other macro>?

I have some macro X and Y, which works well when used independently. However, when I try to put one inside another, it results in some error. Why is that the case and how can I fix it? Note: this is ...
user202729's user avatar
  • 7,503
5 votes
2 answers
2k views

Undefined control sequence when using \edef with \foreach

I’m attempting to define a command to build several similar tikz nodes. These nodes differ only by one parameter (#2 below). Here are the main questions I’ve referenced so far: Foreach inside a TikZ ...
MTCoster's user avatar
  • 153
6 votes
1 answer
783 views

How does \expandafter interact with {?

I am comparing two strings, one of which is the expansion of a command. Neither of the three attempts below yields the correct result: \documentclass{scrartcl} \usepackage{etoolbox} \begin{document} ...
sgf's user avatar
  • 561
4 votes
4 answers
179 views

Delaying a sequence of tokens via \expandafter

Use case: define a command that loops over a list of input names, defining a command from each name. In the working code below, note the \expandafter\definput\expandafter{\x} within a loop with \x as ...
David Fink's user avatar
2 votes
1 answer
419 views

Alternative to `foreach` loop to use an `edef`

I need to create some dynamic name macro and I want to create them from a coma separated list of parameter in #1 in one loop. foreach is not the solution because it forces the use of gdef and I want ...
Tarass's user avatar
  • 17k