17

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
4
  • 17
    This list looks rather poorly thought out to me. Some of these are LaTeX2.09 commands, which you really should not use, some may be better replaced by logical mark up (but this depends on the use case) and some are useful provided they are used only when needed.
    – Joseph Wright
    Nov 12, 2012 at 8:49
  • 1
    Oh, that list got pretty long when I was answering... Some of them look perfectly fine in many situations to me, like \tag for example.
    – T. Verron
    Nov 12, 2012 at 8:53
  • 1
    Maybe this answer by Will Robertson (and the corresponding question) helps?!
    – hakaze
    Nov 12, 2012 at 8:54
  • Erm - did you actually read the text? "Every use of one of these commands within a document is a failure to use proper logical LaTeX (you know who you are). Instead, think why you want the effect, and then code the logical reason, not the physical command." Nov 13, 2012 at 7:57

2 Answers 2

37

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

5
  • 1
    I don't entirely agree about \noindent: if you have a document such as an abstract, the first paragraph should not be indented but does not follow a \section or similar, so the only approach is to do it by hand.
    – Joseph Wright
    Nov 12, 2012 at 14:09
  • 1
    @JosephWright The considerations made are for longer and structured documents; for small documents manual intervention is perhaps the best strategy, unless one plans to use them later on in larger documents.
    – egreg
    Nov 12, 2012 at 14:15
  • I am not disagreeing with you, but how do you leave space for answers when you write an exam? I only know to use \vspace{\stretch{1}}
    – MaoYiyi
    Nov 13, 2012 at 2:21
  • @MaoYiyi I think it's the same as the "dedication" page: in a small document those considerations are not so important, because with a single look you control the whole document.
    – egreg
    Nov 13, 2012 at 7:26
  • @MaoYiyi : that would be a case where writing a macro \answerplaceholder taking as argument the height to keep would be a good idea : it's a macro you'd use several time in the same document, and probably through different documents as well, and it is a macro you might want to change later (add a box, add rules to show the number of expected lines, etc).
    – T. Verron
    Nov 13, 2012 at 11:15
13

These commands are usually disadvised because they do not go "the LaTeX way" : WYSIWYM (what you see is what you mean).

Authors are encouraged to use macros that are specific to the meaning of the content, instead of its aspect.

One easy (and classical) example : imagine you're writing a mathematical paper, and you decide to write your vectors in \mathbf style, as well as your operators (det, ker, etc). Now you realise you'd prefer using arrows over vectors and put the operators simply in roman style. You will have to go through a long process of search/replace to fix it.

Instead, you should have used definitions like these :

\newcommand{\vector}[1]{\mathbf{#1}}
\newcommand{\operator}[1]{\mathbf{#1}}

So that when you need to change the aspect of vectors and operators separately, all you have to do is change the respective command definitions.

Another relevant point for this matter is the readability of the code, but that really depends on whether someone else will be reading your code, and on your/their habbits.

Note also that there will always be some case where you won't have any other easy choice but to use low-level display hacks, some of which will be much dirtier than simply \textbf. As such, this advice should only be taken as such, not as a strongly-enforced rule.

8
  • Oh, that's what he means with physical ! I don't agree with the author and I still wouldn't go as far to put them in Banned LaTeX though.
    – percusse
    Nov 12, 2012 at 8:54
  • Wasn't WYSIWYM the Lyx style of doing it? Nov 12, 2012 at 8:54
  • Lyx is WYSIWYG (what you see is what you get) as far as I remember.
    – T. Verron
    Nov 12, 2012 at 8:55
  • 2
    In my humble opinion, LyX is WYSIWIG and very similar to Word. Remember that in Word, you can define good styles for everything to keep the logical structure and avoid using the B i u_ A+ A- buttons. LyX is doing exactly the same, allowing you both logical structure and direct font changes. The stress on meaning (instead of final appearance) is important in all Word, LyX and LaTeX, it is actually important everywhere.
    – yo'
    Nov 12, 2012 at 9:27
  • 4
    There is no “the TeX way”, go check the source of the TeX book (or most of Knuth TeX files), there are full of visual formatting (to the point of using \ \ \ to align some text). Nov 12, 2012 at 9:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .