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

3
votes
1answer
24 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
28 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
99 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
25 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
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
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
2answers
59 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
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 ...
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
37 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
92 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} ...
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 ...
1
vote
1answer
37 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
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} ...
5
votes
1answer
62 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
184 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
92 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
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 ...
4
votes
2answers
33 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
514 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
56 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
102 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
34 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
58 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
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 ...
2
votes
1answer
44 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
21 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
60 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 {.
2
votes
1answer
69 views

Is it possible to access command parameters?

I use hyperrefs extensively in my document and I define them like this: \hyperref[label]{some text \ref*{label}} It's really annoying that I need to repeat the label twice. Is it possible to ...
15
votes
2answers
298 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. ...
2
votes
1answer
19 views

Using user defined commands within Tikzcd

\documentclass{article} \usepackage{amsmath,amscd,amssymb,amsthm,graphicx,amsxtra} \usepackage{verbatim} \usepackage{tikz-cd,xparse} \usetikzlibrary{matrix,arrows,decorations.pathmorphing} \newcommand ...
6
votes
2answers
87 views

TikZ Macro for Placing an “X” by Coordinate

I would like to make a TikZ macro that will: Have an optional argument of coordinates Place X centered at those coordinates. Is this possible? This is how I put two X's on a 10x10 grid manually. ...
0
votes
0answers
27 views

change the default sidecaption margin at left for oneside memoir option

This question is related to this stack thread About \sidecapmargin Memoir class say that the \sidecapmargin command controls the margin where the sidecaption will be placed. The possible values ...
2
votes
1answer
28 views

How to access per-page variable/command for use in footer

What I would like to accomplish is including a per-chapter variable/command in the header (or footer, would be the same issue). The real crux of this question is, I supposed: how would one include a ...
5
votes
2answers
110 views

How to define a newcommand that expands into another newcommand

I'm not sure exactly what terminology to use to ask this question. What I want to do is define a command pluralize such that I can do this: \newcommand{\individual}{individual\xspace} ...
1
vote
1answer
23 views

Variables defined but used in a class file & want to specify value in tex file

I'm new to TeX & I "inherited" a tex document & class file. The class file has: \newtoks\copyrtyr \newtoks\acmcopyr \newtoks\boilerplate \def\CopyrightYear#1{\global\copyrtyr{#1}} ...
0
votes
1answer
44 views

Comparing macro arguments

I'm trying to compare a and b from \f{a} and \g{b}. It could be done by redefining \f and \g so that they expand to their argument, then comparing the arguments and finally resetting \f and \g's ...
4
votes
2answers
50 views

\xpatchcmd fails in a more complicate command

I've tried to patch the \minitoc@ command to add some additional vertial spacing after \mtctitle is used. (This is a question resulting from Adjust vertical spacing between minitoc title and contents) ...
4
votes
4answers
452 views

One-liner for removing characters from a string

I have a predefined command \mycommand which, for some reason, outputs {"/home/user/di rect ory/"/}. (Yes, there's a slash after the quotation mark, and there are curly braces.) Could one think of a ...