{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
1answer
130 views

Creating a custom rule

Upon trying to answer, How I can customize fbox and hrule? , I tried to do it using basic LaTeX commands as shown in the MWE below. But for some reason or the other the command \egline does not ...
8
votes
1answer
234 views

How I can customize fbox and hrule?

I want to customization a sample exercises for a book. I like so much this style: I think that is possible with fbox and hrule, but I don't know how I can do it. No need to use fbox and hrule if ...
10
votes
2answers
104 views

Reduce code duplication newcommand

I was wondering how to reduce the duplication of code when using \newcommand. The following code is highlights for explaining things, full TeX code can be found here and the compiled PDF here: ...
14
votes
2answers
175 views

What is the easiest way to modify catcodes in a string?

Assume that a token register contains a sequence of letter tokens, each having a catcode of 12. I want to store in a second token register the same sequence of letter token, altering some catcodes on ...
3
votes
1answer
77 views

define a newcommand that will put text in verbatim

For making a report of my work, I am facing a problem of writing varbatim too frequently. So, I need a workout. Say, I define a newcommand as (for example) \newcommand{\uve}{\textbf{In verbatim}} ...
0
votes
0answers
37 views

Choosing what to \ref from a \newcommand

I have this definition in my class (thanks to this answer): \newcommand\clause{% \immediate\write\@auxout{\string\expandafter\gdef\noexpand\csname ...
6
votes
3answers
116 views

Add s or 's to command with text output

If I do something like \newcommand{\mc}{\textbf{MyCommand}\xspace} I would like to be able to add an s or 's to the text. In this case I would like to easily be able to ouput MyCommands or ...
16
votes
2answers
468 views

Writing musical pitches

Is there a package or macro that allows me to easily typeset musical pitches, like the following: ? Indeed I would like to have subscripts for the octaves. Let's say $\mathrm{E}\flat_3$ How ...
1
vote
0answers
62 views

Vertical spaces around display math

(First of all, I know that \[ \] should be used instead of $$ $$ and I do it.) I'd like to know about the vertical spacing around math display blocks. According to texdef -t latex \[ we have \[: ...
8
votes
1answer
78 views

Very simple condition in macros

I try to define a macro in LaTeX. This macro should give a different output when I use condition true and false. This does not work: \documentclass{article} \usepackage{lipsum} \newif\ifABC \ifABC ...
5
votes
2answers
73 views

How to get character code defined with \let (! Improper alphabetic constant)

Here's a example with the "! Improper alphabetic constant" error: %% this is ok \newcount\mychar \mychar=\number`a\relax \showthe a % shows You can't use `the letter a' after \the ...
8
votes
3answers
179 views

How to customize enumeration to implement Brazilian law texts?

This is a standard model of a Brazilian contract: http://www.consultta.com/modelos_contratos/modelos_contrato/0215.htm It more or less follow the way Brazilian laws are written: as you can see, the ...
9
votes
3answers
288 views

How to force LaTeX only commands?

Recently, I learned that for a long time I have been doing all of my mathematics in LaTeX incorrectly! I was using the $ TeX commands instead of the \( and \) LaTeX commands! I immediately went back ...
6
votes
1answer
87 views

Parsing utf8 problems

There are a number of questions relating to problems when using utf8 input encoding, and the closest I found to my problem is, I think, What characters in a normal text document will screw up LaTeX?. ...
12
votes
2answers
170 views

How to test whether the starred-version of a command is defined?

This question is similar to How to conditionally define a new command in LaTeX? but I want to test if the starred version of a command is defined. The naive thing \makeatletter ...
1
vote
0answers
48 views

Would I use \catcode, tokens, or look outside of tex for a markdown-like parser solution?

My use case: a LaTeX template for courseware designed in a beamer presentation style. The template I'm designing is company-specific and the specificity of the company's presentation guidelines limits ...
10
votes
1answer
79 views

Use node name with arithmetic counter expression

I want to call a PSTricks macro with a node name which involves the result of an arithmetic expression with counters. Consider the following, not working example: \documentclass{article} ...
6
votes
1answer
107 views

Why to use [T2A, T1] when [T2A] is enough?

I am writing some seminar in Cyrillic for university \documentclass[a4paper,14pt]{extarticle} \usepackage[T2A,T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage{droid} ...
3
votes
0answers
54 views

Tex document that displays its own source code [duplicate]

Just out of curiosity, I was wondering how it is possible to write a LaTeX document which, when compiled, generates a document that contains exactly its own source code (i. e. a quine). Since LaTeX ...
8
votes
2answers
100 views

Illegal parameter when nesting commands

I keep getting illegal parameter errors when trying to define a command that contains another previously defined command. I know that you have to be careful with nested definitions, but I didn't think ...
37
votes
2answers
443 views

How to implement (low-level) arrays in TeX

Update: I have revised my question based on the comment by Bruno Le Floch and some further research. As some may know, I'm implementing a huge TeX macro package which has to do a lot of internal ...
4
votes
2answers
79 views

Remove spaces from around a “dummy” macro

In the following MWE (it's minimal, so not the original problem). As you can check there is one space on both sides of \mycommand. While I'm making the macro "dummy" for a specific use: can I remove ...
5
votes
1answer
93 views

Can I make an environment that defaults to include \item\relax tags in front of paragraphs?

This certainly sounds lazy, but my use case is designing a crude template for power point presenters to use in converting their content to a company's specific presentation standard, without their ...
2
votes
1answer
108 views

How to insert table in Beamer frame

I understand from this question that using macros within Beamer frames might create issues. Still I don't understand where should I place the macro definition for \pgfplotstabletypeset. Please ...
5
votes
6answers
230 views

How to create new commands with multiple arguments?

I'd like to create a new command \add that accepts 2 arguments, called entity and title. In other words, the command should look like this: \add{entity}{title}. The output should have the following ...
4
votes
2answers
62 views

Why is \color moving the relative position of an entire \picture environment?

I've been writing a set of simple line drawing macros for some piecewise functions. For some reason, when I attempt to add color to the lines, each segment is translated to the right. I've verified ...
9
votes
2answers
138 views

Can spaces at the beginning of a line ever cause problems?

To structure my sourcecode, I often use spaces for padding: \newcommand{\st}[1]{% \begin{tabular}{lr} \emph{Student} & \emph{Score}\\ #1 \end{tabular}% } Can this ever cause ...
6
votes
1answer
140 views

Can I define a variable that contains a URL (youtube) and call \includemedia with it?

I can successfully embed a video in my latex file using a syntax like this: \documentclass[10pt,letterpaper]{book} \usepackage[latin1]{inputenc} \usepackage{amsmath} \usepackage{amsfonts} ...
6
votes
2answers
84 views

Three-way optional argument in xparse

I am trying to programme a command in x parse that has one optional argument, but which can behave in three ways in the following situations: a) no argument specified, b) optional argument specifies a ...
4
votes
2answers
139 views

Making aliases for variables

I'm trying to figure out how best to define an alias. I have some moderately complicated variable names, such as $p^{i,j}_{t}$, and having to type them over and over again is a pain. More importantly, ...
6
votes
1answer
84 views

\alph without counters

When I iterate numbers with TikZ \foreach, they are stored in a macro. Now, when I need the letter corresponding to this macro, I can only convert it by saving it to a counter and then receiving it ...
6
votes
1answer
74 views

@namedef and math mode

I am trying to do something simple: I want to be able to store and retrieve texts and equations via labels. In particular, I want something like \labelput{<label>}{<text>} % sets the ...
6
votes
1answer
82 views

Expanding a macro as many times as possible without error

I'd like compute cosets using the permute package. Here's what I have so far: \documentclass{article} \usepackage{expl3,xparse,permute} \ExplSyntaxOn % Create a new command to compute the right ...
3
votes
0answers
72 views

Custom commands for `xymatrix` paths

I would like to define a custom command to replace \ar@{->}`r[d]`[l]`[llld]_-{\delta}`[d][lld] in this bit of code: \[\xymatrix{ \cdots\ar@{->}[r] & H_n(X)\ar@{->}[r] & ...
5
votes
1answer
52 views

Using xstring macros in edef

I've tried to use \protect to make the following \edef work but no luck. Can it be done somehow? \documentclass{article} \usepackage{xstring} \begin{document} \def\abc{a,b,c} ...
4
votes
1answer
49 views

xparse command with just optional argument fails

I am trying to define a command with xparse that takes an optional argument but no mandatory argument. The optional argument is a number, which works fine with a single digit but not with more. The ...
6
votes
1answer
135 views

Gobble optional arguments

You can use \@gobble, for instance, to restrict the usage of a macro like: \documentclass{article} \makeatletter \newcommand*{\cmd}[1]{% #1 \global\let\cmd\@gobble } \makeatother \begin{document} ...
2
votes
0answers
47 views

How to insert a space after a substitution of a variable or a command? [duplicate]

I am trying to learn how to define commands (\newcommand) and variables (\def) in LaTeX. When I try: \def \new {$new$} or \newcommand{\new}{$new$} and substitute it in the text: ...
2
votes
1answer
53 views

Formatting and newcommand issues

Following from my problems from here - Formatting resume header! I wanted to make the code simpler by adding the tabular part under a method so I tried \newcommand Here is the code ...
2
votes
0answers
54 views

Why is newtcbtheorem not working while tcbmaketheorem does? [closed]

EDIT: It was simply a matter of outdated package versions. On a mac there are those useful commands sudo tlmgr update –self and after that sudo tlmgr update –all. The following throws the error ...
6
votes
0answers
71 views

Testing if inside \halign [closed]

I am trying to write a macro that has a different behavior when called from text mode, math mode, display math, and math tables. The first three are easy enough with \ifmmode and \mathchoice. But the ...
6
votes
3answers
104 views

Trouble defining a macro that typesets underscore characters as _

I want to define a macro that typesets its argument in typewriter font and allows for underscore characters in its argument. Within a group, I make _ active, I define \_ to be typeset as an ...
5
votes
1answer
290 views

Integral Limits Placement in LaTeX

I'm using a converter to generate LaTeX codes. The converter gives me the results below for integral and sum. limits are above and below. I want sum and other symbol limits as given in (1) but ...
3
votes
1answer
250 views

What does the command \ifCLASSINFOpdf mean?

I found this section in my journal template: \ifCLASSINFOpdf % \usepackage[pdftex]{graphicx} % declare the path(s) where your graphic files are % \graphicspath{{../pdf/}{../jpeg/}} % and ...
3
votes
1answer
91 views

one and the same command for different outputs depending on position in document

A few days ago I had an idea for a \newcommand which -- in my eyes -- would be kind of cool to have. Imagine you wanted to write a lengthy text. In this text you mention a bunch of names of ...
5
votes
1answer
101 views

How do I use the etoolbox package to check if an argument to a macro was defined?

I saw this answer, which uses the etoolbox package to create a macro with an optional argument. Unfortunately, I can't get it to work. Here is a minimal working example: \documentclass[12pt]{article} ...
4
votes
1answer
50 views

Blank Space in Tex Macro Definition

I would like to implement a queue in the following way. A macro (variable?) \queue holds a string that may contain dots. Substrings separated by dots are the elements of the queue. Hence, the string ...
0
votes
0answers
65 views

Splitindex: How do I make splitindex either ignore \ or make verbatim work with splitindex?

I´m trying to set up an index for a custom command called \propDesc. This command highlights properties and their description: \newcommand{\propDesc}[2]{ \fcolorbox{white}{propbg}{ ...
4
votes
1answer
174 views

using fbox in a newenvironment [duplicate]

I am trying to write a new enviroment to add text into a \fbox, when I use \fbox on its own, it works quite nicely \fbox{\begin{minipage}{0.9\textwidth} does this work, I would love if it did ...
14
votes
1answer
137 views

How can I wipe TeX's memory of a user-defined control sequence?

I know I can redefine a control sequence to be empty or \relax, as in my example below. However, doing so doesn't prevent one from using that control sequence , because it is still defined. To add ...