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

15
votes
3answers
318 views

Parsing strings containing diacritical marks (macros?)

I apologize that this question may seem very much like several other recent ones I have asked (Parsing leading hardspaces, Parsing a \$ as part of an improved \getargs command). They are all related ...
13
votes
2answers
243 views

Search for most frequently occurring patterns in text (to replace them by macros)

Are there any ready available tools for searching the most frequently occurring text patterns (word combinations, phrases) in the text you work on, so to give ideas, which ones to replace by short ...
2
votes
1answer
231 views

Need help making a data table from \plot function in Tikz

I want to be able to generate a list of points from a plot in Tikz, with an adjustable interval and range for the x-values. So basically something like this: ++++++++++++++ + + + ^ ...
7
votes
1answer
343 views

Building a title block for a class

I am trying to build a class with a title block (using titling) such that the end user enters data into two fields. One variable is sopchaptertitle, and the other is sopchapternumber. I want to then ...
11
votes
3answers
526 views

Command with variable number of arguments to format menu sequences

I would like to define a command that accepts a variable number of arguments: \menu{foo} % would result in \emph{foo} \menu{foo}{bar} % would result in \emph{foo} $\to$ \emph{bar} ...
4
votes
2answers
276 views

Can I change the language the commands are written in to British English?

Hi basically I am a newbie to this software, just getting the hang of the basics but I found that all the commands are in american english. Is there something I can use, download or one of these ...
14
votes
2answers
1k views

TikZ coordinate calculations

I have very simple problem, and I also have a solution to the problem. But I am hoping for a better solution:) Consider the following code: \documentclass{article} \usepackage{tikz} ...
7
votes
2answers
267 views

An even more flexible derivative macro?

I am trying to expand the macro given in Can I have a flexible partial derivative macro? In particular, I would like to add a starred version that does not attempt to sum the exponents of the various ...
18
votes
2answers
1k views

Difference between \newbool and \newtoggle from etoolbox package

Paul Gaborit's answer to How to detect if option provided via \tikzset uses \newbool to define a new boolean \booltrue to set a boolean, and \ifbool to perform a conditional operation all from ...
3
votes
2answers
227 views

Maths expression in the coordinates of rput

I use \rput[B](1.5,4.1){\( 1 \)} to write a number at a specific place, now I would like to express an expression at the place of coordinates, for instance \rput[B](2+#1,4.1){\( 1 \)} where #1 is an ...
6
votes
1answer
148 views

listings package and latex3 variable

I'm trying to change a custom environment from a lot of optional parameters to a ;-separated list (using this answer as a template and writing its main functionality as a latex3 macro). The macro ...
2
votes
1answer
87 views

newcommand out of subsection

I would like to create a new command based on subsection behavior. Requirements are as follows: make a \newcommand support for alternative labels add \vspace{-.2in} after the label The reason ...
7
votes
3answers
181 views

\csname error in defining in loop

In following snippet I try to use TeX programming to define commands \Ab, \Bb, \Cb and so on. Strangely, I get Missing \endcsname inserted error. What is my mistake? I hadn't read TeXBook, so it is a ...
5
votes
3answers
864 views

Need help re-defining the basic trig functions

I'd like to define my own commands to replace \sin, \cos, \tan, etc... I'd like to be able to use \tan[a]{x} to mean \tan^{a}{(x)}, and \tan{x} to mean just \tan{(x)}. I've tried modeling a solution ...
6
votes
1answer
208 views

How to define a macro which declares a fancyref prefix? How to prevent it from outputting text?

In a LaTeX document, I use the fancyref package for in-document references. However, I need a bunch of custom prefixes to reference lemmas, definitions and theorems, which fancyref dos not provide. ...
1
vote
0answers
40 views

Defining command \old| [duplicate]

I want to let the command \old| refer to the command \| (which produces the output ||.) So I do: \let\old|\| LaTeX complains "Missing $ inserted." How can I fix it?
2
votes
0answers
107 views

Can I make a “deep copy” of a macro? [duplicate]

I would like to make a deep copy of macro that I don't have control of, because various packages might change it. So I want to take the current meaning of the macro, patching it, but without changing ...
5
votes
2answers
218 views

Variadic arguments macro

I am trying to make macro with variadic arguments, iterating over them. The final result is supposed to be: \foreach[x]((var = \x )){foo}{bar}{baz}\null evals to var = foo var = bar var = baz My ...
4
votes
2answers
113 views

How to extract the name of a macro? [duplicate]

This is probably obvious to the TeX gurus, but here goes: I want to create a command that takes a control sequence (with no arguments) as input and prints the name of that control sequence, without ...
6
votes
2answers
5k views

Beamer allowframebreaks default option

How do I tell beamer that I want allowframebreaks allowed by default? Something like noitemsep for itemize: \setlist[itemize]{noitemsep} So that I don't have to do: \begin{frame}[allowframebreaks] ...
0
votes
1answer
182 views

Custom command for switching background image

I use the wallpaper package to put a PDF document in the background of my document. I want the user to be able to select in the preamble which PDF should be use as background image like this: ...
1
vote
1answer
81 views

Using verbatim in a definition [duplicate]

I actually need to store some verbatim text in a definition so I can reuse it several times. Here is a very short snippet: % here I store verbatim text \def\foo{ bar \verb'baz' spam } % now I ...
4
votes
1answer
413 views

How can I create wrapper macro for lstinline?

Using \lstinline I can include inline code snippets in a paragraph. I would like to provide a macro that selects formatting, etc, for lstinline so I can just do, say, \codeinline{snippet}. I had ...
13
votes
3answers
287 views

Gobbling an argument if it starts with #

My problem comes from pandoc and markdown, but it is not directly related with these tools, but instead with "customizing" the resulting pdf via some tex macro programming, so I think it is on topic. ...
27
votes
3answers
572 views

Set up a system to alternate between genders per paragraph

In RPG writing it has become traditional to swap he and she on a per paragraph basis. Something like "He can use the smite evil ability one a day at first level. (Blah blah blah, paragraph break) when ...
7
votes
1answer
151 views

Forcing macro expansion with keyval

While trying to provide an answer to this question, I've run into a stumbling block that I can't seem to get over. The listings package (like many others) uses keyval to handle configuration. What ...
2
votes
2answers
36 views

verbatim within… a package delivers a string from a file and that string needs to be printed without interpretation

The csvtools package warns in its documentation from interpretable inputs but offers no solution as far as I can see. This Code generates a table \documentclass{article} \usepackage{csvtools} ...
4
votes
1answer
527 views

Create an environment like the `checkboxes` in exam.cls

I am having trouble on how will i create something like the checkboxesor oneparcheckboxes environment in exam.cls. The only difference is that since the checkboxes gives circle, i'd like to create ...
6
votes
3answers
334 views

Why are some characters not allowed in command sequences

From my understanding a control sequence is ended by any non-alphabetic character such that \mycsA is one token, but \mycs1 is two tokens. This means things like starred commands \mycs* are actually ...
5
votes
1answer
70 views

How to build a conditional based on a resize paramater

I would like to define my own macro that accepts an optional parameter such as \big, \Big, etc that apply that if it is specified, otherwise apply the auto resizing \left, \right pair. So, how do I ...
3
votes
2answers
1k views

Is there a long division macro? [duplicate]

I want to do regular long division in latex. See also: http://en.wikipedia.org/wiki/Long_division Is there a latex macro for this ? Edit: I actually want to use it in mathjax, is this possible ?
3
votes
2answers
121 views

Toggle links globally using macro

I'm writing a CV for my wife using moderncv. We're not sure whether her supervisor wants links in the document, so every time a link might be required, I write the text twice: PhD student at the ...
14
votes
1answer
428 views

Is there a way to have an “empty” environment to merely limit scope of declarations?

I am fairly new to LaTeX, so I apologize if this is a beginner question, but I have not found a good way to query for it otherwise. I have observed that when I use an environment like ...
3
votes
2answers
128 views

Is it possible to declare a footnote in a way that it will attach to the first occurrence of a given word or phrase?

Is it possible to declare a footnote in a way that it will attach to the first occurrence of a given word or phrase? Doing this in a fully automated way might not be possible (see link below), but if ...
1
vote
0answers
75 views

Text in command gets glued to following text [duplicate]

I made this command \newcommand{\BR}{MyBrand\superscript{\scriptsize ™}}, when I use it and write something like this \BR is awesome the ouput is: MyBrand™is awesome What am I doing wrong here?
7
votes
2answers
118 views

Is there a way of defining a command \nullifyifmoved{arg} that will normally act like its argument but act like a no-op if the macro is “moved”?

I'm interested in a macro \nullifyifmoved that takes one argument arg and acts like arg in normal contexts, except it acts like a no-op wherever it is written to a file. Some background: Martin ...
4
votes
1answer
251 views

Command to insert filename in caption of a listing

I would like to have a command to insert listings that contain the filename in the caption. This works well as long as there is no "_" etc. in the filename. I also tried the suggestion from a ...
3
votes
1answer
71 views

List Version of \str_if_eq

I am using \str_if_eq:xxTF{\A}{\Target}{<true>}{<false} to execute the <true> or <false> code if \A=\Target. What is the list version equivalent of this? So I am looking for ...
3
votes
1answer
2k views

Why do I get the error “! Illegal parameter number in definition of \appendix.”while redefining the \appendix command?

I'm trying to redefine the \appendix command so that my appendix headings go to the top of the pages. To do this, I tried the following code, but I get the error ! Illegal parameter number in ...
6
votes
2answers
170 views

Complex parsing of arguments in new environments

I am trying to build an invoice generation system in LaTeX which will be easy and maintainable. Right now we are using longtable and a preprocessing layer. I would like to change this to a .sty and ...
2
votes
1answer
135 views

How to create an optional argument like the 'correctchoice` command in exam document class?

I want to create an alternative to CorrectChoice. That when [answers] command is used it will highlight the correct answer and be printed with the question together. I have seen this command by this ...
6
votes
1answer
813 views

Applying condition around \intertext and \shortintertext leaves excess vertical space

When I try to make either \intertext or \shortintertext conditional I get excess vertical spacing prior to the conditional text as per the MWE below. Note the excess vertical spacing prior to "Albert ...
2
votes
1answer
66 views

Automate replacement of `\not` when in `\bm` mode

Hendrik Vogt has provided a \longnot macro to alleviate the issues related to Interaction of \boldmath and \not. This seems to work fine, but I run into a snag when I try to automatically use ...
9
votes
1answer
156 views

Is there a way of defining a command which is automatically converted to a no-op after its first execution?

Is there a way of defining a command that can be executed only once and is then redefined to be a no-op? Related: Is there a way of defining a command \nullifyifmoved{arg} that will normally act ...
4
votes
1answer
669 views

How can I use renewcommand for toprule of the booktabs package?

I have a LaTeX document and want to change the thickness of \toprule and \bottomrule to 1.5pt. Is there a way to do this with the \renewcommand or do I have to change every \toprule to ...
10
votes
3answers
266 views

I want to create a command that will conditionally gobble up trailing whitespace: I want an “\unxspace” command

I have a command that occasionally produces whitespace that I don't want. \def\testa{a} \def\testb{a} \newcommand{\mycommand}[1]{\ifx\testa\testb{#1}\fi} When \testa and \testb are different, I ...
4
votes
1answer
200 views

Using Hashtag in macro

I had a problem putting the column headers in bold (in a table of course) using pgfplotstable. You can see the problem here I found a way to work arround that. It isn't generic as I wanted it to be, ...
2
votes
2answers
354 views

How to define new command for commands like \frac{} or \int{}^{}?

We know that we could define a new command for boldfaced or calligraphic C, for example I can define \newcommand{\Cx}{\mathbb{C}}, which will produce the boldfaced C, i.e. $\mathbb{C}$ for me. But how ...
5
votes
3answers
149 views

Metacommand for commands that dynamically select a parameter?

Original question I would like to create a metacommand for creating new projection commands. Specifically, \newproj{\cmd}{<n>}{<m>} should create \cmd as a new command of <n> ...
6
votes
2answers
262 views

How to use variables inside a command when generating a table?

I'm not sure about the question, since I do not really understand why it fails. I tend to use commands to generate my tables, and when I use the #1 style of accessing the arguments it works. But now ...