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
1 vote
0 answers
12 views

Using \ifthenelse and \isempty in newcommand used in glossaries's name

I want to use \ifthenelse while defining symbols with \newcommand. This works all fine, until I try to use those symbols (here \densCanv) in my glossary as a name: \documentclass[a4paper,10pt]{article}...
Make42's user avatar
  • 1,812
2 votes
2 answers
125 views

Build a new command "newsymbol" with NewDocumentCommand

I want to create a new command \newsymbol, which functions like \newcommand, but with the difference that math is ensured. I also have another reason, why I want to define this new command, namely so ...
Make42's user avatar
  • 1,812
0 votes
2 answers
31 views

Command doesn't show put after a new line

I used \newcommand to make a label and then label it. \documentclass[12pt]{article} \makeatletter \newcommand{\createlabel}[2]{% \@bsphack \expandafter\edef\csname #1\endcsname{#2}\@...
Povi112's user avatar
4 votes
1 answer
58 views

\IfBlankF in \NewDocumentCommand removes content leading up to argument

I'm trying to define a command with \NewDocumentCommand that create a subsection with a given name (mandatory) and optionally some descriptive paragraph. Since I don't want these paragraph to be ...
bru3s's user avatar
  • 43
0 votes
1 answer
23 views

commands within \subimport

Using a command within subimport leads to problems. Consider the following files, which have to lay side-by-side in the same folder. test.tex: \documentclass[]{letter} \usepackage{import} \def\AV{510}...
user7427029's user avatar
0 votes
2 answers
137 views

design a \Command that allows a Dual-parameter \Command passing its return into another \Command as one (which might be a label) of its inputs

Design: a (La)TeX command (maybe look like this \passresult{\outercommand}{\innercommand}{param1}{param2}), which pass the return of a dual-parameter \innercommand{param1}{param2} into another \...
谢尘竹's user avatar
1 vote
2 answers
115 views

Nesting two environments

The snippet below has been obtained nesting two environments taken from amsthm and tcolorbox. I would like to redefine the environment theorem to produce the same output (I can only modify the ...
Primo Petri's user avatar
1 vote
1 answer
45 views

How to make own title of the part of text?

I'm trying to create titles for pieces of text that won't appear as the last element at the bottom of the page. I haven't been able to find a method to prevent page breaks directly below the title. ...
forrest's user avatar
  • 970
6 votes
3 answers
494 views

Creating a command to display blackboard font

I am relatively new to LaTeX and I want to know whether there is a way to create a command such that it takes whatever capital letter the command is and prints the blackboard font. Here's what I mean: ...
A R's user avatar
  • 161
5 votes
2 answers
256 views

Expand a `.cs` defined by key inside the function

I have a prop list in which I save items using the \addtoprop command and then loop through the prop list and print it with the \foreachinprop command. The \foreachinprop command has several keys, but ...
Pablo González L's user avatar
0 votes
2 answers
71 views

How to check if command received a command as argument

I tried to use ifdef command for that, but it doesn't work. It outputs text when it's passed and executes the true branch. \documentclass{article} \usepackage{etoolbox} \begin{document} \...
Intolighter's user avatar
1 vote
1 answer
65 views

How does one fully expand a macro between \csname and \encsname?

The best way to ask this question is to present two MWEs, one of which works and one of which does not. Naturally, I would like to get this into the second form, but I am at a loss as to what is ...
Mike Pugh's user avatar
  • 319
1 vote
1 answer
51 views

Expanding Variables to Input as Arguments for Macro

I have an issue when trying to use variables in a command (\ResearchModule). I read up to 8 lines from a text file and have them set to elements of an array (using code thanks to egreg!), with \...
MrOakPlanks's user avatar
2 votes
4 answers
163 views

How to modify overlay specifications in a new command in LaTeX Beamer?

I would like to modify the overlay specification that is passed to a custom command, but for some reason, < and > are interpreted as ¡ and ¿ when they are included in a new command. MWE: \...
mapf's user avatar
  • 253
4 votes
2 answers
159 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
144 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
53 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
  • 31
1 vote
2 answers
44 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
70 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
40 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
67 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
51 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
2 votes
2 answers
110 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
67 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,884
0 votes
1 answer
44 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,884
2 votes
1 answer
41 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
65 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
50 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
134 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
50 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
  • 978
1 vote
0 answers
43 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,951
-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
  • 161
3 votes
2 answers
552 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
94 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
231 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
95 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,872
3 votes
1 answer
286 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
90 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,632
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
83 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
55 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
113 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,387
1 vote
2 answers
40 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
20 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,441

1
2 3 4 5
167