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

2
votes
1answer
13 views

hyperrefs have a different spacing when written inside a macro [duplicate]

Let's say I want to make a hyperlink like this: A link is placed \href{www.google.com}{here} to google. Then I decide to make a macro for that: \newcommand\Myhref[2]{ \href{#1}{#2} } A link is ...
3
votes
1answer
11 views

Repeat block without until (or blank line) using algorithm2e

I'm trying to format a "repeat forever" block using algorithm2e. I've found the \Repeat command but this prints an until at the end of my block. I can hide the word until using: ...
4
votes
3answers
68 views

macros with multiple arguments in absence of some arguments

I would like to define a command with two arguments, say \mycommand{arg1}{arg2} in such a way that if the second argument is absent, then it takes the first argument in place of the second one, in ...
3
votes
1answer
94 views

Defining individual glyphs breaks kerning

When I create shortcuts for individual glyphs, no kerning is applied. \documentclass{article} \newcommand{\myF}{\textit{f}} \newcommand{\myA}{\textit{a}} \begin{document} \myF\myA\par \textit{fa} ...
8
votes
2answers
1k views

What is a macro, really?

From the list of catcodes, \ starts a new control sequence, { starts a group, and } ends a group. In LaTeX, a macro appears as \foo[opt-arg]{arg1}{arg2} However, TeX does not seem to have the ...
4
votes
1answer
50 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
74 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 ...
2
votes
1answer
46 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 ...
3
votes
1answer
109 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 ...
4
votes
3answers
87 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 ...
3
votes
1answer
36 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 ...
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
132 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}}} ...
1
vote
1answer
31 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 ...
4
votes
1answer
55 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
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 ...
1
vote
3answers
82 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% } ...
0
votes
1answer
24 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 ...
4
votes
1answer
36 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
40 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}, ...
7
votes
1answer
96 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} ...
5
votes
4answers
94 views
+50

Automatically removing, after compilation, parts of text enclosed in certain strings

Is it possible to create a macro, such that everything that is between the string composed of the characters "whitespace", "{", "L" and the string composed of "L", "}", "whitespace" is not displayed, ...
6
votes
1answer
59 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 ...
1
vote
1answer
50 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”?
2
votes
1answer
40 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} ...
5
votes
1answer
65 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 ...
12
votes
3answers
198 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
3answers
113 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 ...
3
votes
2answers
36 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 ...
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 ...
12
votes
2answers
521 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: ...
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 ...
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. ...
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 ...
2
votes
1answer
37 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
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 ...
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"] \\ ...
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
29 views

Recursive Itemization Macro Output & \@ifnextchar Weirdness

I'm encountering some rather unusual behavior from a macro I've defined. The specific goal of this macro, ultimately, is to set up something easy to call that produces itemized lists to my liking ...
1
vote
0answers
24 views

Expanding to something missing an argument

I have a very weird behaviour where replacing something by its extension removes an error. Here's the problem: \documentclass{article} \usepackage{xparse} \usepackage{mathpartir}% ...
3
votes
1answer
59 views

newcommand with two arguments, one optional

I'm struggling with a command that doesn't do what I expect. This is my code \newcommand{\expectation}[2][]{\mathrm{E}_{#1}\left[#2\right]} \begin{document} I get $\expectation{A}{B}$, but I expect ...
1
vote
1answer
32 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 ...
2
votes
1answer
46 views

Code for capital letter in acronym list clashes with other custom commands

I am writing a large report with many acronyms, some of which include each other. I asked about a way to let them do this in a specific way and got a very nice answer. Acronyms that include other ...
1
vote
2answers
20 views

Error while defining custom tabular column width

I am trying to define the maximum width of a tabular column, see the code below: \documentclass{article} \usepackage[]{float} \usepackage[]{hyperref} \usepackage[]{booktabs} \usepackage[]{array} ...
1
vote
1answer
22 views

Specific formatting for some entries of a glossary

I use the memoir class. In my glossary, I need to emphasize certain terms (and descriptions), but let the others in roman. The command is \glossary{term}{description} so I tried to do ...
3
votes
1answer
63 views

How to remove highlighting color?

How would you remove highlighting color from LaTeX with one command? I have used the soul package with its command \hl.
4
votes
4answers
154 views

Newcommand: underbrace parentheses

I need a newcommand like \underbrace{}_{}, but I want a parenthese like that ( instead of {.