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

1
vote
1answer
36 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
203 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
81 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
70 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
32 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
151 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
57 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
75 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
103 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
44 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
111 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
70 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
76 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
521 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
120 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
69 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
73 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
42 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
524 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
188 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
129 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
107 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 ...
8
votes
4answers
553 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
75 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
40 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
44 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
35 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
54 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
83 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 ...
5
votes
2answers
143 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
191 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
34 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
39 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
18 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
47 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
28 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
45 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
201 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
78 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
45 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
98 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. ...
3
votes
1answer
66 views

Where to put \renewcommand in Beamer

This question is related to Setting default overlay specification for itemize environment. In the above-linked question, Werner provided a solution that uses \LetLtxMacro and \renewcommand. However, ...
6
votes
2answers
149 views

What can go wrong when using macros as arguments of other macros?

Thats a problem I encountered several times during the last weeks. I try to use macros as arguments of other macros, and it doesn't work. The most recent example: I try to use \addcontentsline to put ...
7
votes
4answers
201 views

Command which replaces a certain character of its argument

How to define a command which replaces every certain character in its argument with another certain character? For example, I'd like to define the command \myreplace{1-2-abc-345} which gives me the ...
5
votes
2answers
78 views

Using macros for including tikz graphics

I am not facing any problem, but I need the opinion of the community. I am writing a thesis and have a lot of tikz figures in it. So what I do is pre-compile these tikz files to PDF and then include ...
4
votes
1answer
35 views

How to see which package define a particular command/macro?

We often encounter multiple definitions of certain commands/macros. Then, we often get the error, e.g.: ! LaTeX Error: Command \P already defined. Or name \end... illegal, see p.192 of ...
5
votes
1answer
62 views

Redefine verbatim environment

I have a text with source code, which I would like to display. I am using pandoc, so I have to use either verbatim or listings enviroment. Unfortunately, I can't use listings package (due to ...
1
vote
1answer
80 views

How to make my sty file work only inside a environment?

Say for example, i have a bibpattern.sty which consists of some latex commands (like \COMMENT). I want this bibpattern.sty to work only inside \begin{thebibliography} ... \end{bibliography}. The same ...
2
votes
3answers
52 views

Legitimate “local variable” (argument) command in a macro raising “Undefined control sequence”?

Consider this MWE: \documentclass[varwidth,tightpage,border=1bp]{standalone} \usepackage{tikz} \begin{document} \begin{tikzpicture} \makeatletter \gdef\getMyInfoString{% \let\trfm\relax % ! ...