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

0
votes
0answers
7 views

How to typeset the percent symbol inside \detokenize?

I am writing some personal notes about R programming. I defined a macro to typeset R functions and operators using a different font style and color: \newcommand{\rtext}[1]{% ...
8
votes
2answers
303 views

Is this sacrificial command a good idea?

I have this command: \newcommand{\name}[1]{\edef\name{#1}} You first call it as in \name{Don} and afterwards you can refer to Don using \name. Is this an accetable way to express a constant that ...
0
votes
1answer
42 views

\newcomand causes failure [duplicate]

im new to Latex, so pleas make explenation easy ;) im working with latest latex version on miktex i tried some \newcommand today and caused an error with this command: \newcommand{\N0}{ n_{0} }. when ...
2
votes
2answers
22 views

Keeping underscores in parameters even inside NewEnviron environments

I followed this answer to define a command such that underscores in its parameter can be kept. However, this does not work if the command is called inside an environment that has been defined with ...
4
votes
1answer
29 views

Setting a counter to a value obtained by expansion

I use the glossaries and minitoc packages. Minitocs are generated for all glossaries printed in the table of content, eg with the toc option for the glossaries package. When one prints the glossaries ...
4
votes
1answer
40 views

How to use a command as path in 'includegraphics'?

I want to include a graphic by using \includegraphics{\mycommand} but it doesn't work. The path to the picture will be a combination of text written in .txt files. This is my code: ...
5
votes
2answers
91 views

How can I automatically replace all accentuated characters by the corresponding codes in TeXnicCenter?

First I want to apologise in case the question has already been asked, although I failed to find the topic on this site. So here's the thing : I've recently begun to type my lessons in LaTex using ...
1
vote
1answer
22 views

How to define commands for additonal information in beamer main file for use in themes?

In a typical beamer document I can set various options like \author or \title: main.tex \documentclass{beamer} \author{George Orwell} \title{Animal Farm} \date{\today} \institute[TUD] ...
0
votes
0answers
24 views

tikz/pgf upgrade and decorations

Since a major upgrade in pgf, my code does not compile any more. I am trying to make "decorated" source listing, where the decorations can be like highlighting some lines (see the MWE), balls on some ...
3
votes
1answer
17 views

Redefine command inside page header

I’d like to redefine a command inside a page header that’s generated using scrheading. The reason for this is that the page header should be in all-low-caps; however the chapter header happens to ...
4
votes
1answer
77 views

\begin{document} breaks redefinition of \Re

To replace the Gothic type real-part operator by a plain 'Re', the following works for me: \documentclass[a4paper,11pt,twoside,fleqn]{report} [...] \usepackage{amsmath} \usepackage{mathtools} ...
1
vote
0answers
32 views

defining a new infix command

This question kind of already exists here: How to write infix macro/newcommand? But I'm not looking for a way to divide using an infix command, which I know there already exists a command for. I'm ...
4
votes
1answer
20 views

Passing escaped special characters for use as a URL through macros

From an earlier question on Escaping special characters for use as a URL, using \string to escape the special URL characters in the second example works great: \DefineMyFormatLinkParameters{% ...
4
votes
1answer
62 views

Escaping special characters for use as a URL

If a url contain special characters (~ and #) using it as \href{http://people.brunel.ac.uk/~mastmmg/ssguide/set_work.html#4_32}{people.brunel.ac.uk} works just fine. But, I would like to have macro ...
5
votes
3answers
69 views

Issue: string manipulation with links inside

I have defined a new command \openintro which I call at every chapter of my work. This command basically constructs a lettrine sentence, like the image below (don't bother with text style): ...
2
votes
2answers
83 views

Patching local commands defined within other macros

This is the follow-up - question, respectively the main cause which led to the (yet) unanswered question here: \xpatchcmd defines macros when applied to undefined commands I tried to patch some ...
7
votes
2answers
423 views

How can I write a macro which enters math mode when called in text mode but when called in mathmode doesn't break?

I'm using the package braket for my physics notes, and this speeds things up a great deal but I'm constantly writing \ket{\psi} or \bra{\psi}, and because this specific pair of bra and ket appears so ...
12
votes
1answer
139 views

\DeclareTextSymbol and \DeclareTextCommandDefault in contrast to standard \newcommand et al

In this answer egreg used the macros \DeclareTextSymbol, \DeclareTextCommandDefault and \UndeclareTextCommand where I had previously (and unsuccessfully) tried a simple \newcommand or \let. Could ...
2
votes
0answers
22 views

Vertical spacing in `\newcommand`s [duplicate]

Consider the piece of code. \documentclass{article} \newcommand{\hello}{Hello world!\vspace{12pt}Hello again!} \begin{document} \hello \end{document} This produces the following output. ...
0
votes
0answers
17 views

Macro spacing mystery [duplicate]

I get different spacing results when I define a \hspace directly or as a macro. Directly: \documentclass{article} \title{Title} \author{Daniel Domingues \hspace{0.2cm}$\diamond$\hspace{0.2cm} ...
2
votes
0answers
25 views

How to pass an argument as a new command's name? [duplicate]

\documentclass{article} \newcommand*{\DefineRealCommand}[1] { {The real command name is: #1} \newcommand*{\#1}{I am the real command.} } \DefineRealCommand{HelloCommand} \begin{document} ...
10
votes
1answer
80 views

\xpatchcmd defines macros when applied to undefined commands

I stumbled over this feature (it's part of a bigger question, but I splitted it into two questions): Say, that we want to use \xpatchcmd (from xpatch) or \patchcmd (from etoolbox) and apply those ...
4
votes
2answers
127 views

LaTeX “Variables” - \@varname

I'm currently in the process of writing my first document class file (a personalized resume class), and I want to get a better understanding of what exactly I'm doing. So, right now I'm setting up ...
4
votes
1answer
23 views

mhchem macro in subscript

Consider the following MWE \documentclass{article} \usepackage[version=3]{mhchem} \begin{document} \begin{equation*} % c_\ce{CO2} not working c_{\ce{CO2}} \quad c_\text{working} \end{equation*} ...
4
votes
2answers
105 views

Need a Macro for Tables - independent of row and column size

I have created the following macro for Table: \newcommand{\createtable}[7]{ \begin{table}[htbp] \begin{tabular}{|p{8cm}||p{8cm}|} \hline \begin{center}\textbf{\cellcolor{Orchid!25}{#1}}\end{center} ...
1
vote
0answers
51 views

Failure After Using Latexdiff Script: \begin{description} … ended by \end{document}

After running a script to use latexdiff on a multiple input latex file I am left with a diff.tex file that is generating the following error: ./diff.tex:7009: LaTeX Error: \begin{description} on ...
5
votes
1answer
41 views

Nested \newcommand for creating maps

I want to create a simple map using \newcommand. My \NewMapItem command defines another command which returns item's value. \MapItem simply replaces to that command. \documentclass{article} ...
7
votes
2answers
80 views

New Command For Inline Code

I am using the listings package to enter large blocks of code into my document, however I am trying to write a custom command that uses my current settings to do inline code. For example I want to be ...
2
votes
1answer
31 views

Text in custom command overflows the page

This text is connected to solution described in this question: How to user bold in custom command? When I use this custom command: \newcommand*{\myfont}{\fontfamily{pcr}\bfseries} ...
4
votes
2answers
74 views

Unicode macros for square root and integral

Is it possible to define math-mode macros √ and ∫ which would expand in the following way: √a ≡ \sqrt{a} √{a + b} ≡ \sqrt{a + b} ∫ ≡ \int ∫_a ≡ \int\limits_a ∫^a ≡ \int\limits^a ∫_a^b ...
5
votes
1answer
40 views

TexStudio: Enable spellchecking in user-defined commands

I am trying to find a way to enable spell-check in cases such as: \remark[I don't understend this]{$2+5=7$} I found something that might look as an answer but it sadly does not work ... In ...
1
vote
2answers
63 views

Getting an error when defining a macro in a TiKZ picture

I like a certain style of vertices in my TikZ drawings so I want to define a macro to save time formatting. It has two arguments, one names the node, the next is its location. It should have a blank ...
1
vote
1answer
83 views

Command already defined (custom command)

When compiling following code, I the compiler tells me that a command is already defined (the name is \c@b...). \documentclass{article} \usepackage{calc} \usepackage{ifthen} \usepackage{tikz} ...
5
votes
2answers
86 views

Use \foreach loop to execute macro with parameters of macro provided in a list

I have to execute a macro a number of times, and would like to provide a list of the parameters to be executed. So, instead of \FormatLinks*[Main Search Site]{Google}{http://www.google.com} ...
5
votes
1answer
57 views

trigonometric function inside newcommand

I want to know if there is a way to define a variable that depends on a trigonometric function, like this. \newcommand{\cosTheta}{cos(30)} Such that it is parsed before using it in a tikz segment, ...
7
votes
1answer
35 views

TeX quotation marks short-circuit optional argument with \ifx

In a command with an optional argument, if I put a string beginning with TeX quotes (e.g., ``quote'') in the optional argument, something goes wrong. See the bottom entry in the example below. The ...
0
votes
0answers
23 views

What does the @ symbol sign do in Latex? [duplicate]

The document class my Uni provides has a bunch of lines that appear to define macros with "@" in the name, like this: \newcommand{\uni@title}{} \renewcommand{\title}[1]{\renewcommand{\uni@title}{#1}} ...
9
votes
1answer
94 views

Forcing macro expansion

I have done my best to understand \expandafter, \edef and friends, but I can't find a way of using them to force expansion of the parameter passed in to the macro \FormatDate in the following example. ...
2
votes
1answer
18 views

\NG package conflict

I have a package conflict resulting from a custom command in an .sty file I am using. The command looks like this: `\newcommand\NG[1]{Gram.: {#1}}%Note Grammar Now, if I run pdflatex it gives me ...
7
votes
1answer
343 views

How can latex help me format and present lots of data in a report?

At work I am responsible for creating information security reports that contain long narratives and reference what we refer to as "vulnerabilities". These vulnerabilities are presented in a table. I ...
1
vote
2answers
79 views

Automatically suggest arguments for user defined commands

When using the command \ref{ it automatically suggests several arguments, such as eqn:equation1, fig:figure1, and so on. I have defined the command \newcommand{\fref}[1]{Fig. \ref{#1}}, which rather ...
2
votes
1answer
47 views

How to user bold in custom command?

I would like to highlight some text in my paper as "programming code" with Courier font family and I found this solution. \newcommand*{\myfont}{\fontfamily{pcr}\selectfont} ...
7
votes
1answer
81 views

Why \begin{flushleft}…\end{flushleft} doesn't behave as \flushleft…\endflushleft?

The following MWE points out that \begin{flushleft}...\end{flushleft} doesn't behave as its macros counterpart: \flushleft...\endflushleft: flushleft environment's effect stops after ...
3
votes
1answer
105 views

How to have text inside round brackets on a line and also be added to a second index with predefined index search keys?

I've written a text with 200 quotes. One quote example: "Und wir haben die Liebe erkannt und geglaubt, die Gott zu uns hat. Gott ist Liebe, und wer in der Liebe bleibt, der bleibt in Gott und Gott in ...
3
votes
2answers
130 views

How to tie TeX macros to text or another macro?

Is it possible to tie a TeX macro to some text (e.g. the next paragraph) or another macro? For your information, here is a more specific description of the problem: I am using a set-up macro ...
2
votes
0answers
47 views

Argumentless macros for use in other macros

I'm in need of argument text formatters for use in some environments that use macros to redefine properties (e.g., enumitem). I need to underline text but there is no equivalent argumentless macro ...
2
votes
1answer
18 views

All Environments Share Numbering (According to Subsection)

The numbering scheme I'm looking for causes every environment to share one common numbering counter, according to subsection. For example, in my notes the numbering would look something like this: 1 ...
2
votes
1answer
52 views

LaTeX command or environment to selectively print one out of several given options

I'm currently wasting my time by trying to create a proof-of-concept class to show that writing our university's curricula with LaTeX instead of MS Word would have some benefits. Since these curricula ...
2
votes
1answer
20 views

Hide titleformat in a macro when [explicit] is loaded

This is a follow-up question to: Different titleformat style for different numberless chapters I have something like the following macro: \titleformat{\chapter} {\normalfont\Huge\color{blue}} {} ...
3
votes
1answer
71 views

Multiple Choice Answer Key in exam package at the end of document

I think this is a follow up question to: Print answer key to multiple choice questions I am trying to create an answer key at the end of my exam class document where all the questions are multiple ...