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

3
votes
1answer
779 views

Context-sensitive newline macro

I'd like to write a new command putOnNewLine such that \putOnNewLine{ABC} puts ABC on a new line, with exactly one line's vertical space separating it from what has gone before. It must also ...
4
votes
1answer
757 views

Tikz externalize + macro's ? Or how would you do it?

I'm currently building courses for some of my college teachers. The aim is to make their Word/MS paint generated study material into high grade Latex/Tikz material. I'm aiming for high consistency in ...
1
vote
3answers
3k views

Using predefined constants with TikZ

I can't seem to get definitions of constants working in TikZ. I looked at this related question question and that too did not work for me. This example works, but not if the swap the \coordinate ...
6
votes
1answer
218 views

Expansion of command for language in otherlanguage environment

I wish to keep the language in a command \newcommand{\testlang}{english} \begin{otherlanguage}{\testlang} ... \end{otherlangauge} However, \testlang is not expanded, and i get the error ! ...
18
votes
5answers
9k views

\vec{x} but with arrow from right to left?

I have two variables: \vec{x} and another one which is somehow dual to the first. Therefore I would like to symbolize the second with something similar but a leftarrow on top of the x. I already tried ...
41
votes
2answers
5k views

Macros for common abbreviations

Common abbreviations are surprisingly tricky to format correctly. I'd like some simple macros for them, to be used like so: You should eat more fruit, \eg apples, bananas, oranges, \etc. There are ...
4
votes
2answers
276 views

Ending all pages with period/fullstop

I want to have LaTeX (LyX) make its pages end at a fullstop (.). In other words no broken sentences carried to next page. I hope to use \raggedbottom so that pages will be shortened by a few lines ...
3
votes
2answers
420 views

Macro to allow for alignment points within its argument

I would like to have a macro that allows for alignment points inside it. As a specific example, I would like to be able to say: \begin{align*} a &= b\\ \bracr{c &= d} \end{align*} ...
3
votes
2answers
320 views

Use \def without including the square bracktes with pgfplot?

I would like to define a line style to use in my pictures. But would still like to retain the flexibility to be able to tweak these if needed in the actual picture, as in the third picture ...
10
votes
7answers
320 views

Writing a macro to typeset a variable number of terms of a series

I have been trying to write a macro where I can specify the number of terms of a series and it would then print: n0+n1+n2+n3...+nn It is important for my work that I can print any number of terms. ...
12
votes
2answers
2k views

\addvspace can't replace \vspace

I want to replace \vspace with \addvspace in a command. When so doing, I get obtuse "something's wrong--perhaps a missing \item." errors. I'd appreciate an explanation of why this happens and how ...
24
votes
2answers
431 views

Delimiting a macro argument with the macro itself

Any command sequence can be used to delimit a macro parameter. Even one that has not been defined. For example: \def\YY#1,#2\@@{#1,#2} \YY123,2345\@@ will happily work, even if the macro \@@ has ...
7
votes
5answers
327 views

Typeset a series of characters with equal distances?

for typesetting tables with design of experiments, I have to typeset strings like "+ - + +", - - - +", etc. in a column of a table to represent the so called pattern of the experimental run (sometimes ...
6
votes
2answers
449 views

In the verbatim environment, how can I display an 'if' statement I declared as '\ifcondition'?

I have declared a couple of if commands of the form \newif\iffinal \newif\ifsolutions Now I want to write about it in the same document! So I want to write something like \iffinal (...) ...
4
votes
2answers
822 views

Making \footnote work in leftbar environment

Sorry, it's me again. Gonzalo has hinted me to the very nice leftbar environment in the framed package, which I now use for definitions, theorems and similar environment. Now I've got a new problem: ...
6
votes
3answers
771 views

Is there a way for a command to have a scope within item?

I defined a command \newcommand{\done}{\color[RGB]{124, 124, 255}} Is there a way to use it as \item \done la-la instead of \item {\done la-la} It bothers me to put brackets all the time. ...
7
votes
1answer
163 views

Macro to take {032911} and return 03 29 11

It's in the title -- I am looking for a macro to insert spaces. I would like to call \mycmd{032911} to get 03 29 11.
2
votes
1answer
443 views

renew section command with tabular sections

I want to renew the section command so each section will follow by a fully two columns tabular. it seems that it should be like: \renewcommand{\section}[1] { \hfill\newline {#1}:\newline ...
8
votes
2answers
246 views

Convert macro with one argument to switch

With the package array, I want to define a new column type for my tables with the command \newcolumntype{U}{>{\switchon}{l}<{\switchoff}} However, the command I’d like to use is not a switch ...
15
votes
3answers
464 views

How keep a running list of strings and then process them one at a time

I would like to keep track of all the \AddRef commands in a document and then process them one at a time, for instance print them in the document on one line per value. It seems that this should be ...
9
votes
1answer
2k views

How can one pass the contents of a LaTeX environment to a macro?

I'm working on an exam document class where the user enters in questions something like this: \multiplechoice{Question} {Answer #1} {Answer #2} {Answer #3} {Answer #4} {Correct answer} {Explanation} ...
4
votes
1answer
351 views

Printing verbatim command inputs in commands

I want to define a command \mydef that does something like this: \mydef{\foo{bar}} produces \def\foo{bar} \verb|\foo=bar| The command: \newcommand{\mydef}[1]{\def #1} does the first bit, but ...
4
votes
1answer
290 views

How to test if the value of a token is not a specific value

I have a bunch of tokens with default values. I need to test each of these and print a message in case they are still the default value. I am able to do this manually as shown below. Now when I ...
19
votes
1answer
589 views

Why \( and \) were not defined as robust commands in the first place?

I am aware of the difference between using \(...\) and $...$ (in moving arguments, for example), and yes, I've read the answers to this question: Are \( and \) preferable to $?). I also know the ...
0
votes
0answers
78 views

Proper style macros. [duplicate]

Possible Duplicate: How to write (La)TeX (with braces) [or any other TeX-related logo] I have one of the oddest questions. I know of the macros \LaTeX and \TeX that typesets LaTeX and TeX ...
4
votes
2answers
363 views

Position line in a resume

I am new to LaTeX, and I want to create a command that will display my previous positions formatted appropriately in a resume. The format I am looking for is this: 02.07.2009 - 02.07.2010 ...
15
votes
1answer
834 views

How do I create a macro which reads the content of a file when the macro is defined?

I am trying to do something like: \newcommand{\sometext}{\input{somefile.txt}} This works, but requires inputting the file every time the macro is used in the document. I would like to know a way ...
11
votes
2answers
285 views

Can we easily find all the commands, tokens, whatevers defined by a package?

This is the reverse question of How to find out where a macro is defined? (and Where do I find out how a command/environment is defined? and How to find a package name by a command name?) and is ...
6
votes
1answer
1k views

Using tilde `~` in csname in Beamer

In beamer, I would like to be able to use the tilde character ~ in the name of a command sequence. I tried with adjusting catcodes. While this was successful with the standard article class, it failed ...
12
votes
4answers
2k views

Replace . (period) by , (comma) in numbers

I pass a bunch of numbers into a custom command defined via \newcommand{\mycmd}[1]{...}: \mycmd{1.12} \mycmd{5.32} \mycmd uses the number to draw a certain figure. On top of that, I would like to ...
17
votes
1answer
4k views

Cite in theorem environment argument

When I try to cite a book in such a way \begin{theorem}[\cite[p.~90]{bibitem}] Theorem body. \end{theorem} I've got an error because of multiple use of [ and ]. Is it possible to cite in such a way ...
6
votes
1answer
896 views

Define a custom command with name, label and linkable

I'd like to create a command with the following features: \newcommand{\mycom}[2]{...} \newcommand{\linktomycom}[1]{...} In the doc body: \mycom{firstitem}{This is the first item} and later: ...
4
votes
1answer
412 views

Define command so that \label works properly

I have something like this: \newcounter{Def} \newcommand{\printDef}{\thechapter.\thesection.\theDef} \newenvironment{Expl} {\small\narrower\medskip\stepcounter{Def}\noindent\ignorespaces ...
13
votes
2answers
637 views

Is there a list of general use LaTeX kernel macros?

Here are a few cases in which one could use such a list: Is there a "prepend" version of \g@addto@macro? A "local" version? What's the most efficient way of gobbling n characters? Can I use LaTeX's ...
6
votes
1answer
694 views

Defining new accents in LaTeX

The documents that I type include lots of references to complex numbers and their complex conjugates, such as $j, \overline{j}$. I would find it lots easier to be able to type something as \*j to ...
6
votes
2answers
2k views

Centering and \MakeUppercase with linebreaks

I wish to make the list of authors show up as centered, uppercase and listed vertically on my titlepage. My documentclass contains a section like this \begin{center} ... ...
10
votes
2answers
4k views

How to redefine the \emph command in Beamer?

I am using the Beamer class and would like to redefine \emph to use \bfseries instead of \itshape. I have tried the following command: \renewcommand<>{\emph}[1]{{\only#2{\bfseries}#1}} but I ...
19
votes
1answer
3k views

Define same command with different amount of parameters

I want to define two versions of the command \Set, depending if I provide one or two parameters. I.e. like this: \newcommand{\Set}[1]{\bigl\{ #1 \bigr\}} \newcommand{\Set}[2]{\bigl\{ #1 \bigm| #2 ...
6
votes
1answer
1k views

How do I examine a token?

... let me count the ways. I can test it with \if and \ifx and \show its \meaning And there I stop, both in my knowledge and my poetic ability (though some might argue that the latter never ...
1
vote
0answers
294 views

Different spacing caused by \newcommand and \def [closed]

From the answer to my other question " define something like \lim but for another name", I tried: \def\ext{\qopname\relax m{ext}} and: \newcommand{\ext}{\qopname\relax m{ext}} In " What is the ...
22
votes
3answers
11k views

How to add a custom symbol to LaTeX?

Suppose I need some crazy custom symbol for personal use. e.g. when I write \foobar, LaTeX should show . How do I achieve this? Update: I was writing Klingon writing system for fun. Thank you very ...
7
votes
4answers
2k views

A macro that expands to the length of its argument

If I want to anonymise a paper I've written for review, I don't just want to delete my name from the author field. I want to replace my name with a rule as tall as a capital letter and as long as my ...
2
votes
2answers
1k views

Use (or redefine a) \tag command in text mode

In some times I have to set a tag in front of a text math formula. It seems better to define a command \TAG, as $\TAG{Pythagoras' Equation}a^2+b^2=c^2$ to get <Pythagoras' Equation> a^2+b^2=c^2. ...
40
votes
6answers
2k views

Macros with # as the last parameter

Knuth hid a special rule for delimited arguments in exercise 20.5 of the TeXbook. If the very last character of the parameter text is #, so that this # is immediately followed by {, TeX will ...
11
votes
2answers
287 views

How to find the previously printed character?

Is there a way to find the previously printed character in LaTeX? E.g: \newcommand{\th}{% \ifthenelse% {\equal{\previouscharacter}{1}}% {st}% {th}% } 4\th and 21\th % would like to ...
7
votes
3answers
4k views

How to define macros with numbers in them? [duplicate]

Possible Duplicate: Definining commands/abbreviations that contain numbers How can I define macros as \text1,\text2...\text3 which, when invoked will produce text with different widths?
1
vote
1answer
356 views

Is it possible to make a macro sensitive to \\?

I have the following macro: \newcommand{\INFERRULE}[3][]{% \ensuremath{\inferrule{\mathstrut #2}{\mathstrut #3}\ifx\\#1\\\else\enskip(#1)\fi}} I want to make it sensitive to \\ so that I can ...
4
votes
3answers
695 views

Redefine underscore to produce roman subscript without breaking file names

I've been using Hendrik Vogt's answer to my earlier question Redefine underscore to produce roman subscript, in which he explained how to make the underscore character active and assign a macro to it ...
10
votes
3answers
3k views

Defining a macro in LaTeX with an optional parameter in round brackets

Is it possible to build a macro with an optional parameter enclosed in round brackets () rather than square brackets, where one can say for example: \mymacro(){}{} or \mymacro{}{}
6
votes
3answers
791 views

Redefine a command, including its arguments, to to do nothing

I want to easily typeset my documents without all references (the reason is that I need a version of the document without footnotes to count the words without footnotes). I use biblatex to create the ...