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

79
votes
3answers
13k views

How to write (La)TeX (with parentheses) [or any other TeX-related logo]

I'm looking after a macro to write the (La)TeX logo (with parentheses), i.e. something similar to \TeX, \LaTeX, but where the output includes ()'s.
6
votes
3answers
489 views

What is the difference between \myname and \my@name while writing a .cls file?

What is the difference between \myname and \my@name while writing a .cls file? Are they equivalent? Please let me know if it is necessary to post a minimal example. Edit: Let me ask my question more ...
12
votes
3answers
1k views

Macro for week number

Is there a macro or package to calculate the ISO week number or alternative can someone help me with one?
4
votes
2answers
220 views

Capturing number of decimals in a macro argument

Unfortunately, in some of our documents we need to print both SI units as well as Imperial units. We have some macros defined as follows: \documentclass{article} \usepackage{fp} \def\GPM#1{#1 ...
24
votes
7answers
2k views

Are there purely expandable variants of \MakeUppercase?

\MakeUppercase and \uppercase use TeX's uccode, and they are not purely expandable. Say, \edef\temp{\MakeUppercase{abc}} will fail. Sometimes purely expandable macros are very useful. They are ...
26
votes
4answers
1k views

Alternate he / she in text

This question led to a new package: he-she I have seen a book that instead of using the masculine pronoun (he, his, etc.) alternates the gender ('he' then 'she' then next time 'he' again). Is ...
6
votes
3answers
313 views

Zero parameters in command definition

Let us say I want to define a command for typesetting (a+b)^2: \newcommand{\sumsquare}[2]{\ensuremath{(#1+#2)^2}} How can I modify it so that \sumsquare{a}{0} will produce a^2?
3
votes
1answer
863 views

Redefining the \printindex command and changing it to a desired form

In book class, I want to redefine the \printindex command and change it to something like the following: ‎\addcontentsline{toc}{chapter}{‎Index}‎‎‎‎ ‎\fancypagestyle{plain}{%‎ ‎\fancyhf{}‎ ...
3
votes
1answer
281 views

Defining my own “boxes”?

What I want is a environment that lets me create my own "boxes" (or blocks? I keep confusing them...) with the following properties They visually couple together a piece of sourcecode and a ...
15
votes
3answers
989 views

\def taking rest of the line as argument

I know how to define a macro that will take the rest of the paragraph as parameter. Simply write \def\a#1\par{\textbf{#1}}. But, how do I write a macro whose argument will extend to the end of the ...
13
votes
2answers
5k views

A macro with either one or two arguments

I am trying to define a macro with variable number of arguments. For example I want to define a macro with two arguments that can work with one argument as well. So the same macro works in two ways. ...
6
votes
2answers
590 views

Why is my macro not expanded inside of \special{…}?

I am writing my first LaTeX/TeX macro and not going anywhere with it. Could you please tell me what I am doing wrong in the code below. I have the following definitions. \def\defcolor#1#2{% ...
11
votes
1answer
5k views

LaTeX template for use cases

Currently I am trying to create a template in LaTeX for my team members in order to create a set of use cases. I thought of using tabular to create something like the picture below 2 (without colors). ...
0
votes
1answer
153 views

Help with a custom-command: Space should not be inserted

I have a problem with a command i make for a specific glossary: \newcommand{\term}[4]{\glslink{term:#1}{#2}} \makeatletter \def\term#1{\def\tempa{#1}\futurelet\next\term@i}% Save first argument ...
5
votes
5answers
523 views

Counting tokens

Is it possible to count the tokens/macro parameters. For example: \def\foo#1{...} $ \foo{\alpha\beta} $ % => \somecounter = 2
6
votes
2answers
4k views

How to use parameter numbers and \foreach

Is there a way to use the TikZ \foreach command to do operations with parameters? E.g. I would like to be able to write (just a silly example): \newcommand{\foo}[9]{ \foreach \x in{1,2,...,9}{ ...
12
votes
1answer
296 views

\show with fewer lines?

I am writing some macros for general debugging purposes (See Yiannis' question). I am basically expanding a given input step by step, and printing the result to the terminal and log. In order for this ...
7
votes
2answers
2k views

LaTeX: Use command argument in conditional?

I'm in the process of writing a command that outputs a certain text only if its argument is a nonzero number. I'd like to be able to write something like: \newcommand{mycommand}[1]{ \if{#1 != 0} Some ...
9
votes
3answers
625 views

\edef containing utf8 umlaut characters

Is it somehow possible to have utf8 characters (e.g. german umlauts) inside \edef ? The following example document behaves fine if the umlaut is given directly as argument like \convertTest{Müller}. ...
26
votes
2answers
2k views

\@ne \tw@ \thr@@

The LaTeX (2e) source code is quiet hard to read. There are a lot of macros with @ symbol. I understand those are "latex macros". There is, in particular, a series of macros called \@ne, \tw@, \thr@@ ...
5
votes
4answers
526 views

Output hyphen as en-dash in macro

In my thesis I will include a fair number of tags (morphological tags, in case it matters) that are fixed-width character strings like this: ab-c--d, where dashes denote NULL fields. I'd like to ...
44
votes
4answers
11k views

Defining commands/abbreviations that contain numbers

I tend to use \newcommand to define macros for symbols I use often, e.g. \newcommand{\hankel}{H^{(1)}_0}. One inconvenience of this approach is the fact that command names cannot include numbers. ...
10
votes
5answers
1k views

Parsing optional macro arguments

I am trying to define a macro with flexible arguments: 3 mandatory and 2 optional ones - like this: \macro{<enter code here>}[arg2] arg3 = arg4 | arg5; So args 2 and 5 are optional, as is the ...
7
votes
2answers
1k views

Macro for typesetting acronyms

All-caps acronyms and brand names like IBM look better when typeset a little smaller than usual. My simple solution is the following macro: \def\<#1>{{\small #1}} It's used like here ...
8
votes
3answers
218 views

What is the simplest way to make a command that produces a quadratic expression?

I want to have a command that accepts 1 optional argument and 3 mandatory ones. Example: \qe{a}{b}{c} produces ax^2+bx+c \qe[y]{-1}{0}{-c} produces -y^2-c How to make this command?
9
votes
2answers
2k views

Redefine underscore to produce roman subscript

I would like to redefine the underscore _ to automatically set subscripts in math mode in roman type, as I currently find myself almost always using _\mathrm{}. I can't find a way of redefining what _ ...
1
vote
1answer
536 views

Defining a custom cross referencing style

I want my cross reference links to look like: Chapter X: Chapter Title To achieve that I have created the following command: \newcommand{\fancyref}[1]{\autoref{#1}: \nameref{#1}} The problem is ...
12
votes
1answer
453 views

Simulate the % in a \newcommand

I want to automate quotation marks (not quotes) using a macro. Consider the following code: \newcommand{\mytext}[1]{``#1''} This one works fine: \mytext{This is a very long quote. Lorem ipsum ...
1
vote
1answer
1k views

New command to insert a couple of red XXX as placeholder?

I seem to misunderstand the documentation, as \newcommand\ph{\textcolor{red}{XXX}} causes pdflatex to halt. I'm not sure if this is the error: ! Argument of \sf@@subfloat has an extra }. And I ...
4
votes
1answer
4k views

How can I get capital Angstrom symbol to appear in bibliography (using .bib file and natbib)?

I have search all around but cannot seem to find the solution for getting a capital angstrom symbol (an "A" with a small circle above it) to appear in the bibliography of my dissertation. Instead, it ...
7
votes
1answer
2k views

Redefine default color of todonotes

I'm using the todonotes package with the article class to take class notes, and using the todos as markers (date, comments and so on) so I don't want to use the bright orange, which steals focus. I ...
4
votes
3answers
3k views

Can LaTeX perform simple math operations? [duplicate]

Possible Duplicate: How can I automatically calculate sums in a LaTeX table? Can LaTeX do simple math? I have a table with two columns and want to automatically add a third column which ...
1
vote
2answers
949 views

Combination of \verb and \texttt

Also I read: When should one use \verb!! and when \texttt{} My issue at hand is that I would like to write a little more than just "small pieces" (wording in linked question) of program code, but ...
10
votes
2answers
2k views

What is the right way to redefine macros defined by babel?

If I want to use the babel package and redefine a macro such as \contentsname, what is the right way to go about this? Just putting \renewcommand in the preamble doesn't work. This sort of works ...
29
votes
5answers
1k views

How to find out where a macro is defined?

Using \@ifdefined (in LaTeX), we can check whether a command is defined. Using \meaning, we can get the definition of a command. Can we also get information about where a command was defined? For ...
8
votes
2answers
2k views

\if@ statement explanation

I'm trying to tweak some .cls to fit my needs, and I'd really appreciate it if someone could explain me these statements: \if@radseminar% ... \else ... \fi If I understand correctly, it will match ...
21
votes
3answers
2k views

Why does LaTeX make a distinction between commands and environments?

Why does LaTeX make a distinction between commands and environments? Or also: why do we need environments? I ask this because I am defining a number of custom commands (like \question{} and ...
401
votes
1answer
64k views

What do \makeatletter and \makeatother do?

Many LaTeX “hacks” begin with \makeatletter and end with \makeatother. What do these commands do?
10
votes
1answer
975 views

How can I set single spacing in todonotes?

Question How can I \renewcommand{\todo} to give single spacing in the todonotes of an otherwise double spaced document? What I have tried The documentation (p. 11, section 1.8.6) suggests that ...
4
votes
1answer
1k views

Use \newcommand with a variable inside a style file

I have the following code which I put inside the preamble of my LaTeX documents: \newcommand{\modulecode}{SESG6025} \newcommand{\lecturetitle}{Interpolation} In this case, that means that when I'm ...
16
votes
3answers
774 views

Redefine command when inside a specific other command possible?

How, in general, can I (re)define commands based on in which other command they are nested? A more specific example: I have a custom latex command (say, \code{}) that makes text appear bold. ...
5
votes
1answer
332 views

Performing String Manipulation on result of \cite{}

I would like to perform some string manipulation (using the xstring package) on the result of a \cite{} (the bib package is given to me, and wouldn't allow what I want to do without a major rewrite). ...
52
votes
3answers
5k views

What is the difference between \let and \edef?

When you write \edef\a{\b} \let\a\b the results are often identical. What is the difference between these two commands? When do they behave the same? When do they not? (The question isn't for me; ...
3
votes
3answers
192 views

Automatically Adding Potentially Referenced Macros From Auxillary File

In this question someone asked if there was any way to eliminate user defined macros from a TeX document and replace them with the appropriate primitives. The answer seemed to be that while some ...
26
votes
5answers
680 views

Can one define a '\superexpandafter{n}' that would expand to 2^n-1 '\expandafter's?'

This question was inspired by comment banter in this question. See title.
4
votes
1answer
101 views

Suggestions for Including Confidence Rating in a Citation

As I write, edit, and review my document, I'd like to flag how related a claim and the supporting citation are. For example, if a reference Foo speculates on a topic (and therefore I give it a low ...
10
votes
2answers
972 views

Is it possible to create a \newcolumntype-like macro accepting more than one arguments where one of them is an optional argument?

Is it possible to create a \newcolumntype-like macro accepting more than one argument and one of them is an optional argument? I want to create a column type A that can accept more than 1 argument ...
22
votes
4answers
8k views

Command to uppercase the first letter of each word in a sentence

I'm writing a textboox in latex, and I have things like \textit{some definition}\index{Some Definition} all over the place. I'd like to combine them into something like \define{some definition} ...
11
votes
4answers
9k views

Defining shortcuts

I am using $\longrightarrow{}$ at many places in my document. I should say around two to three times per page. I was wondering if there is a way to assign a shortcut (i.e. lra) and wherever I use lra ...
11
votes
2answers
3k views

What is the difference between \fboxsep=1cm and \setlength{\fboxsep}{1cm}?

Question has been written above.