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
1 answer
11 views

Optional argument "#1" being evaluated before substitution in d\formatdate

I ran into a problem with the datetime package's \formatdate{}{}{} function when I was trying to create a custom environment which is like a journal entry with a date from optional arguments. I ...
anak's user avatar
  • 155
0 votes
2 answers
64 views

is there a way to 'breakeline' a newcommand? (to modify only \textbf color)

i made changes in my tex files, so I am looking for a textbf gray. Now the new command created do not breake lines at the end of the document. (same problem as \colorbox{}{}) I found this: (from: ...
ddavb's user avatar
  • 3
1 vote
1 answer
15 views

position label tree edges using macro

In this tree I want the edge labels horizontally aligned, probably nearer the edges. The tree may not be binary. I would also like to diminish clutter and save typing by putting \edge node[auto=...
Ethan Bolker's user avatar
  • 9,261
0 votes
1 answer
50 views

Saving a math style in beamer

I am trying to build a version of beamer's alt that occupies the space of its larger argument. I do this with some saveboxes and measuring. Because I also want to use it in math, I need to save the ...
Bubaya's user avatar
  • 2,237
3 votes
2 answers
119 views

Expand key-values with \def of \newcommand?

I have multiple repeated \begin{enumerate}[label=A\alph*), ref=A\alph*] and I want to reduce code duplication. I would also like to avoid creating new environments if possible. I just want a simple ...
Edoardo Fiocchi's user avatar
0 votes
1 answer
61 views

User TeX Macro Expansion for XHTML

Is there way especially in math the user defined macros (even complicate definition) should get expand and the expanded version should stored in the respective equation. Basically, this to retain the ...
RampSmart's user avatar
  • 103
2 votes
1 answer
64 views

Applying newcommand/def to subscript whenever one is provided

I have defined a \blue command which I often use with subscripts, e.g. \newcommand{\blue}[1]{{\color{blue} \textup{\textbf{#1}}}} \blue{v}_{\blue{ij}} Question: Is there a way to define \blue in such ...
Louis-Amand's user avatar
2 votes
2 answers
36 views

beamer: How to modify/offset an overlay specification in a custom command?

I want a custom command to show some content in slightly different versions in two consecutive overlays. MWE without a custom command: \documentclass{beamer} \begin{document} \begin{frame}<1-2> ...
TexMax's user avatar
  • 93
5 votes
1 answer
84 views

Create File Path for Listing with Macro based on Arguments

I am trying to make a macro that creates the path to a file from which a listing should be loaded based on its parameters. This fails very early. Here is a schematic of what I am trying to do: \...
Thomas Weise's user avatar
0 votes
1 answer
33 views

How to expand from DLTforeach prior to function call

Apologies if this is a trivial problem, I've seen a lot of similar posts, but i have not been able to solve this. Setup: I have created a table based on this answer. I have created a function for ...
Malle's user avatar
  • 3
4 votes
1 answer
192 views

Can I write a macro that detects if the text mode is currently in '\uppercase{xxxx}'

My aim is to define a macro that can react to the text currently being in \uppercase mode. So for example if my macro is called \mymacro we should be able to print 'UPPER' or 'normal'. In the document ...
Rutger Moody's user avatar
2 votes
1 answer
32 views

Basic usage of \pgfmathsetmacro causes trouble in Overleaf?

I'm experiencing issues with Tikz figures in Overleaf. In particluar, the following usage of \pgfmathsetmacro causes a 'Missing control sequence inserted.': \documentclass{article} \usepackage{tikz} \...
conciliator's user avatar
3 votes
4 answers
119 views

How to pass a \def coordinate to macros

I am trying to pass a \def coordinate to a macro and got an error. Below is the code. The macro with direct passing works, but the two commented out lines don't. \documentclass[border=1cm]{standalone} ...
Leon Chang's user avatar
1 vote
1 answer
77 views

LaTeX: \equal not recognized within \section command

I have the following code, where I want to steer the language of some titles and some texts using a "\newcommand". The following minimal example uses the new command "kLanguage", ...
iGeeks's user avatar
  • 29
1 vote
2 answers
118 views

How to define a command that can be used as a superscript without {} and that can have a subscript

I have used \theta hundreds of times in my document. Now I decided that I would like all thetas to be in red color. So I would like to redefine the command \theta to create a red theta. MWE: \...
Jakob's user avatar
  • 919
5 votes
2 answers
102 views

Why do optional arguments of commands affect spacing of \mathcolor

I am very surprised that simply adding an optional argument to the definition of my command changes the spacing in formulas in combination with \mathcolor. Why does this happen? How can this be fixed? ...
Jakob's user avatar
  • 919
4 votes
1 answer
103 views

Defining alternate notation for tikz calc coordinate calculations

I would like to define an alternate notation for tikz calc coordinate calculations: From, say, ($ (a,b) + (c,d) $) to something like \tzcalc{ (a,b) + (c,d) } but I've run into an error ...
Anthony Pulido's user avatar
1 vote
1 answer
32 views

Storing comma separated entries in a list and print them using pgfkeys, pgffor, etoolbox

Problem Statement I want to store several keywords in a list, then print all items inside the list separated by commas, but the last item should also be separated by ", and ...". For example,...
Rezha Adrian Tanuharja's user avatar
3 votes
2 answers
138 views

How to use `patchcmd` with a code containing `{`?

I have a macro with a long hbox, and I'd like to integrate a simple tikz box by adding a line of code in front of its {. However, I'm facing challenges due to the inclusion of curly braces in that ...
javadr's user avatar
  • 2,394
0 votes
1 answer
42 views

Custom command in \NewDocumentCommand documentation

I'm seeing a rather unexpected result with \NewDocumentCommand. Suppose I have a custom-defined command \mybold{}, like this: \NewDocumentCommand{\mybold}{m}{\mathbf{#1}} Or \oybold[]: \...
Abhimanyu Pallavi Sudhir's user avatar
1 vote
1 answer
25 views

the scale in the macro to select the font

I am trying to define a macro ro select the font for the code within the lstlisting (i.e., using listings package). I am referring to the answer from this question What is the least invasive way to ...
liaoming999's user avatar
3 votes
1 answer
96 views

Replace #1 with something else in the definition of a command

In the develop version of the package cleveref-usedon, there is a command \SetUsedByAndOnMessageStyle, currently simply defined as \NewDocumentCommand \SetUsedByAndOnMessageStyle { m } { \cs_set:...
Jinwen's user avatar
  • 8,092
1 vote
1 answer
71 views

Version of citet without author-year style?

I'm wondering if it's possible to hack my own version of citet that works even for numerical reference styles. Basically what I want is for \citet{foo} to result in AuthorName~\cite{foo} i.e. look up ...
jmite's user avatar
  • 1,549
3 votes
1 answer
82 views

Test if a user command is at the end of the document

Is there any chance for a command \testcommand to test if it is the last user command before \end{document}? Since there are still hooks at enddocument, this seems a little bit tricky. I am thinking ...
Jinwen's user avatar
  • 8,092
1 vote
1 answer
90 views

Using a new command in the custom environment

As you can see the following MWE: \documentclass[twoside,a4paper,cleardoublepage=empty,14pt]{book} \usepackage{exsheets} \SetupExSheets[question]{type=exam} \SetupExSheets{counter-format=ch.qu[1]} \...
MR_'s user avatar
  • 149
1 vote
0 answers
46 views

New environment as a single box [closed]

I am making my new environment for headings. It is as follows: \documentclass[a4paper,12pt]{article} \usepackage[utf8]{inputenc} \begin{document} \newlength{\headspace} \setlength{\headspace}{3mm ...
Vladimir's user avatar
  • 589
4 votes
1 answer
158 views

String-separated arguments in LaTeX

One of the features I like best in Plain TeX is the ability to write macros with arguments separated by a sensible delimiter. For example \def\translate#1 = #2 (#3){...} What is the LaTeX way of ...
richardIII's user avatar
0 votes
1 answer
88 views

Generating bubble answer sheet

I wish to adding bubble answer sheet in the following MWE: \documentclass[twoside,a4paper,cleardoublepage=empty,14pt]{book} \usepackage{exsheets} \SetupExSheets[question]{type=exam} \SetupExSheets{...
tstt's user avatar
  • 149
1 vote
1 answer
122 views

Make hint to use in another chapter

Consider the following MWE: \documentclass[12pt]{book} \usepackage{exsheets} \SetupExSheets[solution]{print=true} \begin{document} \begin{question} This is a question \end{...
tstt's user avatar
  • 149
0 votes
0 answers
34 views

How is it possible make invisible the custom environment sol?

Consider the following code: \documentclass[addpoints,12pt]{exam} \usepackage{environ} \makeatletter \NewEnviron{sol}{% \def\@currentlabel{\BODY}\label{solt:\thequestion}% \begin{solution}% ...
MR_'s user avatar
  • 149
0 votes
0 answers
25 views

CurVe document class: reduce the extra horizontal space between the key and its content in a \entry* row

I am using CurVe document class to create my CV. I want to know if there is anyway to reduce the extra horizontal space between the key and value in one entry (\entry*[...]...). As shown by Figure 1, ...
Sun Haozhe's user avatar
0 votes
5 answers
126 views

Best convention for defining a class of symbols

Say I'd like to follow a convention in my article, e.g. "Summation indices will be denoted by Latin letters i, j, k" or "Free parameters will be denoted by Greek letters \alpha, \beta, \...
Abhimanyu Pallavi Sudhir's user avatar
0 votes
1 answer
47 views

I am trying to pass a command array to the new command or a definition with a `for` loop with `includesvg`

I have learned from the following questions: "For loop" in newcommand Use pgffor to define a new command? \foreach with \newcommand how to use them together? I was trying to pass an ...
Oo'-'s user avatar
  • 269
3 votes
2 answers
183 views

How to figure out which package a command is from at any particular time?

I know there are some posts on this but I don't understand. So for instance I want to know which package contains \restatable. I've tried \show\restatable but I don't understand what the relevant part ...
Hao S's user avatar
  • 848
0 votes
0 answers
44 views

Separate the creation of a command from the assignment of values

I would like to know if it is possible to separate the creation of a LaTeX command from the assignment of its value. Currently, in a file, I have the creation of various commands with their default ...
Developer's user avatar
0 votes
0 answers
33 views

Command with a condition adds white space when written with indentations [duplicate]

I have a command that returns a different word according to a predefined value. \def\isPaper{0} ... \newcommand{\paper}{ \begingroup \def\True{1} \ifx\True\isPaper ...
SIMEL's user avatar
  • 185
2 votes
3 answers
583 views

How to create an environment that allows you to bold words before a " : "

(This is my first question, I hope I'm not breaking any rules in how I'm asking it) I would need an environment that basically takes as input a list of words separated by the ":" symbol and ...
Math Attack's user avatar
3 votes
1 answer
67 views

Redefining \input with itself leads to unexpected behaviour

I am trying to intercept calls to \input and branch of functionality for some filetypes. However, I have run into the following strange error: Consider the M(n)WE given below, where the macro \input ...
marc's user avatar
  • 610
1 vote
3 answers
77 views

How do I tag certain text to distinguish it, but that can also easily be toggled off to exclude from printing?

I've prepared law school course notes/outlines in LaTeX (using Overleaf). I have a school course in which I'll be tested on both the general law in a certain subject across most U.S. states, and also ...
T.C.'s user avatar
  • 111
1 vote
0 answers
27 views

\newcommand with a tikz matrix would not compile

I've made a \newcommand containing a matrix of nodes in tikz. The thing is that when the matrix is one column only, everything works fine. When it's two columns or more it stops compiling. I am ...
Artemij Keidan's user avatar
3 votes
3 answers
162 views

Usage of comma separated arguments in a macro

I've defined a macro \mychapter having an argument which is a list of two comma separated arguments (Author and Title). The macro creates a \chapter and assigns the author and the title to a fancy ...
wolfrevo's user avatar
  • 503
4 votes
1 answer
105 views

Count number of occurrences of a character in the content of a macro string output

How to generalize this macro to make it print the number of times the string occurs and allow arbitrary separator including blank space? Thanks. Outputs could be: 0 if FALSE; 1,2,3... number of times ...
Krantz's user avatar
  • 159
3 votes
1 answer
64 views

Opacity not respected for tikz drawing if inside pgfplots' axis

I define a myDraw command that should draw two lines. The command has an optional parameter. If I don't pass this parameter, both drawings should be opaque. Otherwise, the drawing specified in the ...
Alberto Santini's user avatar
0 votes
1 answer
95 views

Switching between cases in commands [closed]

The following shows the use of \IfStrEqCase{#1}{. But I have also found \str_case:nn. Which would be the most preferable to switch between cases ? Although familiar with expl3 I am confused about on ...
Karl's user avatar
  • 33
0 votes
0 answers
23 views

Is it possible to use environments from existing packages when defining my own custom environment? [duplicate]

I'm trying to define a new environment for my own needs, and I'm trying to use the lstlisting environment from the listings package in the definition of my new environment, but whenever I try to ...
Daaaaaaaavid's user avatar
4 votes
4 answers
210 views

Using \input for command arguments

I'm making an rpg system. I want to separate the contents of the spell from the formatting of the spell to, for example, be able to format the spells differently for character sheets vs a dedicated ...
Amit's user avatar
  • 43
1 vote
1 answer
157 views

Replace "\def" and "\@ifnextchar" with "expl3" code in list environment

I was trying to answer another question I asked here in the forum (How to modify the horizontal and vertical spacing between "\item" in shortenumerate (shortlst)?) regarding the shortlst ...
Pablo González L's user avatar
-1 votes
1 answer
51 views

Referring to arguments in newcommand not working in math mode [closed]

I would like to create a command given the arguments $g,n,d,X$, generates the output $\overline{M}_{g,n,d}(X)$. If no $g$ is given, I would like the default to be 0. What I thought was correct was to ...
Irit's user avatar
  • 1
1 vote
0 answers
85 views

Xetex and combining unicode characters

I decided to use the combining over arrows like the ones in the following characters: Ω⃗,M⃗,B⃗,Ω⃡,E⃡. I am using xelatex already because I need the unicode support for other sorts of characters. ...
Zuchini Alfonzo's user avatar
-2 votes
1 answer
104 views

Amplify precedence of commands [closed]

Have been using \setlength\bigskipamount{#1}. But I want to amplify precedence like this. Is this correct or should {#1} be put inside the braces of \bigskipamount ? \setlength{\bigskipamount}{#1}
Veak's user avatar
  • 1

1
2 3 4 5
163