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

13
votes
3answers
968 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
252 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 ...
9
votes
3answers
535 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 ...
8
votes
4answers
1k views

Control command arguments

Can I define a command that takes an argument but does not eval the argument?
21
votes
2answers
3k views

How do I split a string?

I need to split a string into one or more substrings. I know that I could use the xstring package, but I'd like to do it using only inbuilt TeX/LaTeX commands. So, if I say \def\MyTeXKnowledge{Not ...
17
votes
2answers
217 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
3k 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
726 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 ...
13
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, ...
12
votes
2answers
1k 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] ...
9
votes
2answers
119 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
385 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
2answers
479 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 ...
6
votes
1answer
717 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
3answers
253 views

Looking for an \ignorespacesandpars

Is there an analogue of \ignorespaces which will also ignore the following \pars?
3
votes
1answer
125 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
321 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 ...
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 ...
13
votes
4answers
262 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
709 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.
12
votes
7answers
967 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 ...
7
votes
2answers
237 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 ...
6
votes
2answers
426 views

\makeatletter explained

I am using the following code in my beamer document to make the frame title's appear in the table of contents: \documentclass{beamer} \usetheme{default} \usepackage{bookmark} \usepackage{etoolbox} ...
6
votes
1answer
382 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 ...
4
votes
3answers
386 views

How do I “unprotect” an argument?

I'm having trouble with an argument that I need to "protect" (a concept I don't completely grasp‡) in order to avoid errors. When I write \command{\argument} I get an error; but when I try to ...
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 ...
2
votes
2answers
453 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
124 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 ...
26
votes
9answers
666 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 ...
21
votes
2answers
630 views

Stripping the pt from a dimension

LaTeX defines in ltfssbas.dtx a macro called \strip@pt (at line [246]) which strips the pt part from a dimension returned by \the\dimension. The definition is shown as a minimal working example below: ...
16
votes
2answers
220 views

Duplicating Environments

When I want to globally modify a command in my document, I will often use a duplicated version of the original in the stencil, with the help of the \let macro. For example, if I wanted to do ...
15
votes
4answers
463 views

How does one remove material from a token list?

This is a follow-up question to How does one append material to a token list? The macros \prependto and \appendto work nicely to add content to token lists. How would one go about creating macros ...
14
votes
1answer
431 views

choosing macro names so as to avoid namespace conflicts

I wish to choose names for macros in a manner that is least likely to conflict with names of other macros (including macros in packages that are not included in a document). Therefore, simply ...
13
votes
2answers
337 views

What does the command \@dblarg in a class?

In the definition of a command appears the declaration of \@dblarg, as follows: \def\title{\@dblarg\CJ@title}. What exactly does \@dblarg do?
12
votes
3answers
577 views

How to check if the value of a parameter is a number?

I have a command with a parameter. I want to check if its value is a positive number and perform actions based on that. \newcommand{\mycommand}[1]{ \ifnum#1>0% %some actions \fi } ...
12
votes
1answer
548 views

How do I create a macro which reads the content of a file when the macro is defined?

I am trying to do something like: \newcommand{\sometext}{\input{somefile.txt}} This works, but requires inputting the file every time the macro is used in the document. I would like to know a way ...
10
votes
6answers
752 views

How do I expand a macro into a tabular head?

I would like to be able to define a macro that can be used in the tabular definition. How can I do this? This does not work: \documentclass{article} \begin{document} \gdef\buildtabularhead{|||} ...
9
votes
6answers
631 views

Is there a '\ReallyDontExpandUntilTheLastMinute' command?

There's a couple of things I want to be able to do that are quite similar and basically involve keeping back a macro expansion until the last minute. Possibly the simplest example is that I have a ...
8
votes
2answers
704 views

“TeX capacity exceeded” because of a couple of raiseboxes in a \section?

In a package, I have the following command defined: \newcommand\fkm{ \ensuremath{\mathrm{ \raisebox{-0.1ex}{\rotatebox{22}{f}}\! \raisebox{0.2ex}{\rotatebox{-15} {k}}\! ...
6
votes
3answers
986 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 ...
6
votes
2answers
796 views

Repeating a block of text until it fills a page

Might I please have some help with writing a loop that repeats a block of text as many times as there is remaining space for it on the page? I would like to produce an notebook in TeX which is ...
5
votes
1answer
577 views

Adding the word “Chap” before the chapters numbers in the TOC

I'm using the book class and I need to add the word "Chap" before the chapters numbers in the TOC. Please keep in mind that the "Chap" should only appear before my chapters numbers, not before starred ...
4
votes
2answers
619 views

Iterating through comma-separated arguments

I've looked all over and can't seem to find a succinct answer to this question. Is it possible (and if so, how) to create a command that will iterate through its `arguments' of comma-separated values ...
4
votes
1answer
402 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 ...
4
votes
1answer
397 views

How to adjust macro to respect current \linewidth?

I'm having issues with text going past the end of the specified \textwidth. I posted this question about why text was being placed beyond the specified line width. The MWE provided there produced ...
3
votes
2answers
71 views

Why linebreaks break the line height within certain environments with size-changing macros?

Why linebreaks break the line height within certain environments with size-changing macros? I'm trying to understand what's the difference between these three approaches: \newenvironment between {} ...
2
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 ...
59
votes
1answer
2k views

A LaTeX log analyzer application (visualizing TeX expansion)

Consider the following MWE, test.tex: \documentclass[12pt]{article} \begin{document} \tracingassigns=1 \tracingmacros=1 \def\aaa{something} \def\bbb{else \aaa, else} \edef\ccc{third \bbb, level} ...
35
votes
2answers
956 views

List of higher-level LaTeX commands corresponding to TeX commands

Since LaTeX is a format built on top of TeX, it surely has several high level abstractions that perform similarly to TeX commands, with some added error-handling functionality, for example. I always ...