{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
3answers
80 views

Abbreviating commands with shorter commands, launchable from the body

I have a pretty complicated command, lets call it "C" in the preamble a long document that changes how the document looks. If I'm writing text somewhere in the middle of the document, I'd like to ...
2
votes
1answer
43 views

Build special table header (multicolumn, rotated) automatically

I have to build lots of tables similar to my MWEm only more complex and with many more columns. Manually adjusting the cmidlines and column width etc. is very annoying. What can I do to automatically ...
4
votes
1answer
43 views

Create a new command that makes a footnote

Following some earlier code I've been given, I'm creating macros for meta-data about my papers (such as title, author, etc.). Now I'd like to create my own \thanks macro that should follow the title. ...
1
vote
1answer
67 views

How to do search-and-replace in a macro?

Is it possible to let (La)TeX search and replace text in a macro during compile time? For example, given \newcommand{\sometext}{a b c d e f g} I'd like to have something like ...
3
votes
1answer
101 views

Why don't book, report and article provide the same commands?

The popular question Regarding the `book`, `report`, and `article` document classes: what are the main differences? collects many differences between the book, report and article classes. In ...
5
votes
3answers
112 views

nested \ifnum commands

I'm trying to make macro to work in biblatex edition field. Logic is following: if edition =1 there is suffix -li (1-li) if edition>1 and if edition<21 there is prefix me- (me-15,me-20 ..etc) if ...
2
votes
2answers
76 views

Definition of a macro with multiple arguments and usage of \csname

Why does the following code not work ? \Requirepackage{amsthm} \renewcommand\newtheorem[2]{% \NewEnviron{\csname #1\endcsname}[1]{% ##1 : \BODY } } I have seen examples of the use ...
15
votes
2answers
310 views

Environment to stack a word and a number

There is a requirement to write a list of words, underline each word and place a number centered below the line. Using the stackengine package I have prepared the following MWE. ...
1
vote
3answers
74 views

How to expand macro in a macro call

How can I expand a macro inside an optional argument list \newcommand{\sss}{% label={$\bullet$},topsep=0mm, parsep=0mm,% leftmargin=3mm,rightmargin=0cm,labelwidth=5mm,labelsep=3mm% } ...
3
votes
1answer
34 views

Processing list of values in key argument for tikz plot

I want to pass a list of two values as a key argument and be able to access and use them arbitrarily in a command defined by myself. For example I want a command for plotting an arc of a circle with ...
1
vote
1answer
35 views

Curly braces disappear when reloading LyX document

I have a problem in LyX when using a math macro with an optional argument. I want to have an interval [a,b] as argument, which I need to group in curly braces, otherwise LaTeX will confuse the ...
0
votes
1answer
29 views

Using \MakeUppercase on expanded macro with argument

I would like to have the first letter in an expanded macro shifted to upper case but I can not seem to manage this. In the minimal example below, I would like the two rows to produce the same output, ...
9
votes
1answer
116 views

Understanding expansion of \mathpalette

I'm trying to make sense of the \mathpalette code used in this answer. To repeat it below: \makeatletter \newcommand{\raisemath}[1]{\mathpalette{\raisem@th{#1}}} ...
4
votes
1answer
54 views

How to condense environments and options to one environment?

In order to make grey boxes around code in my document I am using: \usepackage{listings} \usepackage{xcolor} %custom colours \usepackage{mdframed} %nice frames \definecolor{light-gray}{gray}{0.95} ...
1
vote
1answer
29 views

Listings and verbatim-like environments in a tikz node using newcommand

I have seen answers to this question floating around but none of them appeared to solve the problem. I want to be able to throw a code block into an already defined tikzpicture. So I attempted to ...
0
votes
1answer
23 views

Macro for formatting computer code? [duplicate]

I need to create documents containing lots of small bits of R code, which are not to be sent to R via knitr. Ideally, it should work very much like code is formatted here at Stackexchange. It should ...
2
votes
1answer
88 views

How can branch if I'm in a halign or not?

Edit: It seems that I can use \noalign\bgroup before the \halign. That's fine. But how do I test that I'm inside the halign group? I'm able to write an own if, but it would be better to ask tex for ...
4
votes
1answer
35 views

\newcommand and \prescript aren't working together

The code \newcommand{\AMod}[1]{\prescript{}{#1}\text{Mod}} \AMod{A} causes the following error: ! Argument of \text@ has an extra }. The error does not occur when I replace the \prescript ...
1
vote
0answers
18 views

Fraction macro in lyx

I want to create a macro for word-like fraction sign in lyx. Namely, when I write 1/2 I want it to be \frac{1}{2} Any Ideas?
4
votes
0answers
39 views

$\widehat$ prints a reverse paranthesis whenever argument length >5

I am using Babel Greek and the following code for my doc: \documentclass[titlepage]{book} \usepackage[vcentering,dvips,hmarginratio=1:1]{geometry} \geometry{ papersize={210mm,280mm}, ...
6
votes
1answer
745 views

How do I use the etoolbox package to check if an argument to a macro was defined?

I saw this answer, which uses the etoolbox package to create a macro with an optional argument. Unfortunately, I can't get it to work. Here is a minimal working example: \documentclass[12pt]{article} ...
7
votes
1answer
93 views

Should I specify parameters when renaming a command?

For the sake of having semantic code, I wanted to define a command \closure that has the same effect as \overline. Initially, I thought the simplest way to achieve this would be: ...
0
votes
1answer
22 views

Conflict between endfloat and figure floats included via macro

I use \newcommand to quickly include figures. But combined with endfloat, it throws an error. Any ideas how to send floats to end when included this way? \documentclass{article} \usepackage{graphicx} ...
21
votes
4answers
1k views

Why does TeX remove braces around delimited arguments?

On pp. 203–204 of the TeXbook, Knuth describes how TeX absorbs macros' arguments: delimited go until the first appearance of the delimiter, and undelimited go until the next token, in both cases ...
6
votes
1answer
56 views

disabling def from acting on other parts of documents

I use a simple command to stretch rows of a table in my document. (It is Table 1.2) The command is shown below {\def\arraystretch{1.65}\tabcolsep=8pt But what happen is, this stretches all other ...
39
votes
7answers
1k 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 ...
0
votes
1answer
74 views

Apply macro to .tex file and get a new .tex file

Are there a preprocessor for TeX, like for C/C++? Are there a way to apply a macro to .tex file in order to generate new file? For example, I have macro: \renewcommand{asd}{some phrase here} I ...
2
votes
1answer
39 views

Using a macro for table alignment

I am trying to use a macro to define the alignment of a table as shown below: \documentclass{article} \begin{document} \def\align{|l|c|} \begin{tabular}{\align} 1 & 2 \\ \end{tabular} ...
1
vote
1answer
48 views

Split a macro call and its argument in conditional

How can one split a macro call and its argument in a conditional? Why doesn't \ifnum 1=1\textbf\else\textit\fi{Foo} work? Why it yields error “Too many }'s”?
4
votes
5answers
1k views

How to define a command that takes more than 18 arguments [duplicate]

This question is based on this answer. It is a continuation of my previous qestion regarding list of values in latex. According to first link there is a limitation on the number of arguments I have ...
12
votes
3answers
189 views

Useful applications of \edef with macro arguments

Well, it's been in my head for some time, but I haven't got anything out of it, so I ask here. At what places could be useful to have \edef\foo#1{..}? What applications could it have? Is it useful at ...
5
votes
1answer
63 views

Renaming \d for differentials

I know this question might sound dangerously like asking for an opinion, but I nevertheless give it a try. Since I never used the "underdot accent" \d I renamed it to get a differential in math mode ...
3
votes
2answers
35 views

Formatting Strings in Dynamic Variables with xstring

I need to format a string resulting from a dynamic variable set in a separate program for a LaTeX generated report. In particular, if a variable has a negative value (starts with a minus sign), I ...
18
votes
1answer
4k views

Comparing an argument to a string when argument is a result of a command with etoolbox

I've got an example like that: \documentclass{article} \usepackage{etoolbox} \newcommand{\ab}{a} \newcommand{\aORb}[1]{% \ifstrequal{#1}{a}{"a" was given}{not a}, % ...
12
votes
2answers
518 views

Why extra spaces in some cs definitions?

In (La)TeX source code definitions are sometimes written with a space after \def and with a space after the control-sequence being defined. For example, these two lines come from miniltx.tex: ...
4
votes
2answers
34 views

Testing for macro change

In a package I'm writing, I have a macro (call it \foo) which, by default takes one argument and is equivalent to \relax. Under certain circumstances, the user may wish to redefine \foo in their ...
0
votes
0answers
20 views

Correctly handling spaces that occur after a user defined command [duplicate]

I am using LuaLaTeX for a manual and I am running into a spacing issue I am not sure how to resolve. I defined a new command that is simply used to make some text bold. However, I have found that this ...
9
votes
3answers
85 views

Indexing: inverting names

I have defined \Index to mark a word or phrase for indexing and also preserve it in text: \newcommand{\Index}[1]{#1\index{#1}} How would I define a macro to invert the index entry? e.g. ...
1
vote
1answer
56 views

Next word macro inside braces

I have defined a macro that highlights the next word using \def!##1 {\hkw{##1} }% where in this scope, ! is an active character. So it works fine to write. \emph{This is a !good example} but not ...
1
vote
1answer
57 views

Enumerate with \noindent

I am creating a custom macro for enumerated lists, but with this attempt, I haven't been able to eliminate the indentation of the item numbers. Every time I use \myitemize, the lists still indents. ...
2
votes
1answer
36 views

Line breaks introduced in database export as extra lines in table

I am automating the producing of tex files using an access database with many different types of fields. One, a memo field that will contain an itemized list i.e. visible tex including \begin{itemize} ...
3
votes
2answers
104 views

New command without 3 argument brackets

I would like to achieve the result of using the command \scell{111} and have the resultant output be $1\times 1\times 1$ so that it can look like 1x1x1 but with the x being a \times sign. I wrote the ...
41
votes
2answers
47k views

How to color math symbols?

One can use the command such as \textcolor[rgb]{1.00,0.00,0.00}{boundary} to color the word "boundary" in a document. Here is my question: How to color the math symbols in $$? For example, can one ...
3
votes
0answers
23 views

Can I force a pre-process action on all commands or environments without having to redefine them all manually?

I am trying to preserve a history of the latex commands and environment initializations I use in a typeset html or pdf file. Is there a way where I can force a pre-process action on all commands ...
3
votes
3answers
99 views

Replace from a list of possible strings

I'm creating a large number of identical documents in LaTeX, with only the address changing (and the address will be only 1 of 5 possible ) So if my list of possible addresses is: DC | 1600 ...
2
votes
0answers
8 views

Error related to tikz-cd and user-defined commands [duplicate]

My LaTeX document looks like this: \documentclass{article} \usepackage{tikz-cd} \newcommand{\commSq}[8] { \begin{tikzcd} #1 \ar[r, "#2"] \ar[d, "#6"] & #3 \ar[d,"#4"] \\ ...
8
votes
1answer
250 views

Gobble optional arguments

You can use \@gobble, for instance, to restrict the usage of a macro like: \documentclass{article} \makeatletter \newcommand*{\cmd}[1]{% \textbf{#1} \let\cmd\@gobble } \makeatother ...
0
votes
0answers
20 views

Don't eat space after command [duplicate]

I'm writing a Latex document. I'd like to define a synonym for a word that's used throughout the document. For instance, I'll define \newcommand{\productname}{VioletFrog}, so that every place I ...
2
votes
1answer
32 views

Have a macro evaluate to different stuff depending on whether it will be hyphenated

Given a command like this \newcommand{\AB}{$\textsf{A} \subseteq \textsf{B/string}$} is it possible to have the string evaluate to something like \newcommand{\ABhyp}{\textsf{A} is contained in ...
1
vote
1answer
30 views

Having acronym processed differently if used in acronym environment

I have a number of acronyms that depend on each other and I would like a way to determine if the usage of an acronym is in the acronym environment and if so process it in a different way than if it is ...