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

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
31 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
62 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
68 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
45 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
55 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
53 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
40 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: ...
5
votes
4answers
153 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
64 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: ...
1
vote
1answer
50 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 ...
2
votes
1answer
35 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) : ...
0
votes
0answers
37 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
69 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 ...
6
votes
2answers
86 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} ...
3
votes
1answer
68 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} ...
2
votes
0answers
50 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} ...
3
votes
2answers
47 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
83 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
47 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} ...
3
votes
1answer
69 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
50 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 ...
3
votes
1answer
165 views

Why does declaring a command in-document produce horizontal space?

I'm really confused about why there is some extra horizontal space that appears before the second "Test" on my second line: \documentclass[12pt]{article} \usepackage[english]{babel} \begin{document} ...
0
votes
0answers
33 views

What does mbox and fbox stands for? [duplicate]

what does \mbox and \fbox stands for? I felt that it's easier to remember macros when I know what they stand for.
1
vote
1answer
25 views

change caption of multiple listing styles

I want to have different listing environments, each with an own caption. My try was this (vorlage.tex): \documentclass{scrreprt} \usepackage{regexpatch}% http://ctan.org/pkg/regexpatch ...
1
vote
0answers
66 views

Using /csname in

I want to use a smarter solution for a big CSV file with many LocalX columns \documentclass[a4paper,12pt,hidelinks]{article} \usepackage[utf8]{inputenc} %\usepackage[utf8x]{inputenc} ...
13
votes
3answers
330 views

Defining a command to define an asterisk command

I have the following command \defmeta that defines two other commands (one starred and one unstarred) \documentclass{article} \usepackage{suffix} \newcommand{\genericcmd}[3]{#1 #3 #2 } ...
2
votes
1answer
34 views

Pre or post process some node's options (nodes in node and main node labels)

For setting sub nodes in node I use the following code (provided by Mark Wibrow): \documentclass[border=3mm, tikz, preview]{standalone} \makeatletter ...
3
votes
2answers
73 views

Escape hash tag in strings passed to newcommands

I have been trying to write a simple new command to make a piece of code more flexible and readable (a MWE is below). In it I need to be able to pass a string to a new command that contains a hashtag ...
1
vote
1answer
57 views

Environment inside \newcommand [duplicate]

This is my first question so feel free to correct it in any way. I am struggling with the following problem: using an environment in a \newcommand. I want to define the command \describe this way: ...
1
vote
1answer
47 views

Active character in a command

I would like \forall to trigger a certain behavior (for the purpose of the example below: change the text color to red), which is cancelled when the next ( is encountered. I can make this work when ...
3
votes
2answers
36 views

Avoid recursion in \renewenvironment

I'm trying to redefine an environment in order to add a command after the \begin without having to add this command in manually everywhere. For example, I'd like to replace every instance of ...
2
votes
1answer
36 views

Getting user defined constants into the preamble

I think this is a problem of expandable content, a concept I haven't quite got the hang of yet... Lets say I have a preamble or cls file that is trying to configure hyperref. If I have manually setup ...
12
votes
4answers
421 views

High-order recursive macro to define several similar macro at once does infinite loop

I’m a fan of factorization and hate code repetition. So I was trying to define a macro which defines for me all the common mathematical sets commands (\C, \N, etc.) and made a recursive function ...
6
votes
2answers
105 views

Is there a modal command for MakeLowercase?

Analog to this question I've been wondering WHAT is to \lowercase as \bfseries is to \textbf? (... and for uppercase, or \MakeLowercase and MakeUppercase, etc., which also seem to be text-block ...
3
votes
1answer
37 views

Different command definitions with and without optional argument renders incorrectly

I used answers given to this question (in particular, this answer by egreg) to come up with the following code: \documentclass{article} \makeatletter \def\ifemptyarg#1{% ...
2
votes
1answer
39 views

Mark lines like overfull

I apologize if this has been asked before. I have searched and searched to no avail, it seems questions about getting rid of over/underfull boxes drown out any questions about how to produce the ...
2
votes
1answer
42 views

\def'ed plain-text argument behaves differently from plain text

So this is my example, closely related to Remove extra curly braces. Apart from my application, trying to line-break the labels in the margin even if they do not have spaces in them, I am trying to ...
2
votes
0answers
38 views

Bullet and alignment issue in itemize environment [closed]

Itemize environment under the macro is not showing bullet. It's showing dash. Also, there is an issue with horizontal alignment. It's not aligned properly. I already fixed with by using ...
1
vote
0answers
14 views

Tikzcd withing newcommand? [duplicate]

I want to define a new command using the package tikz-cd. For example, suppose I want to define: \newcommand{\simplearrow}[3]{\begin{tikzcd} #1\arrrow[r, "#3"'] & #2 \end{tikzcd}} This would ...
1
vote
1answer
38 views

Passing a macro to a vector declaration in tikz/pgf

Inspired by an answer I gave here, the question arose how I need to properly define a macro, if I want to pass it to a vector declaration in tikz. If you want to modify a vector, the syntax used is ...
4
votes
0answers
80 views

Getting negative vspace to behave

My TeX code (including parameters in command definitions) that creates lyrics sheets and chord sheets of songs is generated dynamically by other code accessing database data and processing it line by ...
4
votes
4answers
97 views

Generating a table from key-value pairs

I want to automatically generate a table from a comma separated list of key-value pairs such as {{x=1,y=2},{x=3,y=1},{x=2,y=3}}. In each "row" the "keys" are always the same (they become the column ...
8
votes
2answers
730 views

Own mathematical function f(x)

I'd like to define an custom function f(x). For example \f{3} should print ln(3) + 3 if the function is set to ln(x) + 3. One should be able change the function: \setfunc{sin(\x}}. This should only ...
1
vote
1answer
51 views

Convert text from mixed case to start case

I'd like to change the capitalization of a macro from mixed case to start case. Let's say the following macro is already defined: \newcommand{\tostring}{toString} I can change the first letter to ...
2
votes
1answer
109 views

Command macro for an environment

How can I define a command macro using \newcommand so that the argument to the command is surrounded by an environment?