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

0
votes
1answer
45 views

Leaving out the curly braces

I'm trying to understand how LaTeX works, but I don't understand the following: \dot X and \dot{\mathcal X} work, but \dot \mathcal X does not work. Can anybody explain why?
4
votes
2answers
60 views

how to change the style of definition of xrightarrow

we know that, the \xrightarrow can give superscript (over the arrow) and subscript (under the arrow). for example X\xrightarrow{f}Y X\xrightarrow[g]{f}Y but, I want to define a command such that ...
12
votes
1answer
153 views

Understanding etoolbox macro \deflength

The etoolbox package documentation says about \deflength: This command may be used as a drop-in replacement for \setlength. I am having trouble getting it to work with the \minof macro from the ...
2
votes
2answers
77 views

How to switch macro expansion by giving optional arguments?

Popular ways to define a macro with optional arguments is using TeX's \def with the aid of \@ifnextchar[ and/or LaTeX's \newcommand. In both cases, macro's definition usually contains its optional ...
2
votes
1answer
28 views

Macro with different font for subscript and superscript text

I need to define a macro, lets call it DifferentFontMacro, that takes a single string x as input. This string x is of the form {string1}^{string2}\_{string3}. Now, I want the output of this macro to ...
2
votes
0answers
32 views

Wrapper around `picture` environment causes page break [duplicate]

A picture environment at exactly the size of the text area can fit snugly on one page. However when I replace the environment with a wrapper environment with exactly the same definition, it takes two ...
0
votes
1answer
73 views

! Missing } inserted. Error with newcommand

I get a Missing } error with the following \newcommands : \newcommand{\bt}[1]{$\mathbf{#1}$} \newcommand{\beq}[1]{\mathbf{#1}} \newcommand{\btF}[1]{$\mathbf{$\mathfrak{e}_{#1}$}$} ...
12
votes
4answers
280 views

How to implement \ifxcase: case equivalent of \ifx

I am looking for a case equivalent of \ifx. So, when I have nested uses of \ifx it would be cleaner to specify it in some sort of syntax similar to: \newcommand*{\ColorSymbol}[1]{% \ifxcase#1{% ...
17
votes
2answers
199 views

How to \let an xparse defined command?

Let \example be an xparse defined command, which takes one optional and one mandatory argument. The definition of \example cannot be modified (e.g. because it comes from a third-party package). The ...
3
votes
1answer
71 views

How to test if two macros have identical definition

I want to test if two macro have identical definition. My naive attempt to use \detokenize does not seem to work in this simple case. However, I have used a similar approach before and it seems to ...
3
votes
1answer
128 views

Eyeglasses as item bullet

I would like to Customizing lists itemize and title of theorem to looks like that : as usual in order to Switch chip, size and color for itemize i use \usepackage{pifont} or we can use Math ...
4
votes
1answer
68 views

Repeating an equation including its content and number

I would like to re-use equations with the same content and number. I know that the thmtools package has a restatable environment to do this for environments (like in this answer), but I would also ...
8
votes
1answer
189 views

Two ways of defining an 'environment' (not a LaTeX environment)

I would like to understand if there are differences between defining an environment by 'paired definitions' and by 'simple definitions'. Consider \long\def\begx#1\endx{\dosomething ...
3
votes
1answer
37 views

prevdepth related error only in case of abscence of whitespace

In the file given below, I am using macros for equations and their environment. The equations use breqn package for breaking them when the width available is not sufficient. I am getting the error ...
2
votes
1answer
50 views

Open another pdf file at referenced label/page

I am having two documents, call them A and B. I want to make several cross-references from file A to file B and by clicking on the hyperlink, I want to open file B at the respective page. In my ...
2
votes
1answer
74 views

New command for filtered colimits and limits

I would like to define a new command (called colim) for filtered colimit (also sometimes called direct limit ...) as nice as the command $\varinjlim$ in amsmath package. So far, I tried ...
3
votes
2answers
150 views

How to define variables with white space

I'm writing a LaTex document in which I must refer to some variables in some points of the document. In order to ensure that each variable is written in the same way, I defined a LaTex variable for ...
16
votes
2answers
228 views

How do I generate a warning for an undefined control sequence

I've defined some setter and getter commands to facilitate entering complex content into my document. The basic definitions are as follows: \newcommand\aeset[3]{\expandafter\newcommand\csname ...
4
votes
2answers
131 views

Manually expanding a macro within a definition

When defining macros using \edef (which by default expands every macro within the definition as much as possible), I can declare some macro within that definition to not expand by using \noexpand ...
4
votes
1answer
50 views

Newcommand with macros as input

I have defined two arrays of points like so: \def\blah{{0,1,2,3},{0,1,2,3}} \def\foo{{0,1,2,3},{3,2,1,0}} I want to use these points in a TikZ image. Since I have a lot of these arrays, I wanted ...
2
votes
0answers
68 views

What causes this \endcsname error? [closed]

I am a beginner to LaTeX, and I don't understand what's going wrong here. I didn't change anything, and all of a sudden, the code won't run. Can you please help me? ) (./Final_Halper_410Latex.aux ! ...
4
votes
1answer
62 views

Command “&” is not working

I am new to TeX and I am trying to write the following \begin{equation} N_{a,0}\begin{cases} R_{0,0} & a=0\\ N_{a-1,0}e^{-m} & 1\leq a\leq a_{max}-1\\ N_{a-1,0}e^{-m}/1-e^{-m} & ...
2
votes
1answer
36 views

Biblatex: Change order of fields (note+pages) for inproceedings/incollection

I'm using the following to change the order of note and pages fields for @article. \renewbibmacro{note+pages}{% \printfield{pages}% \setunit*{\space}% \printfield{note}% ...
18
votes
4answers
1k views

Is there a way to eliminate the “\” in frequently used LaTeX commands?

The "\" in all of the commands requires frequent finger gymnastics of the pinky of the right hand in LaTeX, at least for the touch typist. It occurred to me that although it makes things more ...
1
vote
4answers
134 views

Is it possible to automatically replace commands shortcuts with the corresponding TeX commands?

I would like to make a list of shortcuts like myshortcuts={TeX, LaTeX, copyright, mycoommand } etc. (mycommand is a user-defined shortcut of a user-defined command) and a special command or ...
7
votes
2answers
81 views

How reuse latex code for later expansion?

I would like to make a command to help me writing lines like: The \LaTeX~code is: \verb@e^{i\pi} - 1 = 0@, and the result is: $e^{i\pi} - 1 = 0$. I thought of using a newcommand as: ...
2
votes
1answer
44 views

Defining a command with options

I have two problems. First I don't know why but Texmaker doesn't compile when I define this command: \newcommand{\Axes}{\draw[-{Latex[length=5mm,width=2mm]}](-5,0)--(5,0)\node[below]{$x$}; \foreach ...
2
votes
2answers
96 views

Is it possible to make an environment or a command such that every word inside it is transformed into a TeX command?

My purpose is to eliminate the use of backslash in a long text where each word is supposed to be a command. For example, instead of \def\new{this is a new command!} \def\another{Another one…} etc. ...
2
votes
2answers
86 views

Enable \ifmeasuring@ flag

Apparently the \DHLhksqrt macro in the MWE below measures its content 20 times: Questions: Where exactly can I put the \measuring@true and \measuring@false so that I get the count of 1? If you ...
1
vote
1answer
42 views

How to redefine a command to keep track of page assignments w/o exceeding TeX capacity

Seemed straight-forward enough (and I've changed it per Christian's suggestion of using \edef instead and added some status code): \documentclass{memoir} \newcommand{\tabloidpagecount}{} ...
2
votes
1answer
50 views

Crop output pdf page to \fbox

Is there is any way to crop the output pdf to the \fbox{} with LaTeX Macros? I wrote a macro to test such examples something like: \newcommand{\inlinebox}[1]{ \fbox{#1}% <--crop the output page to ...
11
votes
1answer
108 views

Context-aware commands?

I used command \important throughout the document to mark the important parts of the text, and although it was initially bold and red, in the end I chose to style it simply as bold. However, the same ...
5
votes
1answer
30 views

Operator with different spacing for binary operations

I want to create a macro \d where something like $4+\d x$ is interpreted as $4+d\! x$ but $\int f(x) \d x$ is interpreted as $\int f(x) \,d\! x$ In essence, I want the macro to ...
10
votes
1answer
98 views

\DeclaredPairedDelimiter vs \newcommand

When should I use \DeclarePairedDelimiter and when should I use \newcommand? For example I have defined %Ceiling function \DeclarePairedDelimiter\ceil{\lceil}{\rceil} %Floor function ...
9
votes
1answer
205 views

Can you use two types of delimiters in \def?

In this post, it was mentioned that any character can be used as a delimiter using def. Is it possible to define a function with two types of delimiters? In particular I'm looking to define an ...
1
vote
1answer
64 views

Create macro depending on counter at point of definition

I have a document with various numbered objects, e.g., term rewrite systems with numbered function symbols like this: While I need a numbered output for these symbols (it should illustrate the ...
1
vote
0answers
54 views

\lstlisting in \multicolumn in a macro [closed]

I want to create a macro for putting a multiline JSON code in a multicolumn row in a tabular environment... \newcommand{\apiMethodRequest}[1]{ \multicolumn{5}{l}{\cellcolor{DsnGreen}{Request}} \\ ...
6
votes
3answers
102 views

Alphabetical ordering of items composed of macros in itemize

This is a continuation of the topic: Alphabetically display the items in itemize But sadly I don't have the necessary reputation to comment there. Method proposed by @Werner works perfect, even when ...
2
votes
2answers
351 views

How to redefine one-letter commands?

I want to change the function of some commands consisting of only one letter, such as \e or \i, and make them abide by MY rules. (Mouhahaha!) I have done this before with other commands like \in or ...
2
votes
2answers
231 views

Error when trying to change imaginary unit's style

I want to have a special symbol for the imaginary unit i, but I also need the usual character for the letter i in the same context. So, I tried to change the style of the imaginary unit by setting ...
4
votes
1answer
52 views

\command without {} ending at the end of the line?

In a work, I have to write a lot of dialogue. This is my MWE: \documentclass{article} \newenvironment{dialogue}{% \noindent% \newcommand\one[1]{\textit{##1}\newline}% ...
1
vote
1answer
25 views

Setting a question font / style that will apply to text and inline math environment?

I have defined two commands for the font/style of questions and key concepts in my notes as follows: \newcommand{\key}[1]{{\bfseries\sffamily#1}} \newcommand{\qtxt}[1]{\textbf{#1}} Where the ...
1
vote
1answer
38 views

Input command arguments from file

I created some new commands that take arguments. Several of my commands take the same (lengthy) arguments. Because of this I put those arguments in a separate file. But I seem unable to input or ...
2
votes
1answer
61 views

How to add suffixes to `\newcommand`s in TEX?

I have defined a term using a new command as follows: \newcommand{\ourmethod}{G-MM\xspace} Now I'd like to add a suffix to the term that I just defined, e.g. I'd like to use "\ourmethod" to say ...
0
votes
0answers
13 views

Direct Limits Command [duplicate]

I was trying to do a command for direct limits. My try was: \newcommand{\dirlim}[2]{\stackrel[{\stackrel[#1]{}{\longrightarrow}}]{}{\lim{#2}} } However, with this the arrow is not ...
9
votes
1answer
145 views

Which one should be used: `newcommand` or `sbox`

Suppose I want to use an element numerous times, which is the best way to go at it (I chose a tikz-drawn arrow, because that is what made me think of the question, but I suppose it could be anything, ...
4
votes
1answer
65 views

How to wrap a `\newcommand*` into a multi-paragraph environment?

As stated elsewhere, it is usually quite recommended to use the starred \newcommand* instead of \newcommand since this helps finding missing }s by disallowing paragraphs in its argument. Every now and ...
2
votes
0answers
68 views

A \newcommand type option that runs all subarguments and saves static text

I am trying to write code that uses sage in it, and have a bit of a problem with randomizing stuff around the code. The sagetex part isn't too important (I don't think), what is important is that if I ...
2
votes
1answer
39 views

Redefining a variable inside a newcommand

I have the following code: \documentclass{article} \usepackage{tikz} \usepackage{graphicx} \newlength{\cm} \setlength{\cm}{1cm} \newcommand\scalefactor{2} \newcommand{\bintree}[5]{ ...
0
votes
1answer
129 views

LaTeX macros in markdown [closed]

I'm wondering if markdown supports even the simplest commands like \newcommand \def \declaremathoperator Furthermore, whether or not the use of parameters is possible. For example, ...