{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
2answers
18 views

\newcommand with options

My question is about declaring a "newcommand" with an option. I have defined \newcommand{\bforall}[2]{\forall #1\, (#2)} so that $\bforall{x}{x \in A}$ writes $\forall x (x \in A)$. I would like ...
1
vote
1answer
37 views

Merge consecutive linebreaks

I have something like this : %\newcommand{\maybehide}[1]{#1} \newcommand{\maybehide}[1]{} \newcommand{\thing}[1]{#1} \newcommand{\bigthing}[1]{#1} \bigthing{ \thing{1}\\ \maybehide{\thing{2}}\\ ...
24
votes
3answers
571 views

Do fontsize environments exist?

Without any doubt there are fontsize switches in the form of control sequences (described here for instance.) But, from time to time I ran into code examples where environment versions of those were ...
4
votes
2answers
35 views

\nameref with quotes

How can I redefine the \nameref command to have the referenced caption in quotes? Here is what I have tried: \documentclass{article} \let\oldnameref\nameref ...
3
votes
1answer
66 views

defining a new infix command

This question kind of already exists here: How to write infix macro/newcommand? But I'm not looking for a way to divide using an infix command, which I know there already exists a command for. I'm ...
2
votes
0answers
27 views

Why must parameters for inner macro definitions double each #? [duplicate]

Or "When would an expression like ###1 be useful?" In macro programming, it's a well-known rule that you need to double your parameter identifiers with each successive layer: \def\insult#1#2{% #1 ...
1
vote
1answer
57 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 ...
1
vote
2answers
32 views

Removing annoying braces/brackets

I have a command that works with this syntax: \startmycommand[{ nononononononononononon nononononononononononon nononononononononononon }]\endmycommand A user has provided a(n) (excellent) ...
7
votes
4answers
152 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)} } ...
2
votes
0answers
33 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 ...
3
votes
3answers
92 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 ...
4
votes
1answer
59 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}}} ...
5
votes
1answer
45 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 ...
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 ...
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
1answer
187 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
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 ...
26
votes
5answers
3k views

Macro for \left( and \right)

I know there has been discussion about this topic, but I haven't seen a working solution. Is it possible to define a macro within LaTeX, such that inside math mode, ( would produce \left( and ) would ...
7
votes
5answers
2k views

Wrapping code (listings, verbatim, or other method) inside a newcommand

For some teaching I've been doing, I'd like to have code from two different languages side-by-side. To do so, I hacked together a newcommand which uses a tabular environment to arrange two verb ...
1
vote
0answers
40 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{} } { ...
1
vote
0answers
72 views

Writing modular classes

As an OOP programmer, I am very attracted to the idea of making separate files for independent features within a class definition, where each feature I feel is too long to be included inline in the ...
8
votes
1answer
126 views

Testing for “emptiness”

Sometimes, in LaTeX one wants to do the simple test if a macro is empty, e.g. \def\foo{% This is... \ifx\baz\@empty Sparta! \else a pony farm. \fi } I am interested in how the ...
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 ...
2
votes
1answer
82 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 ...
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 ...
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 ...
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 ...
19
votes
2answers
3k views

How do I use \show?

Q: How do I use \show to determine macro definitions?. I've followed advice here: The definitions of LaTeX commands and here: \show with fewer lines? and am still struggling. I've naively tried ...
17
votes
1answer
4k views

Comparing an argument to a string when argument is a result of a command with etoolbox

I've got an example like that: \documentclass{article} \usepackage{etoolbox} \newcommand{\ab}{a} \newcommand{\aORb}[1]{% \ifstrequal{#1}{a}{"a" was given}{not a}, % ...
7
votes
1answer
120 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 ...
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
113 views

Add index item by macro

I am struggling with creating a macro that would enable me to create index items by macro. From a former post (LaTeX: is it possible to create a macro to add words to index (using TexMaker)?) I have ...
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 ...
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 ...
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 ...
2
votes
1answer
147 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
70 views

Argument until non-alphanumeric character

Not sure if this is possible or not... I would like to turn (say) + into a command with one argument without braces. This argument should be everything following the + up until the first ...
5
votes
2answers
67 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
238 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 ...
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
1answer
33 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 ...
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 ...
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 ...
7
votes
5answers
397 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 ? ...
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: ...