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

5
votes
2answers
371 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
195 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
133 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
392 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
89 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
219 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
274 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
171 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 ...
4
votes
1answer
340 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
113 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 ...
7
votes
1answer
187 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
150 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. ...
9
votes
1answer
169 views

A question about a macro definition error

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 ...
9
votes
1answer
2k 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
822 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
332 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 ...
7
votes
2answers
131 views

Using a required argument as a default for an optional one in \newcommand

I'd like to create a new subsection command with the same calling structure like the original one, but I have no idea on how to handle the case when the optional argument is omitted. Basically I want ...
1
vote
1answer
250 views

adding online profile pages to moderncv

I have been using moderncv and I was thinking of adding my stackoverflow and github profiles to my resume, unfortunately there doesn't seem any macros for that (is there?) I wasn't using ...
3
votes
1answer
267 views

tikz - Multiple nodes with same content

I would like to know how to place multiple nodes with same content in TikZ. I've made a macro for it, but I think that it could have a different approach. \usepackage{tikz} \usepackage{bm} ...
6
votes
1answer
217 views

“No room for a new \read” with writing a journal

I'm fairly new to TeX and learning as I go. I am trying to keep a journal in LaTeX. I'm using the solution provided at Using LaTeX to keep a diary . It's essentially a setup where each day's entry is ...
17
votes
4answers
614 views

How to define a command that bolds the first letter of each word in the input argument?

I want to define a command that takes a sentence, a word or several words as input and bolds the first letter of each word. I need this mostly for abbreviations and so far I have done it manually in ...
5
votes
3answers
120 views

Macro for putting a separator between inline list items

It's late, so I may not be thinking about this clearly enough, but I could have sworn that there exists a macro (possibly not part of a package, but just something that I picked up somewhere along the ...
2
votes
2answers
120 views

Why does defining a new command inside a framed block not work?

Why does the following 'minimal working example' work \documentclass[a4,german]{book} \usepackage{framed} \begin{document} \newcommand{\myText}{Bliblibli!} \begin{framed} Blabla \end{framed} ...
4
votes
3answers
268 views

How do I define a math mode formula with a caret ^ in LaTeX?

This question has two parts. First, is there a way to define a macro only for math mode? Second, how do I specifically get the following definition to work correctly? \def\fi{f^{-1}} One ...
5
votes
1answer
110 views

\IfSubStr does not work when used as parameter of another macro

It seem that if macro \IfSubStr from package xstring is used as parameter it is not expanded like other macros are. Here is minimal demonstration: \usepackage{xstring} \newcommand{\copyArg}[1]{#1} ...
5
votes
2answers
150 views

\uppercase does not work with \IfSubStr?

I'm using \IfSubStr macro of xstring package to decide if user given options contains some letter and if they do I take some actions. I want case independent test on whether user options contain ...
2
votes
1answer
195 views

Specify newcommand to provide default argument to existing command

I have an existing command, defined within a \newenvironment: \newcommand{\param}[3]{\textbf{##1} & \emph{##2} & ##3 \\ } That command on its own works fine. What I want to be able to do ...
11
votes
2answers
2k views

TikZ: Defining and reusing complex objects?

(How) Is it possible to save some complex TikZ objects for reusing them (in the same and in different pictures)? I know it's possible to define own styles, but I'm not sure if it's the right thing ...
14
votes
3answers
1k views

Macro for Declaring Variables in Class Files

I'm designing a new LaTeX class, and trying to write a convenient helper command for declaring new 'variables' for use in the class. Specifically, say I want to use a variable called \foo. I'd like ...
8
votes
3answers
244 views

Useful macro definitions

This question is related to Question: linebreak in macros, however it is not asking for the same information and I separated it out: In my documents, I make use of commands like the following: ...
9
votes
1answer
280 views

Macros and pgfmath within put in picture environment

I am trying to put some TikZ pictures into a Beamer slide to enhance readability. The position of the TikZ pictures on the slide will depend on how much text comes before. Since there will be many ...
10
votes
5answers
920 views

Is it possible to call external programs from LaTeX?

I'm trying to write very specific LaTeX package that does a lot of complex computation. It encloses some parts of text (or whatever else user wants to print) into boxes and then runs quite complex ...
4
votes
2answers
611 views

New command and the corresponding star counterpart with xparse

The following works as expected: \newcommand{\engl}[2]{#1 (en. \textsl{#2})\index{en-ro}{#2}} However, what I want to achieve would be a * version of it which only adds to the indices, without the ...
3
votes
1answer
652 views

How to use \newline in a macro?

I want to introduce \newline after the figure label instead of :. I am aware that caption package does this via \captionsetup. However, I would like to do it without it. I read from the memoir class ...
3
votes
1answer
510 views

Using “German” quotation marks inside \newcommand [duplicate]

Possible Duplicate: babel shorthand "| doesn’t work in macros I know there is a deeper non-understanding of LaTeX mechanics at work here, but I have no idea how to phrase my question ...
5
votes
1answer
299 views

Where should I define new command globally?

I'd like to define a command \alert{} by \newcommand{\alert}[1]{\textcolor{red}{#1}} in a way that I could use it on every new file. I was thinking to define it on some cls file (amsart for ...
3
votes
1answer
1k views

Issue with soul and nested macros

I'm using package soul to highlight text, for example with \hl{some text}. It works nicely in general, but when the text contains other macros, soul simply skips it. For example: \usepackage{soul} ...
8
votes
1answer
306 views

Why do we have something like “-3.5ex \@plus‎ -‎1ex \@minus‎ -‎.2ex” instead of a fixed value? [duplicate]

Possible Duplicate: What is glue stretching? In the book class, we have the following. ‎\newcommand\section{\@startsection {section}{1}{\z@}%‎ ‎{-3.5ex ...
2
votes
1answer
116 views

Tables as commands

I have to do a little work but I have to use frequently the same settings for a table and I put the following code \newcommand{\tab41}[4]{\begin{center} \begin{tabular}{|c|l||c|l||c|l||c|l|} \hline ...
7
votes
1answer
206 views

\ifmmode self-contradictory in amsmath (OK in just LaTeX)

File: \documentclass[11pt]{article} \usepackage{amsmath} \newcommand{\argghhh}{\relax\ifmmode\bar\else\expandafter\=\fi} \begin{document} $ \argghhh a $ \end{document} produces error (but ...
15
votes
3answers
714 views

Shortcuts for code in latex

I am tired of writing \frac{\partial something}{\partial something_else}. Can I automate it by defining some sort of shortcut to it, so that when I write \p(x)(y) it will transform to \frac{\partial ...
0
votes
3answers
579 views

trivlist list environment \item command

My document class uses paralist and redefines \begin{enumerate}[(a)][abc] etc... environments to issue \label for each \item, given a second option (e.g., \abc{a}) that becomes a 1-parameter macro ...
5
votes
1answer
108 views

New command doesn't work the same as in-line code

I have a feeling that this is a profoundly stupid question but I cannot seem to solve it myself. I am trying to write an own macro to create a boxed paragraph. The code works fine in-line but when I ...
1
vote
2answers
162 views

Macro to format text

Good morning, I have the following problem, I have a file with 8000 questions in the following format: COD: 7 ¿A qué número de revoluciones se alcanza la potencia máxima de un motor? A Al número de ...
11
votes
4answers
299 views

What if I use a \def name starting with “if”

Following this answer to Is it possible to use some sort of internationalization in LaTeX? I'm setting up my own dictionaries. When compiling the files I get this error: ! Use of \if doesn't match ...
3
votes
1answer
188 views

Include latex macros in eps/pdf images

Is it possible to have latex macros in eps (or some other format) images instead of using fixed text? I want to be able to change some variable names that are also used in figures.
1
vote
1answer
104 views

Numbering macros [duplicate]

Possible Duplicate: \newcommand name cannot include numbers, e.g., \Mycomand123 I'm trying something that I thought would be simple \def\test{Hello} \def\test2{Hello again} \test \test2 ...
2
votes
1answer
207 views

Re-insert equation by label

I read over the response given here: Is it possible to re-insert a LaTeX equation by label? which says such a thing is possible only with a macro. I would like to do this. I have a bajillion ...
2
votes
1answer
73 views

Pass the contents of an \input command to a macro

I am having some difficulty with the expansion of LaTeX. I would like to expand the contents of an \input command before passing them to macro, in a pattern similar to the following: \outer{\inner} ...
8
votes
1answer
103 views

Omitting arguments in macro expansion

Changing a simple TeX macro like \def\macro#1 #2{#1 #2} into \def\macro#1 #2{#1} alters the output of \macro Hello world surprisingly for me to Helloorld My expectation would have been to ...