{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.

learn more… | top users | synonyms (4)

4
votes
3answers
126 views

Trim braces from macro content

I'm having macros with a content which may or may not have extra curly braces. I want to trim the extra braces but without expanding the rest of the content, if possible. The following code shows the ...
0
votes
1answer
34 views

Mathjax can't render some of LaTeX basic commands [on hold]

Sorry this is probably a very silly question as I'm too new to LaTeX. Mathjax has issues rendering basic LaTeX commands like /xspace and /ensuremath There are some custom macros in my LaTeX files, ...
8
votes
1answer
66 views

TeX-FAQ: Non-letters in macro names - special-command generator

I had a look at TeX-FAQ on Non-letters in macro names and tried to implement the approach #2. It looks like I'm missing something. When trying to refer later to the new commands the result is not what ...
4
votes
2answers
96 views

How to allow # in \newcommand without \# or another way to defer processing of section of code

I am trying to defer processing of some latex code. This works, \documentclass[a4paper,final,11pt]{article} \usepackage{hyperref} \begin{document} here comes a reference ...
4
votes
1answer
38 views

How do you define a command to select nested groups?

Assuming a pair structure (2-tuple) is defined using groups {{<tokens1>}{<tokens2>}} is it possible to define a command \first#1{...} (and \last#1{...}) taking the surrounding group as ...
2
votes
1answer
94 views

Why is newcommand not working?

I am quite new to latex and try to understand the \newcommand command. Since (at least in texmaker which I am using) \autocite does not seem to feature autocompletion and automated display of my ...
5
votes
1answer
66 views

What's special about \: in the implementation of \pgfutil@ifnextchar

There is the following snippet of code in pgfutil-common.tex (with a very similar snippet in pgfmathutil.code.tex`): {% \def\:{\global\let\pgfutil@sptoken= } \: \def\:{\pgfutil@xifnch} ...
5
votes
1answer
64 views

How does \path, and the like, parse its argument?

I'm really curious whether someone would care to take the time to explain how to create macros which work similar to some of the macros in the pgf/TiKz bundle. What I'm particularly interested in is ...
7
votes
3answers
507 views

Defining 3*(2^4) complex macro at once

An Automata can be 1- or 2- ways, With Several Heads or a Single head Deterministic or Non-deterministic With a stack or not That makes 2^4 = 16 possibilities. However, for each combination, I'd ...
0
votes
0answers
21 views

How to define custom macros in MathJax [on hold]

I'm trying to define custom macros used in LaTex files in MathJax. Can define simple macros (single parameter) without any issue such as; \newcommand{\braket}[1]{\langle #1 \rangle} as Macros: { ...
3
votes
2answers
101 views

How do you define one macro with arguments inside another

How do I define a \newcommand (or in LaTeX 3 a \NewDocumentCommand) which itself defines a \newcommand with arguments. For example in \documentclass{article} \begin{document} \newcommand{\test}[1] { ...
1
vote
1answer
50 views

How do you define a command for use in a tikzpicture environment?

I want to define an environment for the tikzpicture environment which defines tikz specific commands. Here's an abbreviated example for a UML environment which defines a \Class command): ...
3
votes
1answer
48 views

Using \newcommand works fine in LaTeX, but when I use htlatex the line of text that \newcommand was supposed to insert gets moved to the next line?

So, I'm trying to write lines of code explaining to new students where to find different files and directories. Because the classname changes on a yearly basis I set up a \newcommand to make changing ...
1
vote
1answer
39 views

ifthenelse to ignore a section

I am writing a textbook which has a student version and a teacher version. I did this: \newboolean{teach} \setboolean{teach}{true} ...
8
votes
3answers
504 views

Without any built-in looping macro, can we just use a recursive macro to get a-b-c-d-e?

Without any built-in looping macro, can we just use a recursive macro to get an output of a-b-c-d-e? \def\aaa #1{#1-\aaa} \aaa abcde % expected result : a-b-c-d-e \bye Edit: Probably the best way ...
14
votes
1answer
166 views

\def two macros with same name, but different argument syntax

Is it possible to have macros with the same name, but different “syntax”? E.g. we have the primitive \font which could be seen as having 3 arguments(a. without size information; b. giving the ...
5
votes
1answer
111 views

Defining a LaTeX macro with optional arguments as keywords inside square brackets

I want to define a macro to insert pictures in figures, called \centeredfigure, which I am hoping to use the same way as \includegraphics. In \includegraphics, all optional arguments are given in the ...
0
votes
0answers
31 views

.sty question regarding the “degree” parameter [closed]

This might be a basic question but I really need help. So, I am writing my dissertation which uses a .sty template in which the degree is defined as: % Possible Degrees ...
8
votes
2answers
86 views

How to use \edef to wrap an existing macro with @inmatherr?

I have a handful of existing macros that I want to wrap in some custom processing. Here's an example of the kind of thing I'm aiming to do: \makeatletter \let\olddag\textdagger ...
8
votes
4answers
519 views

How can I create lambda expressions?

It's common for packages to accept one- or two-argument macros as transformations of some element, and it's at least common for me for these to be one-offs that don't deserve a permanent name—or at ...
5
votes
1answer
66 views

newcommand about array

$ \left\{ \begin{array}{l} a+b=c\\ c+d=e \end{array} \right. $ I define a macro command for it. \newcommand{\curleq}[2]{\left\{\begin{array}{#1}{#2}\end{array}\right.} When I type ...
1
vote
0answers
34 views

indexing with sed using less brittle \gls and \acs and \index commands

I'm writing a book for which I produce sections for glossaries, acronyms and index entries using the glossaries, acronym and makeidx packages on a template derived from the Springer book template. To ...
0
votes
0answers
36 views

How to create another styling format like \emph

I read how to change \emph and changed it to \DeclareTextFontCommand{\emph}{\bfseries}. Now I want to create another command like \secondstyleformat which I can configure aswell. Such a format could ...
1
vote
0answers
28 views

Bind command to command output

How can I bind the command to the output of another command, determined at the time the command is bound? For example with the following code, \newcommand{\hello}{foo} \newcommand{\world}{\hello} ...
2
votes
1answer
37 views

Unwanted vertical space/glue between consecutive custom \section macro calls

I am using XeTeX. I need to redefine the \section and \subsection commands in order to use some macros which don't behave well with the titlesec and/or sectsty packages. I found some code to do ...
3
votes
1answer
54 views

How to make a list of used custom macros

I used to have a separate file where I store my custom macros. It is nothing more than a huge list of \newcommands and \NewDocumentCommands. Now, I have a little note that I would like to share with ...
5
votes
2answers
128 views

Define a New Macro via a Macro Using xparse Syntax

I am trying to set up a macro that defines a macro that is to be executed only once. With what I learned from Define a Macro via Macro if Given Macro is not defined I can do that via the ...
8
votes
1answer
187 views

Understanding token expansion

First of all, note that this question is to be regarded as a learning question as I am not looking for a package (I know very well the xparse package). I am attempting to write a macro which has the ...
1
vote
0answers
25 views

using macro to identify “line breaks” as properties separator, “:” colon as properties name separator, and “-” hyphen as description

Here I have created document as per requirement. But I need to use macro in specific way. Here is my document : ...
3
votes
1answer
34 views

Change figure caption name in “thesis” document

Does anyone have an idea why this approach to changing figure naming doesn't work in thesis type document? I'm using babel and all other captions translate normally, except "Figure", which stays at ...
3
votes
1answer
38 views

Variable scoping of edef definitions in a local group (inside an ifx conditional)?

Consider this MWE: \documentclass{article} \def\testswitch#1{ \def\isA{A} \def\firstOpt{#1} \edef\tmpstr{-init-} { % start local \edef\tmpstr{-loc defined-} } % end local ...
1
vote
0answers
19 views

Redefine \question command in exam class to wrap in an environment

I'd like to redefine the question command from the exam class to wrap each question in a new environment. That's the general description. What I'm trying to do is take a document that is written as an ...
1
vote
1answer
28 views

A dynamic variable as content of a glossary entry

Based on the macro defined here, I would like to use it to create a glossary with a variable in the description. Here is my MWE: \documentclass{article} \usepackage[utf8]{inputenc} ...
8
votes
2answers
186 views

Defining a variable inside an environment, but use it outside

How can I use a variable beyond the environment where it has been set? Following the MWE given below, how can I print the variable it both places (inside and outside the environment) ? ...
5
votes
1answer
66 views

Renew command on mbox makes it freeze - Fix subscript size

I'm trying to change the font style of \mbox, but all my tries have failed. All commands I try either have no effect or make pdflatex recursively keep working and never finish and freeze. This makes ...
3
votes
1answer
37 views

Defining a dynamic variable

Goal : I would like to create a variable that could be dynamically updated. Context : Every chapter of my document has a specific keyword (actually a bibtex entry). And sometimes, I need to print ...
6
votes
1answer
78 views

Macro, new command or new environment for code?

I am using the listings package to typeset code. I have defined a custom style using \lstdefinestyle{verbo} and then typeset code in a lstlisting environment as in the following MWE. ...
3
votes
1answer
44 views

Where to put \renewcommand in Beamer

This question is related to Setting default overlay specification for itemize environment. In the above-linked question, Werner provided a solution that uses \LetLtxMacro and \renewcommand. However, ...
6
votes
2answers
142 views

What can go wrong when using macros as arguments of other macros?

Thats a problem I encountered several times during the last weeks. I try to use macros as arguments of other macros, and it doesn't work. The most recent example: I try to use \addcontentsline to put ...
6
votes
4answers
190 views

Command which replaces a certain character of its argument

How to define a command which replaces every certain character in its argument with another certain character? For example, I'd like to define the command \myreplace{1-2-abc-345} which gives me the ...
5
votes
2answers
69 views

Using macros for including tikz graphics

I am not facing any problem, but I need the opinion of the community. I am writing a thesis and have a lot of tikz figures in it. So what I do is pre-compile these tikz files to PDF and then include ...
4
votes
1answer
31 views

How to see which package define a particular command/macro?

We often encounter multiple definitions of certain commands/macros. Then, we often get the error, e.g.: ! LaTeX Error: Command \P already defined. Or name \end... illegal, see p.192 of ...
4
votes
1answer
47 views

Redefine verbatim environment

I have a text with source code, which I would like to display. I am using pandoc, so I have to use either verbatim or listings enviroment. Unfortunately, I can't use listings package (due to ...
1
vote
1answer
68 views

How to make my sty file work only inside a environment?

Say for example, i have a bibpattern.sty which consists of some latex commands (like \COMMENT). I want this bibpattern.sty to work only inside \begin{thebibliography} ... \end{bibliography}. The same ...
2
votes
3answers
43 views

Legitimate “local variable” (argument) command in a macro raising “Undefined control sequence”?

Consider this MWE: \documentclass[varwidth,tightpage,border=1bp]{standalone} \usepackage{tikz} \begin{document} \begin{tikzpicture} \makeatletter \gdef\getMyInfoString{% \let\trfm\relax % ! ...
0
votes
0answers
24 views

Protecting / escaping the # (number-sign/hash) in a callable macro? [duplicate]

Consider this MWE: \documentclass{article} \usepackage{tikz} % \gdef\myset{ %* \tikzset{ % mystyle/.style={rectangle}, mycode/.code n args={2}{% \typeout{YEAH! #1 #2} % }, } % end ...
4
votes
1answer
63 views

Define a macro with an optional argument that is a space

I'm trying to define a macro replaces a phrase by a single latex expression, e.g., I want \myPhrase to return the phrase "this is the dog". The trouble is that when you do this in the obvious way ...
9
votes
2answers
238 views

How can I define a greedy macro?

I have a feeling this is a duplicate somewhere, but how can I ensure that TeX will keep scanning until \relax or something similar? \documentclass{article} \usepackage{xparse} \pagestyle{empty} ...
3
votes
0answers
26 views

Creating a Macro for an n-by-m Matrix in LyX

Specifically, I'd like to create a matrix such as $\left[\begin{array}{cc|c} a_{1} & a_{2} & a_{3}\\ b_{1} & b_{2} & b_{3}\\ c_{1} & c_{2} & c_{3} \end{array}\right]$ But in ...
4
votes
3answers
115 views

Reusing saveboxes

Since \newsavebox{\name} assigns the box register number to \name, there are probably a maximum of 256 boxes available. Is there a way to release a \savebox after you are through with it?