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

13
votes
2answers
632 views

Is there a list of general use LaTeX kernel macros?

Here are a few cases in which one could use such a list: Is there a "prepend" version of \g@addto@macro? A "local" version? What's the most efficient way of gobbling n characters? Can I use LaTeX's ...
6
votes
1answer
689 views

Defining new accents in LaTeX

The documents that I type include lots of references to complex numbers and their complex conjugates, such as $j, \overline{j}$. I would find it lots easier to be able to type something as \*j to ...
6
votes
2answers
2k views

Centering and \MakeUppercase with linebreaks

I wish to make the list of authors show up as centered, uppercase and listed vertically on my titlepage. My documentclass contains a section like this \begin{center} ... ...
10
votes
2answers
4k views

How to redefine the \emph command in Beamer?

I am using the Beamer class and would like to redefine \emph to use \bfseries instead of \itshape. I have tried the following command: \renewcommand<>{\emph}[1]{{\only#2{\bfseries}#1}} but I ...
18
votes
1answer
3k 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 ...
6
votes
1answer
1k views

How do I examine a token?

... let me count the ways. I can test it with \if and \ifx and \show its \meaning And there I stop, both in my knowledge and my poetic ability (though some might argue that the latter never ...
1
vote
0answers
294 views

Different spacing caused by \newcommand and \def [closed]

From the answer to my other question " define something like \lim but for another name", I tried: \def\ext{\qopname\relax m{ext}} and: \newcommand{\ext}{\qopname\relax m{ext}} In " What is the ...
22
votes
3answers
11k 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 ...
7
votes
4answers
2k views

A macro that expands to the length of its argument

If I want to anonymise a paper I've written for review, I don't just want to delete my name from the author field. I want to replace my name with a rule as tall as a capital letter and as long as my ...
2
votes
2answers
1k views

Use (or redefine a) \tag command in text mode

In some times I have to set a tag in front of a text math formula. It seems better to define a command \TAG, as $\TAG{Pythagoras' Equation}a^2+b^2=c^2$ to get <Pythagoras' Equation> a^2+b^2=c^2. ...
40
votes
6answers
2k views

Macros with # as the last parameter

Knuth hid a special rule for delimited arguments in exercise 20.5 of the TeXbook. If the very last character of the parameter text is #, so that this # is immediately followed by {, TeX will ...
11
votes
2answers
282 views

How to find the previously printed character?

Is there a way to find the previously printed character in LaTeX? E.g: \newcommand{\th}{% \ifthenelse% {\equal{\previouscharacter}{1}}% {st}% {th}% } 4\th and 21\th % would like to ...
7
votes
3answers
4k views

How to define macros with numbers in them? [duplicate]

Possible Duplicate: Definining commands/abbreviations that contain numbers How can I define macros as \text1,\text2...\text3 which, when invoked will produce text with different widths?
1
vote
1answer
355 views

Is it possible to make a macro sensitive to \\?

I have the following macro: \newcommand{\INFERRULE}[3][]{% \ensuremath{\inferrule{\mathstrut #2}{\mathstrut #3}\ifx\\#1\\\else\enskip(#1)\fi}} I want to make it sensitive to \\ so that I can ...
4
votes
3answers
693 views

Redefine underscore to produce roman subscript without breaking file names

I've been using Hendrik Vogt's answer to my earlier question Redefine underscore to produce roman subscript, in which he explained how to make the underscore character active and assign a macro to it ...
10
votes
3answers
3k views

Defining a macro in LaTeX with an optional parameter in round brackets

Is it possible to build a macro with an optional parameter enclosed in round brackets () rather than square brackets, where one can say for example: \mymacro(){}{} or \mymacro{}{}
6
votes
3answers
779 views

Redefine a command, including its arguments, to to do nothing

I want to easily typeset my documents without all references (the reason is that I need a version of the document without footnotes to count the words without footnotes). I use biblatex to create the ...
4
votes
2answers
472 views

Strange expansion of a macro inside an environment

I'm, I should confess, a total newbie. I'm trying to generate invoices with LaTeX, so I'm using the fp package. But the strange thing is that calculations occur many times when they should only ...
24
votes
2answers
6k views

How do I split a string?

I need to split a string into one or more substrings. I know that I could use the xstring package, but I'd like to do it using only inbuilt TeX/LaTeX commands. So, if I say \def\MyTeXKnowledge{Not ...
9
votes
3answers
443 views

Changing href's to footnotes

Here is exactly what I am trying to do. I have a file with many commands of the form \href{a}{b} for strings a and b. I would like to redefine \href so that it executes the following: ...
8
votes
3answers
771 views

Keeping the names of things consistent in LyX.

I'm documenting a software project using LyX and many of the "things" (classes, processes, etc.) that I'm describing don't yet have good names. As my understanding of these things improves, I want to ...
10
votes
4answers
1k views

Control command arguments

Can I define a command that takes an argument but does not eval the argument?
25
votes
1answer
612 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.
41
votes
1answer
20k 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
861 views

How to change the catcode in a macro

I want to change the catcode in a macro, but it seems it doesn't work. Can anyone help me? \def\A{\catcode`\|=0 |bf{test}} |bf{test} would not work as expect.
17
votes
5answers
1k views

How to apply a macro to each column of a table

I want to apply a macro to all the cells of a column with the cell content as the input to the macro. Is this possible? For example if the cell contents have the word TEST, the macro should take TEST ...
13
votes
7answers
1k views

How to get the string with \

Apologized for my unclear description. I wish I could explain my problem more clearly. In document, I wish I can just write something as "how to use \cmd \mbox in xxx" or "what is \cmd minipage ...
7
votes
1answer
397 views

How do I remove spurious parentheses from a macro argument?

I want to store the argument of a macro in a temporary variable, but I know in advance that some people will incorrectly enclose the argument in parentheses as well as braces (long story). ...
20
votes
5answers
6k views

Test if a command has been defined by another package

I normally use the LaTeX \newcommand to define macros. However, when using delimited macros I use \def. Is there a way that I can get LaTeX to trigger an error if the command defined by \def is being ...
10
votes
1answer
3k views

How to delete/undefine macros in Context?

How can one delete or undefine macros in Context? Is there a difference if i've used \def or \define to create a macro?
9
votes
3answers
282 views

Automatically checking for accidental spaces in macros?

It is easy to forget a \relax or % at the line end of commands in the body of macros. For example, in writing \def\myMacro{ \invokeX \invokeY{} \invokeZ } You must add a space swallower at ...
11
votes
6answers
1k views

How do I expand a macro into a tabular head?

I would like to be able to define a macro that can be used in the tabular definition. How can I do this? This does not work: \documentclass{article} \begin{document} \gdef\buildtabularhead{|||} ...
6
votes
1answer
2k views

\excludecomment and \newcommand using it

I have a problem with \excludecomment from comment package and a \newcommand. The following codes work good, which means, it can generate the desired pdf output. \documentclass{article} ...
25
votes
1answer
5k 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} ...
18
votes
1answer
869 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 ...
7
votes
3answers
601 views

commands in interaction mode?

Q: Which commands can I supply back to LaTeX when it pauses on a line of code during compilation and is waiting for me to give it more information before proceeding? E.g., in the post How do I use ...
10
votes
2answers
752 views

\def taking next word as argument?

This question is a variant of my previous question requesting a macro that takes the rest of the line as argument. I would like to write a macro that would take the next word as argument, where word ...
21
votes
2answers
4k 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
4answers
1k views

Google searching LaTeX commands?

Q: How can I best search the web for exact LaTeX commands (e.g., \show as opposed to show)? It appears that Google will not allow us to escape the \ character. So, searches for \show are interpreted ...
15
votes
2answers
6k views

Where to put a custom macros file?

I have a bunch of common commands I put in document preambles. I don't always use them all, but it makes the preamble too long for my tastes. I want to put them all in an external file (preferably in ...
21
votes
2answers
857 views

How bad is slack \makeatother discipline really?

Following Will Robertson's admission that Fwiw, i'm not aware of any troubles with a missing \makeatother, but you're right. It's a bad habit of mine to omit it, and my own progressive slackness about ...
10
votes
2answers
747 views

Can you employ \unskip to automatically place a non-breaking space before \cite or \ref?

It is recommended to place a non-breaking space before \cite, \ref, inline math and perhaps at few other locations. The question is whether you can design an improved version of \cite (say) which ...
8
votes
2answers
1k views

Iterate over space-separated list

I’ll briefly explain the background in case this can be solved simpler but I’d still be interested in an answer to the actual question, too. My chapter titles are very narrow and use a large font so ...
16
votes
2answers
1k 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 ...
2
votes
2answers
670 views

ignorespace and unskip in verbatim/listings?

I am writing a \bashDemo macro that will (a) execute its argument in a shell, e.g., bash, script, and (b) display the argument in a listings. So, \bashDemo ls -ls > myfiles \END will both run ls ...
17
votes
3answers
3k views

Doing maths with distance values in LaTeX source code

I have a sty file with the command \newcommand{\foo}[1]{\noindent\kern#1} but I'd actually like to have something like \newcommand{\foo}[1]{\noindent\kern{#1 *0.5}} meaning that I'd like to have ...
1
vote
1answer
1k views

Why does my linebreak not work?

I have the following code: \section{Questions} \freequestion What is the largest (LOC) class in the project? \par \makebox[\textwidth]{% \begin{tabularx}{\textwidth}{|X|S|S|S|S|S|X|} \hline ...
9
votes
3answers
2k views

Macro for figure position?

Why is the following minimal example not working? I.e., what do I need to do, in order to define the float placement specifier of a figure within a macro? (I know that I should use \newcommand, but ...
6
votes
3answers
2k views

Conditionally displaying/hiding parts of document using macros

I'm currently using the following approach to conditionally display/hide parts of my document: % PREAMBLE \def\MyVersion{1} % BODY \ifnum\MyVersion=1 This is version one. % possibly other ...
35
votes
2answers
4k 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 ...