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

7
votes
1answer
107 views

Is there a switch to turn off LaTeX counters from inside a box?

I know that amsmath typesets at least twice its material, the first one for measurement and that it takes measures (sic) to avoid some counters being updated twice. Is there a switch a macro writer ...
3
votes
3answers
233 views

Problem with addition and macro argument

I need to use a formula like this: y = 1.8pt * x + 1.5pt inside a macro, where x is a scalar macro argument. My idea: \kern \advance #1\dimexpr1.8pt\relax by \dimexpr1.5pt\relax This doesn't ...
9
votes
1answer
960 views

Why does \vfill not work inside minipage?

Perhaps the answer is trivial, and I am facing the scenario as part of a larger macro. I faced a situation where I found that \vfill does not work inside minipage environment. The extracted code from ...
2
votes
0answers
76 views

Defining an abbreviation for `align` [duplicate]

To save myself some keystrokes, I tried to define an abbreviation for \begin{align} and \end{align} \documentclass[reqno, 11pt]{article} \usepackage{amsmath, amsfonts, mathtools, amsthm} ...
3
votes
0answers
38 views

Read single value from a table [duplicate]

I will use in many places in my LaTeX document a specific value given in, say, the row 2 and column 1 from a table. Is it possible to make a macro for it, such as \read{2}{1} ? Here is an simple ...
21
votes
5answers
407 views

How to define a command that surronds an argument with parenthesis if it contains a comma?

I have a very simple command in which one of the arguments can contain commas, in which case the output may not be easily readable since the text in which it is used may contain other commas, making ...
3
votes
2answers
111 views

Why linebreaks break the line height within certain environments with size-changing macros?

Why linebreaks break the line height within certain environments with size-changing macros? I'm trying to understand what's the difference between these three approaches: \newenvironment between {} ...
3
votes
1answer
87 views

How to create nested custom environment with different kind of frames?

So before I write ten pages describing what I'm looking to do, I made a small mock up: I had something like this in mind: \begin{mybox}[Name] \begin{syntax} here comes source code \end{syntax} ...
7
votes
3answers
212 views

Problem redefinning command{\<}?

I have a problem with redefine the command \< \documentclass{article} \renewcommand{\<}{\left\langle\!\left\langle} \renewcommand{\>}{\right\rangle\!\right\rangle} \begin{document} ...
2
votes
1answer
209 views

Alias for chapter with newcommand

I want some files to compile with two different templates, one that has the hierarchy like chapter > section > subsection and the other as section > subsection > subsubsection. For that, I tried to ...
8
votes
1answer
145 views

Undefined Macro in Package xstring

I have a very basic problem. I am trying to use the xstring package in a Latex document and I keep getting the following error message for an undefined control sequence: (c:/Program Files ...
2
votes
1answer
143 views

Macro to get character width in ConTeXt

Background Looking to adjust the location of the first letter in a word based on its width. Problem The calculation resembles: \define[1]\StyleChapterChar{% \cldcontext{string.sub("#1",1,1)}% } ...
7
votes
1answer
113 views

What is wrong with this macro-defining macro?

have this \newsetter macro that defines a "setter" macro (for lack of a better name) and a @-prefixed macro of the same name that holds the value. This is how is supposed to work: \newsetter\macro ...
6
votes
2answers
212 views

Delayed expression evaluation giving wrong result

I have made my own lists. I want to refer to them outside the lists. If I do a calculation using counters at a certain point in my list hierarchy, say \alph{listcounter}, how do I freeze that result ...
4
votes
2answers
214 views

Some misunderstanding about macro expansion

I have the following code which doesn't work: \documentclass[12pt]{article} \tracingcommands=2 \tracingmacros=2 \tracingall \makeatletter \let\sep\relax \def\put@stack@#1#2{\edef#2{#1\sep#2}} ...
4
votes
2answers
252 views

Redefining brackets

In my thesis I'm working with a lot of brackets around fractions and every time I have to use \left( \frac{a}{b} \right). It can get really confusing if i have a long equation and a lot of fractions. ...
4
votes
1answer
269 views

newcommand for foreign language

I started to learn russian, and I need to write russian in LaTeX. I am aware of the \foreignlanguage{russian}{text} function. But how do I make a new command, so I only need to type \rl{text}? ...
2
votes
0answers
90 views

Is there a way to partially evaluate TeX files? [duplicate]

I am looking for tools or techniques that can partially evaluate (e.g. inline definitions) a TeX source file into an equivalent, simplified TeX file with some parameters fixed. Specifically I would ...
1
vote
1answer
133 views

Script dialogues

I'm trying to write a script, and I have defined the following commands: \newcommand{\SpeechText}[1]{ \vbox{\ignorespaces{\quotation{#1}}\par\duplines} } \newcommand{\ParagraphText}[1]{ ...
4
votes
1answer
103 views

How can I influence the spacing of mathematical functions by an own macro?

I would like to get a macro \of to define a function with an optional macro \at to define its restriction. The reason is, that I don't like the spacing for functions (as there is no spacing) and I ...
4
votes
2answers
123 views

Keyword command parameters with table (tabular)

I am trying to make a command with named (key-value) parameters to produce a table row. The reason is that table has more than 9 columns (command parameters) that will have position changed, be ...
2
votes
1answer
71 views

I'm having trouble defining a new command

so what I want to do is make commands that makes mm, in regular font in my equations. So before \begin{document} I have put \newcommand{cm}{\text{cm}} and then it comes up as Latex Error: No ...
11
votes
2answers
195 views

How to create a macro “environmentally-dependent”

Yesterday I was reading the etoolbox documentation where there are defined some new document commands such as: \Before<Begin/End>Environment{<envir>}{<code>} % ...
7
votes
2answers
191 views

Expand LaTeX macros to modify

I am using the polynom package for polynomial long division. For example: \documentclass{article} \usepackage{polynom} \begin{document} \polylongdiv{x^3-x^2+d}{x-2} \end{document} Notice that I ...
12
votes
3answers
259 views

How to renewcommand in newcommand

I have a macro that I use to write units (so that I can write exponents easily), in math or in text mode. I would like to change the definition of \mu in \upmu (from the upgreek package) only in this ...
5
votes
2answers
256 views

How do I extract repeated functionality (exsheets workaround) to make it reusable?

Speaking with Clemens (exsheets maintainer) he pointed me to a workaround by Gonzalo Medina, that helps put verbatim and listings code in the exsheets pseudo (Clemens' word choice) question and ...
5
votes
1answer
197 views

How to use a macro inside tick definition in pgfplots

Consider the following code: \documentclass[border=2pt]{standalone} \usepackage{pgfplots} \newcommand\myxtick[1]{\foreach \x in {2,3,4}{\x,}#1} \newcommand\otherxtick{2,3,4,5} \begin{document} ...
1
vote
0answers
27 views

Name separators, if condition for same command [duplicate]

I am new to LaTeX, just a Beginner, Basically a perl developer, I have created a .tex file \begin{document} \cont{\iname{\isurname{Name1}\ifname{K. C. G.}}\iname{\isurname{Name11}\ifname{Y. ...
6
votes
2answers
140 views

Separators for author group (IF conditon)

I am new to LaTeX, just a beginner, basically a Perl developer. I have created a LaTeX file \begin{document} \cont{\iname{\isurname{Name1}\ifname{K. C. G.}}\iname{\isurname{Name11}\ifname{Y. ...
6
votes
1answer
151 views

Missing number needed to (re)define \hrulefill

The following code works but comes with three errors. Undefined control sequence, missing number, illegal unit of measure. It seems that the redefined \hrulefill is expecting a number to be input but ...
8
votes
4answers
138 views

Defining a command that accepts multiple but non-determined in total number of parameters

I have pretty regular and large descriptions in enumerated items. \begin{enumerate} \item Producers \begin{description} \item[ Vision: ] abc ... \item[ Contribution:] def ... ... ...
2
votes
2answers
227 views

Variable parameters in xcolor package

This doesn't work and I'm having trouble thinking of a minimum working example, but I'd like to do something like this where I have a parameter to a command as a variable: \usepackage{xcolor} ...
9
votes
3answers
230 views

Command doing the same job as StrBefore but being expandable

I am looking for a command allowing me to get 3 as output if the input is 3.2. \StrBefore{3.2}{.} works fine for this purpose but is not expandable and I need to call it in another macro inside a ...
6
votes
2answers
179 views

Use of a macro to set counter value in another macro

I am trying to simply set the value of the counter try which I defined previously to the value of the output of the \foo command. However this does not work. I guess that the problem is coming from ...
7
votes
2answers
132 views

LaTeX float controls - what is the denominator of the fraction macros?

I'm looking in Section C.9 of the LaTeX manual (pages 199 and 200). LaTeX defines a few macros to control the float placement algorithm, namely, \topfraction, \bottomfraction, and \textfraction. The ...
11
votes
2answers
280 views

“Well-formed” LaTeX?

Some "commands" in LaTeX are stand-alone. For example \documentclass{...} or \textemdash. Some others have closing "commands". For example, \begin{document} and \end{document}, or \begin{equation} ...
3
votes
1answer
81 views

Why does my new subsectioning heading not gobble the subsection title?

I hope I'm not missing anything obvious. Instead of trying to elaborate on my title, let me illustrate with an MWE: \documentclass[twocolumn]{article} \makeatletter \setcounter{secnumdepth}{4} ...
4
votes
0answers
52 views

How can a macro detect whether it is invoked in the beginning of a sentence? [duplicate]

I want to have a macro that behaves differently based on the context. Assume I write a tutorial in X language. A term that I use must be written in X language followed by the corresponding English ...
2
votes
1answer
156 views

Modifying \title without recursion problem

EDIT: Much shorter problem definition Having defined a title by \title[short]{long} how can I later add something to the title? The simple assumption \title[\insertshorttitle]{\inserttitle plus ...
6
votes
1answer
67 views

My attempt to local redefine a command is failing and not sure why

I want to decorate some text and then reprint it undecorated. This is the code that I was using to do this. \documentclass{article} \usepackage{xcolor} \makeatletter ...
5
votes
1answer
155 views

Any way to set a variable externally?

I just posted a question and can now generate a conditional section in a text: how to make a conditional document feature But to extend and generalize the question, first how could I create a ...
6
votes
2answers
187 views

how to make a conditional document feature

I saw in another question about how to create a condition, of which the best practice recommended was \iftoggle. I want to create a macro that will allow the creation of a teacher's note, a section ...
1
vote
1answer
48 views

about newcommand [duplicate]

I have trying to use new command to represent math, and this is what I type in: \\ \newcommand\fpi2[2][\pi][2]{frac{#1}{#2}}\\ \newcommand\mylim[2][x]{lim_{#1\to #2}} I'm trying to create a new ...
1
vote
2answers
107 views

Use the argument command itself instead of its argument in newcommand

I want to implement a macro, that uses the command passed in the first argument as the command itself, not as the content passed by evaluating it. Something like: \newcommand{\foo}{bar} % definition ...
10
votes
1answer
122 views

Hyphenate when using underscore as a letter

In many place in my current text I have to insert something like Name_of_model for instance. I found the last suggestion in this answer very helpful. However, I am facing a problem when it come to ...
3
votes
1answer
68 views

Table entry optimization

I am looking to get a better way of creating the following table: \documentclass{article} \usepackage[T1]{fontenc} \usepackage[latin9]{inputenc} ...
-2
votes
1answer
1k views

\newcommand in class - undefined control sequence

I'm trying to write a class based on article.cls and I'm having some trouble with \newcommand. Here go the complete files. Class file \NeedsTeXFormat{LaTeX2e}[1995/12/01] \ProvidesClass{NITclsD} ...
2
votes
1answer
5k views

Format section's title with \renewcommand

I have tried to make my sections appear as "Section I : My section's title" or "Section I My section's title" with the \renewcommand\thesection... command but in the table of contents the word ...
7
votes
2answers
190 views

Using an expanded macro for optional environment argument

I'd like to open an environment, passing the content of a macro to the optional arguments. Up to now I tried different approaches using \expandafter, however I could not get the expected behaviour. ...
15
votes
5answers
686 views

Test if the first character of a string is 'a'

Is there an easy way to make a macro returning a string (e.g. 'true') if the string input begins by some fixed character, say 'a' ? I can't figure how to combine the different packages to do this. ...