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

8
votes
1answer
214 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
39 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
65 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
31 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
58 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
42 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
55 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
265 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
101 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
62 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
134 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
139 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
174 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
206 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
92 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
41 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 ...
5
votes
1answer
119 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
87 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
72 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
25 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
76 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
255 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
56 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 ...
5
votes
3answers
167 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
79 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
266 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
135 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
68 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
120 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
62 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
79 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
81 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
64 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
246 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
94 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
124 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? ...
7
votes
1answer
121 views

How do you define macros to toggle a character active and define a macro for it?

I'm experimenting with core tex in order to learn some basics. My goal is to define a shorthand environment which makes use of active characters. The general idea is to activate the used characters ...
2
votes
2answers
63 views

How to write macros that behave like \item in an enviroment?

I am attempting to add an environment to a project that would take the following form: \begin{example} \source some text goes here to be used as an example. \target some more text goes here as a ...
7
votes
1answer
94 views

Passing values to a command

I am new to Tikz and have been largely following the PGFManual to learn about how to use it correctly. The PGFManual shows examples of using foreach but they do not show how to pass it to a command. ...
3
votes
1answer
73 views

\newcommands in the \standalone file not recognized in the main file

Few \newcommands defined in my standalone .tex file containing tikz figure is not recognized in the main beamer .tex file. Please point out what extra lines should I write to make it work. Here is ...
31
votes
3answers
2k views

Why are LaTeX macros so inconsistent?

I use LaTeX daily to write my papers, and while I find it a very nice tool to make documents in, some things about the system outright bother me; such as the very inconsistent macro system. A few ...
1
vote
0answers
92 views

macro: repeat a command if new page else do nothing

QUESTION: How does one write a pair of macros that work in 1) beamer class and 2) article class, respectively, such that if it, \macroname{...}, is executed at a point in the code, that point ...
3
votes
1answer
49 views

Creating command: FanceVerb Error, Paragraph ended before

Hi and sorry if that question might be already asked. I try to create a command like this: \documentclass{scrbook} \newcommand{\code}[1]{\texttt{#1}} \newcommand{\smallx}[1]{ \begin{center} ...
7
votes
1answer
151 views

How can I throw a custom error from \newcommand

I'd like to write a command that checks the given arguments and throws an error if they are not in a range. I'm imagining this would look something like this: \usepackage{xifthen} ...
1
vote
1answer
80 views

An inconsistency in beamer color handling: how to set color for a specific slide layer?

The following MWE works for setting the color of the bullets, but not the \item text (except at the top level, which turns everything grey). As I step through the slides, I'd like the text of the ...
1
vote
0answers
23 views

Dummy macro for ignoring beamer overlay

I would like a dummy macro that ignores overlay specification (from beamer) when the code is copy-pasted into another class. \documentclass{article} \usepackage{fontspec} \newcommand{\onslide}[1]{} ...
1
vote
1answer
71 views

LaTeX tokenizing

With LaTeX macro \newcommand{\CH}[2]{#1\choose#2} and input \CH63=20 my hope was to get the equivalent of {6\choose3}=20 but I get {6\choose3=20} instead. I know how to fix the text to ...
1
vote
1answer
154 views

fit tikzpicture to page width or height (using macros)

I have a new environment defined that fits tikzpicture to the page width, but when tikzpicture is long in height the bottom part of the tikzpicture is cut and extra blank page appears because of the ...
8
votes
3answers
202 views

Automatic three digit numbers in subsections

I'm a newbie in LaTeX, please forgive me if this is too stupid. I have some code like this: \documentclass{article} \newcounter{qnumber} ...
5
votes
2answers
132 views

How can I force lstlisting to expand an argument?

I'm trying to use the listings package with a variable language (it's actually for a package). However, I can't seem to pass a macro as the value half of a key-value pair. Here's a simple example: ...