[Tex/LaTex] Why are these commands considered as bad practice

best practicesformattingmacros

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 verse)
  • \textbf or \bf (usually need \vec or sectioning like \paragraph)
  • \texttt or \tt (usually need a verbatim environment, or \url command)
  • \textit or \it (use \emph)
  • \textsf or \sf
  • \mathrm or \rm (usually need \operatorname{} or \text{})
  • \tag
  • \eqno
  • \dfrac
  • \displaystyle
  • \hspace
  • \vspace
  • \limits
  • \noindent
  • \newpage
  • \clearpage
  • \linebreak
  • \pagebreak

Best Answer

I beg to disagree with some of the opinions expressed in the linked page. The list of commands to avoid doesn't distinguish between commands to avoid at all costs and ones that should be used to define personal macros in the preamble, for instance; some of the commands listed do have their place in a document body.

Note The following should not be taken as "do so or you're wrong"; most of the recommendations make little sense for a short document where one look is sufficient to control it as a whole and where defining personal commands for just a single use would be a waste of time. For short documents only the first two sections are to be strictly followed.

Commands that must never be used

The two letter font changing commands such as \bf, \it, \tt or \sf must never be used in a document, either in the body or in the preamble. They have been obsolete since the introduction of LaTeX2e in 1992.

The trouble with \\

Somebody may remember Alfred Hitchcock's movie "The Trouble with Harry" where a dead body appears and causes any sort of troubles among a quiet small town in New England. Our \\ is quite similar.

The \\ command should very rarely mean "break a line" except in environments where line breaks are to be marked explicitly: flushleft, flushright, center, tabular, tabbing, align, gather, multline and derived ones. However, in some cases it can be used, but not for denoting an end of paragraph or to "leave a blank line".

The \noindent command is quite similar: I don't think to have used it in a document body other than in very particular situations involving explanations of TeX programming (such documents often require manual tweakings, but are the exception rather than the rule). If one needs \noindent once in a document, then there's something wrong with the way the document is being prepared.

Font changing commands

The "modern" font changing commands are to be considered as tools for building logical structures. For instance, \textit or \mathit (the difference is that the former respects spaces in the input because it switches to text mode) should be used for multiletter identifiers in math formulas. If our variable is called difference, then $difference=a-b$ is wrong, while $\mathit{difference}=a-b$ is right. However, it's much better to say, in the preamble

\newcommand{\mli}[1]{\mathit{#1}}
% macho programmer version
% \newcommand{\mli}{\mathit}

so that it can be redefined at will, if we change our mind about how to denote those variables: just modify the definition of \mli, which avoids hunting in the document for \mathit.

If we want a uniform appearance of symbols for number sets, it's better to say

\usepackage{amssymb} % or amsfonts
\newcommand{\numberset}[1]{\mathbb{#1}} % or \newcommand{\numberset}{\mathbb}
\newcommand{\N}{\numberset{N}}
\newcommand{\Z}{\numberset{Z}}
\newcommand{\Q}{\numberset{Q}}

so that changing the meaning of \numberset will modify all renderings of \N, \Z and \Q.

The same considerations hold for the other font changing commands: look for what appears to be a logical unit in your document and define a macro (or environment) for it.

An exception is \emph which already is a high level command: it means emphasize and it's left to the class (or to the user) how to implement emphasis.

Spacing commands

From a theoretical point of view, \hspace and \vspace have no place in the document body. However, an occasional construction may need them without bothering to define an environment for a single usage. For instance, if we want a dedication page, it's easy to say

\cleardoublepage
\thispagestyle{empty}

\vspace*{\stretch{1}}

\begin{flushleft}
\sffamily\slshape
To the masters in directing,\\
John Ford, John Ford and John Ford
\end{flushleft}

\vspace*{\stretch{2}}

\cleardoublepage

(I assume that the package emptypage is loaded or the class allows for specifying that blank pages automatically inserted are really blank) rather than defining a dedication environment to be used only once.

In the body of the document \medskip or \bigskip may be used, but also for them it would be better to define our personal spacing commands that use them, so that we can rely on uniformity of appearance.

Line and page breaking commands

One should avoid explicit line and page breaking commands, with the exception possibly for \cleardoublepage that's sometimes necessary when dealing with manually inserted hyperlinks.

In the final revision of a document it may be necessary to insert some \linebreak, \pagebreak or \clearpage command. The choice is between defining a personal command that can so be disabled in case a new edition is prepared or inserting them accompanied with a clear and univocal comment line. In both cases, the final TeX document shouldn't have trace of such commands that reveal to be obsolete in the new edition, so a search for them has to be made anyway.

The same considerations apply for \enlargethispage.

Math mode commands

While \limits in inline math formulas should not be used, it reveals useful after \int; if you have an integral over a domain rather than with bounds and the domain symbol is "large", saying \int\limits_{\partial A\int B} is surely better than setting the domain on the side.

I don't agree with the assertion that \dfrac and \displaystyle should not be used in the document body. This is false and there are many situations in which they are useful: complicated formulas must be built from smaller pieces and some of them may need particular treatment.

\tag and \eqno

While \eqno is not a LaTeX command and should not be used, \tag is surely something that can be employed. In many fields of mathematics, papers don't have numbered equations and only some of them need a reference. Many authors prefer not having numbers that would be difficult to find, but rather a symbol or word that can better identify a formula.

(Prof. A. J. Roberts does Mathematical Analysis, where numbered equations are the norm. It's common among analysts to think that what's done in their field is done in the same way elsewhere. Well, it isn't.)

Related Question