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

7
votes
2answers
221 views

Expanding a sequence inside a TikZ path

I am trying to draw a simple path using TikZ, with a custom syntax to specify it. This works: \documentclass{article} \usepackage{tikz} \begin{document} \newcommand{\latticepath}[1]{ ...
3
votes
1answer
136 views

Alternative for \DeclareMathOperator

I'm getting a little tired of defining all my mathematical operators with \DeclareMathOperator. Also it is rarely useful to have them as a macro. On the contrary it sometimes leads to macro name ...
4
votes
2answers
121 views

Build kind of a \includeonlypart for Beamer

(This is a follow-up to a previous question that recieved an answer, but raised a new issue that is presented here) Goal Given that (as far as I know) Beamer doesn't provide a way to include only a ...
9
votes
2answers
128 views

Conditionally use package and define command

I'm creating a class which should define a command if some package is available: \IfFileExists{eforms.sty}{ \usepackage[xetex]{eforms} \everyTextField{\textFont{GaramondNo8}\textSize{12}} ...
7
votes
1answer
113 views

Can I give a function to a label?

I try to create a dynamic way to give labels to my slides in Beamer. \documentclass{beamer} \newcommand{\partName}{blank} \newcommand {\defPartName}[1]{\renewcommand{\partName}{#1}} ...
44
votes
4answers
2k views

What is “expansion”?

I'm relatively new to (La)TeX, but I have a reasonable amount of experience with computational programming languages. Until I began learning (La)TeX, I'd never heard of "expansion"... So, what is ...
7
votes
2answers
155 views

\g@addto@macro appending code using parameter

After a lot of trial and error, I haven't been able to solve the following problem: A simplified version: I want to use \g@addto@macro to add code to another macro wich will use a command of the ...
8
votes
3answers
314 views

How can I add version control info (to footers say?)

I'd like to keep track of revisions to a document and I use version control software for basically everything (SVN by the way, monotonically increasing revision numbers are their own reward). I want ...
3
votes
1answer
72 views

Write a command that dynamically calls the argument of another command

I would like to be able to dynamically call an argument. The following MWE is merely designed to illustrate what I want and nothing more: \documentclass{article} \def\aecommandA#1#2#3{%% ...
2
votes
1answer
302 views

Dynamically format labels/columns of a LaTeX table generated in R/knitr/xtable

I have some tables coming from the statistical package R that I want to export in LaTeX markup. I would like to make every column large as the longest word of its label (assuming for simplicity the ...
1
vote
1answer
137 views

Using variables to draw a tikz diagram

I am defind my own command to plat a diagram with tikz. Instead of constant values I rather want to pass numbers to my command which determine the height of the bars in my diagram. Problem: I am ...
6
votes
4answers
189 views

Standalone package, preserve preamble

Is it in a way possible to preserve parts of a preamble of a standalone document? For example when I have a savebox or a macro inside it and don't want to repeat it in the preamble of my main ...
1
vote
2answers
82 views

Place a document at the end but evaluate it at the beginning [closed]

I would like to collect certain \newcommands in an appendix, so that each one can have a section explaining itself. However, if I put this appendix at the end of the file, then I can't call the ...
9
votes
1answer
92 views

Documenting new commands

Texstudio displays a popup code-completion window for new commands that can give cues about what parameter does what and provides an explanation of the methods: I'd like to do the same with my own ...
9
votes
3answers
139 views

Why is the \endcsname not found in the following code

This is a precursor to my real question. But for whatever reason, when I tried reducing my code for something to post here, I got more errors. In particular, the following code gives me an error ...
5
votes
1answer
74 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 ...
5
votes
2answers
183 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
367 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] ...
54
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
81 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 ...
5
votes
1answer
174 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
115 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
84 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
122 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
41 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
79 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
32 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
81 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
104 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
106 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
154 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
190 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
55 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
56 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
84 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
77 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
70 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
105 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
158 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
128 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
49 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
157 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
125 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
165 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
355 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
61 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
162 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
66 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
67 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 ...