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

5
votes
1answer
89 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
86 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
63 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
73 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
253 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
43 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
147 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
212 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
128 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
60 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
118 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
52 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
68 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
76 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
236 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
92 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
112 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
112 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
61 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
90 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
67 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 ...
30
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
79 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
41 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
130 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
67 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
69 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
139 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
197 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
115 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: ...
3
votes
1answer
62 views

TeX commands and currency symbols

Why does the code \documentclass{memoir} \usepackage[latin1]{inputenc} \usepackage[danish]{babel} \usepackage[T1]{fontenc} \def£#1£{``#1''} \def€#1€{<#1>} \begin{document} Hi, £this£ is nice, ...
3
votes
2answers
203 views

Macros formatting/arranging words {A_1}{A_2},…{A_n} into predefined paragraph for varying n and tagging

How does one robustly (without breaking most environments) construct the macros with arbitrary number of parameters that output the parameters into a predesigned paragraph such that several of these ...
7
votes
4answers
104 views

Ignoring arguments passed to a command depending on the number of arguments specified

Consider the following code: I'm trying to write a \newcommand that will accept either m or n arguments, where m < n. Here m=4, n=6. I want to set things up so that if I call a newcommand, and it ...
5
votes
1answer
74 views

How to store tcolorbox's (multiple) settings in a macro?

I'd like to store tcolorbox' (multiple) settings in a (single) macro (in fact, a xkeyval's \cmdKV@fam@key macro) and use them afterwards via this macro (I know I should use pgfkeys instead, but my ...
7
votes
4answers
244 views

auto-detect conditional probabilities in macro

Is it possible to write a macro that detects whether there is a | character in its arguments, and expands that to something else? In concrete terms, I want to be able to use the following definitions ...
5
votes
1answer
172 views

\pdfoutline, German sharp-s character

I use the following code to produce bookmarks in a pdf document: \pdfdest num 1 fit \pdfoutline goto num 1 count 0 {äöüÄÖÜß} äöüÄÖÜß ... more text ... The text prints fine. The pdf bookmark shows ...
4
votes
3answers
122 views

Macro concatenation via expansion multiple times with some tokens protected?

In the MWE below, I want to create a \doPlotCoords macro from scratch, by appending \addplot commands: \documentclass{article} \usepackage{pgfplots} \usepackage{pgfplotstable} \usepackage{adjustbox} ...
4
votes
2answers
224 views

Macro for removing whitespace from the start of a string

I want a macro that somehow replaces whitespace (spaces, newlines, tabs?) from the start of a string. Something like mystring.replace(/^\s*/g, "") in JavaScript. Is that possible?
2
votes
0answers
84 views

Passing an array type argument for new command

I've looked around and can't seem to find anywhere, but I was wondering if there is somewhere you can do something like the following: \newcommand{\loopy}[1]{ \begin{tikzpicture} \foreach ...
5
votes
3answers
127 views

Define a \newcommand to incorporate colors in \myvariables

I use LaTeX to write my job applications. Since I have more than 50 places to apply for, I like to define variables, such as: \targetorg, \website, \mysignature etc. Since these are sensitive portions ...
4
votes
2answers
109 views

Usage of macros inside \mintinline

I tried to use a macro inside \mintinline. This is the result: \documentclass{article} \newcommand\ab{expanded stuff} \usepackage{minted} \begin{document} ...
4
votes
2answers
85 views

Generate file write handles on the fly

I am experimenting a little bit with automatic generation of file handles via \newwrite. I want to achieve following behaviour: A user provides a list of file categories, for example Hints, ...
1
vote
1answer
51 views

Biblatex create a \citejournal command with journaltitle, date, title

Hello latex community! I'm trying to set a specific command to cite journal articles which doesn't show the author but the journal title, the date and then the article title. I've found this answer: ...
4
votes
3answers
158 views

Build table elements using a macro

1. Small example Consider the following two tables: \documentclass{article} \usepackage{multirow} \usepackage{hyperref} \begin{document} \begin{tabular}{c | c c | c} \multirow{4}{*}{First} & ...
3
votes
2answers
603 views

Why is this parenthesis of a difference size?

I have the following LaTeX: \documentclass{article} \begin{document} \newcommand{\lit}[1]{{\texttt #1}} \lit{()} \lit{(hello)} \lit{(}\lit{)} \lit{hello} \end{document} which produces the ...
5
votes
2answers
74 views

How to make a wrapper for \input

I would like to make a wrapper for \input to include TikZ figures. I have tried something like this: \newcommand{\inputtikz}[1]{% \tikzsetnextfilename{#1} \input{figures/{#1}.tikz} } but with this ...