1
vote
1answer
83 views

Dame latex macros

I am in the initial stages of writing my thesis (Maths). I once wrote a joint paper with someone and because they had an existing template we used it, with all the latex macros it had. Basically ...
4
votes
0answers
35 views

Is there a good reason to define helper macros second? [duplicate]

As a mathematician, my training is to define my terms before I use them. As a computer programmer, I recognize that there are sometimes good reasons to call a method/function/procedure before its full ...
54
votes
4answers
3k views

Defining custom commands is bad style?

I recently received this in a e-mail from my professor Good LaTeX style would preclude creating any of your own commands, counters, etc. (Most journals would reject submissions with user-defined ...
5
votes
1answer
148 views

“Flatten” macros prior to sharing LaTeX file

Is there a way/an existing tool to process a LaTeX source document such that for a given list of macro definitions (using \newcommand), calls to those macros are replaced by their expanded version? ...
6
votes
1answer
121 views

Why to use [T2A, T1] when [T2A] is enough?

I am writing some seminar in Cyrillic for university \documentclass[a4paper,14pt]{extarticle} \usepackage[T2A,T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage{droid} ...
7
votes
1answer
163 views

Gobble optional arguments

You can use \@gobble, for instance, to restrict the usage of a macro like: \documentclass{article} \makeatletter \newcommand*{\cmd}[1]{% #1 \global\let\cmd\@gobble } \makeatother \begin{document} ...
0
votes
0answers
40 views

Improve command definition to avoid possible break

The following defines my MWE: \documentclass{article} \usepackage{amsmath} \usepackage{totcount} \newcounter{totalpoints} \regtotcounter{totalpoints} \newcommand{\shcpoint}[1]{% ...
31
votes
2answers
379 views

What are the standards of TeX/LaTeX coding in order to obtain robust packages?

I have posted several questions ultimately involving various aspects of robustness, that have arisen in the context of other questions in risk of clouding the main point of the question in each case. ...
4
votes
2answers
186 views

Macro names with one single figure like \2, a bad practice?

I know that it is not recommended to use macros like \H0 since it contains non-letters characters. However, what about the macro names like \2 with only one figure, which are allowed without trouble ...
11
votes
2answers
266 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} ...
13
votes
1answer
195 views

What practices are there regarding the use or avoidance of “internal” TeX or LaTeX commands?

What practices are there regarding the use or avoidance of "internal" TeX or LaTeX commands? (About "command" vs "macro", there is some discussion in this TeX.SX answer, though I don't know whether ...
7
votes
2answers
208 views

Finding the depth of nesting in a macro call

Is there a general way to find the depth of a macro evaluation? For example, consider the following script, \documentclass{beamer} \usepackage{mathtools} \usepackage{calc} \begin{document} ...
16
votes
3answers
253 views

Defining Extensible macros

Question: For a macro that has only one parameter, are there any issues with defining it as follows: \NewDocumentCommand{\MyMacro}{% s% #1 = starred variant (*** unused as of yet ...
19
votes
2answers
350 views

Is it okay for a command to slurp more arguments than it is passed to?

Is it okay for a control sequence \foo to include another control sequence \slurp which slurps more arguments than \foo actually passes to it? For example, is it okay to do this: ...
13
votes
4answers
284 views

What are the consideration when choosing either newcommand or newenvironment?

The first time I learnt LaTeX, I thought \newcommand properly fits for inline mode and \newenvironment for displayed mode. Later I noticed it is not correct. So the question is What is the rule of ...
4
votes
2answers
137 views

Why can't I insert a blank line in this code?

In the code below, everything is OK until I insert a blank line instead of one of the \\'s. Upon inserting a blank line, I'll get some errors. How can I get rid of these errors? ...
14
votes
3answers
1k views

Macro for Declaring Variables in Class Files

I'm designing a new LaTeX class, and trying to write a convenient helper command for declaring new 'variables' for use in the class. Specifically, say I want to use a variable called \foo. I'd like ...
4
votes
0answers
63 views

Should I put the name of a new command in braces? [duplicate]

Possible Duplicate: Why do people use unnecessary braces? In so far as I know, the open and close braces around the command name for \newcommand{\commandname}{...} versus ...
13
votes
2answers
600 views

Why are these commands considered as bad practice?

I was reading LaTeX: Do not use these commands, but the author didn't explain why they are bad. Could anyone help me understand. \\ (except inside a special environment like tabular, array, or ...
4
votes
3answers
204 views

Shorthand for variables lead to name clash

In formulas I need often the same constants and variables with lot of "make-up". I want to have readable and maintainable LaTeX code, so I thought about writing \newcommands like ...
5
votes
1answer
698 views

Shortcut commands for referencing floats

I always include the following commands in the preamble of my latex documents to make sure I refer to floats consistently in the text. I was wondering if the community had any thoughts about this, is ...
11
votes
3answers
856 views

Reusing LaTeX code to achieve a consistent layout

What is the best approach to reusing the same layout for numerous tables, paragraphs etc. which share the same structure but different content? Is the best method to use custom commands/macros?
49
votes
3answers
1k views

Advantages and disadvantages of fully expandable macros

As I currently understand them, fully-expandable macros are analogous to pure/effect-free functions in functional programming. Correspondingly, things that are not expandable, such as \def, are ...
17
votes
1answer
696 views

How to write overlay-specification–aware macros that work w/o the beamer class

The LaTeX beamer class provides with \newcommand<> and \newenvironment<> an interface to define own commands that can deal with beamer's overlay specifications. Internally, commands ...
13
votes
2answers
742 views

Best practice to implement a boolean macro argument?

Sometimes I'd like a macro to depend on a boolean argument but I don't know about the best way to implement this. So far, I end up introducing a global (say) \newif\ifextra that is used inside the ...
3
votes
2answers
168 views

Sharing parameters between a command and an environment

(This question is related to Using \total of totcount package in section title) I'd like to keep track of the papers I review, and I have written a code (MWE shown below). The code keeps the count of ...
13
votes
2answers
749 views

LaTeX cookbook?

Has anyone written, or is anyone working on, a LaTeX cookbook? Specifically, a guide to writing intermediate/advanced LaTeX macros and solutions to other common tasks? I found a handful of resources ...
55
votes
4answers
12k views

When not to use \ensuremath for math macro?

I have gotten into the habit of using \ensuremath around math components in every macro that I define, so that I can use the same macro inside and outside of math mode. But egreg's comments in ...
11
votes
2answers
1k views

Is it safe to temporarily redefine \and, \or, and \not?

I'm writing lots of logic expressions in LaTeX and I'd much rather write $p \and \not q \or r$ than $p \land \lnot q \lor r$. I was thinking of doing something like this: \newenvironment{logic}{% ...
36
votes
2answers
1k views

List of higher-level LaTeX commands corresponding to TeX commands

Since LaTeX is a format built on top of TeX, it surely has several high level abstractions that perform similarly to TeX commands, with some added error-handling functionality, for example. I always ...
19
votes
2answers
463 views

How bad is slack \makeatother discipline really?

Following Will Robertson's admission that Fwiw, i'm not aware of any troubles with a missing \makeatother, but you're right. It's a bad habit of mine to omit it, and my own progressive slackness about ...
34
votes
8answers
2k views

Why do people use unnecessary braces?

I often see people creating new macros where the macro token is surrounded by braces. For example, \newcommand{\foo}{foo} This is unnecessary and I find the extra braces make it harder to read. Why ...