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

5
votes
0answers
46 views

What are the differences between creating a new macro command vs. a new environment? [duplicate]

For the purposes of collaboration, I want to create a number of short commands or environments that will color the text within its scope so as to identify the author. My first thought was to simply ...
3
votes
1answer
81 views

Displaying the definition of a macro

I have always wondered how certain macros are made and I usually use the \show command to get a glimps of its definition. Is it possible to print the definition of a macro with a command, say ...
7
votes
1answer
63 views

Modifying alltt

I want to create an environment which wraps alltt in such a way that the character ' is replaced by \textquotesingle wherever it occurs inside the environment but is as normal elsewhere. I have tried ...
3
votes
1answer
145 views

Settting PGFplots axis environment options by means of \newcommand and {\newlength,\setlength}

Because I often use the same options for multiple axes in my LaTeX documents, I use the following code to simplify my life. \documentclass{article} \usepackage{pgfplots} ...
2
votes
2answers
106 views

\begin{problem} analogue to \begin{proof}

I recently learned about \begin{proof} ... \end{proof}, which is a good environment to work in. My question is whether there exists a similar environment to state a problem, or whether I can write ...
3
votes
1answer
49 views

Formatting locally the \hline command in a table

Is it possible to alter the \hline command in a table to mimic commands like \dotfill? I would like to be able to change the way the \hline command looks without loading another package like arydshln. ...
1
vote
2answers
236 views

Customize ModernCV

For my resume I'm using the great moderncv, but I'd like to customize it a little. For example I'd like to reduce the heigth of the blank space after the title. In moderncvstyleclassic.sty, I ...
5
votes
1answer
58 views

How to pass comma in value of a (xkeyval) comma separated list of values at \documentclass level?

At \usepackage level, xkeyval allows us to insert commas in value of a comma separated list of values: it is enough to enclose in braces the values containing commas. For instance, the following MCE ...
10
votes
2answers
136 views

Dynamically define commands

I have some latex code that goes a bit like this: % Sp defines a generic command for an arbitrary space, % and all of the others just delegate the bulk of their % work to it so that when I decide to ...
10
votes
1answer
84 views

What is going wrong with this attempt to use \global?

In this question I have already been given a sophisticated way of achieving what I set out to do. This question is not a "how do I do this" question - I already have an answer to that - it is a ...
4
votes
1answer
84 views

Why does \includegraphics[\varone]{\vartwo} not compile?

I want to convert each EPS image imported from within the input file to a PDF version and save it with its original name separately. The code below simulates the real condition in which we don't want ...
1
vote
0answers
63 views

frame in NewDocumentEnvironment

With beamer frames, this does not work. \newenvironment{itemframe}[1]{ \begin{frame}{#1} \begin{itemize} }{ \end{itemize} \end{frame} } Adding fragile, environment=itemframe as an ...
13
votes
1answer
266 views

\renewcommand for commands defined with \def

In the following MWE I've used \renewcommand to redefine a command defined through \def: \documentclass{article} \def\mymacro{Hello} \renewcommand{\mymacro}{Hello world} \begin{document} \mymacro ...
8
votes
1answer
83 views

Optional arguments: xparse vs. xargs

To implement a macro that takes one or more optional arguments that do not have to be placed in the first position, xargs can be used as well as xparse. The latter seems to have more recent updates ...
8
votes
1answer
53 views

Moving the optional argument

When I create macros using \newcommand, I usually provide default variants setting some of the first arguments in a sort of partial application style \newcommand\five[5]{#1,#2,#3,#4,#5} ...
3
votes
2answers
92 views

Variable color for section titles

The following def takes first three letters as an argument: \newcounter{colorCounter} \def\@sectioncolor#1#2#3{% {% \color{% \ifcase\value{colorCounter}% blue\or% red\or% ...
6
votes
2answers
143 views

How to store a counter value at some point in the document?

I'm beginning to learn LaTeX and I need some help with counters. My goal is to store the value a certain counter reaches at some point in the document and use it later. This is my attempt: ...
5
votes
2answers
112 views

Obtaining “greedy” pattern-matching in macros

Consider the following input to TeX: This is TeX, Version 3.1415926 (TeX Live 2013) **\def\a#1\par{[#1]} *\def\b#1\par{(#1)} *\a\b five\par\par *\end Two definitions have the same delimiter, so ...
2
votes
2answers
154 views

About “markdown” like syntax in latex

What I mean with markdown like syntax, is for example using *...* or **...** instead of \emph{...} or \(...\) or \begin{blabla}...\end{blabla}. It seems to be possible to use this "markdown" kind of ...
4
votes
1answer
181 views

(x)ifthen in TikZ

I am searching for a way to conditionally handle some items in a TikZ \foreach specially using an \ifthenelse condition. However, the compiler responds ! Undefined control sequence. <argument> ...
6
votes
4answers
130 views

How to write a TeX macro that accepts a number or a \count register as argument?

What's the most simple way, in plain TeX, to define a \macro that can be used as: \macro{10} \macro{\mycount} such that I can then assign the number to a \count and manipulate it? Note: ...
5
votes
1answer
61 views

Why can't we use a \define'd value as a parameter to \switchtobodyfont[…]?

This is a followup to the question Are \def and \define the same in ConTeXt? This snippet of code in mkiv ConTeXt (TeX Live 2013 version): \define\smallfontsize{8.1pt} \starttext foo ...
3
votes
1answer
136 views

Using \parbox in \resizebox

I tried resizing a \parbox-d text into a 5cm x 5cm square box (without keeping the aspect ratio). The output is absolutely strange to me, even if I don't specify the height. Couldn't find the ...
3
votes
0answers
32 views

Insert LaTeX command after a character inside \texttt{} [duplicate]

Is it possible to parse the argument of a macro for a specified character and insert another LaTeX command after it? I got this LaTeX source, which breaks the \hbox: \documentclass[draft]{article} ...
3
votes
1answer
84 views

Quotation around text without using brackets

I am using the csquotes package and its \enquote{TEXT IS HERE} very often. Instead of \documentclass[12pt]{article} \usepackage[top = 1in, bottom = 1in, left = 1in, right = 1in]{geometry} ...
0
votes
0answers
21 views

“Expanding” locally defined commands [duplicate]

I wrote a paper using custom ("locally defined") commands and environments (e.g. a new quote environment, loads of abbreviations, etc.). The journal requires me eliminate all non-standard LaTeX ...
4
votes
1answer
73 views

Expanding a variable within a protected label

I have some trouble with expanding variables within a protected label. I need a automatisated caption with a label all inside a command. Within the caption I want to have a two digit number ...
9
votes
1answer
112 views

How can I create a better cryptogram environment?

I put together a macro that takes two arguments. The first argument is a string of letters which defines a cipher. The second argument is a message to be encrypted using this cipher. ...
3
votes
1answer
69 views

Using savebox around the BODY of environ

I tried to use a \savebox around the \BODY macro of \NewEnviron. Can I keep the linebreaks somehow (they are gone, in the MWE)? \documentclass{article} \usepackage{environ} \newsavebox{\mybox} ...
5
votes
1answer
71 views

Print arguments of a macro in a random order

I have the following (simplified) LaTeX code that simply prints all its arguments. \newcommand{\mm}[4]{#1 #2 #3 #4} Now, I would like the arguments to be printed in a random order, e.g., #2 #1 #4 ...
3
votes
1answer
91 views

Xparse macro with optional parameter breaks value for PGF foreach

I write a document class and want to execute something a certain number of times, depending on a user-defined quantity. So I thought I'd use a foreach loop from PGF together with accessor macros: ...
4
votes
2answers
74 views

Creating a new array column type dynamically

I am evaluating toks registers for various uses - they are still fairly new to me. I'm using them to construct a table column-wise. During this, I have come across an issue I have failed to find a ...
10
votes
1answer
72 views

\toks register expansion issue - or is it?

I am trying to assemble a table that occurs multiple times throughout a document. It always consists of some fixed columns, followed by a set of columns that appear in one table but are not needed in ...
1
vote
0answers
42 views

Shortcut for Variable-Taking Command

I'm working with vectors, which I'm denoting with $\overrightarrow{a}$, where a is just the name of the vector, and thus is a variable that can take any value. I would like to redefine this as ...
6
votes
1answer
91 views

NewDocumentCommand-defined command in bookmark

I have a scenario where xparse's \NewDocumentCommand has a regression compared to any alternative I know, including ones defining robust commands. So I'm avoiding \NewDocumentCommand in this case, but ...
0
votes
0answers
35 views

Improve command definition to avoid possible break

The following defines my MWE: \documentclass{article} \usepackage{amsmath} \usepackage{totcount} \newcounter{totalpoints} \regtotcounter{totalpoints} \newcommand{\shcpoint}[1]{% ...
11
votes
2answers
184 views

Creating new primitives

Consider the following TeX: \tt ~~~[def]: \meaning\def \par ~~~[let]: \meaning\let \par [define]: \meaning\define \par ~[macro]: \meaning\macro \def\macro#1{some ...
5
votes
2answers
159 views

Mark a place “to be done” with todonotes

I'm trying to create a \tbd (To Be Done) macro to add a todonote on a chapter/section/subsection/etc easily with the following properties. to have a useful list of todos with a simple macro call: ...
9
votes
2answers
208 views

How do others manage their footnotes?

Sometimes I find footnotes either annoying or distracting when trying to edit the body of a text: particularly one which is heavily annotated with footnotes. One solution I've come up with is to ...
3
votes
2answers
99 views

The √ symbol in the unicode-math package

I'm using the unicode-math package in comination with xelatex. Thanks to this package I can write unicode symbols in the tex code. However some unicode symbols, don't compile the way I would expect ...
13
votes
1answer
193 views

Dos and Don'ts of \countdef\mycount=<number> and \newcount vs \newcounter{} in LaTeX

Let's clarify that countdef\mycount=<number> is a bad idea in LaTeX, then clarify appropriate usage of \newcount\mycount vs \newcounter{mycount} in LaTeX. Background: I only started with TeX ...
0
votes
0answers
68 views

Defining #1^#2 as \overset{#2}{#1} for some characters

When I write math in xelatex, I like notation such as: $x \overset{ℝ}{+} y$ $x \overset{f}{↦} y $ $x \overset{(1)}{=} y$ However, as I type things like this so often, I would like to type it ...
4
votes
2answers
70 views

How can I obtain total number of points?

I defined the command: \newcommand{\shcpoint}[1]{% \ifnum #1<2 (\emph{#1 point})\quad\phantom{s}% \else (\emph{#1 points})\quad% \fi } and I use it in the ...
5
votes
2answers
71 views

Have command's output dependent on where (body or section title) it is called

I am using \newcommand{\PRODUCT}{\textsf{PRODUCT}} to format a product name consistently throughout my document. However, I realized that this should not happen in (((sub-)sub-)sub-)section ...
8
votes
2answers
142 views

If \@percentchar represents %, is there a macro for #?

If \@percentchar represents %, is there a macro for #? I have tried \@sharpchar and \@numberchar but both do not exist. Do you have any idea what is the correct macro name for #?
5
votes
1answer
133 views

Separating a decimal in any format into integer and fractional parts in basic LaTeX

Note: I've separated this question from what was becoming a very tangled discussion. I know egreg already has a solution, so I'll just wait until he posts it here. Question: The solution has to take ...
3
votes
2answers
65 views

Determining spacing by a number that is a multiple of a counter

I have \hspace and I have a stepcounter xyz \documentclass[12pt]{article} \usepackage[top = 1in, bottom = 1in, left = 1in, right = 1in]{geometry} \usepackage[T1]{fontenc} ...
5
votes
1answer
74 views

Write a macro with \command, {, and } in argument

I understand that TeX macro arguments can be parsed using proper delimiters. And as the classic example goes in The TeXbook, Along the same line, I tried to define a macro (for some special ...
3
votes
1answer
97 views

Redefine \item command to not typeset some items

Suppose I want to have an enumerate environment, in which I don't want to typeset certain items. I can obtain this in LateX using (let's ignore the problem that the numbers are wrong, this is easy to ...
6
votes
1answer
155 views

evaluate a string like `sin(x)+3` with `x` given

I defined a macro that gets as input a string like sin(x)+3, a starting x and an ending x, which is plotted using \addplot from PGFplots. Now I want to evaluate this function for x equal to the ...