{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
38 views

Textual replacement macros to wrap environment

I want to create simple textual replacement macros for an environment: \def \myEnvStart {\begin{someEnvironment}[enormous list of arguments]} \def \myEnvEnd {\end{someEnvironment}} This doesn't ...
7
votes
1answer
94 views

Macro for pgfplots/gnuplot exponential regression line

I am trying to create a series of plots with exponential regression that are automatically generated from comma/tab separated .csv files and pgfplots with help from gnuplot. When not using macros I ...
4
votes
1answer
60 views

How to control conditional statements within new commands and environments

I'm writing a pretty complicated class to typeset a book based on memoir. One of my commands draws a caption on the preceding verso page, draws content on the following recto and verso pages, and ...
6
votes
3answers
109 views

substitution problem with plain tex

Can anyone please tell me what I did wrong?? I cann't get the second number of tests to work correctly (and the command appears to be the same argument as done manually) \magnification\magstep1 ...
5
votes
1answer
83 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
28 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
35 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
32 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
38 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
50 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
127 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
87 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
101 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
74 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
290 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
461 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
92 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
53 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
25 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
3answers
112 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
71 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
33 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
255 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
66 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
769 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
64 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
254 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
46 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
56 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
53 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
188 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
65 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
31 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
38 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
36 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
38 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
78 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
34 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
111 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} \\ ...
4
votes
1answer
185 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
52 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
38 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
48 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
86 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
38 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
56 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
84 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
41 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: ...