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

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
1k 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
816 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
130 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
246 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
260 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
214 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
607 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
119 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
117 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
265 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
109 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
148 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
194 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 ...
13
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
279 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
905 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
603 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
639 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
502 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
295 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
302 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
707 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
560 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
107 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 ...
10
votes
2answers
169 views

How do I prevent a command from being invoked by a user while not disabling it?

Let's say I'm working on a LaTeX document collaboratively with someone else. I have defined a bunch of command aliases (such as \true for \top and \false for \bot); their precise purpose doesn't ...
13
votes
3answers
427 views

Making a “For Loop”

I am trying to make a "for loop" that will iterate the variable reaches 1. However, none of the "for loops" I have found in the Internet works. These files will be distributed to other people and ...
1
vote
2answers
93 views

Defining a macro with if statements [duplicate]

Possible Duplicate: Piecewise defined function in tikz or tkz-fct I wish to write a macro that gets a number x. If x is smaller than 1, it should return x, otherwise, it returns x^2. I need ...
11
votes
5answers
319 views

Is it possible to call a latex macro at the command line in order to return a string, not create a document?

I'm curious as to whether there is a way to pass a small amount of LaTeX code to a compiler at the command line and return the string corresponding to the value of a variable or length. For instance ...
13
votes
2answers
306 views

TeX Parameter Processing imitating key-value pairs

I am thoroughly confused by this answer to How to generate n points on a circumference and connect all of them while having constraints on the image size as I don't understand how the parameter ...
25
votes
3answers
819 views

@tempdima, reserved@a, @tempcnta, what else?

I'm aware that some "temporary" LaTeX dimensions etc. exist. I would, however, like to know all of them. I know \reserved@a (macro), \@tempdima (dimension) and \@tempcnta (counter).
10
votes
3answers
191 views

Using \@ifnextchar to define a macro for “ante meridiem” time

I want to create a macro for times of days, as follows: \newcommand{\pmtime}{a.m.\xspace} The problem is that LaTeX thinks that the last period in a.m. denotes the end of a sentence, hence the ...
5
votes
1answer
245 views

problem renaming command in SIunits

I've developed a package in which I want to define a command \power, but that name is taken by a command in the SIunits package (which my package uses). I initially named my command \powr but decided ...
44
votes
1answer
608 views

When to use \LetLtxMacro?

Frequently I see users redefine macros using (for example) \let\oldmacro\macro% Store \macro in \oldmacro \renewcommand{\macro}{% % ...redefined \macro \oldmacro% } and other times they use ...
7
votes
1answer
113 views

Can I detect whether my macro is being used inside a subscript or superscript?

I defined this macro: \newcommand{\foldeq}[1]{\sim_{#1}} Later on, I noticed that when it's used inside a subscript, it looks a little bit hard to tell whether it's $\sim f$ or $\sim_f$. ($\sim f$ ...
4
votes
0answers
63 views

Should I put the name of a new command in braces? [duplicate]

Possible Duplicate: Why do people use unnecessary braces? In so far as I know, the open and close braces around the command name for \newcommand{\commandname}{...} versus ...
32
votes
3answers
1k views

Removing the spaces between words

Is there any way to remove spaces from in between the words in a text? Something like \RemoveSpaces{This is my sentence.} which will be converted to Thisismysentence.