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

4
votes
2answers
78 views

new command using math mode sub index bug

I have defined the following command \newcommand{\gsubselector}[2]{$s_{#1,#2}$} and I'm calling it from a document in the following way: ... \gsubselector{a,i} : \gsubselector{b,j} there is ... ...
2
votes
1answer
120 views

Command to gray words

I would like to create a macro in LaTeX to have the following effect (gray parts) on some text: I would like to have something like \gray{Hello} which puts brackets and grays the text. Can someone ...
9
votes
3answers
196 views

Is it safe to “renewcommand” \SS? (Which packages use \SS command?)

I've tried to set \newcommand{\SS}{\mathcal{S}} in the preamble but I've discovered that this command is already defined. So, I tried native command on my code and I've found that it is a "simple" ...
7
votes
1answer
288 views

What generically CANNOT be compiled inside an equation environment?

Certain macros or whole environments which are themselves not equations, like whole tikz diagrams can be placed in the equation environment and compile. For example Diagram displayed as an equation ...
8
votes
0answers
119 views

How to pass a LaTeX argument verbatim to lua?

I would like to pass an argument verbatim from LaTeX to lua including LaTeX commands and end of line characters. The example below takes care of the former issue, but not of the latter. Is there a ...
4
votes
1answer
124 views

How to declare a macro with a variable argument list?

I am looking for a macro with two optional arguments and tried the following code: \documentclass{tufte-handout} % \usepackage{xparse} \usepackage{lipsum} \usepackage[demo]{graphics} ...
6
votes
1answer
168 views

Defining macros with arguments

With newcommand I can define customized command like \ABC. Is there any way to define a command with arguments. For example I want \brat{A}{B} be the same as [\![A,B]\!].
3
votes
1answer
98 views

How call several commands by one commands?

If you want to write an algorithm, you have to write three commands to initialize a writing environment. \usepackage{algorithm} \usepackage[noend]{algpseudocode} \begin{algorithm} % no.1 ...
1
vote
1answer
46 views

BibLaTeX' \citefield not expanded as expected

I have run into what looks like a macro expansion issue. Consider the following example: \documentclass{article} \usepackage{hyperref} \usepackage{biblatex} \begin{filecontents}{expprob.bib} ...
7
votes
2answers
213 views

How can I use Chinese characters (or more generally, Unicode characters) as a macro name?

\documentclass{article} \usepackage{CJKutf8} \usepackage{ruby} \renewcommand\rubysep{.05ex} \renewcommand\rubysize{0.2} \newcommand\神{\ruby{神}{かみ}} \begin{document} \begin{CJK}{UTF8}{min} \神 ...
4
votes
1answer
91 views

Command \color already defined

I have the following code in my latex command . \newcommand{\color}[1]{\lceil (#1+2)^2/2\rceil} After that I have inserted the following command for insertion of code in LATEX documents . ...
4
votes
2answers
81 views

Using set list with pgfplotstable

I am trying to create a new column in a table using the set list option, but it will not expand the list when stored in a macro. I've tried \expandafter in various locations with no joy so far. ...
2
votes
1answer
38 views

How to define macros for paths to be used by biber?

I want to use a shortcut to define the paths of my bibtex files and I'm using biblatex and biber. I would like something like: \addbibresource{\myPath{biblio.bib}} I tried in several ways i.e. ...
5
votes
2answers
113 views

General way to split a line by a rule of thumb and displaying results

The following is to construct illustrations for concepts of frequency of a properly sampled outcome if any such frequency exists. Doing such illustrations is tedious and liable to error by hand ... so ...
5
votes
3answers
154 views

Trim braces from macro content

I'm having macros with a content which may or may not have extra curly braces. I want to trim the extra braces but without expanding the rest of the content, if possible. The following code shows the ...
0
votes
1answer
72 views

Mathjax can't render some of LaTeX basic commands [closed]

Sorry this is probably a very silly question as I'm too new to LaTeX. Mathjax has issues rendering basic LaTeX commands like /xspace and /ensuremath There are some custom macros in my LaTeX files, ...
8
votes
1answer
82 views

TeX-FAQ: Non-letters in macro names - special-command generator

I had a look at TeX-FAQ on Non-letters in macro names and tried to implement the approach #2. It looks like I'm missing something. When trying to refer later to the new commands the result is not what ...
5
votes
2answers
113 views

How to allow # in \newcommand without \# or another way to defer processing of section of code

I am trying to defer processing of some latex code. This works, \documentclass[a4paper,final,11pt]{article} \usepackage{hyperref} \begin{document} here comes a reference ...
4
votes
1answer
45 views

How do you define a command to select nested groups?

Assuming a pair structure (2-tuple) is defined using groups {{<tokens1>}{<tokens2>}} is it possible to define a command \first#1{...} (and \last#1{...}) taking the surrounding group as ...
2
votes
1answer
138 views

Why is newcommand not working?

I am quite new to latex and try to understand the \newcommand command. Since (at least in texmaker which I am using) \autocite does not seem to feature autocompletion and automated display of my ...
5
votes
1answer
72 views

What's special about \: in the implementation of \pgfutil@ifnextchar

There is the following snippet of code in pgfutil-common.tex (with a very similar snippet in pgfmathutil.code.tex`): {% \def\:{\global\let\pgfutil@sptoken= } \: \def\:{\pgfutil@xifnch} ...
5
votes
1answer
82 views

How does \path, and the like, parse its argument?

I'm really curious whether someone would care to take the time to explain how to create macros which work similar to some of the macros in the pgf/TiKz bundle. What I'm particularly interested in is ...
7
votes
3answers
532 views

Defining 3*(2^4) complex macro at once

An Automata can be 1- or 2- ways, With Several Heads or a Single head Deterministic or Non-deterministic With a stack or not That makes 2^4 = 16 possibilities. However, for each combination, I'd ...
3
votes
2answers
133 views

How do you define one macro with arguments inside another

How do I define a \newcommand (or in LaTeX 3 a \NewDocumentCommand) which itself defines a \newcommand with arguments. For example in \documentclass{article} \begin{document} \newcommand{\test}[1] { ...
2
votes
1answer
78 views

How do you define a command for use in a tikzpicture environment?

I want to define an environment for the tikzpicture environment which defines tikz specific commands. Here's an abbreviated example for a UML environment which defines a \Class command): ...
4
votes
1answer
87 views

Using \newcommand works fine in LaTeX, but when I use htlatex the line of text that \newcommand was supposed to insert gets moved to the next line?

So, I'm trying to write lines of code explaining to new students where to find different files and directories. Because the classname changes on a yearly basis I set up a \newcommand to make changing ...
1
vote
1answer
45 views

ifthenelse to ignore a section

I am writing a textbook which has a student version and a teacher version. I did this: \newboolean{teach} \setboolean{teach}{true} ...
8
votes
3answers
530 views

Without any built-in looping macro, can we just use a recursive macro to get a-b-c-d-e?

Without any built-in looping macro, can we just use a recursive macro to get an output of a-b-c-d-e? \def\aaa #1{#1-\aaa} \aaa abcde % expected result : a-b-c-d-e \bye Edit: Probably the best way ...
15
votes
1answer
200 views

\def two macros with same name, but different argument syntax

Is it possible to have macros with the same name, but different “syntax”? E.g. we have the primitive \font which could be seen as having 3 arguments(a. without size information; b. giving the ...
5
votes
1answer
157 views

Defining a LaTeX macro with optional arguments as keywords inside square brackets

I want to define a macro to insert pictures in figures, called \centeredfigure, which I am hoping to use the same way as \includegraphics. In \includegraphics, all optional arguments are given in the ...
8
votes
2answers
109 views

How to use \edef to wrap an existing macro with @inmatherr?

I have a handful of existing macros that I want to wrap in some custom processing. Here's an example of the kind of thing I'm aiming to do: \makeatletter \let\olddag\textdagger ...
9
votes
4answers
575 views

How can I create lambda expressions?

It's common for packages to accept one- or two-argument macros as transformations of some element, and it's at least common for me for these to be one-offs that don't deserve a permanent name—or at ...
5
votes
1answer
94 views

newcommand about array

$ \left\{ \begin{array}{l} a+b=c\\ c+d=e \end{array} \right. $ I define a macro command for it. \newcommand{\curleq}[2]{\left\{\begin{array}{#1}{#2}\end{array}\right.} When I type ...
1
vote
0answers
48 views

indexing with sed using less brittle \gls and \acs and \index commands

I'm writing a book for which I produce sections for glossaries, acronyms and index entries using the glossaries, acronym and makeidx packages on a template derived from the Springer book template. To ...
0
votes
0answers
51 views

How to create another styling format like \emph

I read how to change \emph and changed it to \DeclareTextFontCommand{\emph}{\bfseries}. Now I want to create another command like \secondstyleformat which I can configure aswell. Such a format could ...
1
vote
0answers
36 views

Bind command to command output

How can I bind the command to the output of another command, determined at the time the command is bound? For example with the following code, \newcommand{\hello}{foo} \newcommand{\world}{\hello} ...
2
votes
1answer
64 views

Unwanted vertical space/glue between consecutive custom \section macro calls

I am using XeTeX. I need to redefine the \section and \subsection commands in order to use some macros which don't behave well with the titlesec and/or sectsty packages. I found some code to do ...
3
votes
1answer
87 views

How to make a list of used custom macros

I used to have a separate file where I store my custom macros. It is nothing more than a huge list of \newcommands and \NewDocumentCommands. Now, I have a little note that I would like to share with ...
6
votes
2answers
154 views

Define a New Macro via a Macro Using xparse Syntax

I am trying to set up a macro that defines a macro that is to be executed only once. With what I learned from Define a Macro via Macro if Given Macro is not defined I can do that via the ...
8
votes
1answer
204 views

Understanding token expansion

First of all, note that this question is to be regarded as a learning question as I am not looking for a package (I know very well the xparse package). I am attempting to write a macro which has the ...
1
vote
0answers
37 views

using macro to identify “line breaks” as properties separator, “:” colon as properties name separator, and “-” hyphen as description

Here I have created document as per requirement. But I need to use macro in specific way. Here is my document : ...
3
votes
1answer
50 views

Change figure caption name in “thesis” document

Does anyone have an idea why this approach to changing figure naming doesn't work in thesis type document? I'm using babel and all other captions translate normally, except "Figure", which stays at ...
0
votes
1answer
24 views

\newcommand to create a command with optional arguments

In Latex, I always use \mathbb{something0}_{something1}^{something2}, wheres sometimes 'something1' or 'something2' can be empty. So I had the idea to create a newcommand using the \newcommand. So I ...
3
votes
1answer
54 views

Variable scoping of edef definitions in a local group (inside an ifx conditional)?

Consider this MWE: \documentclass{article} \def\testswitch#1{ \def\isA{A} \def\firstOpt{#1} \edef\tmpstr{-init-} { % start local \edef\tmpstr{-loc defined-} } % end local ...
1
vote
0answers
33 views

Redefine \question command in exam class to wrap in an environment

I'd like to redefine the question command from the exam class to wrap each question in a new environment. That's the general description. What I'm trying to do is take a document that is written as an ...
1
vote
1answer
47 views

A dynamic variable as content of a glossary entry

Based on the macro defined here, I would like to use it to create a glossary with a variable in the description. Here is my MWE: \documentclass{article} \usepackage[utf8]{inputenc} ...
8
votes
2answers
233 views

Defining a variable inside an environment, but use it outside

How can I use a variable beyond the environment where it has been set? Following the MWE given below, how can I print the variable it both places (inside and outside the environment) ? ...
5
votes
1answer
91 views

Renew command on mbox makes it freeze - Fix subscript size

I'm trying to change the font style of \mbox, but all my tries have failed. All commands I try either have no effect or make pdflatex recursively keep working and never finish and freeze. This makes ...
3
votes
1answer
53 views

Defining a dynamic variable

Goal : I would like to create a variable that could be dynamically updated. Context : Every chapter of my document has a specific keyword (actually a bibtex entry). And sometimes, I need to print ...
6
votes
1answer
112 views

Macro, new command or new environment for code?

I am using the listings package to typeset code. I have defined a custom style using \lstdefinestyle{verbo} and then typeset code in a lstlisting environment as in the following MWE. ...