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

4
votes
0answers
55 views

Strings and memory usage

The TeX engine was originally written in Pascal before dynamic memory allocation was generally available. Modern implementations tend to be done in C. To qualify as TeX an implementation has to pass a ...
2
votes
2answers
70 views

Some questions about making scalar product in latex

I've just got registered here but I always read the site and I haven't found the answer for the following question. I just wanna make a specific view for scalar product. It should look like: . I use ...
2
votes
2answers
65 views

list environment where some items don't start new paragraph

I want to use a list-like environment, but I need to put some short items on the same line. The user interface will be something like: \begin{enumerate} \item First very long element \item* shrot ...
3
votes
2answers
85 views

Latex dynamically named macro doesn't work

In this MWE, \Nba is not created. How to have it ? Edit Remplacing \newcommand by \gdef makes \Nba exist but gives fantaisist value ? Any idea ? \documentclass[10pt,a4paper,french]{article} ...
5
votes
1answer
55 views

Rewrite \begin{foo}\end{foo} to \begin{bar}{opts}\end{bar}?

I know this is likely a simple Latex macro question. I've got a large document with a ton of lstlisting blocks, and I'd like to use minted instead. That means turning blocks that look like this: ...
4
votes
1answer
53 views

how to delete the space if argument is empty

I made a \newcommand for my glossed examples using ExPex package, that looks like this : \newcommand{\exgl}[6]{\ex\label{#1}\begingl\glpreamble \tt #2// \gla #3// \glb #4// \glft #5 // \endgl ...
2
votes
2answers
47 views

Gobbling punctuation if command has no optional argument

I want to define a new macro that gets an optional argument X and a citation key Y. If only Y is present it prints \cite{Y} If, however, also X is present it prints X, \cite{Y} This ...
4
votes
0answers
31 views

standalone package and user-defined macros/lengths

This is my first post on this amazing website, so hi to everybody!! I'd like to know if there is a way to pass some parametrs (macros or lengths) to a standalone file. Here is my MWE: Consider the ...
5
votes
2answers
72 views

Where is \@makefntext defined?

I was studying how footnotes come about in LaTeX and what processes exactly run behind the curtain, and noticed \@makefntext. But in fact, in latex.ltx there are only two occurences of this macro ...
0
votes
0answers
32 views

How can I recognize a dot followed by a space and output dot?

In the following code I cannot figure out what to use for \SPACE and \DOT such that \peektoken is compared to a space( ) and a dot(.) is produced as output along with the result of the test T(rue) or ...
1
vote
3answers
70 views

How to unstyle styled macro in headings?

I have a macro that occurs very frequently in the text. At one occasion, it occurs inside a heading, which causes some problems: \documentclass{scrartcl} ...
3
votes
1answer
103 views

How to recognize double spaces and give meaning to them?

I'd like to recognize two space characters and give my own meaning to it. Why does this not work and how can I fix it? {\catcode`\ =13%make space active ...
3
votes
1answer
39 views

A command for table entry by columns

This question is in followup to this question; an excellent response there has allowed me to very easily make tables for examples in the grammar book I am working on which have one language on one ...
4
votes
2answers
197 views

Simple calculation inside \def command

I would like to define a command that does some simple calculation, like this: \def\rectangle(#1,#2)(#3,#4)#5{ \psframe(#1,#2)(#3,#4) \rput((#1+#3)/2,(#2+#4)/2){#5} } % ...
15
votes
1answer
274 views

LaTeX programming Inheritance with \newcommand \newenvironment \renew… etc

I'd like to create (or renew) several LaTeX commands and environments, and understand how it works. One of my new environments would be equivalent to \begin{quotation}. So, imagine my \begin{foo} ...
6
votes
3answers
287 views

A macro for typesetting sequence with flexible starting index

How can I define a new command called \seq[StartIndex]{Base}{EndIndex} with the following functionalities \seq{a}{n} % -> a_1,a_2,\dots,a_n \seq[3]{a}{n} % -> a_3,a_4,\dots,a_n \seq[k]{a}{n} ...
4
votes
1answer
88 views

Macro for creating a table

I want to have a macro that creates tables of a specific type which specialize in multiple choices questions. The required command \createtable{#1}{#2}{#3} has three arguments: The total number of ...
3
votes
1answer
69 views

Increasing number in a text automatically

Is it possible in Latex to set in the "middle" of a text a field or another thing, that increases a number (without having to do this by hand)? For example: M-ERF020 M-AUSW030 the numbers between ...
4
votes
2answers
55 views

Formatted date inside section

I am trying to compile a document where each section title corresponds to a given date. The date has to be formatted, 2014/01/03 should produce 3rd January 2014 in the title. I was trying to use the ...
4
votes
5answers
1k views

How to define a command that takes more than 18 arguments [duplicate]

This question is based on this answer. It is a continuation of my previous qestion regarding list of values in latex. According to first link there is a limitation on the number of arguments I have ...
7
votes
1answer
125 views

How can I iterate over a newline-delimited text file?

Would I need to use a token list? For the purpose of removing confusion, let there be two delimiters: input delimiter (what LaTeX reads as input) output delimiter (what is seen on paper) I would ...
3
votes
1answer
61 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. ...
11
votes
4answers
238 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) ...
11
votes
2answers
128 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
47 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
93 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
22 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 ...
7
votes
3answers
134 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
34 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
41 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
28 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
55 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
97 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
66 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
3answers
102 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
69 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
265 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 ...
2
votes
1answer
36 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
48 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
72 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
504 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
185 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
80 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
152 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
124 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
88 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
38 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
37 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 ...