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

3
votes
1answer
47 views

Different fnmark style in footer and text

I'm using the memoir document class and redefining fnmark like this in my preamble: \documentclass{memoir} \usepackage{footnote} \usepackage[bottom,hang]{footmisc} \usepackage{xcolor} ...
4
votes
1answer
67 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} ...
4
votes
1answer
34 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 ...
8
votes
2answers
71 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
35 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} ...
6
votes
3answers
120 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}. % ...
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 ...
3
votes
1answer
22 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 ...
1
vote
2answers
71 views

How to use color declarations in titles?

How can I use color declarations when setting the title of a document? I tried \title{\color{blue} Colors in typesetting} but I get an error from LaTeX. Update: The error reads as followed: ...
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} ...
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 ...
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 ...
1
vote
1answer
48 views

Generating a list with macros using tasks package

I cannot figure out how to generate a list with the tasks package using macros. If you swap the three identified lines in the MWE below, you should get the following error message: \begin{tasks} on ...
7
votes
2answers
249 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. ...
5
votes
2answers
180 views

Capacity exceeded while implementing lookup table

I'd like to implement simple key-value lookup table. I wanted to do it in functional fashion, so I've defined initial state of such table as get function causing error (as table is initially empty). ...
2
votes
1answer
58 views

Include LaTeX commands from external file in asymptote file

I have many asymptote drawings in a .asy file whose generated pdf is included in a main.tex. I have many user-defined commands, like \vec or \vxi which I use in my current main.tex and I want to use ...
1
vote
1answer
57 views

Fixing a class file

This may be a problem with too narrow an audience for this forum, but I'm rather stuck at the moment. I'm attempting to build my dissertation document. My school's style guide is decidedly ...
27
votes
3answers
460 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 ...
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 ...
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 ...
1
vote
1answer
31 views

Custom linespacing in a parbox

Is there a way to set the line spacing into a \parbox? What I am trying to do is create a new command from a \rotatebox and \parbox and assign locally, i. e. only inside of the \parbox, custom line ...
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{% ...
2
votes
1answer
65 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 ...
105
votes
2answers
59k views

How do I create an invisible character?

I cannot remember how to create an invisible character in LaTeX, i.e. I want to put a space the that has the width of a particular character, say `M'. I know there is a command for this, and this is ...
3
votes
2answers
134 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 ...
9
votes
4answers
348 views

Problem using macros to define tree substructures

Relatively simple problem: I want to use macros to define substructures of a tree. In the following example for illustration, I want to define some children (left and right) to be used several times ...
2
votes
2answers
106 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 ...
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 ...
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 ...
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
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
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 ...
5
votes
2answers
150 views

New environment, orphan line

I created three environments for my document: a booklet for a treasure hunt with scrreprt. I created 3 environments (the document is in french): enigma: ...
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? ...
3
votes
1answer
122 views

How to make a function inside the tikzpicture behave like outside

I have a macro which generates a structure (rule) and a reference to that structure. It does not behave when inside a tikzpicture. How to make the function robust to reference the structure even when ...
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
0answers
63 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 ...