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

24
votes
2answers
7k views

What is the difference between \def and \newlength?

I wrote the following LaTeX documents. \documentclass[11pt]{book} \newlength{\mywidth} \newlength{\myheight} \setlength{\mywidth}{85mm} \setlength{\myheight}{112mm} \newcommand{\setpagesize}[2]{% ...
14
votes
5answers
1k views

How do I write a macro having comma-separated and variable number of arguments?

I want to write a macro in LaTeX2e that can pass \textcolor, which is embedded in another macro, the values of the colour model gray, rgb, or cmyk. The number of arguments specified implies the colour ...
9
votes
3answers
808 views

Detecting \global, \long, \outer, \protected

Is there a way to detect whether or not the next assignment is going to be \global, \long, \outer, or \protected? That is, is it possible to write a command \detectmodifiers such that code like \def\...
9
votes
2answers
4k views

Biblatex and custom bibtex entries - is it possible?

Is it possible to have entries in a bib file with custom @entry types? For example, below I have entries I've created for a legal encyclopaedia and a United Nations document. @undocument{modeleclaw,...
12
votes
1answer
1k views

Problem with environment expansion and the Tikz external library.

I've created my own environment mytikz, which basically looks like this (full MWE): \documentclass[a4paper]{article} \usepackage{tikz} \usetikzlibrary{external} \newenvironment{mytikz}{%begin code ...
0
votes
1answer
639 views

about overline command

I used to fix the \overline command to get a conjugate complex number for I think the line does not so satisfy me by its length. You may noticed something like: $$\overline{N}+\overline{F}+\overline{...
3
votes
2answers
500 views

Get a “Boxed” page with TeX

I would like to avoid TikZ or another package. I would like the frame surrounds the page with a rule on all sides and I would like to have a page number below the frame in the middle. I have some ...
23
votes
5answers
8k views

How to write a multiple choice test book with LaTeX?

I want to write a book which will consist of many multiple choice exam sheets. Putting the codes below into my preamble, I wrote the question like as \begin{enumerate} \item $2+2=?$ \choice $1$ \...
9
votes
3answers
205 views

Backward compatibility for command names

I have made a class file. It defines commands for use in document files. I want to change some of the command names, but I also want old document files to work without changing them. Here's an ...
4
votes
1answer
243 views

How to use different font and shape characters properly in headers?

I'm using Kpfonts for the text of my documents, but I'd like to use the Computer Modern italic ampersand in my headings. To this end, I've defined a command \amp to insert the proper character. The ...
41
votes
4answers
8k views

Will two-letter font style commands (\bf , \it , …) ever be resurrected in LaTeX?

I understand that \bf and \it are now obsolete in LaTeX and that \textbf and \textit are proper, as they produce more sophisticated (in particular, cumulative and properly kerned) changes to font ...
12
votes
3answers
659 views

Adding a list of bios to the book class

I am busy with a document where I need to add an Appendix with a list of names and short biographies (about a paragraph each). I would be happier if I can do that as I describe the person in the ...
4
votes
1answer
91 views

Command for formatting a special term

How can write a new command which formats a certain 2-word-term always in a special font, all uppercase, with the line-height of the uppercase characters being the same as the line-height of down-case ...
2
votes
1answer
604 views

Macro after heading shall not allow page break.

In a previous question I needed a solution for the following problem: I had defined a command for inserting special custom notes in my document with the fixme package and if those notes followed a ...
19
votes
4answers
3k views

No space present after ensuremath

When I insert a short maths section in a sentence, it renders fine with a space each side as expected: ...returned $\mathcal{P}$ from... If I define a command to do the same thing, it also renders ...
3
votes
1answer
789 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
759 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
219 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 ...
42
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
422 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
321 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
433 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
458 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
825 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
779 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
449 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 \begin{...
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
472 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
294 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
592 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 in ...
4
votes
2answers
365 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
853 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 ...
19
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
907 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
413 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 \textsc{...
13
votes
2answers
645 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
699 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 ...