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

5
votes
2answers
75 views

Matrix of values as parameter for a macro

This is my code: \documentclass{article} \usepackage{polyglossia} \usepackage{forloop} \newcommand{\values}[2]{ \ifcase#1% \ifcase#2% value a% \c% value ...
15
votes
3answers
532 views

How to make a command completely empty / invisible / non-existent?

I have a command like \newcommand{\todo}[1]{#1} which I sometimes replace by: \newcommand{\todo}[1]{} In terms of spacing/whitespace, the behavior of the "empty" command is as follows: Test. ...
3
votes
1answer
21 views

macro with optional argument in eforms textField

This is my code: \documentclass{article} \usepackage{polyglossia} \usepackage[useui]{eforms} \newcommand{\myvalue}[1][]{Testvalue #1} \begin{document} ...
5
votes
3answers
166 views

Defining a command with variable number of primes

I want to construct a new command which allows me to write somthing like: \env{3} Which would then expand to: σ''' I.e. a sigma with the specified number of primes. I however have not been able ...
6
votes
2answers
155 views

Space between commandname and argument-braces

Simple question, maybe duplicate but can't find it. I see some people (especially novices) writing something like \textbf {text} %or \frac {1} {2} It looks not good with the spaces between the ...
1
vote
2answers
61 views

Macro indent line even on newline

I'm new to creating my own commands (this is my first) and I can't seem to achieve what I set out to do. My current command looks like this \documentclass{article} \usepackage{xparse} ...
3
votes
3answers
150 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 ...
6
votes
6answers
244 views

how to make text be copied to another part of a document?

I have a paragraph in one part of the .tex file that I want to be duplicated in another part of the .tex file. I could do ctrl-c, ctrl-v... as easy as that, but then if I modify one place, I will ...
4
votes
2answers
140 views

How can I automatically replace subscripts and highlight GoTo labels?

I have to show a lot of autogenerated code throughout my document. The generated code represents loops with explicit block labels and gotos. The following code applies function f to each element of ...
19
votes
5answers
570 views

Typesetting hashtags with natural syntax

I'm using an online conversation in my document and I've made an environment to use for it. The thing is, there are many #hashtags in each post (that I'd like to color appropriately). To make it ...
3
votes
1answer
54 views

ConTeXt: Macro within macro for URLs

Background Would like to define a base URL that can be reused by other macros. Problem Using the \goto macro requires a fully expanded URL. Minimum Working Example Here's code that illustrates ...
3
votes
2answers
29 views

Page break after each section with title

I'd like to have there be a page break in between each section, just like in this question, but I'd also like there to be no page break prior to the first section (that is, between the title and the ...
7
votes
2answers
91 views

Define a macro changing category code of number sign (namely \makenumbersignletter)

Under Typesetting hashtags with natural syntax Joseph Wrigh ask me to ask a new question: In LaTeX, \makeatletter is short for changing the category code of @. But something like ...
17
votes
1answer
220 views

Why doesn't \makeatletter work inside \newcommand?

After hours of banging my brain against my skull, I narrowed down an issue I'm having to the fact that \makeatletter doesn't work inside \newcommand. Commands that I call after \makeatletter are ...
10
votes
1answer
122 views

Macro parameter delimited by more than one delimiter

TeX user can simply create the macro with a parameter delimited by an arbitrary sequence of tokens. For example \def\macro #1delimiter{...#1...} Is it possible to create a macro with a parameter ...
2
votes
1answer
48 views

Using \newcommand with arguments inside of \newcommand

I'm using the following commands inside my main TeX file right after the ToC. \mainmatter \pagestyle{fancy} \renewcommand{\chaptermark}[1]{\markboth{\chaptername\ \thechapter.\ #1}{}} ...
10
votes
2answers
184 views

Can spaces at the beginning of a line ever cause problems?

To structure my sourcecode, I often use spaces for padding: \newcommand{\st}[1]{% \begin{tabular}{lr} \emph{Student} & \emph{Score}\\ #1 \end{tabular}% } Can this ever cause ...
8
votes
1answer
107 views

Defining a command that scans every arguments' macro “looking for” a token

Knowing that every command declaration with conditionally optional arguments, as \foo{...} expanding into \foo[default]{...} can be defined by \newcommand\foo[1][default]{...} or the safer version of: ...
8
votes
4answers
177 views

Tex capacity exceeded by using renewcommand to add arguments into a list

I was working on a small macro in which I create a \newcommand with two arguments. The second argument is just a name. I want to use this \newcommand more than once and at the end I would like to have ...
3
votes
1answer
50 views

Expanding parameters inside \csname

I've browsed every question I can find on \csname and I see lots of code that uses it inside a macro and passes the arguments inside to be part of the name, but only when defining a macro. I need to ...
4
votes
1answer
118 views

Conditionals—do something, if a given command is being used in the document

Is it possible to have a conditional that allow us to do something if a given command is being used in the document? For example for the \part command would be: ...
1
vote
0answers
28 views

textual replacement within spreadtab

similar to this question I want to use a function inside of a spreadtab region, but i do not want to use it out of a seperate file but just simplify the usage and readability. Unfortuntely the usage ...
5
votes
1answer
50 views

Defining a command that conditionally defines/checks for counters

In order to complete one custom package command I needed an internal macro, I called it \@test@count{❬argument❭}, and should accomplish the following: Internally defines a new counter \❬argument❭ ...
3
votes
0answers
48 views

Retrieving coordinates of every character in a formula

I'm writing a program that uses LaTeX to display formula's. The user must be allowed to click on different parts of the formula, and the program should know on which part the user clicked. Is there ...
32
votes
6answers
2k views

Censoring Curse Words with Grawlixes

Suppose that I would like to censor a curse word <word> using grawlixes, e.g. "What the #@$! are you doing?!" How can I define a command \censor such that \censor{<word>} results in a ...
4
votes
3answers
205 views

How do I make \dots more compact? Or are there alternatives?

How would I go about changing the \dots command to be more compact? I would like the dots to be closer together so that the printed symbol takes less horiontal space. Alternatively, does anybody know ...
1
vote
2answers
85 views

How can I run pdflatex on multiple .tex files on Windows 7?

I built some graphics with TikZ and pgfplots. I have put the code with the most minimal necessary preamble into a standalone document for each figure. Say I put all those files for chapter 3 (hence ...
4
votes
1answer
70 views

Write multiple pdfs with different options

Thanks a lot for the help in advance. This might be a stupid question, or a potential overkill for this kind of forum, but the situation is as follows: I'm writing my dissertation and - of course - ...
3
votes
1answer
20 views

How to properly expand an argument to the \url or \path macro?

In the following MSE: \documentclass{article} \usepackage{url} \newcommand{\rootDir}{\$ROOTDIR} \newcommand{\myDir}{my/dir} \newcommand{\makeFilePaths}[3]{% ...
3
votes
2answers
121 views

How to calculate and use the ratio of two lengths?

I want to calculate the ratio of two lengths in Latex, so that I can then stretch an en dash by that ratio. For example, in the code below, I'd like to replace the "0.7" value of FakeStretch with the ...
3
votes
2answers
54 views

Section and newcommand in LaTeX's memoir

I want to change the section layout. The section layout should start with an § then the number (which should start with 1 instead of 0.0) and then the name of the section. I have tried to make such a ...
7
votes
3answers
199 views

Replace instances of \cite that have a specific argument

In LaTeX, is there a way to define a macro (or something) to replace every instance of \cite{a_literal_string} with \ref{appendix:a_different_literal_string} without touching instances of \cite ...
3
votes
1answer
28 views

verbatim text in tables and macros [duplicate]

I have a cheatsheet with a table that looks like \begin{tabular}{l|l} $k > 0$ & \verb+k > 0+ \\ $k \geq 0$ & \verb+k \geq 0+ \\ $\sum_l$ & \verb+\sum_l+ \\ %etc ...
11
votes
2answers
226 views

Print small TeX code verbatim and render it

To write some documentation, I would like the ability to define a command such as \showcase{x^{y}\in\Omega} which expands to something roughly equivalent to \verb|x^{y}\in\Omega| & ...
14
votes
3answers
630 views

How to draw the following box using TikZ?

How to draw the following box using TikZ?
18
votes
4answers
447 views

Are \end… macro names reserved in LaTeX2e?

Perhaps this question has been asked before, but I could not track the correct question down. I stumbled accidentally over this feature: Say, I want to make a ...
3
votes
1answer
66 views

Use the counter value as an argument

Do you know a simple way to use the current counter value to call the argument in a macro? In myPackage I have this Note: I have the for loop defined as % ...
7
votes
2answers
103 views

newcommand: different behavior depending on number of args?

I want to make my citations simpler. I'm in theoretical physics where citations are numbered, so \cite{citation} will pull up simply "[1]" (for example). Common usage is to write "Ref. [1]." I made a ...
4
votes
2answers
2k views

Vertical addition and multiplication and long division

Is there in existence packages that recreate the following environments: Some of the above have been discussed like in the How to present a vertical multiplication but what I am interested in is if ...
4
votes
2answers
69 views

Defining a macro with combine many options to one bracket

I am beginner in writing macros with multi options. What I want to do, is to combine many options to one pair of brackets. \documentclass{article} \usepackage{tikz} \usetikzlibrary{calc} ...
12
votes
2answers
2k views

TikZ: Defining and reusing complex objects?

(How) Is it possible to save some complex TikZ objects for reusing them (in the same and in different pictures)? I know it's possible to define own styles, but I'm not sure if it's the right thing ...
19
votes
1answer
556 views

A flexible derivative macro with LaTeX3

In an earlier post I asked a question about writing a flexible derivative macro, and someone suggested that a LaTeX3 version might be easier to understand, so I decided to try my hand at writing one. ...
7
votes
2answers
217 views

Lower case first character

How do you make a macro that takes 1 argument and forces the very first character to low? So you could write the following: \firstToLow{SOME TEXT INPUT OF VARIATING LENGTH} And then get this ...
9
votes
3answers
234 views

Is there a way to define a newcommand that can evaluate mathematical expressions

Let's suppose that I have a very complicated function that depends on i and j. So I define a new command, say \newcommand{\foo}[2]{X_{i+j+1}}. % This might be an complicated expression, but I want ...
7
votes
2answers
157 views

Associate counters — stepping (many) counters simultaneously

This is (perhaps) not a real question and there maybe already an answer to my proposition/request. The situation There are packages that provide the number of the last page (i.e. lastpage or the ...
0
votes
0answers
37 views

captionof{} and double-spacing

I am combining Tikz pictures with \includeimage in my thesis, which means I am mixing \captionof{} and \caption for captioning all of my images. I have now noticed that after invoking \doublespacing ...
1
vote
0answers
18 views

Problem with \titleprefixword

I'm trying to make a songbook with Songs Package. The songs are in Spanish and I want to use the \titleprefixword macro to avoid sorting my song titles starting with the articles (El, La, Los, Las). ...
8
votes
3answers
245 views

write , instead of . in mathmode

in my language it's typical to write comma in numbers instead of a dot (12,34 instead of 12.34). However, if I write ",", it automatically inserts space right after the comma. To overcome this, I have ...
5
votes
1answer
108 views

How to forward a command parameter?

I am defining a new command and a flag with: \newcommand{\setActorsStyle}[1][1]{ \ifnum#1=1 \setActorsStyleColor{} \else \setActorsStyleBW{} \fi } \newcommand{\flag}{0} Calling the ...
0
votes
0answers
53 views

Apply macro to .tex file and get a new .tex file

Are there a preprocessor for TeX, like for C/C++? Are there a way to apply a macro to .tex file in order to generate new file? For example, I have macro: \renewcommand{asd}{some phrase here} I ...