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

3
votes
1answer
61 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
41 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
518 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 ...
15
votes
1answer
183 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
114 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 ...
8
votes
2answers
90 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
545 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
67 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
36 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
40 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
31 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
44 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
59 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
133 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
188 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
28 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
36 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 ...
0
votes
1answer
15 views

\newcommand to create a command with optional arguments

In Latex, I always use \mathbb{something0}_{something1}^{something2}, wheres sometimes 'something1' or 'something2' can be empty. So I had the idea to create a newcommand using the \newcommand. So I ...
3
votes
1answer
41 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
20 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
42 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
194 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
71 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
41 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
82 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
50 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
143 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 ...
7
votes
4answers
197 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
77 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
33 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
53 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
70 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
47 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
67 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
241 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
27 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
120 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?
3
votes
0answers
77 views

Identifying and adding macros [closed]

I added two macros: \newcommand{\tblkeyword}[1]{\textcolor{red}{#1}} \newcommand{\tblkeyword}[2]{\textcolor{blue}{#2}} and tried to use at like: \tblkeyword{ObjectId} // which shows red color. ...
6
votes
3answers
161 views

A reusable newlength (no stop/break if length already defined)

Often I have separate .tikz files, which may contain stuff like \newlength{\mytmplen}; and given I'm not very original with names, the same statement ends up in multiple such files. Which turns out to ...
4
votes
2answers
119 views

\expandafter, \expandbefor : what else?

I have a macro that prints exactly what I want, but I can't use it nested in another one. As far as I understand it is because the fist one is not completely executed and commands from first macro ...
5
votes
1answer
50 views

How to build a macro that return the absolute value of an argument of another macro?

How can I build a macro that return the absolute value of an argument of another macro? I would like that the \abs macro return the absolute value of the its argument. \RequirePackage{tikz} ...
7
votes
2answers
103 views

Problem with \newcommand

When I compile the following document, I get the error LaTeX Error: Something's wrong--perhaps a missing \item. \documentclass[11pt]{book} \usepackage[utf8]{inputenc} ...
4
votes
1answer
41 views

\newrobustcmd not expandable as key-value?

I do some TeX experiments with 'postponed' content, writing it to some file to be included later on (not necessarily at end, but most time it would be appropriate to place it there) I defined some ...
3
votes
1answer
56 views

Creating own ref-label system without using additional parameters using newcommand? [closed]

is there any possibility to create a command by to make a reference without using additional parameters? I would use something like \newcommand{\something}[#1]{\label{#1}} Is it possible to do it ...
7
votes
1answer
64 views

Generate automatic revision's numbering tabular

Situation I have to make a cover template for a document. At the end of the page, I have to add the revision number with other useful info like this example: \begin{tabular}{lccl} Revision 0 ...
0
votes
0answers
61 views

using macro to simplify the code

I got my code working with net and SO help. But now I want to simplify it using macro. I dont know macro, but people says it makes code more simplified. can some one guide me to have macro for this. ...
10
votes
2answers
198 views

How to define a macro to make a line of text red?

I'm looking for a way to make a new command that makes text on that and only that line red (or in another way clearly distinguishable). Like the % symbol comments out a line. Are commands that work ...
1
vote
1answer
66 views

Add index item by makro

I am struggling with creating a macro that would enable me to create index items by macro. From a former post (LaTeX: is it possible to create a macro to add words to index (using TexMaker)?) I have ...
9
votes
2answers
98 views

Collecting contents of environment and store them for later retrieval

I want to store contents of an environment and add them to a macro or command I could easily retrieve them, but I do not want to use the collect package. Are there any alternatives? ...