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

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
780 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
615 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
867 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
398 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
875 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
604 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
754 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
7k 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
871 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 ...
12
votes
2answers
580 views

() or {} after a command

I was wondering why for some commands it is "(...)" that follows, while for other commands it is "{...}". For example, "\exp(x)" and "\bar{x}". Are both () and {} for specifying the arguments for the ...
79
votes
3answers
13k views

How to write (La)TeX (with parentheses) [or any other TeX-related logo]

I'm looking after a macro to write the (La)TeX logo (with parentheses), i.e. something similar to \TeX, \LaTeX, but where the output includes ()'s.
6
votes
3answers
489 views

What is the difference between \myname and \my@name while writing a .cls file?

What is the difference between \myname and \my@name while writing a .cls file? Are they equivalent? Please let me know if it is necessary to post a minimal example. Edit: Let me ask my question more ...
12
votes
3answers
1k views

Macro for week number

Is there a macro or package to calculate the ISO week number or alternative can someone help me with one?
4
votes
2answers
222 views

Capturing number of decimals in a macro argument

Unfortunately, in some of our documents we need to print both SI units as well as Imperial units. We have some macros defined as follows: \documentclass{article} \usepackage{fp} \def\GPM#1{#1 ...
24
votes
7answers
2k 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 ...
26
votes
4answers
1k views

Alternate he / she in text

This question led to a new package: he-she I have seen a book that instead of using the masculine pronoun (he, his, etc.) alternates the gender ('he' then 'she' then next time 'he' again). Is ...
6
votes
3answers
314 views

Zero parameters in command definition

Let us say I want to define a command for typesetting (a+b)^2: \newcommand{\sumsquare}[2]{\ensuremath{(#1+#2)^2}} How can I modify it so that \sumsquare{a}{0} will produce a^2?
3
votes
1answer
867 views

Redefining the \printindex command and changing it to a desired form

In book class, I want to redefine the \printindex command and change it to something like the following: ‎\addcontentsline{toc}{chapter}{‎Index}‎‎‎‎ ‎\fancypagestyle{plain}{%‎ ‎\fancyhf{}‎ ...
3
votes
1answer
281 views

Defining my own “boxes”?

What I want is a environment that lets me create my own "boxes" (or blocks? I keep confusing them...) with the following properties They visually couple together a piece of sourcecode and a ...
15
votes
3answers
1k views

\def taking rest of the line as argument

I know how to define a macro that will take the rest of the paragraph as parameter. Simply write \def\a#1\par{\textbf{#1}}. But, how do I write a macro whose argument will extend to the end of the ...
14
votes
2answers
6k views

A macro with either one or two arguments

I am trying to define a macro with variable number of arguments. For example I want to define a macro with two arguments that can work with one argument as well. So the same macro works in two ways. ...
6
votes
2answers
590 views

Why is my macro not expanded inside of \special{…}?

I am writing my first LaTeX/TeX macro and not going anywhere with it. Could you please tell me what I am doing wrong in the code below. I have the following definitions. \def\defcolor#1#2{% ...
11
votes
1answer
5k views

LaTeX template for use cases

Currently I am trying to create a template in LaTeX for my team members in order to create a set of use cases. I thought of using tabular to create something like the picture below 2 (without colors). ...
0
votes
1answer
153 views

Help with a custom-command: Space should not be inserted

I have a problem with a command i make for a specific glossary: \newcommand{\term}[4]{\glslink{term:#1}{#2}} \makeatletter \def\term#1{\def\tempa{#1}\futurelet\next\term@i}% Save first argument ...
6
votes
5answers
525 views

Counting tokens

Is it possible to count the tokens/macro parameters. For example: \def\foo#1{...} $ \foo{\alpha\beta} $ % => \somecounter = 2
6
votes
2answers
4k views

How to use parameter numbers and \foreach

Is there a way to use the TikZ \foreach command to do operations with parameters? E.g. I would like to be able to write (just a silly example): \newcommand{\foo}[9]{ \foreach \x in{1,2,...,9}{ ...