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

2
votes
1answer
9 views

Treating the contents of a TeX-style group ({\blah …}) as macro arguments

I am trying to make adjustments to a large document that uses TeX-style macros, like this: {\defun SomeFunctionName arg1 arg2} The \defun macro is defined as \newcommand{\defun}{\tt}. Can I ...
8
votes
2answers
156 views

How to define a wrapper to a command that takes an optional argument?

What is the proper way to define a wrapper to a command which takes an optional argument (such as \chapter)? I mean a wrapper, not a clone, such that we can inject code into the wrapper without ...
1
vote
1answer
22 views

How to pass text/strings from main file to beamertheme via beameroptions or is there an alternative way?

In this and this question I learned how to pass simple definitions like a location from my main file to a e.g. beameroutertheme. However this approach fails for longer strings or text blocks, in this ...
2
votes
0answers
15 views

\ifbeamer@anotherslide and \ifbeamer@localanotherslide in beamerbasedecode.sty

At the beginning of the source file beamerbasedecode.sty of beamer class, two switches are defined: \newif\ifbeamer@anotherslide \newif\ifbeamer@localanotherslide By reading beamerbasedecode.sty ...
5
votes
1answer
40 views

Unused \setbox0 in beamerbasedecode.sty

Inside the source file beamerbasedecode.sty of beamer package, there are the following lines: \def\beamer@stoptexts{| stop:0| } { \catcode`\|=13 \catcode`\:=13 \catcode`\,=13 ...
1
vote
0answers
22 views

How to include input filename in error message?

I want to add an error message to a class I'm building for when the user (which will generally be me...) forgets or messes up a macro call sequence. I can do this: ...
2
votes
1answer
36 views

Disable some xunicode macros in case of T1 font encoding?

I was hoping that, except for inputenc/fontenc versus fontspec, old .tex files encoded in UTF-8 could be used without changing anything with either pdftex, xetex or luatex engines. But the following ...
0
votes
0answers
37 views

script to create a table with multiple rows

I'm wondering how to quickly put a bunch of data into a table. I have a rather basic knowledge so I'm asking for a way to read in data by the following format: It has 4 columns, first is formatted in ...
2
votes
2answers
111 views

Why is this macro putting an element of a table on the wrong row?

Consider the following MWE: \documentclass[a4paper,10pt]{article} \newcommand{\macro}[2][]{% & something & #2 & #1 \\ } \begin{document} \begin{tabular}{lccc} \macro{3}{4} ...
6
votes
3answers
82 views

Use the result of FPeval to color a table cell

I am trying to give a table cell a grayscale color value based on it's numeric value. So far I have the following code \documentclass{article} \usepackage{fp,xcolor,colortbl} \FPeval{\resb}{0.5} ...
6
votes
2answers
111 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
307 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
46 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
32 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
46 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
93 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
25 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] ...
2
votes
1answer
44 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
81 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
63 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
84 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
425 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
142 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
20 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
83 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
129 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
106 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
52 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
42 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
88 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
58 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, ...
8
votes
1answer
42 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
344 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 ...