{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
0answers
28 views

(Is it wrong to) Use commands to begin and end equations (?) [duplicate]

I'm helping a professor write the second edition of his book, so I'm working with a lot of "old" code and bad practices. Something I've found is that he has defined macros for beginning and ending ...
5
votes
1answer
43 views

Why does it appear that some lineno internal commands are never called?

At the end of lineno's cryptic documentation, the author lists certain "for wizards commands." I'm trying to implement a special tag for the first line number, so I thought I would probably begin by ...
4
votes
1answer
58 views

Defining multicolum by macro with optional argument

I try to define macro for shortcut form \multiline{1}{<pcolumn type>}{\textbf{text}}: \documentclass[12pt,border=1mm,preview]{standalone} \newcommand\mcbf[2]{\multicolumn{1}{#1}{\textbf{#2}}} ...
2
votes
2answers
36 views

Merge double subscripts in macro

I would like to define a macro \des that has one argument and adds a subscript to it i.e. \des{a} should correspond to a_{des}. So far the solution is obvious, however the macro should also accept ...
2
votes
2answers
58 views

Definition of a macro with multiple arguments and usage of \csname

Why does the following code not work ? \Requirepackage{amsthm} \renewcommand\newtheorem[2]{% \NewEnviron{\csname #1\endcsname}[1]{% ##1 : \BODY } } I have seen examples of the use ...
1
vote
1answer
15 views

Use macro as totcount counter name

In the top level of the document environment, a macro defined (using \def) can be expanded into the name of a totcount counter. This, for some reason, does not work inside an environment definition. I ...
2
votes
1answer
184 views

Define a command with an odd number of braces

In my code, I change to '2 columns' mode typing: \twocolumn[{ I'm trying to simplify this code, by creating a new command: \renewcommand{\twocolumn}{\twocolumn[{} Is this possible to insert a ...
1
vote
0answers
38 views

Define new command using \DeclareTotalTCBox in tcolorbox package

I have defined a command using \DeclareTotalTCBox command in tcolorbox package as blew: \documentclass{article} \usepackage[most]{tcolorbox} \DeclareTotalTCBox{\myverb}{ O{red} v O{} } { ...
3
votes
3answers
207 views

Amplifying fractions

I want to make myself a math portofolio (as a quick reference) and I have a part where I have to 'amplify' a fraction like here: But I don't know how can I do this thing, can you help me? Thank ...
3
votes
3answers
91 views

Expl3: Constructing command sequences from macro arguments

In my LaTeX laboratory I am doing weird experiments with expl3 (just started to use it some days ago, so regarding l3 I am complete newbie) I am trying to generate command sequence within of another ...
1
vote
0answers
40 views

how to expand some macros in latex file [duplicate]

I have a latex file that uses some of my own macros (a mix of tex & latex macros). I need to post the latex source, but don't want to expose the macros (some of which are nasty hacks that just get ...
4
votes
1answer
77 views

Can you interpret macro parameters as verbatim?

Basically I want to define a macro whose parameter should be treated as a "script", meaning that I want to print it in a verbatim way including line breaks and special characters. Furthermore, I want ...
2
votes
1answer
62 views

Can a command be defined to have key=value in it?

I am learning about making LaTeX commands. I thought that they were just macro, and the command is replaced literally by its definition. But the following example does not work and I wanted to ask if ...
3
votes
1answer
74 views

Items from file in itemize enviroment

Is it possible to import items from a file into an itemize environment? For example, consider a file with just words and no formatting: Elem1 Elem2 Elem3 Elem4 ... Elem120933 I like to read in this ...
5
votes
1answer
43 views

Define nested sections in a relative way

When working with large tex documents I often find myself using search/replace to restructure them (eg. make sections out of chapters or subsubsections out of subsections) Is there any way to define ...
2
votes
2answers
152 views

how to define newcommand that takes []{} as arguments and not {}{}?

I find myself doing a lot of things like this below in order to compile document for both pdf and tex4ht \ifdefined\HCode \includegraphics[width=0.5\paperwidth]{foo.eps} \else ...
2
votes
1answer
60 views

etoolbox package explanation requested

I am trying to understand the following package etoolbox. I am unsure about the meaning of the following syntax since I am not sure what is the correct question to ask in google or in the book of ...
7
votes
4answers
139 views

Detect if a macro argument is only one symbol

I define a bunch of functions (or operators, if you like) using a little helper \parens, which adds parens on demand: \newcommand{\parens}[1]{ \ifthenelse{\equal{#1}{}}{}{(#1)} } ...
4
votes
2answers
42 views

Problem with gb4e and macro for tabular with curly brackets

When using the macro \CurlyBrackets at the beginning of a gb4e example, the example is not typeset as expected. Is there a better way to do this to get the desired output? MWE ...
5
votes
3answers
100 views

Check occurrence of a macro inside another macro

With the substr (or xstring) package you can, of course, identify whether a control sequence contains some text string: \documentclass{article} \usepackage{substr} \def\somecontrolseq{some silly ...
4
votes
0answers
46 views

What does `\escapechar` do? [duplicate]

In latex.ltx you can find several situations where \escapechar is set to -1 -- from what it's clear that it has to be a count register. But, what does it actually "count" or control? A small ...
2
votes
1answer
143 views

Using command parameters to use another command

Say I have written two commands, CommandA and CommandB. I wish to have a third command that takes inputs to determines which of the two previous commands to execute. Very naively this how I would try ...
1
vote
1answer
43 views

Next word macro inside braces

I have defined a macro that highlights the next word using \def!##1 {\hkw{##1} }% where in this scope, ! is an active character. So it works fine to write. \emph{This is a !good example} but not ...
5
votes
2answers
65 views

Creating a \newcommand for a tikz diagram

The document I'm writing is full of diagrams of arrows, therefore I'd like to create a newcommand \diagram that avoids me to write every time the settings of the tikzpictures. I put ...
7
votes
1answer
237 views

plus/minus vs +/- in latex preamble

In the following code, I need to use +/- where I have used it, and plus/minus where I have used it. \documentclass{amsart} \usepackage{lipsum} \usepackage{calc} \parindent=0 pt \parskip=12 pt plus 0 ...
2
votes
1answer
32 views

Shortcut/macro for surrounding words with brackets

When using BibTeX I usually need to fix broken capitalization by surrounding words with brackets (as answered in BibTeX loses capitals when creating .bbl file). I also use this to fix some issues ...
4
votes
0answers
52 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
67 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
60 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
82 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
51 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
48 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
27 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
62 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
66 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
101 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
38 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
165 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
245 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
282 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
80 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 ...
2
votes
1answer
64 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
53 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
966 views

How to define a command that takes more than 18 arguments

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
119 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
212 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. ...