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

17
votes
2answers
319 views

Why do some commands use []s, some use {}s, and some use both?

I find it confusing to remember which commands take {} arguments, and which ones take [] arguments. Is there a rule-of-thumb or semantic difference between these two? If so, what? (Because they seem ...
17
votes
2answers
1k views

Difference between \newbool and \newtoggle from etoolbox package

Paul Gaborit's answer to How to detect if option provided via \tikzset uses \newbool to define a new boolean \booltrue to set a boolean, and \ifbool to perform a conditional operation all from ...
17
votes
4answers
330 views

Is it possible to add an “or” condition to a \def?

Is it possible to have something like \def\fiveorsix{5,6 OR 6,5} So that the following works: \documentclass{standalone} \def\fiveorsix{5,6 OR 6,5} \makeatletter \newcommand{\test}[1][]{ ...
17
votes
2answers
367 views

Why does this simple \ifx test fail?

This should be easy, but I don't understand why the test below fails... I expected Hurrah! to be printed when the \currentchar count reaches 90 (i.e. the character code of Z). There must be some ...
17
votes
2answers
2k views

How do I use \show?

Q: How do I use \show to determine macro definitions?. I've followed advice here: The definitions of LaTeX commands and here: \show with fewer lines? and am still struggling. I've naively tried ...
17
votes
5answers
1k views

Are there purely expandable variants of \MakeUppercase?

\MakeUppercase and \uppercase use TeX's uccode, and they are not purely expandable. Say, \edef\temp{\MakeUppercase{abc}} will fail. Sometimes purely expandable macros are very useful. They are ...
17
votes
1answer
412 views

Newcommand: What cannot be done?

It is not the first time I tried to create a new command unsuccessfully. Some things I found out did not work (getting "undefined control sequence" or other errors). Use a quote-endquote argument. ...
17
votes
2answers
1k views

How to do a recursive renewcommand?

I'm trying to renew a command in terms of its old definition... something similar to this: \renewcommand{\vec}[1]{\vec{\mathbf{#1}}} But this seems to send the interpreter in an infinite loop. How ...
17
votes
2answers
236 views

Can I turn a collection of optional parameters into a macro?

I currently have several environments from mdframed that have a large number of options that are shared between them. The situation looks like \newmdtheoremenv[options0,options1]{env1}{Environment 1} ...
17
votes
2answers
479 views

Selecting random elements from a comma separated list

I would like to have a command (either user-defined, or from a package, or whatever) that has the basic form: \selectNrandom{N}{list, of, comma, separated, elements}{code to execute} which will ...
17
votes
1answer
787 views

Abbreviations and full stop--how to avoid double dots?

I have trouble with macros expanding to an abbreviated expression. Say I have \WHP which expands to "with high prob." (artificial example). I want to avoid the dot after the abbreviation colliding ...
17
votes
1answer
220 views

Why doesn't \makeatletter work inside \newcommand?

After hours of banging my brain against my skull, I narrowed down an issue I'm having to the fact that \makeatletter doesn't work inside \newcommand. Commands that I call after \makeatletter are ...
17
votes
1answer
585 views

What does the # symbol do in LaTeX?

I know most of the effects of the special characters in LaTeX, like \ is used for most commands, or $ is used for opening or closing the math ambience, but I don't know what the symbol # does, and I ...
17
votes
1answer
413 views

How do I make a macro require math mode?

I have defined a macro that I would like to be used exclusively in math mode. In order to enforce this, I would like the macro to throw an error message whenever it is used outside of math mode. What ...
17
votes
3answers
2k views

How do magic \dots work in amsmath?

The amsmath package redefines the \dots command so that it "guesses" the correct height of the dots with respect to its context. For example $x, \dots, y$ will produce three lowered dots, aligned ...
17
votes
1answer
4k views

What is the difference between \vspace{\fill} and \vfill

What is the difference between \vspace{\fill} and \vfill? What about the starred version of them?
17
votes
2answers
8k views

Block comments with *% and %*

I know the package comment which allows to use : \begin{comment} Lines to comment \end{comment} This is not very friendly to use. I would like to have the following possibility: *% Lines to ...
17
votes
1answer
699 views

How to write overlay-specification–aware macros that work w/o the beamer class

The LaTeX beamer class provides with \newcommand<> and \newenvironment<> an interface to define own commands that can deal with beamer's overlay specifications. Internally, commands ...
16
votes
3answers
688 views

Short version of emph?

Is there something like a short version of \emph? What I want is something comparable to \lstShortInline or what the shortvrb provides, just not for the \verb command but for the \emph command ...
16
votes
6answers
499 views

A new environment to decide dynamically which commands to run?

I am having some user defined commands defined and used in my latex document. I need a way to check whether any of the commands is used. I want to make decisions based on the argument used in the ...
16
votes
3answers
730 views

Shortcuts for code in latex

I am tired of writing \frac{\partial something}{\partial something_else}. Can I automate it by defining some sort of shortcut to it, so that when I write \p(x)(y) it will transform to \frac{\partial ...
16
votes
4answers
535 views

Do starred commands eat up space after them?

Do starred commands eat up spaces after them, like unstarred ones do? That is, is \somecommand* nextword equivalent to \somecommand*nextword? And: Does it depend on the particular way a starred ...
16
votes
3answers
2k views

What is the deal about these semantic vs syntactic commands?

I keep hearing people on this site talking about "semantic" vs "syntactic" commands and that the "semantic" ones are somehow better. I don't really get what they are talking about, could you explain ...
16
votes
3answers
683 views

Custom LaTeX logo

I'm trying to get this "logo" At the moment I use the following command \mbox{% M\hspace{-0.25ex}% \raisebox{0.18ex}{\tiny A}\hspace{-0.65ex}% T\hspace{-0.65ex}% \raisebox{0.18ex}{\tiny ...
16
votes
3answers
711 views

Using command to compute sum?

I must admit this sounds like an easy question. I'm creating a grading model for a homework assignment, and I'm adding the maximum amount of points to each question. Is there a way to have LaTeX ...
16
votes
3answers
1k views

Doing an interlinear text

I want to produce a three-line interlinear text with numbers and asterisks in the top line, Greek in the middle, and the vernacular (Portugese) in the bottom. An example is below: The challenge, as ...
16
votes
3answers
336 views

newcommand does not work with \fi

I tried the command \newcommand{\fistudenti}{\fi} but it seems to work properly only in some cases. Here below there are two insances when it works and when it does not: WORKS: ...
16
votes
3answers
253 views

Defining Extensible macros

Question: For a macro that has only one parameter, are there any issues with defining it as follows: \NewDocumentCommand{\MyMacro}{% s% #1 = starred variant (*** unused as of yet ...
16
votes
3answers
522 views

Is it wrong to use \frac1{}?

When typing math in (La)TeX, I often omit the braces surrounding the first argument to the \frac macro, at least when it's 1, writing things like \frac1{1+x^2}. I initially came by that use while ...
16
votes
3answers
1k views

Why does LaTeX make a distinction between commands and environments?

Why does LaTeX make a distinction between commands and environments? Or also: why do we need environments? I ask this because I am defining a number of custom commands (like \question{} and ...
16
votes
2answers
1k views

Expanding arguments before macro call

I've been banging my head against this for days. I have a macro which takes a macro name and its arguments. It then re-arranges the arguments a bit and then calls the passed macro with the re-arranged ...
16
votes
4answers
874 views

Understanding a \@for loop

I'm having trouble with a \@for loop. I've got a macro that takes a comma delimited list and puts each element into a row of an array. When I do this using a \@for loop, I get an extra row that I ...
16
votes
3answers
4k views

\DeclareMathOperator won't take arguments

I'd like to define a family of math operators that have the same superscript, but different subscripts. My first attempt was: \DeclareMathOperator{\Upd}[1]{U^M_{#1}} But the log tells me that: l.3 ...
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 ...
16
votes
2answers
269 views

“Namethatchar” macro

I am searching for a macro/package that would give the name of characters. Here are a few examples of a possible behaviour: \namethatchar{A} → A \namethatchar{À} → Agrave \namethatchar{a} → a ...
16
votes
3answers
353 views

Print 'system information' in LaTeX doc

I've used TeX quite a bit before but am getting back into it at the moment. I want to print a document details page with info such as: Compiled on: Compiled by: OS version: LaTeX version: ...
16
votes
2answers
182 views

Why is unskip not working here?

I'm trying to define a macro to be used as follows: \usepackage[normalem]{ulem} \newcommand{\thesis}[1]{\uline{\ignorespaces #1\unskip}} % underlining required by school - I know, I know % later... ...
16
votes
2answers
352 views

Duplicating Environments

When I want to globally modify a command in my document, I will often use a duplicated version of the original in the stencil, with the help of the \let macro. For example, if I wanted to do ...
16
votes
1answer
890 views

What does \marks do?

Recently I had cause to define a macro called \marks. If I try something like \newcommand{\marks}{fred} I get the error ! LaTeX Error: Command \marks already defined. In LaTeX, if I do ...
16
votes
2answers
486 views

Writing musical pitches

Is there a package or macro that allows me to easily typeset musical pitches, like the following: ? Indeed I would like to have subscripts for the octaves. Let's say $\mathrm{E}\flat_3$ How ...
16
votes
2answers
623 views

Macros in LaTeX and in programming languages

There is a fairly widespread consensus that macros are a bad idea in most programming languages. (For example, cf. http://scienceblogs.com/goodmath/2007/12/17/macros-why-theyre-evil/ .) That said, I ...
16
votes
2answers
2k views

Difference between \relax and % for ending a line

when would I use one over the other? Are they the same?
16
votes
2answers
934 views

Comma-separated list

I would like to produce comma-separated lists, like "a, b, c, d" or "a, b, c, and d". Requirements: In the Latex source code, each line of the source code should contain one list element, and as ...
16
votes
1answer
630 views

babel shorthand "| doesn't work in macros

The package babel with the ngerman option (and most other languages as well, but not english) provides the shorthand "|, which prevents a ligature at the given position (see p. 81 of the babel ...
16
votes
1answer
493 views

What exactly does \@doendpe do?

Quoting from the LaTeX2e sources: [\@endparenv, \@doendpe] To suppress the paragraph indentation in text immediately following a paragraph-making environment, \everypar is changed to remove ...
15
votes
3answers
6k views

How to add a custom symbol to LaTeX?

Suppose I need some crazy custom symbol for personal use. e.g. when I write \foobar, LaTeX should show . How do I achieve this? Update: I was writing Klingon writing system for fun. Thank you very ...
15
votes
4answers
434 views

Reasons for saving a box?

I've been reading through a number of answers that use \newsavebox to save the contents of a box. As far as I can tell it's a workaround for fragility of some kind. Is that right? If not, what is the ...
15
votes
5answers
604 views

command for floor

I need something that corresponds to floor() to use it in a macro (I don't mean the notation, I really mean the function that rounds downwards). Something like this: \floor{34.75} produces 34 ...
15
votes
2answers
244 views

Placing math environments inside math environments

I have a macro which appears throughout my document in various places: \newcommand{\placefraction}[2]{ $\frac{#1}{#2}$ } Sometimes it is placed with regular text. Sometimes it is placed within ...
15
votes
3answers
1k views

Expand after all that stuff?

Often I find myself in the need of expanding some macro, whose contents should be given as an argument to another command. The usual solution is to invoke some \expandafter concoctions to somehow ...