{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
58 views

How do I add a newcommand which includes formatting?

Currently I'm using \newcommand{\ps}{\textbf{\psi}} but this bolds everything after $\ps$. What do I do to get the desired result of inserting a bold $\psi$ when I use $\ps$ ? Thanks
1
vote
3answers
119 views

Renewcommand \textspanish

Let's say I write a LaTeX document that usually is compiled with xelatex (and polyglossia), but I'd like to have pdflatex (and babel) as a fallback (when I send it to someone who might not have ...
3
votes
1answer
48 views

newcommand with an argument behaves differently from newcommand with no argument

When I use newcommand with no argument, I get expected behavior. When I add an argument to my command, latex adds an extra space. Here's an example: \documentclass{minimal} \parindent=0 pt ...
3
votes
1answer
48 views

A way to generate Dynamic command names

I want to save blocks of code/info in a LaTeX file using commands, but I have no way to know how many blocks will be needed. I am wondering if there is a way to create dynamic names of commands so ...
2
votes
2answers
66 views

I want to create a new command for making a table, parameters in the command would fill up the table

For making play cards, I need to make a table of 5 by 5 cells. First row and first column would always be the same. But the other cells would depend off the card. So it would be nice to gave a ...
3
votes
2answers
94 views

Shade a line whose format is given as macro's parameter

At the moment I can generate this kind of picture with the macro \mylines shown below. But I would like to obtain a result with the second arrow shaded some per cent of the first one: Here is ...
3
votes
2answers
32 views

How to interpret the contents of a macro as key=value assignment for pgfkeys

Based on this pgfkeys method, I tried to collect options in a macro for later re-use: % Set options for a photo % #1 = options, #2 = photo name, i.e. June \newcommand\SetPhoto[2][]{% ...
3
votes
1answer
37 views

Successive macro calls with keys has unexpected output

when I make two successive calls with macros that have key values (defined using package keycommand), I do not get the expected result. Look at the code below, the macro \firstmacro calls ...
2
votes
1answer
52 views

I need to write “relation”-sign like one in the picture

I need to write A R B in Latex. I know that there is /rho option, but I need exactly what you see in the picture.
4
votes
1answer
40 views

pgfkeys pass font command

I am defining options using the pgfkeys command. \newcommand{\subtitlefont}{} \pgfkeys{ /titleblock/.is family, /titleblock, default/.style = {titlesize = 48, titlelineskip = 52, ...
3
votes
2answers
82 views

Counters, assignments, and groups

I have learned at my own expense to be careful with scratch counters. However, I recently encountered a situation I cannot understand. Consider the following code \documentclass{article} % print the ...
7
votes
5answers
421 views

Automatically replacing \º with $^\circ$

I don't like the º-symbol, that LateX is typesetting, because it has this strange underline. So I wanted to make a new-command, that's replacing \º with $^\circ$ and i tried to define it like this ...
1
vote
0answers
77 views

Measuring Length cause wrong equations alignment [closed]

Forgive my poor language and my unprofessional question but i need to understand more. I wrote 2 definitions for a commands, the first command write the current X position and Y position BEFORE the ...
5
votes
1answer
178 views

“Command \th already defined.”

I tried to define \th to put the letters "th" in superscript for ordinal numbers. LaTeX tells me that \th is already defined. How is it defined? Would it be really bad to redefine it?
3
votes
2answers
64 views

Using comma separated list input to call appropriate command

I imagine this has to be asked somewhere but I've been searching for a while with no luck, so if there is an answer feel free to just direct me there. I have a series of functions that all do ...
5
votes
2answers
474 views

Writing IP Addresses with a different font

I'm trying to create a command to printout IP addresses on a LaTeX document with a different style. It's really simple what I want to do, but I would like to do it scalable. I've already done this: ...
4
votes
1answer
72 views

Create index entries from \textbf

I've just recently completed my undergraduate mathematics degree, and have been compiling all of my lecture notes into one document for future reference. The document is long, and since it is based on ...
4
votes
1answer
83 views

\newcommand with \raisebox in section title

I have defined the following command to typeset 'C++': \newcommand{\Cpp}{C\raisebox{-.23ex}{\texttt{++}}} Using the command in a paragraph works as expected. However, I can't use it in a section ...
0
votes
0answers
24 views

Problem with \iftoggle and \notblank [duplicate]

I'm having a problem passing parameters through \iftoggle to a \newcommand using \notblank inside; it's much easier to explain by showing a small example: \documentclass{article} ...
1
vote
1answer
36 views

Why I can not define commands starting with \end? [duplicate]

I am trying to define some new commands starting with the word end and I found that it is impossible in TeX. For example, the following code does not work. My question is: Is it possible to define ...
2
votes
0answers
64 views

Unwanted vertical space at top of page before subsection heading

I have been using LaTeX for a while now, but I am very new to defining my own commands in the preamble. I am working on my thesis, and I'm using a custom .cls file which has been passed down by other ...
0
votes
2answers
110 views

How to use `\begin` & `\end` in a new command

I am trying to define a new command to customize the item-based behavior within the LaTeX, as below: \newcommand{\myitemize}[2]{ \begin{description} \item[$\{#1}$]{#2} \end{description} } It is ...
1
vote
2answers
68 views

pass escapechar to newcommand inside listing

i have defined a new command for colored bold text as follows to use in listing environment: \definecolor{mycolor}{rgb}{0,0.8,0} \newcommand{\lstemph}[1]{\textcolor{mycolor}{#1}} In my ...
1
vote
1answer
86 views

How to create an environment to dump a longtable sideways after currentpage, which works under pandoc

Sorry for the long title (and even longer question), but this is a rather complex subject and requires a bit of elaboration. Goal: I want to define a pair of latex macros which I can write in the ...
4
votes
1answer
60 views

Why SetKwData defined macro for algorithm2e doesn't work in caption?

I defined a macro with \SetKwData command from algorithm2e but it doesn't seem to be working in the caption. My code: \documentclass[10pt,a4paper,twoside]{report} ...
3
votes
1answer
60 views

Shorthand for addplot function

I'm a beginner at LaTeX. I want to create a shorthand for the addplot calls in the following: \begin{tikzpicture} \begin{axis}[axis y line=center,axis x line=middle, xmin=-1, xmax=4, ymin=-3/2, ...
3
votes
1answer
109 views

Using a macro inside a Tikz coordinate calculation

I am trying to create a general macro that prints a particular custom character, based on an answer to a previous question of mine. Here is a minimal (non-)working example: %!TEX encoding = UTF-8 ...
2
votes
1answer
32 views

summarizing option enumerate in a command

How summarize option enumerate in a command. like this \newcommand{\enumseting}{leftmargin=.7cm,itemindent=0cm,labelwidth=0cm,labelsep=.2cm,align=right}‎
7
votes
2answers
161 views

Problem in a macro definition (plain TeX)

I'm trying to write a \multicenter macro that acts as \centerline, except that it splits the text in different lines whenever it encounters the command \\. For example, \multicenter{ciao\\a\\tutti!} ...
2
votes
1answer
35 views

Calling macro from a macro breaks argument formatting causes odd environment behavior

I'm trying to write a little Latex package to learn more about Tex and to help me out with writing long and annoying proofs for a course by creating macros to retrieve rule names from a table given ...
2
votes
1answer
92 views

Installing the olympiad package on Mac

I've been trying to install the [Olympiad package][1] for asymptote on my Mac to use in TexShop, but I have no idea where to install it. I've tried to move the olympiad.asy file into the ...
7
votes
1answer
109 views

Has LaTeX3 syntax possibly changed since this question was last answered

I am adapting the LaTeX3 answer in this question: http://tex.stackexchange.com/a/61603 But I can't get the original MWE answer to compile using xelatex. I have renamed the variables, but the error ...
0
votes
1answer
113 views

Library with xkeyval, fp and newcommand

Been searching the net here and did not find any solution to this. I am having some problems with a defined library structure (xkeyval) with FPeval calculation and then passing this ...
4
votes
1answer
71 views

Arguments to macros in mathmode lose their mathmode typesetting

I'm writing a little semantics package(I know that there already exists some good packages for this) in latex to help me and my friends out with our assignments. but im having a broblem that ...
2
votes
1answer
52 views

Texshop macro for braces

How to insert \left( \right) by simply typing e.g. 'cmd+m' on Texshop. As an example: write 2+2 and then 'cmd+m' and the output is: \left(2+2\right)
0
votes
0answers
39 views

Macro to define in which order some text appears

I have several piece of text for which I would like to be able to change easily the order in which they appear. Is there a way to do that? The only solution I found until now is the following: ...
8
votes
1answer
398 views

A “#1#” argument. What is the meaning of the second hash? [duplicate]

In an answer to this question Automatically replace environment align by equation+aligned combination egreg uses \def\relaxtag#1#{\relaxrelaxtag} \def\relaxrelaxtag#1{} The role of the second # is ...
7
votes
2answers
161 views

Replace certain Unicode character with another in XeTeX

I use XeLaTeX and XePersian to write Persian documents. Unfortunately, some frequently used fonts in Persian does support important characters like ی so I should replace them with Arabic counterparts ...
3
votes
1answer
55 views

Thmtools example & solution environments share numbering with other environments

Following the answer to this question, I defined example and solution environments using the thmtools package, which I want to share numbering with the other environments in my document. Here is my ...
8
votes
3answers
251 views

macro for writing vectors

I want to simplify codes for writing vectors. For example, if I write \vector{1,2,3} it would be equivalent to \begin{bmatrix} 1 \\ 2 \\ 3 \end{bmatrix} Similarly \vector{1,2,3,4} would be ...
0
votes
1answer
50 views

Repetition of \def commands

Below is my code \documentclass{article} \def\a{\alpha} \def\b{\beta} \def\a{\theta} \newcommand\s{\alpha} \newcommand\f{\beta} \newcommand\s{\theta} \begin{document} Sample Text $\a$ ...
4
votes
2answers
138 views

Move command to the beginning or end of the paragraph

I have a macro that replaces a word in the middle of the paragraph and figure (inside a wrapfigure environment). But the text justification looks awful and it seems to be because wrapfigure cannot be ...
0
votes
0answers
7 views

odd vertical alignment for mathop [duplicate]

I have encountered an odd vertical misalignment when using mathop to define some one-character macros. Specifically, I am (re)defining \i via \renewcommand{\i}{\mathop{\mathbbl{i}}} (for ...
5
votes
1answer
104 views

Command with simple parsing

I would like to write a command \foo that takes a math-mode expression and renders it with some selected symbols (say denoted by #) printed in \mathcal. For example, \foo{#X^A_B} should expand to ...
6
votes
2answers
187 views

Pass a command as optional argument of environment

Sorry for the beginner question, but I'd like to know if there is a robust way to do what the title says. The following MWE \documentclass{book} \usepackage[demo]{graphicx} ...
2
votes
0answers
49 views

Defining and expanding macros In loops

I want to define and expand macros in a \foreach loop. The names of the macros depend on the iteration step. The macros I define are interpreted as strings rather than sets of numbers that I actually ...
4
votes
1answer
52 views

Patching a command with an optional argument or declared with \DeclareRobustCommand

To re-define a command to contain itself (patching in TeX parlance) you usually use \let. This answer by @egreg says: Never use \let on commands defined with \DeclareRobustCommand or commands ...
3
votes
1answer
49 views

Expanding code in etoolbox's \ifblank

I am trying to use the etoolbox \ifblank (and its cousin \notblank), but I want to expand any macros in its test statement. For example: \documentclass{article} \usepackage{etoolbox} ...
2
votes
1answer
60 views

Referring to delimiter separated arguments in new commands

Another question gave me hope that there is an elegant way (without using additional packages) to refer to a comma separated argument in \newcommand, maybe something like (just a guess, not tested): ...
1
vote
2answers
75 views

Define a section-like command with three parameters

I'm looking to define a section-like command for a CV document that takes three arguments: role, company, and time - like shown below. Because I lack the TeX experience I used the titlesec package but ...