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

6
votes
1answer
266 views

How to make a package play well with others?

I have an ever growing preamble and it contains commands like \su and \so for the special unitary and special orthogonal group algebra, just \mathfrak{SU}. Then later I wanted to use the soul package ...
4
votes
1answer
70 views

Reset counter via macro with \ifcase in Plain

I am not able to reset a counter to zero using a macro in Plain TeX. This code uses \ifcase and the counter animalnum to output one of a list of animal names, incrementing the counter each time it is ...
16
votes
1answer
481 views

Learning to use xparse

I'm learning to use xparse to build commands with optional arguments. But I'm having problems: I want to make a command called \topcat with output: \mathcal{O} if no argument is specified \mathcal{...
4
votes
3answers
242 views

How to change the output of a command if it has been called already?

I want to create a command that changes its output the second time it gets called. For example, I want it to yield 1 the first time it's called, and 2 the second time: \newcommand\mycommand { do ...
0
votes
0answers
50 views

Simple homework template doesn't work

I want to make a simple template to do my homework in a textbook where \chap{1} becomes \section*{Chapter 1} and \begin{part}{foo} becomes \subsection*{foo} \begin{enumerate} (so \end{part} becomes \...
6
votes
2answers
254 views

double sqrt (surd) symbol

I want to define a macro that prints two adjacent sqrt symbols. (Notation from Cauchy's analysis book). I get something close but the spacing is changing depending if there is a number before it. ...
2
votes
1answer
44 views

How to define space as a variable?

I want to define a command that makes vertical space like \\[30pt] variable. I want to define the string between the brackets so that it is variable like 20pt or 1.5cm. Thus I would be able to define ...
1
vote
1answer
69 views

Date translated to Chinese

The English dates are strings like 1 January 2016. To translated them in Chinese, I use the following way with the help of Date Calculations. \usepackage{advdate,xparse} \ExplSyntaxOn \...
2
votes
0answers
57 views

Ignore special characters in \newcommand argument to generate section labels?

I am editing a rather large document and have replaced \section, \subsection etc with \newcommand macros that include \section etc but also spacing and other commands. I am trying to get it to ...
0
votes
0answers
58 views

ordinals for a new language

In this post nested \ifnum commands ordinal number naming for Georgian for biblatex. This works fine.I have defined alphabetic numbering for \renewcommand{\thesomecounter}{\anbani{somecounter}} for ...
3
votes
2answers
42 views

How to process only tokens containing a lower case letter?

The goal is to have a macro with single argument, that looks at all tokens in turn and if it sees a lower-case letter it is wrapped in \texttt{<token>}. All other tokens are passed through ...
0
votes
1answer
35 views

xparse: missing space after document command expansion [duplicate]

I'm having a problem with the below code. It's the smallest I could make the example. I'm working on a document with an index of persons, and have for this purpose created a command for each person. ...
7
votes
1answer
137 views

LaTeX newcommand with a variable number of arguments

I'm trying to create a new command in LaTeX that will let me do \begin{bmatrix}1\\2\\3\end{bmatrix} Like this: \m{1\\2\\3} I can make two functions, one for the begin and one for the end ...
2
votes
2answers
73 views

Combining \chapter command and \newcommand

I attach my MWE: \documentclass[12pt, a4paper]{book} \usepackage[utf8]{inputenc} \newcommand{\upper}[1]{\expandafter\MakeUppercase\expandafter{#1}} \begin{document} \chapter{\upper{Foo bar}} \end{...
1
vote
2answers
121 views

Define a new command in a `declarative way"

There are commands that look like pressing a button in MS Word(I have Windows...). For example \textbf{small bold text} compared with {\bf lengthly bold text } My question is : Is it posible to ...
0
votes
1answer
48 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
65 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
159 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
85 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
29 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
93 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}$}$} \newcommand{\beqF}[...
12
votes
4answers
293 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
221 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
75 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
140 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
93 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
193 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 #1\...
3
votes
1answer
43 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
51 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
107 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 $\newcommand{\...
3
votes
2answers
162 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
229 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 ae@#1@#...
5
votes
2answers
177 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
64 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
69 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} & a=a_{max}...
2
votes
1answer
43 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}% \setunit*{\addcomma\...
19
votes
4answers
2k 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
138 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
86 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: \newcommand{\...
2
votes
1answer
45 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
88 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}{} \newcommand{...
2
votes
1answer
51 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
114 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
33 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
105 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
207 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 ...