Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

6
votes
4answers
120 views

Loop over an optional argument

I'd like to use the command \foo with an optional argument to step and print the counter value iterated according to the number passed. So, for example, \foo[5] should step the counter 5 times, one ...
0
votes
3answers
71 views

An ellipsis with N dots

How might one define a lualatex macro \lip, taking optional arguments * and [N], such that, with no argument, the expansion is an ellipsis consisting of three dots, with [N] it has N dots, and with * ...
2
votes
1answer
19 views

Check if mmode Command Doesn't Work in Tikz-cd environment

I have a command that allows me to write \terminal in math mode and it print in its bb-bold style, but also allows me to call it in text mode as \terminal (as opposed to \(terminal\) or whatever). The ...
0
votes
0answers
45 views

How to draw manifolds charts with TikZ?

I'm quite new to TikZ, so I would love to get some help with the drawing! What I intended to draw was not exactly what is shown in the picture, as that is probably not possible. I only want to draw a ...
6
votes
1answer
48 views

Reverse direction of writing automatically with RTL script

A new interesting feature with latest release of babel a lua algorithm which detect the beginning and the end of Arabic sentences and revers direction of writing without adding explicit markup (\...
2
votes
1answer
28 views

Using newcommand to produce (simple) newcommands [duplicate]

I would like to have, say, two custom comment macro for every author. For example suppose there are two authors Alice and Bob and they would like to have commands: \newcommand{\acom}[1]{\textcolor{...
3
votes
1answer
43 views

Using tex4ht to convert from XeLaTeX source that uses Unicode-named macros to Word (.docx) format

I asked a very similar question several years ago on the tex4ht listserv and received a very helpful answer from Michal Hoftich. He described certain limitations for working with Unicode and tex4ht ...
0
votes
0answers
27 views

Customize acronyms usage of first use

So I have a list of acronyms defined with the glossaries package, like such: \newacronym{mac}{MAC}{Medium Access Control} but also some of these: \newcommand{\mk}{Master Key} because the latter ...
0
votes
1answer
39 views

Numbering List of Appendices

I use the following for creating my own list of appendices (which comes as the e.g. table of figures after the toc): \newcommand{\listappendicesname}{Anhangverzeichnis} \newlistof[section]{appendices}...
1
vote
1answer
28 views

How to create a string comparison with xparse's \NewDocumentCommand?

My MWE was created with the help of these two Q&As: 1 and 2. MWE: \documentclass{article} \usepackage{xparse} \usepackage{xstring} \usepackage{pdftexcmds} % Command declaring a global ...
0
votes
1answer
43 views

How to use xparse's NewDocumentCommand for global definition?

This is re: egreg's solution to this question. Issue: I would like the \NameOne command to replicate the \NameTwo command where it outputs only when being called on like so: \NameOne. When an ...
0
votes
2answers
61 views

How to call command with optional arg using {} instead of []

This is a question re: Lost global definition after \ifthenelse using package xifthen. I'll reference the Answer given in this question here since it's clear and clean. MWE: \documentclass[parskip]{...
12
votes
1answer
497 views

A curious dependency between \newcommand and curly braces

An example is a bit artificial, but the point is that I do not understand why {} influence the outcome of \newcommand in the way described below. Consider the following definition: \newcommand\...
0
votes
1answer
26 views

Problem calling \creflabelformat from a command

I'm using the cleveref package with some customizations, using \creflabelformat. Because cleveref should be the last package to load, and because the customization commands should come after cleveref ...
3
votes
1answer
21 views

renewing the \mintinline command to disable italics (or any other alternative)

For the minted environment, you can disable italic comments / preprocessor includes etc by using etoolbox and then doing \AtBeginEnvironment{minted}{\let\itshape\relax}. Using \let\itshape\relax ...
1
vote
1answer
70 views

clean up definition file

I've got a problem with my custom definitions-file. The file has hundreds of command definitions (with \newcommand or \renewcommand; mainly shortcuts for mathematical terms, programm names,...). I ...
3
votes
1answer
56 views

Lost global definition after \ifthenelse using package xifthen

I created my MWE with the help of this Q&A. MWE: \documentclass{article} \usepackage{xifthen}% provides \isempty test \newcommand{\GlobalDef}[1][]{ % \ifthenelse{\isempty{#1}} % {} % ...
7
votes
3answers
524 views

Who ate my space? (How to stop \exp_args:Nf from consuming a space?)

I have a macro that uses \prg_replicate:nn to produce a number of spaces, then pass those spaces, after f-expanding \prg_replicate:nn, to another macro. The problem is that when I use \exp_args:Nf, it ...
1
vote
1answer
20 views

Macro inputs from text file to draw nodes at x,y where x,y values are read from the file

I am drawing boxes using a macro like \newcommand{\drawbox}[2]{ \node[box, fill=green] at (#1,#2){}; } where I specify the arguments #1 and #2 (that correspond to x,y values) when calling the macro. ...
0
votes
0answers
36 views

automatic list of abbreviation macro in texstudio

Texstudio has a powerful tool called macro. Theoretically, it shouldn't be hard to make a list of abbreviations through this tool by finding all the parentheses and checking previous words. However, ...
1
vote
1answer
104 views

Can we automatically assign labels to numbered equations corresponding to their number in the text?

Can we automatically assign labels to numbered equations corresponding to their number in the text? Is there a latex macro that does that, regardless of the particular editor which I'm using? Can ...
2
votes
2answers
30 views

Nested newenvironment definitions, within a table

I'm trying to define two environments, one to be used inside the other. The first is a section in a CV, the second a subsection (cvitem). The latter holds an unordered list (commented for now, to ...
0
votes
0answers
31 views

Macro trigger in TeXstudio does not work

I am trying to define a macro in TeXstudio. When I am typing "itemslide" nothing happens.. Only when I am typing "\itemslide" the text is replaced by the content of "LaTeX-Text". What am I doing ...
1
vote
3answers
82 views

How to properly use delimited macros

I read about the delimited macros in this answer. Actually, I would like to do something similar to the following: \documentclass[a4paper]{article} \def\insert this[#1]{% this macro: #1\\ } \def\...
0
votes
0answers
14 views

How to create a dynamic macro to detect if display style is enabled [duplicate]

I don't really have much insight on how \displaystyle actually works, i just see the difference between in-line equation like $\frac{1}{2}$ which displays a small fraction and $\displaystyle \frac{1}{...
3
votes
3answers
61 views

How can I put every `verbatim` environment inside a `Shaded` environment by changing the preamble only?

Unfortunately, I have a lot of TeX code which should look different that it does not, but I cannot modify its code body. However, I can modify the preamble and for example, I have learned that I can ...
5
votes
2answers
139 views

Cannot use \textit or \url in \edef

I'm trying to write a Tex command that automatically prints out attribution information for images I use in my document. I created 2 different commands. The first one is \nounattr (with 3 parameters) ...
17
votes
3answers
664 views

What is the difference between 'macro' and 'command'?

Some people use the word 'macro' and 'command' interchangeably to refer to the instructions given to LaTeX. Is there a real difference between the two terms? If there is, can we see some examples on ...
1
vote
2answers
40 views

Identical math appears differently if defined in a \newcommand

My short example .tex line is: $\myCommand$ or $\boldsymbol{d}_{x}^{\textrm{word1},\textrm{word2}}$ Where I have defined: \newcommand{\myCommand}{ \boldsymbol{d}_{x}^{\textrm{word1},\textrm{...
1
vote
2answers
54 views

! LaTeX Error: Command \removefromreset already defined

There are ready files for preparing Latex document. I used .cls template file and it has below code: \newcommand{\@removefromreset}[2]{{% \expandafter\let\csname c@#1\endcsname\@removefromreset \...
1
vote
1answer
53 views

Error: Argument of \newcommand{…} has an extra }

I am trying to create a new command to help formatting the entries of the list of figures. Argument 1 should be optional and contain the date the source was accessed, argument 2 is simply the figure's ...
3
votes
3answers
86 views

Redefine `\uline` so `\colorbox` is locally defined to have underlined text, too

Initial problem: I want to underline the text with a continuous line with the following code: \uline{No underlining for \colorbox{lightgray}{everything} inside the colorbox.} Workaround: A ...
3
votes
2answers
116 views

How to fix this capitalization issue of a macro in the title-command?

I wrote the following code to typeset the title page of a paper: \documentclass{amsart} \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage[USenglish]{babel} \begin{document} \title[...
3
votes
2answers
47 views

Mysterious vertical space when using \newcommand with expex

Ok, so here's some code that shows off the problem i'm having: \documentclass[10pt,letterpaper]{article} \usepackage{expex} \newcommand{\gloss}[3]{\ex[numoffset=2em,aboveglftskip=0pt] \begingl \gla #...
4
votes
1answer
123 views

How to add conditions in LATEX macros?

I would like to create custom macros with conditions. For example, I would like to add an "if-condition" to a macro that I created to write derivatives of any order in relation to a single variable. ...
0
votes
1answer
73 views

LaTeX unable to parse the names of journals in my bib file due to backslash

I have downloaded various bibtex references from NASA ADS (the astrophysics article finding tool). They all refer to journal names with a backslash as if its a code. For example for an article from ...
2
votes
1answer
30 views

New command for multiple subsection

I am writing an university report and I have to answer to a series of topics divided in points. I'd like to obtain a header like this 1.1.a,b,c. I have written this command to generate a single ...
0
votes
0answers
32 views

Own command for references - TexStudio does not recognize referenced labels

I'm currently writing a thesis using LaTeX. I have a couple of figures (diagrams) in my document and wanted to reference them in a more convenient way than always writing "bla in figure \ref{labelname}...
1
vote
2answers
59 views

Defining a macro to output a Greek symbol

I'm writing a document with a lot of Greek letter combinations like . I'm tired of having to type \gamma^{\mu} or similar every time. I wanted to define a macro which would produce the same result. If ...
4
votes
2answers
126 views

Define macro as wrapper for parameters of a command

I'm trying to define a macro that is a little wrapper to a common parameter of a command. The macro is expanded, but the parameter is not taken into account by the command. The macro, \sp is used ...
8
votes
2answers
367 views

Environment decorators

I'm looking for a way to write a "decorator" (in Python terminology) or a "wrapper" for LaTeX environments: a way to give addition behaviour with save of the notation. For example, before every \begin{...
9
votes
2answers
491 views

Is there a list of expandable TeX primitives? LaTeX? e-TeX? others?

According to Christian Hupfer's comment I understood that calculations are possible in a keyval list when the macro is expandable. The macro \numexpr being expandable, calculations are possible. ...
4
votes
1answer
77 views

Commands inside textbf

I was working on creating a small table of formulas for my Math class. Since I will be using a lot of vector related stuff I defined and redefined some commands to suit my needs. Below you see my ...
7
votes
2answers
246 views

LaTeX 2e environment that “knows” the name of surrounding environment

I'd like to have a LaTeX 2e-environment which when occurring inside another environment "knows" the name of the surrounding environment. Is this possible? I know that \@currenvir provides the ...
1
vote
1answer
26 views

Error when defining a math operator and corresponding `\renewcommand`

I tried to define a new math operator - essentially a math macro. I wanted to define an operator for the Eccentricity of a graph or network. The code seems to work when I generate a PDF, however I am ...
3
votes
1answer
38 views

How can I wrap `\colorbox` around `\Verb[commandchars=\\\{\}]` by only changing the preamble?

This is a follow-up question to How can I use `\renewcommand` to wrap `\colorbox` around `\Verb`? I have TeX files which contain code like: \Verb|print("Hello World", end="")| The \Verb content ...
2
votes
1answer
43 views

How can I use `\renewcommand` to wrap `\colorbox` around `\Verb` by only changing the preamble?

What works: I have TeX files which contain code like: I want \texttt{this text} to have a background color. I want the \texttt to have a background color: I want \colorbox{lightgray}{\texttt{this ...
1
vote
1answer
35 views

Biblatex remove dot at the end at footcite and bibliography

like it is said in the heading I need your help at handling dots. I like to have such a footcite and I do not know how to approach it: First Name, Last Name, Title, Location, Publisher, Date And a ...
0
votes
1answer
41 views

mcexam a custom type question

I'm trying to create an exam using the code provided by him. Here is the code: \documentclass[twoside]{article} \usepackage[english]{babel} % set fonts \usepackage[utf8]{inputenc} \usepackage[T1]{...
3
votes
1answer
71 views

Macro Source or Definition

How can I see the definition of the macro? I come from the programming background and it would be nice to see how the macro is defined. Perhaps even better if there would be something similar to Lisp'...