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

1
vote
0answers
34 views

What's the shortest input that makes TeX and/or TeX-based systems go into a loop? [duplicate]

The following 12-character input causes TeX to go into a loop. \def\x{\x}\x It won't crash, it won't produce an error message, it'll just sit there for ever, trying to compile the document (but not ...
12
votes
2answers
242 views

All about \shipout

While reading about packages that allow to hook macros to certain events, I came across this command, \shipout. Searching on the internet didn't help a lot but if I'm not so wrong it's somehow related ...
2
votes
1answer
129 views

LaTeX: is it possible to create a macro to add words to index (using TexMaker)?

I'm just finishing my first document (a book), and I have to create an index (\makeindex, \printindex, \index{WORD}, ...). I am using TexMaker on Linux. I was wondering if it's possible to define ...
8
votes
1answer
73 views

How to use a string in an auxiliary file to update the header?

A document (typical of many) has a header which displays a timestamp in the form of a text string (“25 December 2013”). The timestamp string originates in a file "update" which is loaded with \input. ...
4
votes
1answer
88 views

Producing an empty argument

I've been using Herbert's answer in Check for empty macro argument to check if an argument is empty. I was wondering if it is possible to expand Herbert's solution to also detect if a macro argument ...
1
vote
0answers
32 views

Is there a way to `\show` a protected macro? [duplicate]

When I want to see how things are done in LaTeX, I often face a protected macro and I can't see its definition. For example, \documentclass{article} \usepackage{amsthm} \begin{document} \show\qed ...
9
votes
1answer
107 views

Multilevel bullets

I want to write something that I could use for multilevel bullets, for example: I. Title Subtitle a. sub-subtitle ... In LaTex I got \def\startitems { \begingroup \parindent\z@ ...
1
vote
1answer
74 views

Define new argument in LaTeX

I have tried many times something like the following: \def\variable{English} that can be used in the following way later: \selectlanguage{\variable} I am searching for a generic way to solve ...
17
votes
4answers
312 views

Is it possible to add an “or” condition to a \def?

Is it possible to have something like \def\fiveorsix{5,6 OR 6,5} So that the following works: \documentclass{standalone} \def\fiveorsix{5,6 OR 6,5} \makeatletter \newcommand{\test}[1][]{ ...
11
votes
1answer
227 views

How to put A under B with syntactic sugar?

Say I would love to have a command that would put text A under text B. Yet I do not want to write my command arguments in \commandname{A,B} fashion. Instead I would love to write something like to ...
1
vote
0answers
30 views

\newcommand vs. \def (LaTeX/XeLaTeX/LuaLaTeX) [duplicate]

I've been trying to understand what something like \def\mapu#1#2#3{\overset{#1}{\underset{#2}{#3}}} does, and it seems it does the same as ...
6
votes
2answers
102 views

Using boxes to define an adjusting (Dirac) bracket

I'd like to define a set of adjusting bracket, called in physics Dirac brackets. This brackets accept three arguments, separated by vertical lines, and all of them are enclosed by angles, e.g. in ...
4
votes
1answer
42 views

Alternative eqref command (generating a footnote)

Sometimes I think it is helpful to have a visual reference to a cited equation, besides its reference number. Let me give a (manual) example of what I'm talking about: \begin{document} (...) ...
0
votes
2answers
93 views

Is there an Autocorrect feature in TeXStudio 2.6.2?

I was wondering if there's an Autocorrect feature in TexStudio 2.6.2 that works like in MS Word so that if I have to type a certain word many times, the editor writes it for me as soon as I press ...
1
vote
1answer
100 views

How to define a command that could generate similar environments just as \newtheorem does?

It's well known that the LaTeX built-in command \newtheorem could generate a series of the theorem environments that are similar: they share the same theme of layout style but differ in their name and ...
6
votes
1answer
77 views

A command to define other commands with arguments [duplicate]

I want to define a command that defined other commands. A similar problem was considered in Dynamically define commands. However, I couldn't figure out how to adapt that solution to my needs because I ...
3
votes
0answers
72 views

Replacing text with another one

I need a command to replace the text from left to right given below. for example the command should change ü into \"{u}. I found some command about this but i could't apply. {ü}{\"{u}} {ğ}{\u{g}} ...
5
votes
5answers
191 views

how to make text be copied to another part of a document?

I have a paragraph in one part of the .tex file that I want to be duplicated in another part of the .tex file. I could do ctrl-c, ctrl-v... as easy as that, but then if I modify one place, I will ...
9
votes
1answer
105 views

Suggestions for an automatic taxonomy environment

Background In this site there are excellent examples of How to draw up a hierarchical tree diagram for taxonomic classification of several groups but often you must show only the position of a ...
5
votes
1answer
55 views

New commands having variable numbers of parameters and being used in subscripts

Is it possible to make the last two cases work without the need in wrapping the command calls in curly brackets? \documentclass{article} \usepackage{amsmath} \usepackage{amssymb} \makeatletter ...
7
votes
1answer
62 views

Trim spaces in a macro with expl3

I'm inserting graphics from data in a csv-file and due to lazy input I have to get rid of leading and trailing spaces. It works fine with the trimspaces package. \documentclass{article} ...
4
votes
1answer
93 views

\includegraphics{\input{|shell command}}

I want define a command "\foo" which outputs the result of a shell command, such as: \newcommand{\foo}[1]{\input{|"#1"}} This works, except if I'm trying to use this command in the context of ...
1
vote
0answers
56 views

Is it possible to change the \cite command in the following way?

I know this does not follow very good citation guidelines, but I want to change the cite command so that in addition to whatever the current bib file dictates, it will also print in the name of the ...
7
votes
2answers
188 views

math conditionals using (if - else - fi) command

I saw these command when i searching sth. I wonder if we can increase numbers if conditions. it's like if{0} = a, if{1}=b, if{2}=c, if{3}=d etc. \newcommand{mycommand}[1]{ \if{#1 != 0} Some text, ...
4
votes
2answers
103 views

\renewcommand for \forall to add a parameter

Hi I'm trying to redefine the \forall command so that it accepts an argument instead of using the regular juxtaposition. What it looks like at the moment is ...
3
votes
1answer
79 views

Inserting the MacTeX logo into a document

What is the MacTeX equivalent of \LaTeX? \MacTeX doesn't work.
4
votes
1answer
49 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 ...
2
votes
0answers
74 views

Problem with overwriting diagram files using feynmf

I've just installed feynmf package and tried working with a standard example. I'm working with MikTeX 2.9 on Windows. The compilation worked fine and I got the diagram in the PDF, but when changing ...
7
votes
2answers
75 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
65 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 ...
2
votes
0answers
158 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?
39
votes
3answers
2k 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
73 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
82 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
99 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
138 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} ...
11
votes
2answers
162 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 ...
2
votes
0answers
98 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
23 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: ...
6
votes
1answer
148 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
61 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
155 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 ...
6
votes
1answer
183 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
108 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
38 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 ...
3
votes
1answer
90 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
94 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
128 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
233 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
103 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: ...