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

16
votes
2answers
757 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
4answers
824 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
2answers
858 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 ...
16
votes
3answers
3k 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
3answers
3k views

Is there any way to generate custom errors/warnings in LaTeX?

I want something like \ifmmode\else\GenerateWarning{The command \backslash uzuka is supported only in math mode.}\fi, which is supposed to generate a warning "The command \uzuka is supported only in ...
16
votes
3answers
317 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
151 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
218 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
2answers
609 views

Difference between \let\foo\relax and \def\foo{} for disabling

When I want some macro to (temporarily) do nothing, I normally write \let\foo\relax But somebody asked me why I don't just do \def\foo{} and I realized I couldn't answer his question. So, I ...
16
votes
1answer
825 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
468 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
516 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
902 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
568 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 ...
15
votes
3answers
647 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
388 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
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 ...
15
votes
3answers
644 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 ...
15
votes
4answers
463 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
3answers
307 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: ...
15
votes
3answers
227 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 ...
15
votes
2answers
819 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
574 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
558 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
3k views

What is the difference between \ifx\somecommand\undefined and \ifdefined\somecommand\else?

What is the difference between \ifx\cyrdash\undefined and \ifdefined\cyrdash\else? \cyrdash is any macro.
15
votes
3answers
288 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
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 ...
15
votes
3answers
590 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
2answers
2k views

What is the difference between \def and \newlength?

I wrote the following LaTeX documents. \documentclass[11pt]{book} \newlength{\mywidth} \newlength{\myheight} \setlength{\mywidth}{85mm} \setlength{\myheight}{112mm} \newcommand{\setpagesize}[2]{% ...
15
votes
2answers
256 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 ...
15
votes
1answer
209 views

Behavior of \\ in Plain TeX

According to \show, the pre-defined control sequence \\ is supposed expand to its argument without the suffix "pt": This is TeX, Version 3.1415926 (TeX Live 2012/Debian) **\show\\ > \\=macro: ...
15
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 ...
15
votes
3answers
2k views

Problem with redefining Tabular environment with the \renewenvironment ‎command‎

In a book I'm typesetting, I want the tabular environment to be in footnote size and the other body of the book to be in normalsize font. To do this, I've tried something like the following: ...
15
votes
1answer
517 views

Macro that knows it is at the end of a section?

In Is it a bad idea to use \begin{section} ... \end{section} in LaTeX?, Jan Hlavacek says: Of course it is typically possible to recognize an end of a section, but there is actually a number of ...
15
votes
2answers
1k views

How to add a hook to a macro

LaTeX uses hooks extensively, one method employed is the command g@addto@macro. It is defined in source2e as: \long\def\g@addto@macro#1#2{% \begingroup \toks@\expandafter{#1#2}% ...
15
votes
2answers
2k views

How to create new table environment

I am working on a book that has many many such tables. Is there a way to create shortcut for the code shown below. I want to make table caption a variable, because in the MWE shown below except ...
15
votes
2answers
2k views

Difference between \relax and % for ending a line

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

The scope of LaTeX commands

This is a very basic question. However, I didn't find simple rules for it, so I asked it here. Some LaTeX commands (like \noindent) affect the whole paragraph. Some of them (like \emph) affect their ...
15
votes
1answer
494 views

Transition from LaTeX to Plain TeX

For several reasons I need to typeset in Plain TeX, however I have always worked with LaTeX. So how hard will this be? I basically need something like the book or report documentclass (with toc, ...
15
votes
1answer
462 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
1answer
9k 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?
15
votes
1answer
176 views

First occurrence of a command

I'm writing some macros that need to behave differently after first occurrence. I decided to use the etoolbox package's toggle. My MWE is as follows: \documentclass{article} \usepackage{etoolbox} ...
15
votes
1answer
372 views

Why use \DeclareTextFontCommand vs. just \newcommand?

Why should I use \DeclareTextFontCommand vs. just \newcommand? In the answer to my previous question, @egreg said: With \DeclareTextFontCommand you get a robust command that will remain ...
15
votes
1answer
774 views

biblatex: Is it possible to patch macros created with \newbibmacro?

This question led to a new feature in a package: xpatch The etoolbox package provides various tools that "are useful to hook into or modify existing code" (etoolbox manual, section 3.4). The ...
15
votes
1answer
464 views

Is \toks necessary to define \g@addto@macro? Can token registers be avoided in generel?

In LaTeX2e kernel, there is a useful macro \g@addto@macro: \long\def\g@addto@macro#1#2{% \begingroup \toks@\expandafter{#1#2}% \xdef#1{\the\toks@}% \endgroup} However, I think the ...
15
votes
1answer
1k views

Define same command with different amount of parameters

I want to define two versions of the command \Set, depending if I provide one or two parameters. I.e. like this: \newcommand{\Set}[1]{\bigl\{ #1 \bigr\}} \newcommand{\Set}[2]{\bigl\{ #1 \bigm| #2 ...
15
votes
1answer
3k views

TikZ \foreach loop with macro-defined list

I have a small problem with the TikZ \foreach loop whenever the list, over which we loop, is defined my a macro. The following code example will show my problem: \documentclass{scrartcl} ...