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

17
votes
3answers
380 views

Always use \NewDocumentCommand instead of \newcommand?

Are compelling reasons to stick with \newcommand or should one always use \NewDocumentCommand instead, even when not using any of the additional features offered by xparse? In addition and more ...
4
votes
1answer
82 views

cool package derivative and eulervm \mathbold fails with 'Missing control sequence inserted.'

Compiling \documentclass{article} \usepackage{cool} \usepackage{eulervm} \begin{document} $\D{a}{T}$ $\pderiv{a}{T}$ $\mathbold{T}$ $\D{a}{\mathbold{T}}$ $\pderiv{a}{\mathbold{T}}$ ...
3
votes
1answer
145 views

How do I create the following macros?

I would like to define the following macros. \newcommand{\NC}{\ensuremath{\mathbf{NC}}} \newcommand{\NC}[1]{\ensuremath{\mathbf{NC^{#1}}}} But LaTeX complains that \NC is already defined. So, I ...
3
votes
2answers
114 views

Toggle visibility of solutions in LaTeX output for exams

So I have my own layout for my exams based on scrartcl and to prevent anomalies during some changes I want to have only one file per exam which holds both questions/excercises and solutions. Yet I ...
5
votes
2answers
62 views

passing current content of commands to a macro

I am sorry for this is probably a current question with a well known answer, but I was not able to google it out. I am trying to build a macro adding content step by step; at every step I need to ...
2
votes
1answer
52 views

Biblatex custom cite macro

I don't really understand how to use macros, but this would be a good way to learn. Currently, I simply use \cite, which prints Author, Year. When I have this in a sentence, I want the year to be in ...
8
votes
1answer
121 views

Which commands exist to define new commands?

Which commands are there that one can use to define new commands in (La)TeX? There are: \let, \def, \[re]newcommand[*], \DeclareRobustCommand[*], and ...? (And I've seen things like ...
8
votes
1answer
124 views

how to redefine \begin{align*} … \end{align*} to \begin{eqnarray*} … \end{eqnarray*}

Scientific word insists in generating displayed math using \begin{align*} ... \end{align*} and htlatex has a bug in that it does not generate bit mapped images in this case. The fix that I found ...
16
votes
4answers
403 views

Do starred commands eat up space after them?

Do starred commands eat up spaces after them, like unstarred ones do? That is, is \somecommand* nextword equivalent to \somecommand*nextword? And: Does it depend on the particular way a starred ...
7
votes
1answer
69 views

Is there any reason against changing the starredness of a command upon redefinition?

If an original definition of a command used \newcommand, is there an obligation for me to redefine it with \renewcommand instead of \renewcommand*? If an original definition of a command used ...
11
votes
2answers
107 views

Is there any reason to define a zero-argument macro using a starred defining command?

Is there any reason to define a 0-argument (read: zero-argument) macro with a starred command (\newcommand* instead of \newcommand or \DeclareRobustCommand* instead of \DeclareRobustCommand)? After ...
0
votes
0answers
64 views

True `macros' in (La)TeX [duplicate]

When using \newcommand and the like, LaTeX seems to create a new box for the content (I'm probably observing things wrong). For example, I have \newcommand{\p}[1]{\ensuremath{\left(#1\right)}} in my ...
0
votes
1answer
69 views

Expansion of single line vs multiple line gather

As described in Multiple split equations I want to create an equation environment that inserts aligned and lets me split equations with \n. The solution I found there is a bit hackish I guess, but ...
5
votes
3answers
148 views

\includegraphics optional argument not resolved if macro

\documentclass[a4paper,10pt,twoside]{book} \usepackage[demo]{graphicx} \begin{document} \newcommand{\scalefactor}{scale = 0.25} \begin{figure}[!ht] \centering %Next line does not work ...
4
votes
2answers
98 views

Line break (continuation) for commands (options, arguments)

How to do proper line breaking (continuation) for commands, i.e. their options and/or their arguments? For example, in order to transform this: \usepackage[top=1.0cm, bottom=1.0cm, left=1.0cm, ...
2
votes
1answer
62 views

How to put R code into a parameter of a newcommand?

I would like to put R code into a parameter of a newcommand in LaTeX. To do it, I make the following: %Define the newcommand: \newcommand\solution[1]{\sf #1} %Then, after the \begin{document}, I ...
7
votes
1answer
136 views

Generating code examples

I would like to make a table showing some custom commands that I have defined. It would be nice if I could do something like the following. \documentclass{article} ...
1
vote
1answer
64 views

Problem if csv list is stored in macro for later use with \forcsvlist

I need to store a csv list for later use in the end code part of an environment. Can somebody explain me what's going wrong in the following example? \documentclass{article} \usepackage{etoolbox} ...
16
votes
3answers
267 views

When is it better to use \par than \endgraf?

Just yesterday I had to patch a package file (changing the description to indicate that the file had changed) to replace some \par to \endgraf because the code had bad interactions with non-\long ...
5
votes
1answer
86 views

Underscore should not force mathmode in macro

When trying to color words in arabic (transliteration), LaTeX wants me to be in mathmode (Missing $ inserted.), as there is an underscore in the transliteration. This is of course completely wrong as ...
1
vote
0answers
121 views

Is there a \newcommand manager program?

I type my latex document with gedit. I use a lot of macro to facilitates typesettings. I put all of them just after the begin{document} tag. For a homework question says, I use at least 20 macros. For ...
10
votes
2answers
188 views

What does \relax do? [duplicate]

Possible Duplicate: How can I speed up LaTeX compilation? What is the difference between \relax and {}? The title suggest the question. On and off, I see macros here in TeX.SE and I see ...
5
votes
1answer
108 views

How to define macro containing TikZ \coordinate

I am trying to create a macro to calculate the center of a shape. Consider the following code: \documentclass{article} \usepackage{tikz} \usetikzlibrary{calc} \newcommand{\getcellcent}[4]{ ...
6
votes
3answers
126 views

How to define a new command for guillemets marks [duplicate]

Possible Duplicate: babel shorthand "| doesn’t work in macros I would like to define a new command for guillemets marks. I know how to obtain them in LaTeX and those I would like to ...
5
votes
1answer
215 views

force section and subsection to capital letters

hi Im trying to renew the section cmd to make all sections in capitals. i have tried stuff like \newcommand{\tmpsection}[1]{} \let\tmpsection=\section ...
6
votes
3answers
105 views

PGF keys error with key filter for keys containing \par

I am trying to use pgfkeys to store some text for use later. The end goal is to use a key filter to process options first and then apply them to text before it is stored. In the MWE below, if it try ...
1
vote
1answer
84 views

Automatic subscript command

I am working on a document that has a lot of subscripts. I am getting really tired typing the _. Is there a way to do the following: Everytime I want $v_1$, I just want to type in v1. Or b1 produces ...
2
votes
2answers
95 views

Error with \DeclareRobustCommand, \usepackage{hyperref,xcolor} and \usepackage{graphicx}

In order to tie capital letters with a capital hyphen, I created a command \DeclareRobustCommand{\capitalhyphen}{\raisebox{0.24ex}{\resizebox{0.4em}{\height}{-}}\kern-0.07em} which uses graphicx ...
10
votes
2answers
141 views

Flexible parenthesing command

I would like to create a smart parenthesing command without using the xparse package. \p(1) prints (1) \p[1] [1] \p{1} {1} \p(1|2) (1|2) I tried this code but it ...
4
votes
1answer
59 views

Create function for setting variable

I have been using LaTeX for some years now, but I've only recently noticed its scripting features. Although, I find it hard to grasp many of the concepts. For example, I want to have a command ...
1
vote
2answers
106 views

Regarding variable names and values of variables inside macros

I have to questions that I'd like to solve since I'm trying to build up a macro for my examination duties here. The first one is: is there a way to include numbers in the definition of variables? Say ...
5
votes
2answers
307 views

Shortcuts and/or user-defined shortcuts for math symbols in LaTeX?

I am very new to being able to use LaTeX to type up mathematical papers, and I just got my "system" set up. Currently I have installed TexWorks, and MikTex, and I have put together a 'hello world' ...
8
votes
1answer
70 views

Changing case of URL in \href argument

I would like to write a macro similar to the \href command from the hyperref package, but which takes a single argument. The URL is generated by making the argument lowercase. Here is a minimal ...
4
votes
1answer
103 views

Manipulating arguments in newcommand

I'd like to manipulate the arguments in \newcommand. More explicitly, I'd like something like that: \newcommand{\X}[1]{ #1+1 } And if I call \X{0}, I want it to return 1 and not 0+1. Thank you :-) ...
5
votes
2answers
134 views

Multiple split equations

I find myself again and again using a combination of the gather and aligned environments. So it would be nice to not have to write so much. In particular, it is often only clear after writing the ...
8
votes
3answers
117 views

Questions on macro writing in TeX to modify an existing style file: fancybox.sty

I've decided that I must become more adept at TeX if I'm to become proficient with LaTeX. While this is probably obvious to most readers who pass by, my ability to muddle through has hidden this small ...
2
votes
1answer
90 views

Passing name ending with number to \csname does not work [duplicate]

Possible Duplicate: macro names with special characters When I use \yyy defined bellow it does not print yyy, but if I use \xxx it prints xxx. How can I make \yyy work? \def\P1{yyy} ...
10
votes
1answer
153 views

How can a command take #1 as an argument?

I was wondering how some commands manage to take #1 as an argument when used, not when declared. For instance, biblatex's \DeclareFieldFormat can be used like this: \DeclareFieldFormat {postnote} ...
2
votes
1answer
59 views

Custom Command cannot use equation mode?

I have defined a new command below, but when ever I pass an equation into, it will not work. \newcommand{\defn}[1]{ {\textbf{Definition}}\\ \parbox{5.2in}{\begin{flushright} ...
2
votes
1answer
99 views

Define listings language using variable

I'm using the listings package to document excerpts from my programs. I have been creating new environments for the various programming languages and wondering whether there was a way to hack the ...
12
votes
3answers
154 views

Ignoring all but certain text

I'm wondering if there's a way to define a command so that, when a flag is specified, I can ignore everything but text within the tag. For instance, if I had ... This is a \dontignore{bird}. I ...
2
votes
2answers
92 views

Runaway argument error when creating a macro for code that works outside a macro

I'm certain my problem is due to my almost complete lack of understanding of LaTeX's expansion rules... I wrote some code, which uses the SageTeX package to keep track of a list of answers to ...
2
votes
1answer
122 views

wrapping inline long lines and adding background color

Objective I'm trying to achieve the following output. Here's the code I used to produce it. I had to hack it \begin{document} \begin{description} \item In ...
4
votes
1answer
88 views

How to define a command that returns its argument as a superscript?

How can I write the following code more concisely, without an ifcase statement? Please assume the command will only be called with integer arguments between 1 and 8, inclusive. Sorry for asking such a ...
6
votes
1answer
71 views

How to detect that some macro expands to empty string or spaces only?

I need to check several macros and do some actions only if their expansion is not empty nor space only. In pseudo code I would look like this \if\macroToBeTested \doSomething ...
6
votes
2answers
133 views

Is “conditionals” name of package?

In some package I have seen construct like this one: \if\blank{\myMacro}% %do something \else %do something else \fi I like it and I want to use it to test if call to a macro has empty result. ...
8
votes
1answer
82 views

A question about a macro definition errors

Given: \documentclass{minimal} \newcommand{\emrule}[1]{\rule[4pt]{#1em}{0.2pt}} \newcommand{\endash}{\emrule{.5}} \begin{document} 2000\endash2013 \end{document} I get: ! LaTeX Error: Command ...
6
votes
1answer
219 views

Difference between \newcommand and \pgfmathsetmacro used in TikZ \coordinate

Consider the following code: \documentclass{article} \usepackage{tikz} \begin{document} \begin{tikzpicture} \newcommand{\MA}{4} \pgfmathsetmacro{\MB}{4}; \coordinate (V11) at (0,0); ...
19
votes
7answers
444 views

How to create a command that automatically escapes curly braces?

How could I create a command that will automatically escape all curly braces within the current environment? For instance, I would like a command (or environment, I suppose) that allows me to write ...
14
votes
3answers
220 views

What is the difference between local and global in a TeX meaning?

In tikz declare function and babel french option it came to the question about the difference between local and global in a TeX meaning. In the liked question the babel shorthand ; should be ...

1 4 5 6 7 8 32