Questions tagged [macros]

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

1
vote
3answers
56 views

How to create enumerated local commands

I have a custom environment to recreate a certain layout formatting a variable number of text entries in multiple enumerate environments. So far I have been defining multiple similarly named commands ...
6
votes
2answers
73 views

How to set replacement text of function from token list variable?

I'm trying to define a local function with parameters in expl3 where the replacement text of that function should be the content of a token list variable. My current approach is \tl_set:Nn \...
6
votes
2answers
83 views

Recording the inputs of a command and producing a list of them later on

I have some macros I use a lot, mostly just for my digital note keeping. Because of the nature of these macros, I could use a specific versions of these. For example I mention some file names ...
1
vote
2answers
29 views

If I redefine \citep, then \citep[prefix][postfix]{citation} does not work

I have refined \citep so that the colour of the hyperlink turns "Teal": \let\oldcitep=\citep \def\citep#1{\hypersetup{citecolor=Teal}\oldcitep{#1}} %changes colour of citep link to Teal. NB: I have ...
0
votes
0answers
14 views

Spacing after definition [duplicate]

I have the following definition in my latex document: \newcommand{\emp}{\texttt{EMP}} This eats the space after it. For example, if I type Assume that relation \emp is fragmented The latex output ...
1
vote
1answer
35 views

Starred version of macro causes hyperref error if used in section command

In the following MWE \documentclass{article} \usepackage[T1]{fontenc} \usepackage{lmodern} \usepackage[utf8]{inputenc} \usepackage[pdftex,unicode,final]{hyperref} \input{glyphtounicode} \...
10
votes
3answers
139 views

How to make \{ and \} automatically have \left and \right

Desired behavior \{ and \} should turn into \left\{ and \right\{. Attempt 1 \edef\{{\left\{} \edef\}{\right\}} Error message TeX capacity exceeded, sorry [input stack size=5000]. \font@name ->...
3
votes
1answer
29 views

list of numbers as command option, numbers will be used to define colors

What I'm trying to do is to pass a list of numbers as an option to a command. The numbers will be used later to define colors inside a tikz picture. The first part I can do, here's an example \...
3
votes
1answer
47 views

How to define two expl3 functions with the same base name and different signatures?

I need to define a function that takes no parameters, then define a function with same name but with a single parameter, and call the first function from inside the second. If this is not how it's ...
3
votes
2answers
79 views

keyval - function for keyB should act dependent on value of keyA - how to do this?

I'm new to LaTeX. I learn and I use article class. I struggle learning working with keyval package: I try to write macro \macro which only uses one mandatory argument where user can provide key value ...
15
votes
1answer
247 views

pic versus macro in TikZ

Consider this code in the TikZ - PGF manual, which uses a macro % Main code from % The TikZ - PGF manual % Author: Till Tantau et al % Version 3.1.3, released May 9, 2019 % Page 40 \...
0
votes
0answers
22 views

Narrower kerning of symbols generated by Tikz [duplicate]

I'm using LaTeX to render a set of custom glyphs. Each glyph is perfectly rectangular, at a 3.5 x 5 aspect ratio, and they're defined something like this (the following example just lines the borders ...
3
votes
1answer
53 views

An understanding trouble with \framebox

I'm reading More Math Into LaTeX, and it introduces the command of \framebox at section 3.9.2 on page 91-92. There are the two following code examples which show different output: \framebox{\makebox[\...
3
votes
1answer
18 views

\newcommand for short notation for a \multicolumn [duplicate]

Many times is handy to define \newcommand for short notation for \multicolumn. For this purposes I test two definition for such commands: \newcommand\my[2]{\multicolumn{1}{#1}{#2}} \newcommand\mx[2][...
5
votes
2answers
332 views

How do I superimpose two math symbols?

I want to create a symbol that superimpose \top and \bot. I have done this \documentclass[12pt]{article} \usepackage{amsmath} \newcommand{\modd}{\top\hspace{-3.17mm}\bot} \begin{document} $\modd \top ...
5
votes
3answers
98 views

Looping over charts and names simultaneously

I want to use a common index to loop over two separate comma-separated lists at once, one which is a list of abbreviations and one a list of names. I want to use the abbreviations to import charts as ...
2
votes
1answer
33 views

Redefining \label to not default to <1>

According to this question, labels are defined by default on a beamer slide to always be defined at the first slide <1>. Indeed \show\label shows > \label=macro: ->\@ifnextchar <{\...
1
vote
0answers
28 views

Using pgfkeys to make a custom tikzpicture command with multiple use of addplot

Consider this MWE: \documentclass{article} \usepackage{tikz,pgfplots} \usepackage{pgfkeys} \usepackage{xparse} \usepackage{filecontents} % DATA 1 \begin{filecontents*}{data1.txt} 1 1 2 4 3 9 4 16 5 ...
0
votes
0answers
21 views

Setting defaults with keyval-interface - do it in the current scope or do it globally?

Assume a LaTeX 2e-macro, be it named \foo, which processes the content of one optional argument via keyval-syntax. E.g., \foo[key1=value1, key2=value2,...,\keyN=valueN] I would also like to have a ...
17
votes
2answers
342 views

Are there guidelines for finding good names for LaTeX 2e packages and control sequences defined in these packages?

I have written some code which I would like to submit to CTAN as a package for LaTeX 2e. (readme, dtx, ins, pdf with manual and commented sources.) I need a good name for the package. Question: Are ...
0
votes
0answers
15 views

Spacing of a macro similar to \sin [duplicate]

I want to create a macro \dom (for domain) that behaves similarly to \sin in the sense that it has spacing \, if it is followed by a letter such as in \dom a and that is has no spacing if followed by ...
7
votes
3answers
268 views

How to test if argument is a single space?

I am currently writing a document, that sometimes requires me to alternate the colors of the letters in a sentence. I thought it would be easy to find a way to create a macro that does that, but I've ...
1
vote
1answer
32 views

\dif command doesn't work as intended

I've defined the command: \newcommand{\dif}[1][]{\mathrm{d} {#1}\,} since I use the notation: \int \dif{x} f(x) so that there's a space after every differential. However, it doesn't work as ...
2
votes
2answers
21 views

macro within pgfplots in beamer

I want to create a macro so that in a beamer presentation it produces the same plot with slightly different data. But it seems as though a problem exists before I include an argument in the macro. ...
5
votes
3answers
175 views

How do I unravel apparent recursion in an edef statement?

The text book that I'm writing requires the ability to dynamically build an alphabetically sorted list. As to not invoke the overhead of high powered, general purpose packages, I have opted instead to ...
7
votes
2answers
202 views

Can I have a delimited macro with a literal # in the parameter text?

I'm trying to define a macro which grabs everything until the next # (parameter token). My twisted imagination wants something like this: \def\test#1###2{(#1)[#2]} \test hello#{world} to grab hello ...
1
vote
0answers
31 views

How to check if attempts at totally expanding the tokens of an arbitrary sequence of tokens would yield an error?

How to check if attempts at totally expanding the tokens of an arbitrary sequence of tokens would yield an error? How to check if attempts at totally expanding the tokens of an arbitrary sequence of ...
6
votes
5answers
156 views

Appending to a command while also expanding a counter

I want to append some text to a command but expand a counter while doing so. Here is an example of what the problem is: MWE: \documentclass{article} \newcommand{\topics}{} \newcounter{topic} \...
0
votes
0answers
34 views

Is there a package for abbreviations management? [duplicate]

I wonder if there is a way to efficiently manage abbreviations. When I do my Ph.D. work, I usually copy the contents from one document to the other. When rewriting contents to a journal or for a ...
0
votes
1answer
24 views

Savebox from within enumerate [duplicate]

I'm completely puzzled by this: I'm trying to create a simple command that will modify a savebox from an enumerate, and I've worked it down to a minimal example of some weirdness: ... % Create our ...
0
votes
2answers
76 views

How to call a command accepting 2 optional args defined with `\NewDocumentCommand` and pass only 2nd optional arg to it (skipping the 1st)?

If \myB accepts two optional arguments, \myB sets both of them to default values, \myB[5] sets first to 5 and second to default value, \myB[5][10] sets first to 5 and second to 10. But how do we set #...
4
votes
5answers
243 views

How to epxand macro with optional argument equal to (x,y) so that it becomes part of \path(x,y)--(a,b); inside another macro (expansion problem)?

When \myCoordinate accepts MANDATORY argument, following works: \documentclass{standalone} \usepackage{tikz} \newcommand\myCoordinate[1]{#1} \newcommand\myPath[1][(1,1)]{\path[draw=red]\myCoordinate{#...
2
votes
1answer
18 views

Transforming string wrapped with double asterisks on both sides to a bold text

I am trying to convert **sometext** to bold. I came across the following snippet: \makeatletter \def\starparse{\@ifnextchar*{\bfstarx}{\itstar}} \def\bfstarx#1{\@ifnextchar*{\bfitstar\@gobble}{\...
1
vote
0answers
39 views

Is there a way to create a “function” that generates LaTeX code based on the parameters?

Context: I work as a statistican for a high school. One of my responsibilities is to generate performance reports for every teacher in the school, based on how well students evaluate them. I use ...
7
votes
3answers
230 views

Macro that takes any latex code as an argument

So I am thinking of creating a macro that takes any latex code as an argument. For example, \newcommand\purp[1]{\color{purple} #1} I hoped that this macro would make any latex code inside of \purp ...
1
vote
1answer
46 views

Repeat blocks of code

I'm looking for a way of repeating an entire part of a document n times. The documents I create look like the following : most of the time, I'm repeating half a page. This is because I print those ...
2
votes
2answers
58 views

How to use a string to form the name of an existing command?

In my project, I already have a file containing commands for names of my documents : \newcommand{\docOne}{Title of my first document} \newcommand{\docTwo}{Title of my second document} ... I've also ...
1
vote
1answer
65 views

ConTeXt Project Structure: Add metadata to component

I am setting up a project structure for a new journal and I want to use a structure like the one in this answer. However, instead of using document:start I tried \startsetups component:start, but no ...
2
votes
2answers
40 views

How can I force resized mathmode symbols to respect fontsize changes?

I want to make a latex symbol that contains a resized math symbol using \scriptscriptsize. However, when the scope containing the symbol is subject to a font resize, the \scriptscriptsize-ed symbol is ...
0
votes
1answer
63 views

Adjust photo macro to change format [closed]

Using the LaTeX CV template available under this Link (login: gafavekor@cyber-host.net ; pw: 123456) and I've realized that the picture is automatically cut to a vertical format. I would just like my ...
3
votes
3answers
81 views

Append unique characters read from filecontents to a string

I have a list of 2-character strings that is read from table, e.g. \begin{filecontents*}{attributetools.dat} Attribute SL SK MC SL AA PT SK UP MC \end{filecontents*} I want to create a string that ...
0
votes
1answer
50 views

What is the basic definition of \newcommand?

Awkward it is! I can not find the basic definition of \newcommand, though it is used a million times. I suspect it needs improvement.
2
votes
2answers
47 views

Add two macro results together

I have a macro for a word count in my overleaf document, its currently in each .tex section of my document, but I want to be able to add the results of them together (i.e. the word count of all ...
2
votes
1answer
52 views

Setting \crefname dynamically

My goal: \begin{equation}[singular=<sing_flag>,plural=<plur_flag>]\label{eq:1} a < b \end{equation} \cref{eq:1} yields <sing_flag> (1) for any input for singular and plural (...
4
votes
2answers
237 views

List of newcommands used

I have large files that I am inputing the beginning of my texts that contain all my \newcommands. They are quite a few. Most of them will not be used in a given document. But which ones are used ? Is ...
3
votes
2answers
77 views

Set command option with document wide newcommand

I work a lot with the siunitx package and I've got many numbers with a high decimal precision. Now I'd like to be able to just copy these numbers in full precision in the relevant positions in text, ...
2
votes
3answers
147 views

Multiple options for Pseudonyms

I'm looking for something fairly similar to this problem, of defining macros to print pseudonyms for people, but I'm not sure how to modify it (or if it is actually the right approach for what I'm ...
1
vote
1answer
25 views

Define an environment from tcbhighmath

Let's assume that I have defined very carefully the parameters of the highlight math style from the tcolorbox package. I would like to define an environment \newenvironment{equationbox}{% \begin{...
4
votes
1answer
80 views

Seemingly unused \edef prior to an \ifx mysteriously affects the outcome of the \ifx. Why?

It is my understanding that in \ifx\x\y xx \else yy \fi, \ifx does NOT expand its arguments. If you want \ifx to compare the expanded values of \x and \y, then we need to do the expansion ourselves ...
1
vote
1answer
50 views

Looping over characters in a string and applying a macro with an additional argument

The following code was kindly provided for me in TeX Chat by @egreg. This LaTeX 3 code loops over a list of characters, and puts a box around each character. It does not skip whitespace \...