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

29
votes
1answer
8k views

What is the difference between \vskip and \vspace?

I found myself writing: \vspace 1 \baselineskip and then when not compiling changing without thinking to: \vskip 1 \baselineskip but what is the difference? Perhaps knowing this will make me ...
19
votes
5answers
1k views

How does one append material to a token list?

Several times, the floatrow package uses \newtoks which (according to this website) means that a token register is allocated. An example code snippet is ...
22
votes
4answers
4k views

Repeat command n times?

Is it possible to define a command, which repeats the following command n-times? Call it for example \Repeat, then \Repeat[4] \command{...} should be equivalent to \command{...} \command{...} ...
10
votes
2answers
478 views

create a framed environment for a margin note

What am trying to achieve is the following: Of course, if this can be done so that there is a switch between even and odd pages. Currently I am only interested in the not appearing on the LHS ...
24
votes
4answers
2k views

On testing two fully expanded character strings for equality

I know three macros that test two fully expanded character strings for equality: \ifthenelse{\equal{<op1>}{<op2>}}{<true>}{<false>} (ifthen package) ...
16
votes
3answers
341 views

Print 'system information' in LaTeX doc

I've used TeX quite a bit before but am getting back into it at the moment. I want to print a document details page with info such as: Compiled on: Compiled by: OS version: LaTeX version: ...
15
votes
2answers
2k views

How to create new table environment

I am working on a book that has many many such tables. Is there a way to create shortcut for the code shown below. I want to make table caption a variable, because in the MWE shown below except ...
8
votes
1answer
759 views

Problem with environment expansion and the Tikz external library.

I've created my own environment mytikz, which basically looks like this (full MWE): \documentclass[a4paper]{article} \usepackage{tikz} \usetikzlibrary{external} \newenvironment{mytikz}{%begin code ...
30
votes
2answers
9k views

newcommand vs. DeclareMathOperator

As far as I understand, whatever can be done using DeclareMathOperator can also be achieved using newcommand, but not the other way around. If this is the case, what are the circumstances where ...
27
votes
3answers
1k views

Defining a new function with argument in LaTeX environment

I want to define a function in a LaTeX document. More precisely, I want to define a function, say \ang{x}, where x is any input, such that the output is \rangle x \langle. Is there a way to go about ...
25
votes
1answer
491 views

Is there a \die command?

Is there a command that generates the error or warning of my choice? I'm planning to put it in an \ifthenelse, so it can't be a syntax error.
24
votes
2answers
711 views

Arguments for TikZ style

Motivation To put arrows inside of a TikZ path I have defined myself a TikZ style arrow inside. To make it even more portable I want it to take arguments like this \draw[arrow inside={pos = 0.1, end ...
20
votes
3answers
1k views

Why does TeX remove braces around delimited arguments?

On pp. 203–204 of the TeXbook, Knuth describes how TeX absorbs macros' arguments: delimited go until the first appearance of the delimiter, and undelimited go until the next token, in both cases ...
17
votes
2answers
455 views

Selecting random elements from a comma separated list

I would like to have a command (either user-defined, or from a package, or whatever) that has the basic form: \selectNrandom{N}{list, of, comma, separated, elements}{code to execute} which will ...
14
votes
4answers
579 views

Create fill-in-the-blank version of a document with ability to toggle blanks on and off

I am preparing some lecture notes/slides and would like to efficiently create two versions of the output: a complete version for myself, and a version for my students with certain text replaced with ...
10
votes
3answers
592 views

Censor text spanning multiple lines

I'd like to censor or hide some text while replacing it with the appropriate amount of white-space. The replacement text cannot be searchable. The text to be hidden usually exists in the LR mode. The ...
9
votes
1answer
751 views

Highlighting line ranges in a lstlisting: partial solution, but expansion issues

In my quest for a better solution for How to change appearance of a particular line when using \lstincludelisting, I came across the linebackground= option Martin Scharrer added to the listings ...
16
votes
3answers
4k views

\DeclareMathOperator won't take arguments

I'd like to define a family of math operators that have the same superscript, but different subscripts. My first attempt was: \DeclareMathOperator{\Upd}[1]{U^M_{#1}} But the log tells me that: l.3 ...
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 ...
12
votes
1answer
259 views

\show with fewer lines?

I am writing some macros for general debugging purposes (See Yiannis' question). I am basically expanding a given input step by step, and printing the result to the terminal and log. In order for this ...
8
votes
4answers
1k views

Control command arguments

Can I define a command that takes an argument but does not eval the argument?
7
votes
2answers
526 views

Where can I find an online manual for low-level LaTeX commands?

Is there an online manual for low-level LaTeX commands I can download? I am looking for something which would have, for example: \newif\ifportrait \newif\ifcustomsize \newif\ifdebug \makeatletter ...
20
votes
2answers
3k views

What are the differences between \newdimen, \newskip and \newlength?

What are the differences between \newdimen, \newskip, and\newlength? When should I use each of them? Please give me a non-trivial example for each case.
17
votes
2answers
232 views

Can I turn a collection of optional parameters into a macro?

I currently have several environments from mdframed that have a large number of options that are shared between them. The situation looks like \newmdtheoremenv[options0,options1]{env1}{Environment 1} ...
16
votes
3answers
2k views

How do magic \dots work in amsmath?

The amsmath package redefines the \dots command so that it "guesses" the correct height of the dots with respect to its context. For example $x, \dots, y$ will produce three lowered dots, aligned ...
14
votes
3answers
755 views

\def taking rest of the line as argument

I know how to define a macro that will take the rest of the paragraph as parameter. Simply write \def\a#1\par{\textbf{#1}}. But, how do I write a macro whose argument will extend to the end of the ...
14
votes
1answer
2k views

Abbreviations and spacing

I'm sure this is a pretty standard questions that's been asked (and answered!) a hundered times before, so apologies for boring people. In LaTeX, I'd like to write a macro for abbreviations, such as, ...
13
votes
2answers
2k 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] ...
13
votes
7answers
985 views

How to get the string with \

Apologized for my unclear description. I wish I could explain my problem more clearly. In document, I wish I can just write something as "how to use \cmd \mbox in xxx" or "what is \cmd minipage ...
12
votes
1answer
930 views

Nesting command definitions more than two levels

How do you access macro arguments if the macros are nested by more than two levels? To explain it in more detail: Creating a new command in another command (nesting command definitions), it is ...
12
votes
2answers
829 views

Minimal \protected@edef example

I recently came across \protected@edef in the/a LaTeX2e source. Can anyone give me a minimal or simple example, where I need this? I know this has to do with fragile commands/robustness, but I am ...
9
votes
2answers
123 views

How do you peer into the definition of a robust command?

I know that, whenever I want to see how some control sequence, say \mycontrolsequence, is defined, I can use \show\mycontrolsequence then compile my code and look up the .log file. However, robust ...
9
votes
1answer
403 views

Alignments by means of the tikzmark macro

This is a follow up of my previous question Issues and potentiality of the tikzmark macro: dynamic box adaptation. I thought should have been better to ask two questions although they are related to ...
7
votes
1answer
1k views

How can one pass the contents of a LaTeX environment to a macro?

I'm working on an exam document class where the user enters in questions something like this: \multiplechoice{Question} {Answer #1} {Answer #2} {Answer #3} {Answer #4} {Correct answer} {Explanation} ...
6
votes
1answer
789 views

Using \leftroot{}, \uproot{} with closed square root symbol

As mentioned in this answer to Nice-looking p-th roots the amsmath package provides \leftroot{} and \uproot{} which allow you to move the position of the root to the left, and up in small increments. ...
6
votes
1answer
415 views

How to expand values stored in a token defined by newtoks

In this project, the directory structure and file names are based on three parameters, with there being one exception to both. Directory Path: \GetTexFilePath{}{}{} The directory path is based on ...
3
votes
1answer
135 views

Mark portions of text without affecting spacing

I would like to mark portions of my text that requires special attention during the review process. This marking won't be in the final document, so would like to be able to add these marks without ...
2
votes
1answer
359 views

Command that gobbles all following empty lines

One distinction between knitr and Sweave is that the former forcibly inserts two empty lines in the generated TeX source for chunks that do not do any output. I'm not sure if this issue is a bug or a ...
26
votes
9answers
702 views

When is it appropriate to use \outer?

\outer is a strange beast. Any control sequence declared \outer cannot be used as either the parameter text or replacement text of a macro, at least if the control sequence is declared \outer at the ...
18
votes
1answer
246 views

Defining multiple shorthands quickly

Most of the bloated preambles I see have dozens of lines like \newcommand{\Acal}{\mathcal{A}} \newcommand{\Bcal}{\mathcal{B}} %... \newcommand{\Gcal}{\mathcal{G}} While I can easily code a macro to ...
13
votes
4answers
277 views

What are the consideration when choosing either newcommand or newenvironment?

The first time I learnt LaTeX, I thought \newcommand properly fits for inline mode and \newenvironment for displayed mode. Later I noticed it is not correct. So the question is What is the rule of ...
12
votes
3answers
726 views

Why don't I get any space after \thepage?

The code \thepage of yields the output 3of. I can fix it by writing \thepage~of, but what causes this in the first place? I can't imagine when it would be useful.
7
votes
2answers
246 views

Emulate a “tuple” data structure (when you are free to choose the syntax)

How can a "tuple" data structure be implemented in LaTeX? The idea is to store several elements (possibly a predefined number) in one macro and then be able to extract each of these elements by index ...
7
votes
3answers
1k views

LaTeX command with optional arguments

While writing lecture notes from statistical physics I found out, that I am often writing very similar long LaTeX sequences like \frac{\partial }{\partial <foo>} \frac{\partial ...
7
votes
3answers
1k views

Macro for figure position?

Why is the following minimal example not working? I.e., what do I need to do, in order to define the float placement specifier of a figure within a macro? (I know that I should use \newcommand, but ...
4
votes
1answer
332 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
2answers
2k views

Incomplete \iffalse using pgfmath naming a TikZ node

In trying answer Is it possible to use a macro to name a TikZ node?, I attempted to use the solution provided at pgfmath expansion - call a command from within a pgfmath environment, but this yielded ...
3
votes
5answers
2k views

Arguments of custom commands as comma separated list?

Consider the follwing command: \newcommand{\vektor}[3]{\left(\negthinspace\begin{smallmatrix}#1\\#2\\#3 \end{rsmallmatrix} \right)} I can use it like $\vektor{1}{2}{3}$ Now my question is ...
2
votes
2answers
483 views

Making more easy the itemized of item with tabulation system

Actually, isn’t not really a question. (Since my examinations get close, I don't really have the time to search for a solution to my problems.) Rather than using the common \item, I'd like to use ...
2
votes
2answers
128 views

Automatically Adding Potentially Referenced Macros From Auxillary File

In this question someone asked if there was any way to eliminate user defined macros from a TeX document and replace them with the appropriate primitives. The answer seemed to be that while some ...