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.

Filter by
Sorted by
Tagged with
0 votes
0 answers
26 views

creating random numbers in a tikz diagram for use in a formula

I would like to create a worksheet similar to this https://pastebin.com/fSuS4C9f but for circumferences of circles not to bothered about the answers section at the moment but I can't even get the ...
user avatar
  • 405
4 votes
1 answer
39 views

Generate TikZ Node with a macro

Inspired by this post, I tried to wrap this normal node... \node[fill=blue!20,shape=ellipse, draw=black] (nodename) at(0,0){\begin{tabular}{l} Main Text\\ \hline extension point: \\ Some ...
user avatar
  • 93
2 votes
2 answers
27 views

Macro with variable length list as an argument

I have a book which includes lots of circular diagrams generated using TikZ. This is being compiled using XeLaTeX (and I specifically don't want to switch to LuaTeX). To simplify the code for these ...
user avatar
  • 570
0 votes
0 answers
36 views

Defining a custom newcommand-like command [duplicate]

For a package I'm writing, I would like to provide a customised way to create a new command. The idea is that the user will write something like \DeclareFancyThing{\myfancything}{parameter1}{...
user avatar
  • 3,225
4 votes
1 answer
122 views

\def with number in macro works?

I know that numbers cannot be used in macros, e.g., in \def/\newcommand definitions. Can anybody explain to me why this \documentclass{article} \def\i2{\frac{i}{2}} \begin{document} $\i2$ \end{...
user avatar
2 votes
1 answer
46 views

Defining a table template for a document

I am trying to create a document which automatically updates certain values according to an output from a python code. From this python code, it produces a latex table, which looks pretty basic. ...
user avatar
2 votes
2 answers
60 views

Print sequence of property lists as table

I want to define two macros, that together should generate a table for an invoice. Add entries to a sequence. Does not generate any output. % \addentry{description}{quantity}{price} \addentry{Item 1}...
user avatar
  • 350
3 votes
2 answers
91 views

Spacing in macros with potentially empty subscript

I have the following problem of spacing not being quite right: This is produced by the following LaTex code: \documentclass[a4paper, 12pt]{article} \newcommand{\opens}[2][]{\restr{\mathcal{T}_{#2}}{#...
user avatar
  • 501
5 votes
1 answer
129 views

\newcommand named \endomorphism does not work [duplicate]

I want to define a new command via \newcommand{\endomorphism}[1]{\mathrm{End}\left(#1\right)}, but this does not work since a latex error tells me "Command \endomorphism already defined" (...
user avatar
  • 53
3 votes
1 answer
146 views

Coding non-trivial algorithms within TeX

This is kind of a hard question to formulate correctly, so forgive me if I have to clarify this question later. I want to draw a lot of somewhat complex TikZ diagrams, which to be done effectively ...
user avatar
  • 3,225
2 votes
2 answers
110 views

Detect paired nested macros

I created a macro that automatically detects if \dif, defined as \newcommand{\dif}{\mathrm{d}} delimits an integral and in this case a small space between the argument of the integral and \dif is ...
user avatar
1 vote
1 answer
51 views

separate random questions and answer onto different pages

I can create simple random addition questions, but when I try to separate the question and the answers onto 2 separate pages, I assume because its a random generator the answer sheet is not the same ...
user avatar
  • 405
3 votes
1 answer
42 views

Passing command arguments to header

I wrote a custom class where I have the command \myTitlepage to display a custom titlepage. It takes five arguments. Among them is the title. I would like to pass this argument to the command \...
user avatar
  • 322
1 vote
1 answer
36 views

how to pass content of URL to macro without getting errors due to some characters in URL?

I have macro that adds one entry in a table. The first entry is URL. This works on most URL's except some with funny characters. I want to use a macro, since inside the macro I'd like to customize it ...
user avatar
  • 18.4k
0 votes
0 answers
21 views

How to edit a command autocomplete template in Overleaf? [duplicate]

In Overleaf, commands such as \begin{figure} and \begin{table} will automatically add a template after using the auto-complete option, such as: \begin{table}[] \centering \begin{tabular}{c|c} ...
user avatar
0 votes
1 answer
38 views

How to Underline (with Linebreaking) within Contiguously Highlighted Text Using Soul

I would like to use the command \ul within a block of text that is contiguously highlighted using the macro contained in the following code: \documentclass[12pt,openany]{book} \usepackage{soul} \...
user avatar
0 votes
0 answers
25 views

Error when I try define more than one variable on \newcommand [duplicate]

When I define one single newcommand the document it is fine, there is a MWE: \documentclass{article} \newcommand{\varB}{\def \@varB} \newcommand{\printvarB}{\@varB} \varB{variable B} \begin{document}...
user avatar
  • 113
4 votes
2 answers
83 views

What's the best way to avoid ignoring leading space tokens with arguments of LaTeX commands where command before argument does space-hacking?

In LaTeX there are commands that process arguments but do not produce visible output. For example, the command \label, or, if you use the package color or xcolor, the command \color. When the closing ...
user avatar
0 votes
1 answer
19 views

Create hyperref form fields with macro

I would like to create a macro that will help me configure hyperref form fields. Can someone tell me why my minimal example does not work? \documentclass{article} \usepackage[margin=1.25cm]{geometry} \...
user avatar
  • 93
1 vote
1 answer
57 views

Undefined control sequence in \newcommand that only ocurrs in document, not in minimally reproducible example

I'm following this example on how to get strikethrough to work across multiple paragraphs (which contain citations, a sticking point for many strikethrough solutions): More robust strike-through / ...
user avatar
2 votes
1 answer
57 views

A macro that takes in a variable that is a number, interprets it as a string, check if it has a plus sign, removes it, then stores it to the variable

I want to create a macro \foo that takes in a \newcommand variable that is a number, e.g., \bar where it's defined as \newcommand{\bar}{<number>} and interprets it as a string, then checks if ...
user avatar
1 vote
1 answer
146 views

Customizing my TOC

I am trying to edit the cls file from my university, specifically to change the toc macros. What I have (the macros): \renewcommand*\l@chapter[2]{% \ifnum \c@tocdepth >\m@ne \setcounter{secnumdepth}...
user avatar
2 votes
1 answer
42 views

Create a command using a `tasks` environment

I would like to use a command bitcol (see below) with a tasks environment, but the following code give an error. How can I fix it ? \documentclass[a4paper]{book} \usepackage{tasks} \usepackage{...
user avatar
  • 749
1 vote
1 answer
67 views

Randomly sampling a subset of images without replacement from a larger list of images

I am trying to create a 10x10 matrix of external images, where the placement is a given image is random and the selection of images are randomly sampled from a larger set of images. Specifically, I ...
user avatar
  • 55
0 votes
0 answers
38 views

Changing \textcite to \cite within footnotes only

For complicated reasons, the LaTeX file I get from pandoc doesn't produce the output I'm after. This comes down to the fact that pandoc, quite reasonably, puts \textcite{} commands for author-in-text ...
user avatar
9 votes
3 answers
1k views

Within a macro, what's the most convenient way to force the compile to fail?

In a macro containing some conditions searching for existing macros that match a pattern, I have a combination of conditions that should be impossible. If the user mistakenly provides parameters that ...
user avatar
1 vote
1 answer
91 views

Why does this command defined with \NewDocumentCommand behave differently from \def inside tabular column specification?

On the first glance \NewDocumentCommand{\foo}{m}{#1} and \def\foo#1{#1} should be identical and in most scenarios they actually are, but when the argument is not explicitly follows \foo, the command ...
user avatar
  • 2,793
0 votes
2 answers
30 views

Conditionally specify an optional argument to a command

I have these two new commands defined: \usepackage{tcolorbox} \newcommand{\mycommand}[1]{ \begin{tcolorbox}[ center, colback=black!20!white, width=.75\textwidth, boxrule=0pt, ...
user avatar
3 votes
3 answers
262 views

Define \myfun which gives \myfun{a \\ b} = a and \myfun{a} = a

How can I define a function \myfun which gives \myfun{a} -> a \myfun{a \\ b} -> a \myfun{a \\ b \\ c} -> a \myfun{$\theta$ \\ b \\ c} -> $\theta$
user avatar
3 votes
1 answer
124 views

inserting Tikz diagrams into a table

I would like to insert some diagrams into a table, I know the scaling will be wrong but both files work separately just not together here is what I have so far. \documentclass{article} \usepackage{...
user avatar
  • 405
0 votes
2 answers
54 views

Is there any way to pass variables to commands?

Right now I'm doing some math homework that has lots of ordered pairs. Being lazy, I got tired of writing \langle x, y \rangle and so I was wondering if there's a way to define a command, say \ordered,...
user avatar
  • 7
0 votes
1 answer
37 views

Help with a tikz picture to create blocks

I am trying to an illustration of the usual place value cubes, so far I have: \documentclass[tikz,border=5mm]{standalone} \newcounter{x} \newlength{\x} \setlength{\x}{.8cm} \newcounter{y} \...
user avatar
  • 405
0 votes
0 answers
30 views

layout - How to create a personnalized header's layout?

I'm writing a thesis and I wanted to personalized my headers like on this picture: In a first time (1): On even pages, I'd like to have on left, the page number, and on the right, the chapter name. ...
user avatar
0 votes
0 answers
34 views

Difference Between Break and Linebreak Commands [duplicate]

The motivation for this question originates from the answer given to Centering an Arabic Section Number Above Justified Title Text Consider the code \documentclass{book} \usepackage{titlesec} \...
user avatar
  • 5,445
0 votes
0 answers
50 views

Use greek in newcommand, LaTeX

I have problems with inserting the characters of the Greek alphabet in the source code. I like to use Greek also in mathematical formulas, but as you can see from the photo when you finish the ...
user avatar
1 vote
3 answers
68 views

is the following conditional macro possible in latex?

I have a simple macro that I want to define as \newcommand{\myalert}[1]{\textcolor{red}{ALERT: #1}} However, I want to have a conditional such that if #1 is one of two strings (say "noalert"...
user avatar
  • 9,030
9 votes
2 answers
245 views

Why does \newcommand{\do}{do} not work? [duplicate]

I'm trying to define a command \do in LaTeX, but for some reason, it does not show up. Why is this? MWE: \documentclass{article} \newcommand{\do}{do} \newcommand{\doo}{do} % Dummy command for ...
user avatar
4 votes
3 answers
357 views

Is there a way to mass create \newcommands?

At the beginning of my documents, I tend to have a long list of macros I've defined, which looks like \newcommand{\Cat}{\textup{Cat}} \newcommand{\Dog}{\textup{Dog}} \newcommand{\Grape}{\textup{...
user avatar
1 vote
1 answer
32 views

xkeyval define@choicekey - which macros are defined without <bin>?

The xkeyval manual gives the following syntax for \define@choicekey*: \define@choicekey*[〈pre〉]{〈fam〉}{〈key〉}[〈bin〉]{〈al〉}[〈dft〉]{〈func〉} ... the optional 〈bin〉 should contain either one or two ...
user avatar
  • 11.6k
0 votes
1 answer
35 views

Macros and spacing [duplicate]

Since an e with an acute accent is a pain to type, I have a macro for the name Bézier: \def\Bez{B\'{e}zier} I swear this used to work fine, but today I tried typing The so-called \Bez curve is not ...
user avatar
  • 2,362
2 votes
1 answer
65 views

additional text if argument in \footnote

I am trying to make a custom footnote, which should print footnotes as follows: cf. author (title), year, page So far I tried to achieve this by using \newcommand{\customfootcite}[2]{\footnote{cf. \...
user avatar
  • 23
1 vote
2 answers
34 views

substitution with trailing space except before punctuation

I am currently using many simple substitutions like: \newcommand{\abc}{{\small ABC}} \newcommand{\ABC}{{\abc} } And then in my document text: I use \ABC if I want a space and if not then \abc. I'm ...
user avatar
  • 13
2 votes
1 answer
32 views

latex macro fails to parse expression although bracket groups match

The tensor package allows the typesetting of tensors using commands like, \[ \tensor{X}{^b^o_a_t} \] to produce the following expression: Together with the physics package it is possible to ...
user avatar
  • 125
0 votes
0 answers
34 views

What's difference between renewcommand and renewcommand*? [duplicate]

Example usage: \documetclass{article} \begin{document} \renewcommand*{\captionformat}{ -- } \renewcommand{\captionformat}{ -- } \end{document}
user avatar
1 vote
2 answers
89 views

How to get unbalanced opening brace behind macro argument?

Editor's note: this question was significantly revised, it might or might not reflect OP's original intention. OP might want to rollback it and clarify the question/provide a proper MWE if it does not....
user avatar
0 votes
0 answers
26 views

Compile multiple .tex files

I have multiple .tex files (eg 1.tex, 2.tex, 3.tex etc) that don't contain a preamble or \begin{document} \end{document} commands. The contents of each .tex files follows the simple structure below. ...
user avatar
0 votes
0 answers
25 views

Getting numerical value for day of the month [duplicate]

When I use \today it gives me July 11, 2022 I would like to get the numerical value of the day of the month instead. Kind of like this: \todaynum 11 How could I make a command that would return ...
user avatar
0 votes
1 answer
39 views

Print multiple choice solutions dynamically

I trying to figure out how to print the multiple choice answers of my exam paper dynamically using the tikz package. This is what I have so far: \documentclass{exam} \usepackage{tikz} \newcounter{...
user avatar
0 votes
2 answers
58 views

Taking in optional boolean flags in a macro without expl3

I want to create a macro \verticalStep which will produce a vertical skip of fixed length, and take two optional arguments, negative and small. So for you could use \verticalStep for a standard ...
user avatar
3 votes
2 answers
155 views

Command to cycle through synonyms

Is it possible to define a command to cycle a list of predefined synonyms? For example, define a list of adverbs (however, nevertheless, nonetheless, notwithstanding) for the \adverb (or something ...
user avatar

1
2 3 4 5
153