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

Automatically colourize all occurrences of certain strings (different colouring for different sets of words)

This question is a follow-up of Macro: Replace all occurrences of a word, but I would like the same for different colours, that is to have different pre-defined sets of text strings which will be ...
1
vote
0answers
52 views

Macro: Replace all occurrences of words which are identical to content of \label{…} into \nameref{…} (unless of course the \label itself)

This question is a follow-up of Macro: Replace all occurrences of a word, but would like to ask for a possibility to do the same with words (e.g. foo) that are identical to the contents of certain or ...
2
votes
3answers
58 views

Ignore parenthesis contained in a macro parameter

I want that the macro ignore the parenthesis which are parts of the parameter and only conside the last parenthesis as the delimiter, I found a solution with \text{}. Are there any better (and simple)...
4
votes
2answers
36 views

ifboolexpr with a list of toggles - true if any toggle is true

I'd like to write a single file with a collection of e.g. questions, but I want to produce various outputs with a different subsets of all questions each. So at the beginning of my file I want to ...
4
votes
2answers
86 views

Conflict when using \newcommand

I've just realized that I made a big mistake sometime ago when in my preamble I defined the new command \renewcommand{\v}{\mathbf{v}} Now, I'd like to type the czech s using \v{s}, but I can't. ...
1
vote
1answer
26 views

How can I keep everything within a variable/macro on the same line?

I know there are various techniques to keep things on the same line. I have a two-word variable input. For example, Settings App. Let's say there are a group of apps, and I would like them always ...
1
vote
1answer
41 views

TikZ: cannot extract coordinate from intersection point

I am applying the solution proposed in this answer in order to automatically draw a vertical line at the point where to functions intersect. That solution implies creating a new commands that receives ...
2
votes
1answer
47 views

Macro to auto-convert english quotes (“”) to french («»)

French quotes can easily be obtained using \og and \fg commands. Although this is perfectly fine, it's not very intuitive to use them when typing. Is there a way to make latex automatically ...
4
votes
2answers
150 views

\bold in math environment

Having forgotten the command to make text bold in math mode I naively tried $\bold{bold var goes here} these maths symbols are not bold$ and it worked! I became immediately suspicious as I know ...
7
votes
2answers
77 views

read and write commands to auxfile

I have a problem with the aux-file. According to some posts here on Tex-Exchange, the aux-file is read at the beginning of the document (is this at \begin{document} or \documentclass? I wanted to ...
2
votes
1answer
28 views

Modifying command globally from within command

I've seen a couple of somewhat similar questions, but none with similar construct or -- I'll be honest -- none with answers I've been able to understand well enough to adapt to my situation. The ...
4
votes
1answer
55 views

Why does having an empty definition, {}, when defining a new command execute whatever is between the brackets when the command is called?

Here is an MWE: \documentclass{article} \newcommand{\new}{} \begin{document} \new{Why is this printed?} \end{document} Which outputs a document that says "Why is this printed?". My main question ...
4
votes
1answer
60 views

How to call a command in a loop?

there is a code \documentclass{beamer} \usepackage[utf8]{inputenc} \usepackage[english,russian]{babel} \makeatletter \newcommand*{\dothis}[1]{% \stringcases {#1}% {% {a}{so you typed a}% {b}{now ...
2
votes
1answer
52 views

Command suggestions in winedt

How do I get command suggestions in Winedt like in texmaker? I have tried exploring the options but couldn't find anything.
16
votes
1answer
619 views

What is the programming term for the command invoking '\' in latex?

I don't think it would be called a delimiter. Is there a specific term for this character? Just to clarify, I'm talking the slash here: \frac{1}{2}
5
votes
2answers
127 views

How do I nest a command with an optional argument?

I'm having problems making a normalizer command that can nest. Here is my code so far: \documentclass{article} \newcommand{\nrml}[2][]{N_{#1}(#2)} \begin{document} $\nrml[\nrml{H}]{J}$ \end{document}...
5
votes
2answers
112 views

compare a value from \newcounter to value from \newcount

I searched for this topic, but I didn't find anything, so I hope this isn't a duplicate. I've got the following code: \documentclass[12pt,a4paper]{article} \usepackage[utf8]{inputenc} \usepackage[...
1
vote
1answer
59 views

Declaring again the same command

I defined a certain command, but now I want to change its definition. I tried to simply change it, but it doesn't compile. What should I do? Thank you very much. EDIT The former command was \...
14
votes
2answers
392 views

Is there any reason not to use \let to redefine a deprecated control sequence to the currently recommended one?

I understand that \bf and \it are both deprecated in the current version of LaTeX. To the best of my knowledge, the correct control sequences replacing them are \bfseries and \itshape. Is there any ...
4
votes
3answers
78 views

Change counter in \edef

When I try to change a counter in an \edef using \stepcounter, I get a whole lot of error messages ("Missing \endcsname inserted"). When I try to do the same with \addtocoutner I get no error, but the ...
6
votes
2answers
93 views

Trouble with patchcmd and double #

I need to patch the following macro from gloss-greek.ldf (polyglossia): \def\greek@numbers{% \let\latin@alph\@alph% \let\latin@Alph\@Alph% \if@greek@numerals \def\greek@alph##1{\...
1
vote
1answer
94 views

macro: call parameter of level above - double pound ##1 doesn't work

Once again, I have a macro problem. It works almost. I spend a lot of time googling about \expandafter, \noexpand, \unexpanded and others. I used some of them, but nothing lead to the desired result. ...
5
votes
7answers
306 views

newcommand with comma separated argument, and optional arguments

I want to define a command (not with \def) the simplest possible way that it takes arguments separated by a comma, supports an optional argument (the first one). maybe another solution with extra ...
0
votes
1answer
43 views

Kile: How can I insert repeated code snippet and make keyboard shortcut in kile for LaTeX?

To insert figures in LaTeX document I use this code repeatedly: %%%%%%%%%%%%%%%%%%%%%%%%%%% figure environment start %%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{figure}[hb!] \centering \includegraphics [scale=...
7
votes
2answers
1k views

Why is the \bye command not used by LaTeX?

Is there a technical reason why the \bye TeX command was replaced in LaTeX by \begin{document} and \end{document}? I suspect there must be a good technical reason behind this, as otherwise it would ...
2
votes
1answer
33 views

\citefield to include abstract from BibTeX file

I am trying to use \citefield{soure1}{abstract} to include an abstract from my BibTeX file in my document. But, I always receive the message Undefined control sequence.\citefield Here is an MWE: ...
1
vote
2answers
83 views

Adding a tikz picture to every slide in a beamer presenation

I have a tikz drawing I would like to add to every slide in my beamer presentation. Presenly I have to add it manually to every slide - a bit tedious! Is there a way of using a \newcommand to do this ...
1
vote
1answer
69 views

.aux round-trip changing encoding?

I have a situation where I write a simple string out to the aux: \ifinlist{#1}\list {} {\listgadd\list{#1}% write to aux "\macro{#1}"} \def\macro#1{\listgadd\list{#1}} When the \ifinlist ...
5
votes
1answer
49 views

TeXstudio freezes when opening a macro

Since several weeks all my TeXstudio installations show this irritating behaviour: Write a macro like \cite, \input, \SI, \gls, \label, ... Type the opening bracket { As soon as typing the { the CPU ...
4
votes
1answer
48 views

\ifcase suddenly complaning “Extra \or”

For some strange reason, I have an \ifcase which has started to complain "Extra \or" but since \ifcase can have many \ors, how can it have an "extra" one? It's part of a large package, the relevant ...
0
votes
0answers
11 views

Problem using \newcommand [duplicate]

I am using a chemical notation repeatedly so made this new command \newcommand{\MolCState}{$\text{C}^3\Pi_u$} The problem is that in the text when I type \MolCState and the rest of the text the ...
2
votes
0answers
69 views

Automatic lettrine in chapters

I'm trying to get lettrine dropcaps applied automatically on the first word of each chapter. I found some code here: http://dererumnatura.us/archives/2009/02/automatic-usage.html which I've tried ...
3
votes
1answer
59 views

Increment counter with name based on input

I have different counters, and I want to increment them. After I do not want to increment them separately, I wanted to write a macro which does that for me, depending on the input. I have the ...
0
votes
1answer
41 views

\newcommand with intercalated arguments

I want to create a command which works like this: Writting: \w1o2 Should yield: W^{1,2}o(I) I am aware of the parameters use for \newcommand, that would work like this: \newcommand{\wo}[...
5
votes
4answers
166 views

Use \newcommand in \newenvironment - content of environment is argument of \newcommand

I want to create an environment, that generates a new command. There are some similar examples on google, but nothing fits exactly. The minimal (not) working example shows best, what I want: \...
2
votes
2answers
65 views

Call command based on comma-separated list

I have several commands, called \cata to \catd. Now I need a command which loops over a given, comma-separated list, and calls the respective command. My current approach is: \documentclass[10pt,...
1
vote
1answer
51 views

Define \def commands which expand non-static

I have two new commands like \def\test[#2]#1{ \test#1[#2] } \def\testOne[#2]{ #2 is given } if I use the following command \test[xy]{One}, it doesn't work, because \test#1[#2] expands to \test{#1}[...
2
votes
1answer
40 views

Colored custom bytefield

I've made a bytefield packet (see picture), and I want to color the field with the field 256-bit RSA Signature : Here is the code I used (from another question) : \documentclass[10pt,a4paper]{...
0
votes
0answers
38 views

Command calls with multiple parameters

I'd like to improve the latex code from a previous answer by using it all along a resumé which I've reproduced below. The MyFrame command have to be called around 20 times but using different items ...
3
votes
2answers
72 views

How to implement a verbatim or null environment using a boolean within \newcommand

I am trying to use a boolean environment within a \newcommand statement to selectively implement a verbatim environment. When I set the boolean to true it should put the "Answer" within the verbatim ...
5
votes
2answers
61 views

Create new command based on an existing one, but with certain characters escaped

I have to escape underscores very frequently inside \texttt, because I use it to mark functions and variables. I'd like to redefine \texttt, under different name, so I could write \mycommand{...
6
votes
2answers
89 views

Summarize two item levels and combine first level if repetition

I have to write some reports in which I will assign several actions to do to some people. I would like to simplify the creation of an action thanks to some macro and to automate the creation of a ...
1
vote
0answers
24 views

Using newcommand and newenvironment to print a labled tabular [duplicate]

I posted this question as guest with some issues that should be fixed in this version so here it goes. I have the following self defined counter and command: \documentclass{article} \newcounter{...
3
votes
1answer
72 views

Using newcommand inside newenvironment to print a table

I have the following self defined counter and command: \documentclass{article} \newcounter{usecase}[section] \newcommand{\usecasenumber}{\arabic{usecase} \stepcounter{usecase} \newcommand{\usecase}[...
2
votes
0answers
54 views

how to use a \global \foreach? [closed]

Is it possible to make a global foreach? How is the correct way to define arguments inside a \csdef command? \documentclass[a4paper,12pt,hidelinks]{article} \usepackage[utf8]{inputenc} \usepackage[...
3
votes
2answers
56 views

Creating new counter formats on-the-fly with enumitem's \AddEnumerateCounter*

Aesthetic caveat: I am actually using small-caps with hanging figures and not lining. However, in creating a minimal example, I have succumbed to the defaults and created a typographical monstrosity. ...
9
votes
2answers
85 views

\ref with macro as parameter

I would like to write a macro (using Latex3/expl3) that can automatically refer to say plot using several key-value parameters. Here is what I currently have: \keys_define:nn{label}{ Re .tl_set:N ...
1
vote
2answers
48 views

\IfStrEqCase issue using \csname

I want to use \csname inside \IfStrEqCase but I have an error. Here is my code: \documentclass[a4paper,12pt,hidelinks]{article} \usepackage[utf8]{inputenc} \usepackage[brazil]{babel} \usepackage[T1]{...
3
votes
1answer
73 views

Tikz Diagram - Macro Help

I have some code for a network diagram that works when I use it in the body. I've been trying to define a macro so I don't have to write this repeatedly. I have named tikz coordinates defined directly ...
2
votes
1answer
51 views

Forloop with tikz-cd

I am trying to write a macro that (for now) takes as input a number n, and outputs a tikz-cd diagram consisting of n consecutive arrows. However the following code leads to an error: You can't ...