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

2
votes
1answer
51 views

How to use macros to repeat math equations in different settings

Suppose I have an equation like y=a+b that I want to repeat multiple times. I want to use macros to define this equation. First, I thought that the following definition would do the tric. ...
10
votes
4answers
187 views

New command with two definitions [duplicate]

I want to define a new command that serves two slightly different purposes. Can I define a new command called \set such that it's definition is chosen according to the number of argument(s) is(are) ...
8
votes
2answers
74 views

issue with macro expansion

The following code works, but if you comment line 20 and uncomment line 21 LaTeX complains about \endmap being undefined. I do not really understand why that is and even less what to do about it. ...
4
votes
1answer
37 views

Length operation within a newtcblisting

Consider the following code: \documentclass[10pt,letterpaper]{article} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage[french]{babel} \usepackage{calc} \usepackage{tikz} ...
4
votes
1answer
79 views

Making headings that depend upon later environments

I want to typeset a test and a marking scheme. I have the following code: \documentclass{article} \usepackage{ifthen} \usepackage{amsmath,amsfonts,amsthm,amssymb} \setcounter{secnumdepth}{0} ...
1
vote
0answers
21 views

How to compile the document in particular orders? [duplicate]

\documentclass{article} \newcommand{\reflog}[2]{\cleardoublepage ref log --~#1 \\ #2} \newcommand{\obsform}[2]{\cleardoublepage obs form --~#1 \\ #2} \newcommand{\lessonplan}[2]{\cleardoublepage ...
6
votes
3answers
121 views

How to define a newcommand for this type of indexing?

\documentclass{article} \usepackage{makeidx} \makeindex \newcommand{\key}[1]{ #1 \index{#1} } \begin{document} \cleardoublepage This shows \key{1.1},\key{1.2},\key{1.3},\key{1.4},\key{2}. % ...
3
votes
1answer
23 views

Data structure: Define a command or environment only valid inside a certain type of environment

I want to script the generation of LaTeX documents, and therefore, I will need to use a data structure to organize the information. For example: Person: Name Phone Address I know in LaTeX you ...
4
votes
1answer
36 views

Minimize effort separate pdf and single pdf versions; ref and url issues

I want to create LaTeX content which consists of many sections. I will either typeset all of the sections together to get one PDF or typeset each one separately. If they are typeset together, then I ...
0
votes
1answer
25 views

Why doesn't my \csname-based glossary macro work inside \section and \caption?

I'm a LaTeX newbie. I have a custom macro called \gloss that decorates its argument in a certain way - let's say that it adds a star symbol for the purpouse of the MWE. I have wrapped it around a ...
2
votes
1answer
48 views

Testing an existing macro doesn't work

Once defined, I don't want the macro \Stepx be redefined : \documentclass[xcolor=dvipsnames,professionalfont,french]{beamer} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} ...
2
votes
1answer
86 views

Why this dynamically named macro doesn't work?

\documentclass[xcolor=dvipsnames,professionalfont,french]{beamer} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage{fourier,tikz,ifthen} \usetikzlibrary{calc} ...
4
votes
1answer
59 views

How to expand control sequence in argument of a macro

Consider the following: \def\foo#1#2 {% \if#1a% \message{#2} \fi} \def\x{abc} \edef\y{\foo\x} \y The result: ! Argument of \foo has an extra }. The expected result: bc
3
votes
2answers
47 views

Replace from a list of possible strings

I'm creating a large number of identical documents in LaTeX, with only the address changing (and the address will be only 1 of 5 possible ) So if my list of possible addresses is: DC | 1600 ...
3
votes
2answers
56 views

How to make more-than-9-argument-commands work with tabular?

I have a command that needs more than 9 arguments. I stumbled over this solution: How to define a command that takes more than 9 arguments. This works fine in regular text. But I tried using this ...
7
votes
2answers
250 views

How to repeat over all characters in a string?

I have a command that formats a single character, let's call it \d{}. (In my case, \d{} adds a dot under a Chinese character, as this is the custom to emphasize Chinese texts). I want to define a ...
0
votes
0answers
27 views

Splitting commands over multiple lines [on hold]

We have a command used to typeset things in a specific font and colour. Sometimes, what is given to this command is large and it needs to be split into multiple lines within the same align or ...
2
votes
1answer
27 views

Double backslash or \cr in \newcommand to be used in a table

I have a \newcommand*\mycmd[3]{#1 & #2 & #3 \\} that is used in a tabular environment later, like this \begin{tabular}{ccc} \mycmd{a}{b}{c} \mycmd{d}{e}{f} \end{tabular} But the double ...
2
votes
1answer
42 views

Compare Variables

I want to have a macro that checks if the string has been used in the previous call of the macro as well. I found some examples here how to create switch structure comparing strings in latex but I ...
2
votes
0answers
13 views

Using one group separator for integer part and another for decimal part (siunitx) (modified) [duplicate]

I found this link Using one group separator for integer part and another for decimal part (siunitx) the code from jfbu is almost perfect, except I need grouping of three on each side of the decimal. ...
2
votes
2answers
53 views

Check options in \newcommand or \NewDocumentCommand?

I'm trying to implement a custom command that is called like this: \mycommand[hello][world]{mandatory1}{mandatory2} OR: \mycommand[hello,world]{mandatory1}{mandatory2} However, I can't figure ...
27
votes
3answers
462 views

How to define phantoms for depth and height?

In the third "dangerous bend" on page 178 of of The TeXbook there's the following description of \vphantom: Even more useful than \phantom is \vphantom, which makes an invisible box whose height ...
4
votes
1answer
150 views

Calculate the hash (MD5 or otherwise) of a string

I'm trying to cache the results of a macro, similar to that question, but the argument of the macro can contain arbitrary characters and it's not suitable to be inside \csname ... \endcsname. So, I'm ...
5
votes
1answer
60 views

build a capitalized CS from a lowercase string and to give it a definition

Is it possible to build a capitalized Control Sequence from an argument of lowercase string and to give it a definition? I tested two codes, but both didn't work well. code1: \def\makecs#1#2{% ...
3
votes
2answers
135 views

Writing literal “#1” into an auxiliary file from a command with arguments

I am trying to write into an auxiliary file from a command with one argument. The written text is another \createcommand with one argument too. When I use "#1" the argument of meta-command is ...
0
votes
0answers
14 views

\edef together with microtype generates an error [duplicate]

In a previous question, I asked why \edef produced an error when trying to expand commands that takes an argument in the belief that this was the cause of it. But in actuality, I've realized that the ...
2
votes
2answers
107 views

Why does \edef produce an error if its arguments is a command that takes an argument?

If I have the following piece of code, everything compiles: \documentclass{article} \newcommand{\mycmd}{ \edef\tmpcmd{test} % No commands with arguments \tmpcmd } \begin{document} \mycmd ...
2
votes
1answer
66 views

How can branch if I'm in a halign or not?

Edit: It seems that I can use \noalign\bgroup before the \halign. That's fine. But how do I test that I'm inside the halign group? I'm able to write an own if, but it would be better to ask tex for ...
3
votes
1answer
27 views

How can I use \noexpand and \unexpanded without appending a space to the unexpanded tokens?

One of my current tasks involves composing an auxiliary file with extra commands to be loaded at a separate compilation. Here's an MWE: \documentclass{memoir} \newwrite\testaux ...
1
vote
0answers
35 views

Typeset code within a simple macro?

I want to use a macro to typeset programming code with the usual characteristics (particularly lines should be obeyed - this is the most important issue; highlighting and such stuff is - for now - not ...
8
votes
1answer
66 views

xparse's \DeclareDocumentEnvironment gives error on already-defined environment

I'm trying to redefine an existing environment subfigure defined by the subcaption package. To do this, I'm using xparse's DeclareDocumentEnvironment since that's suppose to declare a new environment ...
1
vote
0answers
19 views

Consistent formatting for \glft in expex

In the ExPeX documentation, all of the examples with \glft wrap the glos with single quotes; the examples in my document look the same: \pex \begingl \gla bu nɛmə // \glb this what // \glft `What's ...
1
vote
1answer
21 views

How can I include external macros for every line of the source code?

An answer to my last question gave a solution for hooking a small command onto line breaks in the TeX source. \documentclass{memoir} \usepackage[spacing, tracking]{microtype} \usepackage{libertine} ...
7
votes
1answer
91 views

Accent i in plain TeX fails inside array loop

In Plain TeX, when I try to create an array of control sequences (\word0, \word1, etc.) and print it out using a loop, TeX stumbles over the accented-i control sequence \'{\i}. I get this error: ! ...
1
vote
2answers
34 views

\newcommand error

I am using following new command: \newcommand{\legend}[3]{ \begin{itemize} \item Serial Number: #1 \item #2 \item #3%\href{http://#3}{#3}} \end{itemize} } \legend}{5, April 2015, ...
13
votes
3answers
1k views

Hooking every line of the source code

I've been considering a more radical solution to the problem k.t.hagen posed a while back. Would it be possible (perhaps by catcode hijacking) to put hooks on individual lines of the source code? ...
1
vote
1answer
58 views

Macro/shortcut for defining text portion as code

I'm currently converting my thesis into LaTeX, and i have an issue: being an IT thesis, I have tons of code quotes. The problem is not about the blocks of code: they are not that many and i can wrap ...
0
votes
0answers
64 views

Is there a LaTeX-to-HTML package that uses TeX?

I know that there are a lot of ways to "convert" LaTeX source to HTML markup that, when rendered, resembles the hypothetical original PDF. Is there such a package that works within LaTeX? I'm ...
0
votes
0answers
20 views

Putting a commonly-used piece of text in a new command [duplicate]

I am working on a document in which I need to insert a long piece of text for several times. In order to avoid writing the same long piece of text over and over again, I decided to define a new ...
3
votes
3answers
106 views

Optional newpage command

Does there exist a command (which I will call \newpageoptional) which acts in the following way: Text and code 1 \newpageoptional{ Text and code 2 } Text and code 3 The effect ...
3
votes
1answer
60 views

Style stored in command

I have created a \newcommand with some arguments that allow me to call an other command. Command syntax: \newcommand{\nodeperso}[1]{\node[\noexpand\type#1](){\noexpand\nom#1};} I have declared a ...
2
votes
1answer
46 views

Referencing custom environment

I am using \begin{figure} \includegraphics{} \caption{Caption} \label{fig:fig_name} \end{figure} and \begin{table} \begin{tabular} .... \end{tabular} \caption{Caption} \label{tab:table_name} ...
0
votes
1answer
62 views

How to repeat cell content with slight modifications on next page for longtable using multirow using LaTex

Given this approach: How to Repeat Cell Content on Next Page for \longtable using \multirow What if I wanted to slightly "modify" the text that is repeating so that on the originating page I want to ...
0
votes
0answers
40 views

Writing modular classes

As an OOP programmer, I am very attracted to the idea of making separate files for independent features within a class definition, where each feature I feel is too long to be included inline in the ...
5
votes
2answers
274 views

How to get rid of “c-cedilla” in math mode?

This code: \documentclass{scrartcl} \providecommand{\c}{\mathrm{c}} \begin{document} Complement of $A$: $A^\c$. \end{document} Produces the following error: ! Missing { inserted. <to be read ...
1
vote
1answer
65 views

How to name arguments in \newcommand?

How to name the arguments in \newcommand so that when you call the macro they don't appear as {arg1}{arg2}... etc. but with the names each argument represent {caption}{label}... etc. without the use ...
3
votes
0answers
39 views

mouse over (highlight) acronyms using acronym package. is that possible?

Is it possible to highlight acronyms (mouse over shows the acronym definition) by using the acronym package \ac ....? In this post, there is a macro that was working somehow but by using the acro ...
0
votes
0answers
25 views

Creating a myenumerate-environment with a counter [duplicate]

I want to have the counter use roman numbers, so it should be something like: (i) ... (ii) ... (iii) ... I tried defining a macro \myitem, but it´s not really working. Does any have any ideas?
9
votes
1answer
136 views

Somewhat versatile usage of \@gobble and \@firstofone found in several macros

I was doing search about my question (see here for more detail) and found a thread commath and \ifinner. In the thread, there is a macro named \spx , the definition and usage of which are extracted ...
2
votes
1answer
53 views

Can one modifiy an argument within its macro?

I wish to give a default value to a series of arguments when they are empty. I could make a test prior the use of the argument and modify the value just before each of the usage. I could even make a ...