{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.
3
votes
1answer
51 views
How to enforce newlines in latex
I am creating a macro driven songbook in LaTeX, and have run into a problem:
Linebreaks. I want the input text:
Line1
Line2
Line3
To output like that in the PDF as well.
It is not an option to use ...
16
votes
1answer
691 views
Abbreviations and full stop--how to avoid double dots?
I have trouble with macros expanding to an abbreviated expression. Say I have \WHP which expands to "with high prob." (artificial example). I want to avoid the dot after the abbreviation colliding ...
13
votes
0answers
65 views
How to design a command inquiring internally required packages?
How can I define a document command \FilesRequire that writes to the .log (or to the output console) a list of all packages internally required by the declared document class and by the packages that ...
3
votes
2answers
55 views
Selecting grammatical form depending on programatically defined cardinal number (a la ngettext)
There are many languages where grammatical form depends on number of elements described. In English it is singular and plural form (plural usually but not always is generated by adding suffix 's', ...
1
vote
0answers
38 views
Texmaker. Color in the editor. Math mode
I am starting to use Texmaker with the default configuration.
When I use the math mode ($...$) all of it is coloured in green in the editor, making long formulas difficult to follow.
I would like ...
8
votes
1answer
66 views
\href is not working inside \xdef
this is my first question here. I've already spent a substantial amount of time searching this before posting it here.
This is my code:
\documentclass[]{article}
\usepackage{hyperref}
...
3
votes
2answers
50 views
New commands for the equation environment
I'm trying to define a bra-ket command so that I can easily build things like:
\langle e^+ | \gamma^\mu | e^-\rangle
At the moment I have this:
\newcommand{\brak}[3]{
\langle #1 \| \gamma^{#2} \| ...
3
votes
1answer
41 views
Small letters as input but capital letters as output
Is it possible to define (or is there already) a macro which takes small letters as input but gives the same letters in capital as output?
Example:
\CapLet{horse} and \CapLet{fish}
wiht the output
...
5
votes
0answers
75 views
How to anonymize paper without black highlighting [duplicate]
I tried to anonymize a paper with black highlights, thinking it was a good and easy way (even though I could not figure out yet how to do it in the references and citations, since it is my first ...
7
votes
2answers
79 views
Finding the depth of nesting in a macro call
Is there a general way to find the depth of a macro evaluation? For example, consider the following script,
\documentclass{beamer}
\usepackage{mathtools}
\usepackage{calc}
\begin{document}
...
13
votes
1answer
137 views
What is the difference between \vspace{\fill} and \vfill
What is the difference between \vspace{\fill} and \vfill? What about the starred version of them?
0
votes
0answers
39 views
tabular in newcommand multiple parameters
I would like to have multiple parameters that fill a table
One parameter works for definition in preamble:
\newcommand{\Mytest}[1]{%
\begin{tabular}{c}
#1 \\\hline
\end{tabular}%
}
...
9
votes
1answer
53 views
Why doesn't \@ifstar work inside a caption?
For some reason, the following minimal example doesn't compile:
\documentclass{article}
\makeatletter
\newcommand{\testMe}{%
test
\@ifstar{1}{2}%
}
\makeatother
\begin{document}
\testMe
...
6
votes
1answer
48 views
Declare new command using another command with a name based on its input? [duplicate]
I'm trying to write a command that will declare another command with a name that will be based on the input given to the outer command: e.g.
\newcommand{\buildcommand}[1]{
...
6
votes
4answers
67 views
How can I capture both superscripts and subscripts after a macro
This question piggy-backs on the answer to Capture a macro's subscripts/superscripts by the macro by egreg.
I'm attempting to use the xparse package to create some macros and I'd rather not have ...
4
votes
2answers
69 views
Strategies to deal with \ being in an awkward place on the keyboard?
So, I'm typing on a standard EN-US Qwerty keyboard, where the \ key is in the top right below the backspace key. I find that LaTeX requires me to repeatedly type this key for macros and such, and that ...
6
votes
0answers
426 views
How to automatically generate Venn diagrams given the inclusion relations?
I'm writing a paper about classes of formal languages, and I'd like to have a diagram showing their heirarchy.
Something similar to this (from Wikipedia:)
Is there a LaTeX package which, I can give ...
5
votes
2answers
38 views
Macro parameter character in \input file
I would like to include some paragraphs from external .tex files in my document, very similar to what \lipsum does. As far as I understood it until now is using \input equivalent to directly typing ...
5
votes
1answer
39 views
Empty List Environment
I created commands for resume fields. This is a simplified example of the desired outcome:
Currently, I have to create two separate commands to do this, one with \begin{itemize} and the other ...
1
vote
1answer
50 views
Positioning \NewEntry elements in a CV
I need to write a CV that is attached to my thesis. Because I wrote my thesis in latex (classic thesis), I would like to set my CV in latex as well so it fits the layout of the thesis.
I use this ...
9
votes
3answers
133 views
Transforming numbers to \alph numbers
Is it possible to have a simple command \makeAlph which would do the following :
return a when it receives 1
return b when it receives 2
etc.
return nothing (or whatever ; actually that's not ...
7
votes
5answers
103 views
Preventing math mode from parsing macro input as math?
Basic Problem
I'm trying to produce a command sequence \m that
Is called from within math mode, with a single argument list
"Replaces" all instances , and ; in list with & and \\ (resp.)
...
14
votes
5answers
598 views
Splitting a string greedily
I would like to split a string on a certain character, say /, but with the first part being matched greedily. In other words, my first approach
\makeatletter
...
22
votes
3answers
2k views
Defining commands/abbreviations that contain numbers
I tend to use \newcommand to define macros for symbols I use often, e.g. \newcommand{\hankel}{H^{(1)}_0}. One inconvenience of this approach is the fact that command names cannot include numbers. ...
6
votes
3answers
99 views
Commands that may take a variable number of arguments
I have a situation where I want to define a command that takes a variable number of arguments, where the number of arguments is known programmatically via a \count, and process the parameters in some ...
1
vote
2answers
44 views
Print macro content with condition
I would like something like the following:
\documentclass{article}
\newcommand{\acell}{}
\newcommand{\bcell}
\newccomand{\zcell}[1]{#1}
\ifx\acell{A}
\ifx\bcell{A}
\zcell{yes}
\else
\zcell{no}
...
4
votes
1answer
48 views
pgfplots: using macro for tick label
I would like to use a macro to define the label of an extra tick in a pgfplots picture. When the macro uses a greek character it generates an error:
! Missing \endcsname inserted.
Here is my MWE:
...
25
votes
5answers
964 views
Censoring Curse Words with Grawlixes
Suppose that I would like to censor a curse word <word> using grawlixes, e.g. "What the #@$! are you doing?!" How can I define a command \censor such that \censor{<word>} results in a ...
1
vote
1answer
25 views
Issue wrapping a titlesec titleformat in a newcommand
I have a long document where I change the style of subsection headings in different parts of the document. I'm using titlesec with the explict option as it is necessary for the way I'm formatting ...
0
votes
1answer
47 views
No space after the word when I defined a macro, bug? [duplicate]
I defined a macro but I found the word spacing is gone. Am I missing something?
\documentclass[11pt, oneside]{article}
\newcommand{\abc}{$abc$}
\newcommand{\abcSpace}{$abc$ }
\begin{document}
Word ...
3
votes
0answers
29 views
Adding an asterisk to specific numbering in the multienum package
@egreg answered beautifully my question on adding an asterisk to an item locally by introducing the command \moditem. I am wondering if this is possible with specific items in the multienum package. ...
4
votes
1answer
42 views
Bold enumeration in multienum package
I am trying to bold the enumeration in the multienum package. The MWE illustrates what I have so far:
\documentclass[letterpaper]{article}
\usepackage{multienum}
\begin{document}
...
8
votes
2answers
69 views
How can I combine two text strings to represent the name of a command?
I want to combine one command with a text string to represent a second command. In MatLab it would be possible to concatenate these two strings into one string and evaluate this new string. However I ...
13
votes
3answers
126 views
\newcommand argument confusion
I'm trying to work through LaTeX Beginner's Guide by Stefan Kottwitz. Here's where I got stumped:
\documentclass{article}
\newcommand{\keyword}[2][\bfseries]{{#1#2}}
\begin{document}
...
9
votes
2answers
149 views
Is a TeX macro defined?
I am looking for a way in TeX to check if a macro was defined.
Currently I use a rather tangled way. I exploit a sort of side effect when comparing two macros via \ifx; this command returns:
true, ...
7
votes
0answers
46 views
Skip spelling in EMACS for the content of a user macro
In EMACS, in order to skip spelling for the arguments of a user macro, one appends an entry to the ispell-tex-skip-alists variable.
For example, to skip parsing the argument of \mycommad, one adds ...
8
votes
2answers
94 views
How do you peer into the definition of a robust command?
I know that, whenever I want to see how some control sequence, say \mycontrolsequence, is defined, I can use
\show\mycontrolsequence
then compile my code and look up the .log file. However, robust ...
4
votes
2answers
78 views
Wrapper around xdef to check for conflicts
How can I write transparent wrapper around xdef that, depending on package options, report error, override or obey previous definition without sacrificing all flexibility? I have no idea how to pass ...
3
votes
1answer
38 views
Errors in passing a previously concatenated string to foreach
Motivation
While attempting to answer Pie chart with values as angles not percent, I stucked on passing a string to a foreach.
The context
To makes things clear, I briefly introduce the context. ...
3
votes
2answers
82 views
How to store and append text for later use (inside enumerate environment)
I'd like to make a container in LaTeX in which I can store and append LaTeX-code for later use.
I have found many solutions to what I'm basically try to do (here for instance), but if they work, ...
9
votes
2answers
95 views
Expansion problems with pgfkeys
I'm using pgfkeys, and a fairly adventurous syntax in which the values for some keys contain additional key/value pairs. (For instance, the value of the nodes key is a list of pairs, and the second ...
8
votes
4answers
106 views
Partially expanding a command
My \john command is defined like so:
\def\john{\DontExpandMe}
I would now like to repeatedly change its definition, to keep adding some extra stuff on the front.
\foreach\i in {ape,bat,cow,dog} {
...
9
votes
1answer
101 views
A question about a macro definition error
Given:
\documentclass{minimal}
\newcommand{\emrule}[1]{\rule[4pt]{#1em}{0.2pt}}
\newcommand{\endash}{\emrule{.5}}
\begin{document}
2000\endash2013
\end{document}
I get:
! LaTeX Error: Command ...
18
votes
2answers
266 views
Difficulty with macro expansion
I'm not getting the output I want from my LaTeX code, and I think the problem is that I'm not expanding things at the right times.
Code
\documentclass{article}
\usepackage{tikz}
...
11
votes
2answers
77 views
Duplicating Environments
When I want to globally modify a command in my document, I will often use a duplicated version of the original in the stencil, with the help of the \let macro. For example, if I wanted to do ...
2
votes
1answer
44 views
Problem with \newcommand that mimics lstinline
I'm trying to replicate a part of a scanned book. Book is about programming (pure C).
I need to use many commands with a same name but with different surrounding, for example, background color etc. ...
50
votes
2answers
1k views
If LaTeX is only a macro package, why does it have its own executable?
From other answers on this site and the FAQ of the TeX User Group my understanding is that:
TeX is the original typesetting program, written by Knuth
Omega, eTeX, pdfTeX, XeTeX, LuaTeX are engines. ...
6
votes
1answer
40 views
Macro limited in scope to the tabular cell in which it is invoked?
How do I reuse cell delimiter of a tabular environment (usually ampersand) for delimiting a macro parameter?
Like this (which unfortunately doesn't work):
\def\mymacro#1&{#1}
...
...
8
votes
1answer
46 views
A proxy command for deprecation
I'm interested in defining a macro to deprecate other macros. The system on which we are working goes through a lot of refactorings and is used by more than a couple people, so we want to be able to ...
1
vote
1answer
41 views
How to create extensions for LaTeX?
I want to create extensions in LaTeX.
What I really want to do is be able to write \myOwnCommand and have something happen to it, like a new class and functions in programming.
It would be great to ...


