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

5
votes
1answer
93 views

Repeat geometry / body / object / shape in PGFplots

I depicted a pentahedron by means of the code \documentclass{standalone} \usepackage{pgfplots} \pgfplotsset { plotOptsA/.style={surf,patch,patch type=triangle,shader=faceted interp}, ...
2
votes
1answer
45 views

\pgfplotstablegetelem in \section does not work

I read in some dates with \pgfplotstableread and want to use this dates. The idea is, I want to be able to change its values without having to change my LaTeX code. The following MWE will not compile ...
0
votes
0answers
36 views

Text tool to expand TeX macros [duplicate]

a few months ago I heard of a tool für TeX but I can't find it, so I want to ask you whether you know what tool am I talking about. The function is: Say you have some own macros like ...
2
votes
1answer
47 views

How to define a numeric variable?

Following the Latex wiki page I tried \newcommand and \DeclareRobustCommand: \documentclass[a4paper,10pt]{article} \usepackage[utf8]{inputenc} \newcommand{\marginProportion}{0.76} ...
0
votes
1answer
58 views

\textbf does not work insine \newcommand [duplicate]

I'm trying to make a new command, to add autoincrementing numbers to the definitions throughout my thesis. Here's what I have. \newcounter{DefCounter} \setcounter{DefCounter}{0} ...
3
votes
2answers
64 views

new command for nested enumerate with variable arguments

I have some text that I want to turn into a template which looks like this: Extensions: \begin{enumerate} \item[2.a] xyz \begin{enumerate}[i.] \item a \item b ...
5
votes
2answers
134 views

How can I define a macro, so that is does not have to be preceded by \protect in headings, captions etc.?

I tried to define a macro myself, which outputs different strings according to the input variable (like select-case statements in other programming languages). The problem: If I use the code in ...
5
votes
1answer
127 views

LuaTeX: How to handle a Lua function that prints TeX macros

Let's say that I have a Lua function that prints TeX macros: How can those macros be executed during compilation with LuaLaTeX? In the following example, I defined a LaTeX macro that should print a ...
2
votes
1answer
109 views

How can I know if I am inside an equation environment if it's nested with others?

I wanted to define some partial derivative commands that would be \partial y/\partial x if it was inside an inline equation and would use \frac{\partial y}{\partial x} if inside an equation ...
3
votes
1answer
81 views

How to avoid typesetting any cell if a table is empty

Following How can I define a macro that adds a row to a table that has not yet been printed?, I came up with a macro (\AddToTable) that “builds” a table, i.e. appends its argument as the last row of ...
0
votes
0answers
14 views

How to disable a self-made command [duplicate]

Is there a way to disable a self-made command? I thought of the following: %!TEX TS-program = lualatex \documentclass{scrbook} \DeclareRobustCommand{\mycommand}[1]% % {\textbf{#1}} ...
8
votes
7answers
323 views

How to define optional second argument for macro?

I've defined a command which lets me quickly reference to the number (of figure or table) AND page at the same time: Command \newcommand{\kplref}[2]{~\ref{#1}, S.~\pageref{#1}{#2}\xspace} The ...
11
votes
5answers
488 views

Basics of scanning

I'm trying to master the art of scanning text one character at a time. The following is what I've discovered so far. Is this as good as it gets? I would really prefer not to do all those \edefs as ...
6
votes
2answers
102 views

Suffixed macro and uppercase

when I declare a macro with suffix, its use inside a \uppercase commands doesn't work. See the MWE \documenclass{article} \usepackage{suffix} \begin{document} \newcommand{\AcCan}{\emph{Actes des ...
0
votes
0answers
89 views

Customize index with section name, not page number

I would like to build an index where instead of a reference to a page number, I would have a reference to the section name of the term. So this is what I did (but which doesn't work) : ...
17
votes
3answers
1k views

What is the purpose of hash (#) as a special character sign?

I understand the purpose of all special characters, $, &, %, _, {, }, ^, ~, and \, but just except for hash (#). When and why should it be used?
1
vote
1answer
41 views

How to fix the spaces of superscript text

I'm trying to typeset an old bible which has all the verses superscripted. I created a command that produces a superscript number corresponding to the verse number, and then this is increased by one. ...
5
votes
6answers
179 views

loop and char &

I can't find the problem in this code \documentclass{article} \newcount\mt \newcount\mtt \newcommand{\mttab}[2]{% \mt=0 \loop \advance\mt by 1 \mtt=1 {\loop ...
4
votes
2answers
87 views

How to create a custom environment with a listing inside it?

Well consider the following code: \documentclass[a4, oneside,openleft]{book} \usepackage{listings} \begin{document} \begin{flushright}\begin{minipage}{0.9\textwidth}\begin{lstlisting} for (i) { ...
1
vote
0answers
40 views

How to define a simple command for “mark” in an exam paper?

Here is the link for a .cls file. http://phyweb.phys.soton.ac.uk/ugadmin/Staff%20forms/EXAM%20TEMPLATES/su-exam.cls But all I want, is to be able to use \mark. And being able to get a simple total ...
6
votes
3answers
287 views

Parse argument with a number and an optional letter

How to define a macro which takes a string made by number and an optional letter and then branches on the basis on the letter? Since this is an extension of an existing package, it is preferable not ...
1
vote
3answers
89 views

How to add a framed box inside a paragraph?

I'm using little markers in some parts of my text and I wanted to add one of those to a paragraph entitling a list: \newcommand{\hip}{{\color{BlueViolet}\framebox[1.1\width]{HIP}}} ...
17
votes
4answers
920 views

On/Off switch (redefine a macro at each use)

I try do define a macro \onoff, which alternatively prints "on" and "off" each time it's used. For example the sequence \onoff \onoff \onoff would print on off on My first guess would be to use the ...
0
votes
0answers
94 views

TeXstudio does not auto-complete newcommands

I've just updated my TeXstudio to version 2.9. Unfortunately, this was kinda destructive to my ability to efficiently use it. I have a project with file main.tex which then calls (using input{}) ...
14
votes
3answers
276 views

Creating a newcommand with indefinite arguments

I am kind of new to LaTeX. I am doing project which contain resources (formula, solutions to problems, e.g.) i can bring to the Exams day on 16th March. I have been looking for a solution to my ...
1
vote
1answer
116 views

How to get pgfgantt today to be set to the \today macro

I want the pgfgantt chart to automatically update the "today" line so that it always shows \today when compiled. The problem is that though I am using time slot format=isodate and have set the ...
3
votes
1answer
71 views

Dynamic length variable with argument? (like “\setlength{\foo}[1]{0.5+#1*0.5}”)

Is there a way to define some kind of a length function that takes an argument, sort of a mixture between \newcommand and \setlength? The following example should illustrate what I want. (I'm using a ...
8
votes
1answer
134 views

Using \ifdefined on \csname macros

I've run into this issue several times now, and have just worked around it in other ways. But it would be simpler just to know how to do it properly. I would like to use \ifdefined in the context of ...
7
votes
1answer
219 views

Understanding how a TOC is generated

I'm trying to understand, in some detail, how a toc is generated. But now I'm thoroughly confused and perplexed after examining the .toc file before and after making a ``slight'' modification. I hope ...
5
votes
1answer
104 views

How to write custom configuration for TeX4ht

I have some macros in my document, and I want to create my own HTML for there. I follow this blog entry but I can't to make it work. I put this code before my \begin{document}: ...
1
vote
0answers
38 views

pgfplots(table) protect ##1 when in a `\newcommand` with optional arguments

I am using the excellent answer from @percusse to the question How to rotate head row cell entries of pgfplotstable which works great if you always want rotated headers. I am calling ...
3
votes
1answer
48 views

Table of Contents labels not directing hyperlinks to correct page

Being only a LaTeX novice I may have introduced a bit of customizing code renewing part formats and adjusting numberings which may have messed up the ability for hyper-references accuracy in heading ...
5
votes
2answers
44 views

latex tokens reader breaks on \iffalse

everyone, I've found a very strange behavior of latex \iffalse with \newcommand\NAT@parse... inside of it (\NAT@parse taken directly from natbib). If I add that macro in style, then latex breaks with ...
2
votes
1answer
41 views

What does \csappto does and where does it come from?

What does the macro \csappto do, exactly? I've seen it in multiple code snippets throughout the website and on the internet in general, but I've never seen an explanation of what it does. I've looked ...
1
vote
1answer
110 views

Latex Macros: Local Variables and Path Names

I initially have a group of TeX codes that looks like so: paper.tex assignment.tex Where paper.tex is the main TeX and takes in the assignment.tex file and adds it in there. The assignment.tex is ...
1
vote
1answer
60 views

Create new fields in glossaries newglossaryentry

As an alternative to the question detailed Nested conditional glossary terms using Glossaries \ifglsused in \newglossaryentry I would like to add some fields to a glossary definition. Is this ...
1
vote
1answer
117 views

How can I wrap this code in a function?

I have a text that describes spell powers in a game. The following pattern is repeated for each spell: \documentclass{article} \begin{document} % Template for spell powers. \textbf{Small Heading} \\ ...
7
votes
5answers
388 views

Command to count characters in a specified string

Is there a way to count the number of characters in a specified string? Suppose I had the following code. \documentclass{article} \newcommand{\numchars}[1]{\noindent The string ``#1" has ? ...
4
votes
2answers
53 views

Defining own command

I'm trying to create a command to save me some heartache when writing the rest of this document. What I'm attempting to do is to create a command like \double{-}, which when used will produce: ...
4
votes
2answers
55 views

Delayed expansion of StrSubstitute argument with active characters

This is an extension of my previous question. The accepted answer provided a way for me to delay expansion of a marked-up easylist list until the string was processed inside the environment. I'm ...
4
votes
1answer
61 views

Command doesn't expand into other commands after string substitution

The MWE should explain it all (use LuaLaTeX): \documentclass[11pt]{memoir} \usepackage[T1]{fontenc} \usepackage{fontspec} \usepackage{xstring} \usepackage{easylist} \begin{document} ...
6
votes
2answers
94 views

Iterator-like command, where each use expands to an item from list defined earlier

What is the simplest way to create an iterator-like macro (in the functional programming sense) in pdfLaTeX? I'd like to predefine a list of elements (to simplify we can assume that it is plain ...
5
votes
1answer
40 views

Replacing an id (integer) with a string?

I have a tex document that contains sections that are automatically generated. These sections have strings that are observation IDs. I would like to have latex replace all occurrences of an ID with ...
3
votes
3answers
58 views

Creating a new list Environment, how to change the length of \items

The code for the environment is bellow, For the longer lines in \list item how do I change the length of the \items so that it lines up with the date? Basically I want a kind of "margin" that is on ...
0
votes
2answers
102 views

Redefining math symbols like \eta (with ensuremath)

An easy one: I would like to define a shortcut so that I can write \eta without having to enclose it in $\eta$. However, the naive approach will not work: \documentclass{article} ...
3
votes
1answer
44 views

Creating a command within a list

So I'm trying to create a simplified kind of list inside of an environment, so that calling one command will create an enumerated item and calling another will create a subitem. Here's my code: ...
5
votes
1answer
74 views

Why am I getting an error when using \renewcommand, here?

I try to type \renewcommand{\mr}{\mathrm}, so that I can then use \mr in my text instead of \mathrm. I get the error \mr Undefined. what is going on?
5
votes
2answers
113 views

Defining a command and its starred version with different number of arguments

I want to create the commands: $\vecbi*{A}{s}$ and $\vecbi{A}$ To write bold vectors in my text. However, I have tried the following code, but I am still stucked without a solution. \makeatletter ...
4
votes
1answer
115 views

problem with newcommand with line break \\ and tabular inside

I define a new command \nonBranchingRule that takes 3 arguments. Intuitively, it defines a rule where the last argument is a comment (optional argument) for the rule. I want to place the comment under ...
2
votes
2answers
68 views

new command definition brings extra space

Sorry for my original example code can not relect exactly what I mean. I have made a new one. I am trying to define a new command, but it seems some unwanted extra spaces are generated together. ...