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

10
votes
3answers
11k views

Redefining sectioning commands

I'm trying to redefine the \subsubsection of the report class to behave like \paragraph and not have a linebreak after the title. It's closely related to this question but I have no idea how to ...
9
votes
3answers
859 views

How can I redefine the \verb|…| command?

I'd like to redefine the \verb|...| command so that it had a light-gray background and a little bit darker border around it, and a little bit of padding to make this background "box" noticable. Anyone ...
10
votes
1answer
3k views

How to define a macro with parameters inside a beamer frame

To ease the typesetting of nontrivial beamer frames I often employ local helper macros. This is not too easy in beamer, as defining a macro with parameters (e.g., \def\myfmt#1{\emph{#1}}) between \...
3
votes
1answer
592 views

\rule doesn't work inside an \xdef command

This code: \documentclass{article} \begin{document} \def\a{} \newcounter{mycounter} \def\b#1{ \def\p{#1} \ifnum\value{mycounter}=0 \long\xdef\a{\a\rule{3mm}{3mm}\par #1} ...
8
votes
1answer
3k views

Is there a LaTeX/TeX preprocessor/inliner that replaces only selected macros with their definitions?

I have the following situation: Like most LaTeX users that write much, I have my own header files where the packages I use normally are required and the macros I use often are defined. So if I write ...
16
votes
3answers
2k views

Expand after all that stuff?

Often I find myself in the need of expanding some macro, whose contents should be given as an argument to another command. The usual solution is to invoke some \expandafter concoctions to somehow ...
5
votes
2answers
325 views

Why does enumitem need the macro to exist already?

I'm using pgf and enumitem to define a hexadecimal enumeration scheme as follows: \documentclass{article} \usepackage{pgf,enumitem} \makeatletter \newcommand*{\Hex}[1]{% \expandafter\@Hex\csname ...
5
votes
1answer
953 views

How to disable the TeX primitive $$?

I would like to disable the LaTeX$$ command (since I wrote things like $equation1$$equation2$ for some reasons and I cannot merge the two equations) Is it feasible? Is there a command to "remove" a ...
29
votes
4answers
3k views

Can I have a flexible partial derivative macro?

I was thinking about writing a partial derivative macro that has a similar syntax to the Mathematica D function. (example) The syntax could be like this: \D{f}{x} expands to \frac{\partial f}{\...
8
votes
3answers
239 views

How do define a command that takes parameters like \verb?

I would like to define a newcommand that takes one required parameter, but instead of passing it in using {...} as normal, to use a different parameter delineator like the \verb command does (e.g., \...
13
votes
4answers
420 views

\let and sneaky redefinitions that are wrappers for the original macro: is there a similar thing for environments?

Let's say I am using some macro \foo that almost does what I want, but I actually want to add space either side of the output of \foo. I can do the following: \let\tempfoo\foo \renewcommand\foo{\...
11
votes
2answers
995 views

Has anyone written a script to resolve a certain set macros?

Here's the idea: Like most people, I use a lot of custom macros that are often nothing more than shortened versions of commands that I use often. This is great for me, but makes the latex cryptic for ...
9
votes
4answers
289 views

Does macros get applied to the source code before compilation?

I wonder if this is true. The latex compiler first run though the document, and search for all the macro declarations. the compiler then go though the document, apply each macro as a string ...
2
votes
1answer
846 views

How to put the text and symbols “Italic” quickly?

The following is my original texts. \textbf{The Interior Dirichlet Problem:} Given $f\in C(S)$, find $u\in C(\overline{\Omega})$ such that $u$ is harmonic on $\Omega$ and $u=f$ on $S$. Instead of ...
54
votes
2answers
70k views

How to color math symbols?

One can use the command such as \textcolor[rgb]{1.00,0.00,0.00}{boundary} to color the word "boundary" in a document. Here is my question: How to color the math symbols in $$? For example, can one ...
26
votes
4answers
815 views

Why isn't a command defined by \newcommand with an optional argument expandable?

In trying to fix a problem with a nested macro repeatedly calling itself, I tried expanding the inner call before passing it as an argument to the outer one. This failed miserably because the macro ...
5
votes
1answer
326 views

Nested macro envocation - syntax error?

I get a Argument of \\drs has an extra }. when I try to process the following: \documentclass{article} \usepackage{tikz} \newcommand{\drs}[2][lambda/.initial={}]{% \{% {\pgfkeys{/drs/.cd, #1, ...
2
votes
1answer
654 views

Macro for tabbing with complex line breaks (or similar environment)

I have a complicated transcription with mid-line aligned text. I've been using tabbing to do it automatically, but it obviously doesn't do line breaks. I want to write a macro (unless something ...
14
votes
5answers
955 views

Test if token is a control sequence

Sometimes more complex (La)TeX macros test the next input token and branch dependent on its type. I'm aware how to test for catcodes and character codes, but sometimes I like to handle control ...
3
votes
1answer
3k views

Implementing “aside” environment for explaining details of calculation

I would like to have parts of the text set in smaller time with different indentation, and separated from the rest of the text visually (e.g. by horizontal rules). I would like to use this to set off ...
3
votes
1answer
593 views

Placing a list of nodes in TikZ

I would like to define a macro, which would take a list of node definitions, like this \mymacro[boxes={{\node[rectangle] {foo};}, {\node[rectangle] {bar};}, {\node[...
4
votes
1answer
1k views

Execute own command in listing

I create an own command like this \newcommand{\hostname}{this.is.my.hostname} Now I want to use this command in normal text (no problem) and inside of a listing Nun kann die Funktionsweise ...
34
votes
4answers
2k views

What do \@firstoftwo and \@secondoftwo do?

The LaTeX kernel uses these two all over the place. For example, apparently the correct way of defining something like \ifeq{\macro 1}{\macro 2}{true}{false} is (note Martin's response: each case ...
7
votes
3answers
324 views

How to define a macro containing a tabbed line (\+…\cr)?

\def\test{\+test\cr} \test \vfill \eject The above gives error: ... Runaway definition? -> ! Forbidden control sequence found while scanning definition of \test. ...
9
votes
3answers
764 views

\expandafter, \csname issue related to test for macro being defined

Just when I think I starting to understand \expandafter I run into this problem where I am trying to test if \ConditionG, \ConditionH, etc are defined in a loop. I tried all the combinations I could ...
6
votes
1answer
899 views

latex flashcard problem

I use a package to make flashcards which has the formatting \card{#1}{#2}, where #1 and #2 represent the front and back side. The package works great. I like to block out text, so I have made ...
15
votes
2answers
2k views

Using counters or macros

Should I use counters or macros to store numerical data? Is there a limitation on a number of counters that can be used at the same time or other considerations? I would also like to perform simple ...
15
votes
2answers
3k views

Define an “escape underscore” environment

I am writing a text document in LaTeX where I need a lot a words with underscores: foo_bar_1, more_bar_2_long_expression_3. I know about the underscore package, but for some reason the [strings] ...
3
votes
4answers
265 views

Can (La)TeX compare the time stamps of two external files?

Scenario I have a bunch of standalone PSTricks files. Each of those files can be compiled by latex-dvips-ps2pdf-pdfcrop-pdftops to produce a PDF image. I have made a batch file to do latex-dvips-...
2
votes
1answer
593 views

Scope of catcode change for escape character ?

In the following macro, I change the category code for the escape character (\) to "other" (12): \def\xxA{\begingroup \catcode`\\ = 12 \gdef\xxB ##1z{\tt ##1\endgroup} \xxB} How the heck does ...
11
votes
2answers
1k views

Using pgfkeys as an argument to a macro

I would like to use pgfkeys in a macro but find the documentation a bit hard to get started with. The following code should illustrate the problem I am trying to solve: \documentclass{article} \...
25
votes
3answers
813 views

Does \newenvironment have a \provideenvironment cousin, as \newcommand has \providecommand?

To avoid the problem of having to decide whether to use \newcommand or \renewcommand, LaTeX has the option of \providecommand. Is there something corresponding to this for environments? I'd like to ...
17
votes
2answers
3k views

Difference between \relax and % for ending a line

when would I use one over the other? Are they the same?
30
votes
4answers
5k views

How to undo a \def (i.e., Need a \undef capability)

I thought the way to undo a \def was to define it to \relax, but that does not appear to work. Also, am not sure why this produces no output if I try to use \def instead of \let in my attempt to do ...
20
votes
1answer
2k views

How to test if a directory exists

The command \IfFileExists works great to test is a file exists. Is there an equivalent to test if a directory exists? \IfFileExists does not seem to work for directories. \documentclass{article} \...
24
votes
1answer
999 views

Tex Capacity Exceeded (if remove % after use of macro)

I don't understand why this simple (but lengthy) iteration results in TeX capacity exceeded, sorry [main memory size=3000000], if I remove the last % following the call to \DoNothing. I thought that a ...
9
votes
2answers
2k views

Signature in preface

I would like to make a signature field in the preface which looks like this: City(#1) \today ___________________ ______________________ ...
2
votes
2answers
403 views

Combine expandafter, setlength, csname and define@key

I try do define a command \tes@define@key@length. Everything work but when I use the following line: \expandafter\setlength\csname test@#1@length\endcsname{\csname testl@#1\endcsname}% I get an ...
6
votes
3answers
1k views

Removing a backslash “\” when passing arguments to newcommand

Consider the following minimal example: \documentclass{article} \usepackage{glossaries} \makeglossaries \newcommand{\NewS}[4]{ % Q1: How can I use argument #1 without the backslash in the ...
21
votes
2answers
716 views

Which is better: a dimension or a macro?

When messing around with TikZ/PGF then I frequently find myself wanting to store a length for later use. By "length" here, I mean the word in its non-TeX meaning. As I'm doing stuff in TikZ/PGF then ...
15
votes
2answers
883 views

Equivalent of \show to display the LaTeX code in the document

I am looking for a command similar to show, but want the output in the document itself. All the examples I have found produce the output in the terminal, not the document. So, I want to replace the ...
24
votes
6answers
5k views

“For loop” in newcommand

I have this command \newcommand{\pdfappendix}[1]{ \includegraphics[scale=0.6]{pdf/#1.pdf} } It works well when I have 1 page pdf but is not including the other pages. Now I decided to change ...
8
votes
3answers
2k views

How to make a newcommand producing a matrix

I would like to do something like this \newcommand{\pmat}[1][2][3][4]{\begin{pmatrix} #1 & #2 \\ #3 & #4\end{pmatrix}} But this produces the error ERROR: LaTeX Error: Missing \begin{...
6
votes
1answer
2k views

newcommand containing tikz node

I am using tikz-qtree to draw a binary tree. As I need to have them labeled I wanted to ues the following macro which work in ordinary tikz: \newcommand{\A}[1]{\node(a#1){Activity #1};} However, ...
15
votes
2answers
550 views

How to detect whether a command enters math mode behind the scene?

Commenting out the %\usepackage{hyperref} in the following code snippet will produce some warnings. Using \usepackage{hyperref} and \section{} to detect whether a command enters math mode may not be ...
4
votes
1answer
597 views

pgfmath expansion - call a command from within a pgfmath environment

I am trying to define a newcommand using pgfmath. This commands calls a previously defined command but it fails. It propably has to do something with expansion. I've read this question about ...
2
votes
1answer
864 views

ctable width of column, \tnote and pos.

Have two problems regarding ctable. Have multiple ctables and would like the first column in the tables to have a fixed width (also the tables to have the same total width)? When I add a \tnote[]{} ...
2
votes
1answer
153 views

Storing environment arguments

Consider this example: \documentclass{article} \newcommand{\baz}{} \newenvironment{foo}[1]{#1}{\makeatletter\g@addto@macro\baz{#1}\makeatother} \begin{document} \begin{foo}{bar} \end{foo} \end{...
1
vote
2answers
298 views

newcommand for hvfloat

Using the hvfloat package: \documentclass[pdftex,10pt,b5paper,twoside]{report} \usepackage[showframe,lmargin=25mm,rmargin=25mm,tmargin=27mm,bmargin=30mm]{geometry} \usepackage[demo]{graphicx} \...
6
votes
2answers
5k views

Proper way to use \ensuremath to define a macro useable in and out of math mode

Based on this solution related to defining a macro I came up with this macro to help me define a macro that I can use either in or outside of math mode. The example as is functions as I want. However,...