{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
1answer
392 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
1answer
10k 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?
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
664 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
676 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
492 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
4answers
504 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
672 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
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
996 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
328 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
242 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
2answers
781 views

Lisp relics in LaTeXe logo

I always thought TeX's macros are very Lispy like and stumbling across the definition of the LaTeXe logo confirmed it. The macro is defined as follows: %\LaTeXe The LATEX2" logo as proposed by A-W ...
16
votes
3answers
505 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
4answers
866 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
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 ...
16
votes
3answers
342 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
173 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
302 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
311 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 ...
16
votes
1answer
873 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
479 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
595 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
924 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
3k 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?
16
votes
1answer
608 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
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 ...
16
votes
1answer
482 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 ...
16
votes
0answers
497 views

A flexible derivative macro with LaTeX3

In an earlier post I asked a question about writing a flexible derivative macro, and someone suggested that a LaTeX3 version might be easier to understand, so I decided to try my hand at writing one. ...
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
3answers
692 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 ...
15
votes
4answers
425 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
592 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
4answers
476 views

How does one remove material from a token list?

This is a follow-up question to How does one append material to a token list? The macros \prependto and \appendto work nicely to add content to token lists. How would one go about creating macros ...
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 ...
15
votes
2answers
849 views

Using simple quotes “” instead of \text{}

Is there a way to use newcommand or some other nice technique to transform any occurence of "bla" in math mode into \text{bla} The reason I ask is because it is easy, and doesn't interrupt the ...
15
votes
3answers
638 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 ...
15
votes
3answers
587 views

How would you name these fraction macros?

I've got four macros now for typesetting fractions in text mode. The first writes them horizontally (shilling style, with a hyphen), the second writes them diagonally, the third writes them ...
15
votes
3answers
346 views

How keep a running list of strings and then process them one at a time

I would like to keep track of all the \AddRef commands in a document and then process them one at a time, for instance print them in the document on one line per value. It seems that this should be ...
15
votes
3answers
304 views

Parsing strings containing diacritical marks (macros?)

I apologize that this question may seem very much like several other recent ones I have asked (Parsing leading hardspaces, Parsing a \$ as part of an improved \getargs command). They are all related ...
15
votes
3answers
612 views

Redefine command when inside a specific other command possible?

How, in general, can I (re)define commands based on in which other command they are nested? A more specific example: I have a custom latex command (say, \code{}) that makes text appear bold. ...
15
votes
4answers
1k views

Is there a vertical equivalent for \rlap?

I'm looking for some sort of vertical equivalent for \rlap, which can be used to typeset maybe one or more paragraphs (or minipages), but do not advance vertically the content that would appear ...
15
votes
2answers
2k views

Extendible equals sign

I have a command that has been floating around in my standard preamble for a while: \newcommand{\xeq}[1]{\stackrel{\;#1}{\cleaders\hbox{=\!}\hfill}\:} It is meant to mimic the AMS-LaTeX extendible ...
15
votes
2answers
316 views

How to display command name and its value

Latex displays the command values by default - I am finding it more difficult to display the command names along with the values. I have a list of commands that I would like to loop over and print ...
15
votes
2answers
421 views

What's the meaning of the macro `\m@th`?

I found this macro from Voss' Math mode v2.47, page 21: \makeatletter \newif\if@borderstar \def\bordermatrix{\@ifnextchar*{% \@borderstartrue\@bordermatrix@i}{\@borderstarfalse\@bordermatrix@i*}% ...
15
votes
3answers
12k views

\uppercase in \newcommand

I tried to use \uppercase in \newcommand: \newcommand\universidad{My University} \newcommand\Universidad{\uppercase{\universidad}} When I use this I get My University and not MY ...
15
votes
2answers
262 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 ...