{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
65 views

\savebox in page header with redefinable commands

I'm making a document class with some redefinable commands for page headers. However, I'm running into the following issue: \documentclass{article} \usepackage{fancyhdr} % In custom document class ...
4
votes
2answers
158 views

Bouncing ball over time

I have this clumsy code to plot the height of a bouncing ball over time. Is there a possibility for optimization? Perhaps writing the functions directly with the tikz math library? Also at the moment ...
6
votes
3answers
175 views

Adding vertical space (\vspace) around custom environment

I have document with custom environment myenv which left margin is 4em. \documentclass{book} \usepackage{lipsum} \newenvironment{myenv}{ \setlength{\leftskip}{4em} } \begin{document} \lipsum[1-2] ...
52
votes
4answers
3k views

Defining custom commands is bad style?

I recently received this in a e-mail from my professor Good LaTeX style would preclude creating any of your own commands, counters, etc. (Most journals would reject submissions with user-defined ...
4
votes
1answer
68 views

Using counters in macros to manage Beamer overlays

I have a very complex Tikz figure that is uncovered piece by piece during my presentation. While tweaking the presentation I decided to change the order of things being uncovered and due to the large ...
4
votes
1answer
136 views

Creating a simple list of symbols

Inspired by this great answer I tried to manually create a glossary-style environment for a simple list of symbols. Basically I wanted to create a command newsymbol that can be executed from anywhere ...
1
vote
1answer
100 views

How to create a macro for a customized frame in Beamer?

I'm looking for a way to create a macro like \chapterFrame{Title of the chapter}which adds a new slide customized as I want. As an (ugly) example, here is what it could look like. I tried the ...
3
votes
1answer
70 views

\newcommand with variable name

I am typesetting a long mathematical text (lecture notes), in which I use the alphabets \mathbb A \mathcal A \mathfrak A very often, so I decided to name them \A \sA \fA (For bb A, script A, ...
2
votes
2answers
114 views

Why can't I renew the \label command in math mode?

When I'm writing a paper and want to refer to a section, figure or equation in a different part of the document, I end up spending a lot of time scrolling through my source code so that I can see what ...
3
votes
0answers
39 views

Preserving the value of a macro outside the local scope [duplicate]

I'm writing a (supposedly) simple financial tracking program using tikz and the fp package. Within a tabular environment I compute a value using \pgfmathparse{adding some numbers}\pgfmathresult. ...
8
votes
0answers
61 views

create list of thumbnails for each section

I want to create a cooking book. There I want to define for each receipe a thumbnail image. At the beginning of each chapter I want to show instead of a TOC a gallery of thumbnails of each subsection ...
3
votes
0answers
30 views

Managing collections of shortcut-macros in collaboration projects

I write a lot of very similar documents, and thus make heavy use of shorthands such as % Partial derivative \newcommand{\pder}[2]{ \frac{\partial #1}{\partial #2} } As of now, I have a single file ...
7
votes
1answer
64 views

Reversing the effect of a \newline with the next command?

I'm using the harvard package and the agsm bibliography style. I'm aware that there are alternatives, e.g., natbib plus har2nat, and I will be looking into those in the not-too-distant future, but at ...
8
votes
1answer
98 views

footnote boolean: how to check whether currently in a footnote

Is there a way to check whether I'm currently in a footnote? (This question has already been asked on tex.stackexchange.com, but the accepted answer only provides a solution to the user's specific ...
11
votes
2answers
101 views

Determine whether the first non-space character of #1 is a letter?

Let's say I have a class file with \title command, and I want to check that the title starts with a letter, and not with math or a number or a symbol. How can I do that? This is my MnWE, the syntax ...
4
votes
1answer
140 views

Is it possible to define abbreviations for coding?

I am using the tikz-timing package to create a timeline since chronosys and chronology wouldn't cooperate and were too limited and archaic-looking to suit my purposes, and moderntimeline unfortunately ...
5
votes
2answers
148 views

define new command: \renewcommand{\longto}{\longrightarrow}

I define this new command: \documentclass[8pt,a4paper]{article} \newcounter{conto} \setcounter{conto}{\time} \usepackage{lmodern} \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} ...
4
votes
1answer
49 views

Nested call for brackets

I need to create a custom command that behaves differently when it is called. For example consider \documentclass{article} \newcommand{\bkt}[1]{\left( {#1} \right)} \begin{document} ...
3
votes
1answer
54 views

Use of \Tree with a macro

I am using the qtree to produce some trees, for example with this syntax \Tree [.foo bar ]. Now, I have automated some part of the tree and get troubles. When I place [.foo bar ] inside of a macro, ...
4
votes
1answer
65 views

`split` not working with self-defined command

I have defined a handy little macro to typeset matrix elements in braket-notation and now want to align the next line to a part of this matrix element, because the equations are really long and ...
4
votes
0answers
69 views

Format \ref as a roman numeral? Strange bug [closed]

How do I get a \ref to format as a Roman numeral? At the moment I have the code: \newcommand{\appendixref}[1]{Appendix~\romannumeral 0\ref{#1}\relax} This works great... except for when it ...
0
votes
0answers
44 views

I need some help debugging this LaTeX macro - TeX “skips past” a bunch of code?

I'm trying to test and debug a collection of LaTeX macros that I've been working on, and I have run into a problem that has me totally stumped. Essentially, the problem is that at a certain point in a ...
10
votes
3answers
1k views

Define a “square” command

I try to define the following command, for drawing a square in pstricks: \newcommand{\square}[4] { \rput(#1,#2){\psframe[linecolor=#4](0,0)(#3,#3)} } I use it like this (for drawing a red square ...
8
votes
2answers
102 views

save optional parameter of command

I want to have a command that by default uses a default string and if supplied the optional parameter. I tried it using let, but that gives strange results \documentclass{minimal} ...
4
votes
2answers
109 views

Concatenate macro with string

I try to expand a macro containing a string with another string. It is in the document and thus I want to avoid using @. I tried the following using etoolbox ...
8
votes
1answer
99 views

Cut last word from sentence one by one

I want to execute particular command for some space separated list as argument. And then execute the same command for the same list without last element and do it until list is empty. As extra point ...
4
votes
1answer
44 views

Strange behaviour of \iftoggle inside tikzpicture

I want to set flag from inside of decoration which I want to check outside of the decoration. I set the flag (call \toggletrue{} or \togglefalse{}) but when I check this flag it always false. For MWE ...
13
votes
1answer
143 views

What could go wrong if I don't use \detokenize when creating macro names using macro arguments?

I was in correspondence with the author of a LaTeX package in which I volunteered code similar to the following (I have anonymised it so that it is not obvious what package): \makeatletter ...
8
votes
1answer
117 views

Is there a better way to “absorb” the subscript than this \@ifnextchar-hackery?

In this example document, I want to make a math relation called R which gets typeset as R^X, but as a math relation. But I want to maybe be able to subscript it. The macro \myRbad looks okay without ...
6
votes
2answers
147 views

Counters and macros?

Not sure how I should post my question but here it is: I've seen that in plain TeX, \newcount is illegal inside a macro \definition. Is there a way to allocate a register inside a macro? Also, if I ...
7
votes
4answers
331 views

How to access i'th argument of a macro?

How can I access the i'th argument of a \newcommand declaration via an iteration variable? Assume I want a command \foo like: \newcommand{\barr}[1]{argument 1 is: #1} \newcommand{\foo}[6]{ ...
2
votes
1answer
53 views

Dynamic macros with csname and utf-8

I wrote the following commands for dynamic variable names and assignment % in class file \RequirePackage[ngerman]{babel} \RequirePackage[T1]{fontenc} \RequirePackage[utf8]{inputenc} % in latex file ...
8
votes
2answers
125 views

new command and L with stroke

I need a boldface L often, so I'd like to use \newcommand\L\{\mathbf{L}}. This gives me a problem however, because I need a L with a stroke to write "Łoś's Theorem", for which the command is \L. Is ...
3
votes
2answers
49 views

Decrement macro, subtract 1 in side equation

While doing general math inside a math macro is not very feasible. I feel like a mecro that does, only for single digits should be possible, with default for other inputs \dec{1} to 0 \dec{2} to 1 ...
1
vote
1answer
56 views

How to make figure captions working inside a macro?

I am writing a report often having the need to insert two figures next to each other with separate figure numbers (not subfigures a,b). To speed up the process I wrote a macro but somehow the captions ...
1
vote
1answer
66 views

How to export custom TexStudio shortcut and macro?

Since I usually re-install, either the OS or TexStudio. It's frustrated to configure everything again. I save the profile and restore but those information were not in there.
4
votes
2answers
64 views

How to deal with macro expansion and 'TeX capacity exceeded' when using write18?

this thing is driving me nuts. ever since the friendly and knowledgeable people here on tex SE have guided me to doing multiple string replacements the proper way, i've been trying to incorporate that ...
11
votes
3answers
178 views

Insert newpage before section but prevent pagebreak after part

Maybe some of you can already guess what I'm trying to achieve; I want to redefine some commands with the following result: every \section should start on a new page except for sections which are ...
13
votes
2answers
397 views

What's the meaning of the macro `\m@th`?

I found this macro from Voss' Math mode v2.47, page 21: \makeatletter \newif\if@borderstar \def\bordermatrix{\@ifnextchar*{% \@borderstartrue\@bordermatrix@i}{\@borderstarfalse\@bordermatrix@i*}% ...
6
votes
2answers
144 views

Allowing first undelimited argument to be empty

Consider the following macro definitions: \def\mymacro#1{\mymacroii#1\nil} \def\mymacroii#1#2\nil{% \ifx\\#1\\% empty% \else #1% \fi }% \mymacro{foo}% -> f \mymacro{} \bye This is ...
3
votes
1answer
93 views

Leading zeros when cross referencing

I have a custom counter and output it with leading zeros. When I reference it, I get some real strange output, but the enumeration itself works. Preamble: \newcounter{reqcount} ...
2
votes
1answer
38 views

How to add another \cc tag in a letter class?

I need to create a legal document similar to a letter for a bussiness. I use the stardar class letter for be the best that fit at my needs. In fact I need to create a formal document but I need to ...
6
votes
1answer
76 views

Macro expanding to comma separated list

I'm trying to use a macro for pgfplotstable labels but the macro is treated as a single entry of a csl rather than a csl. The Question asked in Using a macro as value of addtotoc in \includepdf ...
23
votes
2answers
503 views

Backward definition of (La)TeX commands

Again and again I see, that TeXnicians define commands and do several things with them in the reverse order, I would do this as amateur. See this example: In his answer to scrpage2: Three ...
14
votes
1answer
170 views

Please tutor the usage of patchcmd and xpatch

I understand that the patchcmd package provides a command \patchcommand that can be used to add material at the beginning and/or end of the replacement text of an existing macro. It works for macros ...
0
votes
1answer
33 views

Findig the latex-command for a character [duplicate]

How can I write in latex? Which command should I use?
6
votes
1answer
80 views

Custom environment vs macro inside a tabular

In a document I'm writing I have a nested tabular structure that I want to capture as a macro for reuse. I'd like to define the nesting using a new environment but it doesn't seem to work. I have ...
5
votes
1answer
108 views

“Flatten” macros prior to sharing LaTeX file

Is there a way/an existing tool to process a LaTeX source document such that for a given list of macro definitions (using \newcommand), calls to those macros are replaced by their expanded version? ...
1
vote
0answers
41 views

How to define pathname variables?

How do I define a variable (pathname) that can be recognized by various commands, such as \input{} and \includegraphics{} ? I tried the following \newcommand{\patha}[]{./folderA} \def \pathb ...
2
votes
1answer
66 views

How to save a list as a macro for pgfplots

I want to create and store a list then use that list in a pgfplots scatterplot. My attempt is \documentclass{standalone} \usepackage{pgfplots} \begin{document} \newcommand{\listA}{ (1,2) (2,3) ...