{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
1answer
94 views

Make the pattern of a \def depend on another macro

I would like to set up a macro defined something like this: \def\processline string: #1.#2\relax{\gdef\errorline{#1}} The catch is that the string should be given by the contents of another macro. ...
2
votes
1answer
105 views

Defining a new command whose argument doesn't need braces

I created a \newcommand to allow me to quickly create one-item lists. \newcommand{\itemm}[1]{\begin{itemize}\item #1 \end{itemize}} When I used \item, I don't have to put braces around the text. Is ...
6
votes
2answers
102 views

Text Editor Autocompletion vs direct LaTeX macros

In terms of research paper writing and in general usage, is there a preferred convention for one or the other? I'd like to know simply so that I get into the habit of using the norm as opposed to ...
4
votes
2answers
84 views

How to remove white space before reference?

I'm using \usepackage{cite} to reference bibliography (I'm using bibtex). In general the text is in greek, but bibliography is in english. I'm using babel package, so in order to write in english ...
7
votes
2answers
154 views

How to create a wavy lines with MetaPost?

I am looking for a macro or whatever code that can draw a wavy curves with MetaPost. In other words, I need a wavy/spring version of what follows: beginfig(1); z1 = (0,0); z2 = (3,2); z3 = (6,0); ...
1
vote
1answer
42 views

Active quotes in macro

I would like to use csquotes to activate quotes. That is, taking This is a "quote" inside other text. and turning it into This is a ``quote'' inside other text. csquotes makes this possible via ...
3
votes
1answer
46 views

Command to increase spacing in table

WHen I needed to increase vertical space in a matrix I found this great custom command: \makeatletter \renewcommand*\env@matrix[1][\arraystretch]{% \edef\arraystretch{#1}% \hskip -\arraycolsep ...
1
vote
1answer
35 views

How do I create a newcommand which outputs a letter with an index? [duplicate]

When I use \newcommand{\F1}{$\mathrm{F}_1$} I get the Missing \begin{document}. error and missing $ inserted if I move it inside the document. How do I define a macro so that \F1 would expand to ...
20
votes
2answers
216 views

Defining arithmetic operators that insert brackets according to usual precedence rules

I have a program that generates bits of Tex code like these: $\product{a}{\add{b}{c}}\leftrightarrow \add{\product{a}{b}}{\product{a}{c}}$ $\add{a}{\add{b}{c}}\leftrightarrow \add{\add{a}{b}}{c}$ ...
5
votes
1answer
37 views

Using \newcommand to format numbers/strings according to a pattern [duplicate]

I'm an aspiring LaTeX user and have so far managed the first steps and created my first few documents. Coming from a programming background I've been wondering how you could use \newcommand to create ...
3
votes
0answers
56 views

pdflatex: How to automatically quit on compile error?

See also this question on Reddit. I want to automate running pdflatex over and over with make and guard. However, when pdflatex encounters a syntax error, it hangs, preventing guard from being able ...
5
votes
1answer
78 views

Macro for promoting sections to chapters

I have a document where I would like to "promote" all sections to chapters, all subsections to sections, etc. That should affect not only the table of contents, but the documents as a whole. For ...
4
votes
1answer
66 views

Create macro from fairly complex pgfplots code

I have this pgfplots code that takes data from a file mydata.tsv and creates a bar plot. Now I would like to transform it into a macro in order to use it for several files. \pgfplotstableread[col ...
2
votes
1answer
97 views

Dynamic table column generation

I'm trying hard in finding a way to streamline my table generation. As you can see in the attached code, the problem is related with the code "\@for \el:=#1\do{\textbf{\el} &}", where "&" ...
0
votes
0answers
64 views

Mass replace custom macros in a LaTeX document?

I'm typesetting a document and to make it more editable I'd like to find a nice way to write the document making custom commands left and right for my ease, then go and replace them with their ...
1
vote
1answer
41 views

TeXstudio readAllStandardOutputStr seems not to work

I try to insert automatic timestamps into a LaTeX file, to get id's for some items On a windows machine I have got the following macro (JavaScript): %SCRIPT var ...
3
votes
2answers
119 views

create macro to verbatim output of command [closed]

The code \newcommand{\dosomething}[1]{#1 #1} \expandafter\verb\expandafter+\dosomething{blub}+ produces the verbatim-output blub blub. Now I want to create a macro \myverb for the second line, ...
13
votes
3answers
166 views

How to define a new command based on \section with its optional argument?

I've defined a new command called \mysec like the below: ‎‎‎‎‎‎ \documentclass{article} \newcommand{\mysec}[1]{\section{#1}} \begin{document} \mysec[Foo foo]{Bla bla bla} \end{document} But in the ...
0
votes
0answers
65 views

How to check if the selected letter is uppercase or lowercase in a macro?

I'm using Texmaker and want to define some custom macros. The macros shall check if a selected letter is uppercase or lowercase and then replace that letter by a sequence defined in the macro. I need ...
4
votes
1answer
80 views

How to install LawTex on MacTex

I'm relatively new to LaTeX, and I run Mac OSX 10.9.1. I have the latest MacTex, and have used it with relative ease for basic documents. I'm a law student, and I'm required to make a complex document ...
4
votes
1answer
67 views

Redefining environment within a macro

Hel-lo, I am a LaTeX programming newbie. While formatting my document, I found that it will look nice if I can modify the theorem environment (with amsthm package). So I tried the following code ...
1
vote
1answer
37 views

Pre-compiling with a different syntax [closed]

I am looking for a pre-compiler to introduce a customized syntax into LaTeX. Hope that an example will be worth a thousand words: I would like to compile this \thm The sum $ 1+2+3 is equal to ...
2
votes
1answer
39 views

Trouble including graphics from csv file into Pgftable, commands are dissapearing (local maybe?)

I've been trying to add eps graphics with the filename in a csv file. Take a look at the CSV to get an idea of what I mean: ...
2
votes
1answer
81 views

mathjax \sqrt command

I don't if this forum is the right place where post my question, anyway, it concerns TeX. Mathjax seems to create the bar over the argument of \sqrt command as a box with a sequence of very densely ...
6
votes
3answers
83 views

xstring test for numbers within a range

I'm working on a document command that has a variety of optional arguments for different results. I need to add an option that yields 'true' for an optional argument within a range of numbers, for ...
17
votes
2answers
348 views

Why does this simple \ifx test fail?

This should be easy, but I don't understand why the test below fails... I expected Hurrah! to be printed when the \currentchar count reaches 90 (i.e. the character code of Z). There must be some ...
6
votes
1answer
56 views

Expand package option, to make contained character math-active

In an answer to another question of mine, egreg posted code, which activates a character in math mode and gives it the function of \operatorname. Now I want to put this into a package and set the ...
8
votes
2answers
60 views

Indexing: inverting names

I have defined \Index to mark a word or phrase for indexing and also preserve it in text: \newcommand{\Index}[1]{#1\index{#1}} How would I define a macro to invert the index entry? e.g. ...
7
votes
2answers
157 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
107 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
105 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
90 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
96 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}} ...
42
votes
4answers
1k 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
90 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
260 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
67 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
197 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
94 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
157 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
84 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
121 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
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
168 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
134 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 ...