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
15 views

Suppress vertical space at beginning of macro when there is no preceding paragraph

I want to create a variant of the itemize command for Beamer that spreads the items vertically. This should increase the space between items as well as to preceding text. With other words, I want a ...
Wrzlprmft's user avatar
  • 759
0 votes
0 answers
19 views

Interaction between pgfplotstable and a newcommand

I'm trying to generate a big table with informations that are comming from an external csv file that I have generated. I don't really understand what is going on in the following code. I have defined ...
Rhylx's user avatar
  • 3
1 vote
3 answers
44 views

Figures not indenting with a custom environment

For my homework questions, I have multiple questions which present proof-type and standard solution-type answers. So as something similar to the standard amsthm \begin{proof}....\end{proof} ...
Ammardian's user avatar
0 votes
2 answers
105 views

Remaping align* to \[ or $$

I would like to remap the align* environment to \[ \] or $$ $$. The reason is that I am using a conceal plugin that removes unnecessary stuff when viewing the code. The issue is that when it removes ...
Maths Wizzard's user avatar
0 votes
1 answer
38 views

Automatically set command for each capital letter in `\mathsf`, `\mathbb`, and `\mathcal` [duplicate]

I typically create new commands for every capital letter in \mathsf, \mathbb, and \mathcal. # Sans-serif capital letters \newcommand{\Asf}{\mathsf{A}} \newcommand{\Bsf}{\mathsf{B}} . . . \newcommand}{\...
Physics_Student's user avatar
0 votes
2 answers
56 views

Expand macro in options list for environment

I am trying to define some options for an environment using a macro. \usepackage{tabularray} .... % previous parameter definition, does not scale \def\cellax{1} \def\cellay{2} \def\cellaw{4} \def\...
stimulate's user avatar
  • 107
1 vote
1 answer
49 views

conditionals inside newcommand with multiple argument

This question is an extension of conditionals inside newcommand with empty argument I have a macro that looks like \newcommand{\pcs}[3]{{#1}_{#2}^{(#3)}} It is the third input where I would like to ...
Sayan's user avatar
  • 199
14 votes
1 answer
609 views

TeX jargon - Difference between "argument" and "parameter" in TeX?

What's the difference between the term "parameter" and the term "argument" in TeX jargon? Are outermost enclosing pairs of matching curly braces of undelimited arguments to be ...
Cattleya's user avatar
  • 349
3 votes
1 answer
43 views

Prior working macro to bold author names, now causes complex errors

I have long used to below macro, originally adapted from another Answer. This macro is used with BibLaTeX, to automatically bold the provided author. %------------------------------------------------ %...
Coby Viner's user avatar
  • 1,909
17 votes
3 answers
960 views

Can names of defined LaTeX commands be retrieved from a compiled PDF?

I am aware that a compiled PDF typically cannot be decompiled back into LaTeX without using workarounds. However, I am worried about portions of the information available in LaTeX still being ...
Toivo Säwén's user avatar
1 vote
1 answer
38 views

Use of \l@addto@macro

I am trying to change the font size of the achemso document class, and I came across this snippet of code on the second answer here: Is it possible to use 12 pt font size in the achemso package? \let\...
the_chemist's user avatar
4 votes
3 answers
108 views

One command/environment for both equation and equation*

I want to define a new command/environment for both equation and equation*, based on whether the content contains \label. For the following equation, \begin{mymath} f = g \end{mymath} environment ...
atlas's user avatar
  • 85
4 votes
3 answers
149 views

Command gobbling extra letters not working when passed another command

On another topic, I was given the following command as an answer: it takes either a two letter font shape (sc, it...) or a full version (scshape, itshape...) to set the corresponding font shape. \...
Vincent's user avatar
  • 4,683
5 votes
4 answers
156 views

Passing macro parameters with \DeclareKeys/\SetKeys

Just as an exercise I'm trying to make a keyval interface to amsthm's \newtheoremstyle in the manner of thmtools, but using the kernel's \DeclareKeys instead of keyval and kvsetkeys. Every argument of ...
mbert's user avatar
  • 2,521
2 votes
1 answer
38 views

A command that would always place text at the beginning of the document

I am keeping something like a diary, that helps me keep track of things that I am working on. Occasionally there are some actions (To do's) that need to be taken, which I would like to keep on the ...
Steve OB's user avatar
0 votes
1 answer
78 views

Automatically wrap a macro

Is it possible to automatically wrap a macro with its arguments? (or at least do that for macros defined with \NewDocumentCommand, as I guess it might be hard to do it for any macro?) I would like my ...
tobiasBora's user avatar
  • 7,407
3 votes
0 answers
63 views

Are there tricks for detecting whether a `\csname..\endcsname`-thingie went wrong and, if so, delivering additional messages explaining the issue?

For the sake of having expandable tokens expanded before stringification I sometimes combine \csname..\endcsname-expansion with \string as in \chardef\stopromannumeral=`\^^00 \edef\gobbleToPrefix{% \...
Ulrich Diez's user avatar
  • 26.9k
2 votes
2 answers
29 views

customing mdfdefinedstyle using newcommand

I'm currently experimenting on mdfdefinestyle to achieve different colors without having a hard time to adjust its style or rather renaming it one-by-one. So, here's the mdfdefinestyle I used, \...
Wilory Lu's user avatar
  • 101
1 vote
3 answers
72 views

Branch over number of characters of an argument provided to a macro

I currently have the following command: \newcommand*{\setfontshape}[1]{\@ifnotmtarg{#1}{\csname#1shape\endcsname}} that helps me produce the command: \scshape from text sc. I would like to modify my ...
Vincent's user avatar
  • 4,683
2 votes
1 answer
100 views

How to shorten a math command in Latex

I am trying to shorten the adaptable bracket size left[ into \l[ (same for \right]). I have tried both: \DeclareMathOperator{\l[}{\left[} \DeclareMathOperator{\r]}{\right]} and: \newcommand{\l[}{\...
Julep's user avatar
  • 123
1 vote
0 answers
36 views

Descriptive position in document like "in the middle, at the top" etc

In a math book (which is written in a nice, more or less informal tone) from which I don't know if it was really written in LaTeX I found something very interesting. In the text there was written ...
TeXMax's user avatar
  • 11
1 vote
1 answer
38 views

Compute depth without using any macro

For a library robust-externalize, write in a new file something like: \newsavebox\boxRobExt% \savebox{\boxRobExt}{% my content }% \usebox{\boxRobExt}% % some code to write `\the\dp\boxRobExt` into ...
tobiasBora's user avatar
  • 7,407
5 votes
3 answers
310 views

Why isn't my environment restored?

I don't know why, but I tried to follow https://tex.stackexchange.com/a/286089/116348 to redefine an environment like: \let\answers\questions \let\endanswers\endquestions in order to save and restore ...
tobiasBora's user avatar
  • 7,407
2 votes
3 answers
107 views

Create a macro to append elements to another macro

General overview The goal is to make a list of photo credits at the end of a book. MWE \documentclass{article} \newcommand\credittable{} % This command contain the final rendering. \newcommand{\...
fauve's user avatar
  • 2,437
0 votes
0 answers
10 views

Fancyhdr - Missing number treated as zero in chapter [duplicate]

I tried to setup a fresh LaTeX template for my thesis. I wanted to display the chapter number and name as well as the section number and name in the header using fancyhdr following the convention . ...
delta_impulse's user avatar
0 votes
0 answers
49 views

Subscripts and superscripts breaking if used on mathematical formula contained by braces

If I contstruct two different commands capturing a subscription: \newcommand{\nobraces}{a_b} \newcommand{\braces}{{a_b}} then the \nobraces version works according to expectations, when e.g. we want ...
atti6j's user avatar
  • 1
1 vote
3 answers
92 views

The display math mode and the `center` environment

I have asked a question at How to delete a command in the \BODY macro of environment defined by \NewEnviron about the problem when I try to convert my ex environment to the multi environment of moodle ...
phchon's user avatar
  • 51
0 votes
0 answers
30 views

How to unify a number of separate latex articles into a thesis?

I am about to compile a number of different published articles into a single thesis. While each document on its own can compile and produce a PDF, there are several macros files (shorthands for ...
Ameer Jewdaki's user avatar
2 votes
2 answers
61 views

Generating tensor expression with macro

I am trying to create a command that given a comma separated list of subscript indices, subscript values, superscript indices, superscript values and then name of the tensor generates the following ...
Ted Black's user avatar
  • 381
1 vote
1 answer
21 views

Replacing a block of code with a macro (Beamer)

I use a block of code frequently when I use the Beamer package. \RequirePackage{etoolbox} \documentclass[handout, 14pt]{beamer} \usecolortheme{seahorse} \begin{document} # Start of the block \def\...
prosseek's user avatar
  • 6,003
-2 votes
2 answers
71 views

Looking for \newcommand code for the following purpose [closed]

Command name resumeAchv Should look like the following Achievement name: Achievement description (multiple lines,‎ more text ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎‎Year of achv should go into multiple lines,...
Advaita Mallik's user avatar
3 votes
2 answers
97 views

LaTeX macro for summing numbers

I have a very simple LaTeX problem which confuses me. I want to write a macro which creates a running total of given numbers. The answer by Ulrike Fischer here is almost exactly what I want - simple ...
SvenForkbeard's user avatar
0 votes
0 answers
31 views

Automatically calculate years of experience from provided start/end dates

I'm very very new to LaTeX and not even sure if this is possible. \resumeSubheading {Undergraduate Research Assistant} {6 Years \& 3 Months} % 1 <---------------...
Aagam Sheth's user avatar
0 votes
1 answer
33 views

newcommand that includes parse lines

I am trying to typeset a series of verses some which have long lines. I want the long lines to be indented when it overflows to the next line. The package parselines does serve the purpose nicely. ...
mas's user avatar
  • 1,311
1 vote
0 answers
31 views

typesetting equations based on external text file gone wrong [duplicate]

This example reads n lines and prints them out as addition problems. $ cat equations.txt 8 1 2 3 4 5 9 6 7 13 18 7 25 34 66 100 94 21 115 0 31 31 27 18 45 84 51 135 64 9 73 $ cat equations.tex \...
tzr381's user avatar
  • 11
4 votes
3 answers
358 views

Is there a way to add optional and/or named argument to command

I'm writing a handbook for my students and I want to create a command which should draw a task definition, its type and possible features, like source and link to the solution on YouTube. In my plan ...
Nikita Vasiliev's user avatar
0 votes
0 answers
64 views

When to use \NewDocumentCommand vs. \newcommand [duplicate]

I'm a layperson who is wondering about the difference between \NewDocumentCommand and \newcommand. I don't know when to choose one or the other. I'm asking because The Not So Short Introduction to ...
Adrik Ivanov's user avatar
0 votes
1 answer
54 views

Stepslist: "Step k of n"

I am trying to come up with a new enumerated list environment "stepslist" such that the items are marked with "Step k of n", where n is the total number of items in one stepslist ...
Alp Uzman's user avatar
  • 284
1 vote
1 answer
36 views

Making straight quotes in TeX appear as straight quotes in document [duplicate]

So I'm writing a book, and I've used straight quotes (") in my latex files throughout the entire project. Now whenever I compile my document in Overleaf, these, to no ones surprise, come out as ...
Henrik Hillestad Løvold's user avatar
5 votes
4 answers
174 views

Trouble with nested macros containing ifnum

I have problems with macros containing ifnum. After using the command \noexpand one macro works fine, nesting two of them does not compile but causes the error message Extra \fi. \fi as in the ...
gschaaf's user avatar
  • 147
9 votes
1 answer
341 views

Why can the name of a `MathOperator` have a number?

This does not compile, which is what I'd expect: \documentclass{amsart} \newcommand{\G2}{G_2} %\DeclareMathOperator{\G2}{G_2} \begin{document} \(\G2\) \end{document} produces ! LaTeX Error: Missing \...
LSpice's user avatar
  • 1,394
1 vote
1 answer
63 views

Verbatim inside tabular, inside a macro

I would like to achieve a macro which makes a 2x2 table to show example inputs and outputs of a program (test cases). Something like this: --------------------------- |input | example input | |-----...
broland's user avatar
  • 11
0 votes
1 answer
69 views

Exercise 5.7 in TeX - define control sequences with grouping

I want to solve Exercise 5.7 in the TeXBook by Donald E. Knuth. Define control sequences **\beginthe**<block name> and **\endthe**<block name> that provide a “named” block structure. In ...
GarretW's user avatar
8 votes
2 answers
2k views

Why do curly braces break this loop?

I was trying to solve 'Exercise 20.20' from the TeX Book which asks to create a macro \punishment capable of repeating a given sentence n times using the Plain TeX format. My first attempt was the ...
HomoVafer's user avatar
  • 183
1 vote
1 answer
16 views

Errors setting up a custom equation environment using \tcbhighmath

Currently, I'm writing a Macros package to store my custom environments and macros for my homework sheets. I'm trying to create a custom environment which I can define within my package (a .sty file), ...
Ammardian's user avatar
4 votes
2 answers
220 views

Can I nest the \newcommand command with itself?

Currently, I want to define a command that makes it easy for me to write the usual notation for a set in set theory. Using the \newcommand command, I was able to define the following: \documentclass{...
Darkmaster's user avatar
2 votes
1 answer
143 views

Undefining/redefining already defined commands within expl3

I am not sure about the forum protocol regarding when to ask a new question and when to lump it in with an existing one, so I apologize if this is unorthodox. The question stems from ! Missing \...
Mike Pugh's user avatar
0 votes
1 answer
65 views

Convert key-value argument into \str_case comparison

This was the underlying motivation for a previous question of mine. However, after several hours of failure, I decide to ask this problem directly. The goal In order to support the four declensions ...
Jinwen's user avatar
  • 7,808
6 votes
4 answers
222 views

Use two comma lists to build a test function using \str_case:nn

Suppose given two comma lists of the same length: \clist_set:Nn \l__mymodule_keys_clist { key1, key2, key3 } \clist_set:Nn \l__mymodule_acts_clist { act1, act2, act3 } How can one convert them into a ...
Jinwen's user avatar
  • 7,808
4 votes
3 answers
318 views

Problem facing when I define a new operator

Working with LaTeX, I want to define a new operator, specifically a projection operator. I am able to define the operator, but it is not working how I want. This is how I define the operator: \...
RIPAN DAS's user avatar

1
2 3 4 5
162