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

Inserting the MacTeX logo into a document

What is the MacTeX equivalent of \LaTeX? \MacTeX doesn't work.
4
votes
1answer
66 views

How to make a hbox several lines under the specified place?

Recently I asked How to colourfuly highlight some lines of an algorithm using algorithm2e? I wanted to acheive this effect using the algorithm2e package: Thanks to JLDiaz's answer I know how to do ...
8
votes
2answers
100 views

same command with output X in main body and Y in footnote

In reference to this question, I would like to ask whether there could be a command that produces the output X when issued in the body of a text, but the output Y when issued in any sort of footnote. ...
5
votes
2answers
111 views

Comparing the arguments passed to a macro

I want to write a command which makes a norm of a vector, with following syntax: \xnorm{v}. I want the norm delimiters to adapt to the size of the expression contained in \xnorm{}, BUT I want also an ...
3
votes
1answer
840 views

ProvidesPackage and usepackage

I have seen papers containing a command \ProvidesPackage. Is it different than \usepackage? What is the difference between \ProvidesPackage and \usepackage?
42
votes
3answers
6k views

Why are some LaTeX macros defined using \newcommand and some using \def?

We have seen this excellent discussion on the differences between \def and \newcommand. From the answers the relatives merits of using \newcommand over \def are obvious. Why are some LaTeX macros ...
7
votes
1answer
124 views

Remove space before macro if exist a environment

I create a new macro: \newcommand{\intersection}[1]{% \par\vspace{\baselineskip}% \noindent\textbf{\large\bfseries\sffamily #1}\par} It works perfectly for what I want, but when there is a ...
6
votes
2answers
121 views

Macro with local variables expanding over several tab-points

I finally developed from egreg's answer in my previous question ( Defining a macro with three optional arguments in the form \newmacro{a}{b}[c]{d}[e][f] and \newmacro{a}{b}[c]{d}*[f] ) While my ...
7
votes
1answer
165 views

New math command with alternative definition for inline mode

I'm interested in writing a command which would result in output that varies when called within $...$ tags and when called within, say, displaymath environment. For instance, assume that I want to ...
6
votes
1answer
207 views

Defining a macro with optional parameter

I like to define a macro with an optional parameter. As an example, consider a macro for the differential: \documentclass[11pt]{article} \usepackage{amsmath} \usepackage{bm} ...
12
votes
2answers
239 views

New command with if/then statement conditioned on non-integer number?

In LaTeX, how do I declare a new command that gives different output depending no the result of a test with non-integer numbers? Specifically, I'd like to a command to compare a number with 0.01 (the ...
3
votes
0answers
272 views

Using the correct amount of space around unit symbols

This is from an old package I developed back in 2003. The idea was to cover international system units (SI) and other type of units, roughly following guidelines from that document. Units should ...
4
votes
0answers
29 views

Format first row of table differently [duplicate]

I have a need to format the first row of my table differently from the rest, and read this answer, which was very useful. So I tried to encapsulate the \multicolumn{1}{c}{#2} into a macro: ...
7
votes
1answer
265 views

Changing from \def to \newcommand*

Consider the following example: \documentclass{article} \usepackage{pstricks-add} \def\door(#1,#2)#3{ \psline[ linecap = 0, linewidth = 1.5\pslinewidth, linecolor = white ...
4
votes
1answer
133 views

A macro adding or removing parenthesis automatically

This is a second question on this macro definition: Defining a macro with three optional arguments in the form \newmacro{a}{b}[c]{d}[e][f] and \newmacro{a}{b}[c]{d}*[f] To sum up: I had define a ...
9
votes
2answers
227 views

Defining a macro with three optional arguments in the form \newmacro{a}{b}[c]{d}[e][f] and \newmacro{a}{b}[c]{d}*[f]

I am defining a macro in LaTeX2e for writing function declarations. I want that the macro has tree compulsory arguments: the name of the function (v.g f), a depiction of the type of variable it takes ...
8
votes
1answer
713 views

Non-italic \emph, italic biblatex titles

The internal Biblatex \mkbibemph macro defaults to being an alias for \emph (see section 4.10.4 Auxiliary Commands and Hooks in its documentation). It is used with \DeclareFieldFormat to typeset ...
11
votes
1answer
157 views

Replacing # characters with luatex

The minimal example below should replace all # characters with another symbol. This works well if I use \# to escape it, but the user should later be able to enter it directly, e.g. to enter hash ...
0
votes
1answer
78 views

How to encapsulate row predicates in `pgfplots`

I'm trying to encapsulate some pgfplotstable code that involves setting up a row predicate. If you are checking table values amongst the predicate code you need access to the table and the only thing ...
4
votes
1answer
392 views

Macro to apply tabcolsep to a table from external file

I am using R to produce my tables via xtable, but I am not using Sweave to write my document. Instead I am using TexStudio and if possible would like to stick with it. Therefore I am using \input to ...
4
votes
2answers
413 views

TeX capacity exceeded in Table of Contents due to macro

I'm working on a macro that when given Hello will make a chapter named hello, and number it like this: 1 - Hello, with the 1 - inside the margins. I also want it to automatically label the chapter by ...
4
votes
1answer
292 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
387 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
125 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
229 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
206 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}} ...
6
votes
3answers
152 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
572 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
210 views

Vertical spaces around display math [duplicate]

(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
97 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
612 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 ...
10
votes
3answers
345 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
363 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
146 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
231 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
66 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
116 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
178 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
57 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
155 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 ...
39
votes
2answers
662 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
110 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
128 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 ...
3
votes
1answer
1k 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 ...
6
votes
6answers
6k 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
71 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 ...
12
votes
2answers
230 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
193 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
151 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
881 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, ...