Skip to main content

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
4 votes
2 answers
129 views

Confused about optional argument with \NewDocumentCommand result

Given this MWE: \documentclass[12pt]{report} \usepackage{fontspec} \setlength{\parindent}{0pt} \NewDocumentCommand{\testone}{m m m }{% \if\relax\detokenize{#2}\relax \textbf{#1}\dotfill#3\...
hsmyers's user avatar
  • 1,573
2 votes
2 answers
139 views

Memory usage of new commands requiring several intermediate commands

The following command \newcommand{\PDef}{\mathcal{P}_{\operatorname{Def}}} can be defined, alternatively, by iterating several new commands: \newcommand{\CP}{\mathcal{P}} \newcommand{\PDef}{\CP_{\...
Matemáticos Chibchas's user avatar
0 votes
0 answers
52 views

Rules upon % at end of line [duplicate]

When writing macros, the trailing comment character is used to ignore the rest of the input line, suppressing spaces, and the end of line character that is appended gets ignored too. Which aspects of ...
Liccu's user avatar
  • 1
1 vote
2 answers
43 views

Can I change the effect of a command depending on the environment in which it's invoked?

I need a user-defined command to behave differently depending on whether it's invoked inside a \begin{quotation} environment or not. Is that possible? I don't know where to start!
digitig's user avatar
  • 125
3 votes
1 answer
69 views

Modify command for sum so that substack unnecessary

Is there a way to modify sum so that \sum_{...} behaves as \sum_{\substack{...}}? It is of course possible to have a command containing the underscore, but I'm interested in if the underscore can be ...
user2472071's user avatar
1 vote
2 answers
39 views

Counter value not displayed in \foreach loop

I try to write a command that displays a table with the number of lines passed as parameter. It's working fine except that in this MWE, the value of the \i variable is not displayed. I have no idea ...
Sylcha's user avatar
  • 43
0 votes
1 answer
61 views

Getting the Maximum Width of a List of Items

I'm trying to write a command to get the maximum width of a (comma separated) list of items, for example \myLengthCommand{lorem,ipsum,lorem ipsum} should return the width of the text "lorem ipsum&...
Dave's user avatar
  • 317
0 votes
1 answer
49 views

LaTeX command for sets of elements set using \mathtt?

I teach a course in automata and computability theory and often have to define alphabets (sets of symbols). Typically, using amsmath, I write things like this: Let $\Sigma = \set{\mathtt{a}, \mathtt{b}...
templatetypedef's user avatar
0 votes
0 answers
35 views

What commands or tutorial should I use to create a dossier? [closed]

ex. index, several pages with images and comments around them I have windows system
Roberta Turco's user avatar
2 votes
2 answers
103 views

hyperref warning: Token not allowed in a PDF string - macro Refactoring as a fix

I have a macro that takes a comma-separated list of lists and applies some formatting to it. The list consists of the first and last names of the document's authors. I managed to create a macro - \...
Mycroft_47's user avatar
3 votes
2 answers
66 views

Add "identifiers" to questions for printing

So, I have this code that lets me number questions/ exercises according to chapters ("Exercise 1.1", etc). I have one count to "identify" the question and one count to display the ...
Vebjorn's user avatar
  • 1,854
0 votes
1 answer
40 views

Numbering exercises by chapter and printing solutions by chapter in appendix

So, I have a basic tcolorbox that I want to write my exercises in. I want the exercises to be numbered by chapter, i.e. Exercise 1.1 is exercise 1 in chapter 1 (and still be able to print the answers ...
Vebjorn's user avatar
  • 1,854
2 votes
1 answer
40 views

Nested custom commands not working

I have defined the following commands for my latex document: \newcommand{\uat}[2]{\ifthenelse{\equal{#2}{}}{\boldsymbol{u}_{#1}}{\boldsymbol{u}_{#1}(#2)}} \newcommand{\opt}[1]{\ifthenelse{\equal{#1}{}}...
Trb2's user avatar
  • 123
2 votes
1 answer
60 views

How to properly expand expl3 Macros within tblr environment (from tabularray package)

I've been working on a macro that takes a comma-separated list of lists and converts it into a table that spans the full width of the page, with specific text formatting applied to certain columns. ...
Mycroft_47's user avatar
1 vote
0 answers
44 views

Issues with Misplaced Alignment Tab Character and Table Width in tabularray Environment [duplicate]

I've adapted the code below from this answer to switch from the tabular environment to the tblr environment from the tabularray package. While the original code works perfectly with tabular, I'm ...
Mycroft_47's user avatar
0 votes
1 answer
35 views

Create static variable inside of \pgfplotstableset definition

I try to understand, how to create a variable inside or outside of the \pgfplotstableset environement which is static and will not be resetted all the time. Probably this is a generic question for ...
PascalS's user avatar
  • 750
2 votes
1 answer
49 views

`already defined` error with scoped newcommand

I want to make it easier on myself to write large commands like this by "naming" the arguments. I did this: % Define the command for vector projection with named arguments \...
Boris Month's user avatar
1 vote
1 answer
129 views

Creating LaTeX Macros to Generate Tables from Predefined Variables

I've been struggling for the past two days to create macros for populating a thesis title page, as I'm planning to share it as a template with my colleagues. As you all know, thesis title pages have ...
Mycroft_47's user avatar
1 vote
1 answer
45 views

How to extend upon siunitx to list units?

I have made this trivial additional macro using siunitx called \qtyalt{} and \numalt{} that helps me add the separator "or" at the end of the list like so: \documentclass{article} \...
Miloop's user avatar
  • 966
1 vote
0 answers
40 views

Redefine commands, changing a catcode

Background I'm the author of the altsubsup package, which set to 12 (other) the catcode of the circumflex ^ char. As it, expressions as x''^2 raise a Double superscript error because the latex ...
jlab's user avatar
  • 3,759
-1 votes
1 answer
43 views

Include font size specification to a command

I would like to include the specification of the font size (\huge \large \normalsize) in the key-value specification. \documentclass[a4paper,12pt]{article} \ExplSyntaxOn \tl_new:N \l_hlov_tipoa_tl ...
Bulldrive's user avatar
  • 153
3 votes
2 answers
547 views

What's wrong with my new environment?

I'm trying to write this new environment, but produces this error when I use it: This is my code: \documentclass{article} \newcounter{questao} \newenvironment{questao}[1][]{ \ifx\relax#1\relax ...
Lenin de Castilhos's user avatar
3 votes
3 answers
89 views

How to create a conditional command depending on the number of argument (two or three)?

I defined a macro with variadic arguments as below, and it works fine. $\un{N}$ => [N] $\un{J}{s}$ => [J/s] \makeatletter \newcommand\un[1]{\@ifnextchar\bgroup{\un@double{#1}}{\un@single{#1}}} \...
Larynx's user avatar
  • 131
9 votes
3 answers
228 views

Newcommand with adaptive number of arguments

What I am looking for is a single newcommand, let's call it \wedges, with a variable number of inputs that yields in a flexible way the following result: I have already written the code for the ...
Freestyla's user avatar
  • 117
0 votes
1 answer
89 views

How can I change the form of coordinates of a point from the form (1, 2, 3) to the form (1; 2; 3)?

I have this picture. I tried \documentclass[12pt,a4paper]{article} \usepackage{amsmath} \begin{document} Let $ABC$ be a triangle with $A(1,2,3)$, $B(4,5,9)$, $(7,8,6)$. Coordinates ...
John Paul Peter's user avatar
1 vote
1 answer
29 views

label inside a newcommand doesn't work

I am defining a \newcommand to shorten a notation I use frequently. To comment reasonings during computations I put daggers over the equal sign where such reasoning is done and hyperref it to a ...
Freestyla's user avatar
  • 117
11 votes
1 answer
1k views

Why Donald E. Knuth used obeylines + gdef instead of def

I am trying to understand Knuth's manmac.tex. At line 436 you can find the following code: \newwrite\ans \immediate\openout\ans=answers % file for answers to exercises \outer\def\answer{\par\medbreak ...
Alexey Ismagilov's user avatar
2 votes
3 answers
101 views

Creating a command that returns colors

My need I want to create a command that returns a color depending on the value of the argument. My attempt I've tried the following but it does not work. The error is Argument of \XC@col@rlet has an ...
Colas's user avatar
  • 6,832
3 votes
1 answer
273 views

How to create a custom command (control sequence) with special characters in its name

I want to create a custom command (control sequence) whose name contains special characters (such as numbers, underscores _, or -). In order to better distinguish different commands, my code is as ...
Tommk's user avatar
  • 31
1 vote
2 answers
86 views

Macro copy, add/remove last token

Suppose I have a macro with only argument that has such a structure \def\foo#1{% {\textbf{#1}}{aaa}{bbb} } I need to create two copies: \bar that is \foo but withouot the last token: \...
antshar's user avatar
  • 4,612
0 votes
0 answers
22 views

How can i fix the error on " Error line 191! Missing number, treated as zero.< to be read again>\[email protected]|Idf@finish\currentoption"

I need help. My text in Miktex + texmaker end on line 40 but I get an "Error line 191! Missing number, treated as zero. \I@English. 1.191\Idf@finish\currentOption". please help me to fix ...
George Darius Ocen's user avatar
2 votes
1 answer
80 views

Print macro in \addplot node label

I use a foreach loop to plot multiple curves via the \addplot command. The values that are necessary to define the relevant curve in each iteration are defined through some macros with the command \...
Laura Roich's user avatar
1 vote
0 answers
49 views

MacTeX on macOS: how to get the SyncTeX library?

I have MacTeX installed on macOS, and an executable called synctex is already in my PATH. However, I cannot find a file named libsynctex.so anywhere on the system, which is what I need to compile some ...
Ma Joad's user avatar
  • 191
1 vote
0 answers
14 views

Information about surrounding text [duplicate]

I'm trying to define a command which raises an issue about spaces. Basically, I want to have a single command for these two : \documentclass{article} \newcommand{\Cinf}{$C^\infty$ } \newcommand{\...
Louis Lascaud's user avatar
3 votes
2 answers
112 views

Error Handling for TeX Command Definition with Spaces in Arguments

I'm currently working with TeX to define a command, as shown below: \def\@fancybook@reset@counter#1,#2\stop{% \if\relax\detokenize{#1}\relax% \else \setcounter{#1}{0}% \fi \if\relax\...
ljguo's user avatar
  • 1,377
1 vote
2 answers
37 views

`verbatim*` environment in a `minipage` defined by a `\newcommand` does not work

Still a novice at LaTeX - I was attempting to define a custom command for creating minipages of a certain width using this code: \newcommand{\col}[2]{\begin{minipage}{#1\linewidth}#2\end{minipage}} ...
invisi.'s user avatar
  • 13
0 votes
1 answer
18 views

Define a new command with the same effect as \quad \text{...}

I have a tex file \documentclass[11pt]{article} \usepackage{mathtools,amssymb,amsthm,enumitem,fullpage,microtype} \usepackage[hypertexnames=false]{hyperref} \hypersetup{ colorlinks=true, linkcolor=...
Akira's user avatar
  • 1,409
3 votes
2 answers
107 views

Best Practices for Integrating Computer Algebra Systems (CAS) into LaTeX Documents

I am currently working on enhancing my LaTeX documents to involve complex mathematical equations. Managing these equations manually often leads to errors, especially when changing dependent equations ...
Foad's user avatar
  • 981
2 votes
1 answer
27 views

Remove "(chairman)" when using sapthesis

I'm using the sapthesis package. It allows for indicating multiple examiners via the command \examiner (e.g. \examiner{Jon Doe}). If at least one examiner is indicated, after the first one it appends ...
Luke's user avatar
  • 23
0 votes
0 answers
12 views

pgfplotstable: compute averages of columns

\documentclass{article} \usepackage{pgfplots} \usepackage{pgfplotstable} \pgfplotstableset{ create on use/mean/.style args={#1#2#3}{ create col/expr={(\thisrowno{#1} + \thisrowno{#2} + \...
Simon's user avatar
  • 325
3 votes
2 answers
105 views

How I can I set a default question point value in the exam class?

I'm writing an exam in the exam class and I'd like to set the point value for an entire group of questions at once. For example: \documentclass{exam} \title{Know your US States and Capitals!} \begin{...
Matthew Leingang's user avatar
0 votes
3 answers
100 views

Associative arrays [duplicate]

I was trying to understand the article given at Storing an array of strings in a command but could not find the (obvious) solution to the following problem: I have information about composer, title, ...
mf67's user avatar
  • 668
2 votes
1 answer
48 views

Function values in columns rather then rows with numerica-tables

Package numerica-tables helps create of multi-column tables of mathematical function values, the package arranges values on rows like in this simple example \documentclass{article} \usepackage{...
Salim Bou's user avatar
  • 17.1k
2 votes
1 answer
86 views

Definition of \sum -- how does the size selection work

When writing \[\sum\], a larger summation sign is used than when writing \(\sum\). How does the \sum command find out which size to use? What does \sum expand to? I am guessing it is just a shorthand ...
Oliver Leenders's user avatar
2 votes
1 answer
46 views

"Advanced section/subsection" custom command produces unexpected numbering behaviour

I am attempting to create new commands for "advanced sections/subsections" (similar to what you might see in a textbook, where a "starred section" indicates an advanced topic or a ...
user319109's user avatar
4 votes
5 answers
285 views

Convert control sequence with a variable number of undelimited parameters into a token list

In expl3, I can translate a token list \l_greet_tl into a control sequence \greet that takes two parameters as follows: \tl_new:N \l_greet_tl \tl_set:Nn \l_greet_tl { Hello,~#1!~How~is~#2~doing? ...
Witiko's user avatar
  • 1,006
0 votes
2 answers
38 views

Default not working for new command

\newcommand{\initialize}[2][tmargin=1in, bmargin=1in, right=0.75in, left=0.75in]{ \geometry{#1} \ifthenelse{\equal{#2}{}}{\setboolean{indent}{false}}{\setboolean{indent}{true}} \...
xyz04's user avatar
  • 137
1 vote
3 answers
158 views

I made a complex number command

So I've written a command as a homework assignment to render complex numbers correctly. Like, when I write \complfull{5}{-2} the output is 5-2i \documentclass{scrartcl} \usepackage{amsmath} \...
editilly's user avatar
3 votes
1 answer
53 views

Checking if the contents of the \item's of a \list environment are entirely in inline math mode

I have a list \begin{list}{}{} \item[(1)] First things first. \item[(2)] There are \(1 + 1 = 2\) types of "normal" math \[e^{2\pi i} + 1 = 2\] \item[(3)] Third time's \(\...
grepgrok's user avatar
0 votes
2 answers
65 views

Macro expansion crashes oddly

Here is my mwe.tex \documentclass[12pt]{report} \usepackage{xifthen} \usepackage{xstring} \def\test{\textnormal{test}} \newcounter{wordCount} \setcounter{wordCount}{0} \newcounter{AllWord} \...
hsmyers's user avatar
  • 1,573

1
2 3 4 5
166