Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

So LaTeX has a lot of commands that do very similar things. Often this is a result of some of these being old.

For example: $x^2$ vs \(^2\); As I understand it, the second example is the more modern version and should be used when possible.

Other examples: \it vs the more modern \itshape and the one I'm actually supposed to use \textit{}

I've heard enough mention of these that I think I know which one I'm supposed to use; however, there are also things like \begin{center} vs \centering where it is contextual (Due to vertical spacing)

These are examples I picked off the top of my head; $$...$$ vs \[...\] vs \begin{equation}...\end{equation} is another one that someone mentioned below.

Is there an easy way to tell which command I'm supposed to use when? For stuff from packages, it is usually easy to look at the manuals and see which is more up to date, but what about core LaTeX stuff? Is there a list of when to use various versions of commands? Or better yet, a general rule of thumb so I can tell if I should be learning a new way to do things?

share|improve this question
2  
nag package seems useful to address some concerns –  cmhughes Dec 17 '13 at 22:55
2  
Browse {best-practices}? ;) –  doncherry Dec 17 '13 at 22:55
1  
    
I am not sure this is a duplicate. The OP is not asking which practice is best, but how we decide that it is. I would tend to agree with @David – you don't, because it depends on what you want to achieve. When some "old" commands have inner workings that work better for your purposes, why not use them? –  ienissei Dec 17 '13 at 23:04
    
Also texdef script to track out definition of (LA)TEX commands and latex command reference texdoc latex2e with fixltx2e –  texenthusiast Dec 17 '13 at 23:09
show 3 more comments

4 Answers

up vote 17 down vote accepted
  1. $...$ is mentioned in the LaTeX manual as a ‘shorthand’ for \(...\). We know that it's not really so, but the manual doesn't go into the details of TeX programming, so this is a good approximation to the truth, for the purposes of the manual, which recommends $...$ for very short formulas, recommending \(...\) for longer ones.

  2. Commands such as \it and \bf have been formally declared obsolete. So they shouldn't be used. End of the story.

  3. $$...$$ is not mentioned in the manual and we know it's wrong to use it in LaTeX for various good reasons.

  4. Several commands have a ‘double’ form, but this is not really true. There is a noticeable difference between

    Your {\itshape hovercraft} is full of eels
    

    and

    Your \textit{hovercraft} is full of eels
    

    but this doesn't mean \itshape shouldn't be used. Its better place is in definition of environments, say

    \newenvironment{iquote}{\begin{quote}\itshape}{\end{quote}}
    

    that defines the iquote environment which typeset a quote in italics. Using \textit would be wrong here.

  5. There are some pairs: \raggedright and flushleft, \raggedleft and flushright, \centering and center. This is similar to the distinction between font switch and font command discussed above. The ‘switch’ form, say \centering, is better used for defining environments, since center also leaves some space above and below the centered text; the same for flushleft and flushright. Note that all switches here need an explicit paragraph termination at the end, be it given by \par or by an \end{...} command that provides it, for instance \end{quote}. So, if you need ragged right quotes, you can define

    \newenvironment{rquote}{\begin{quote}\raggedright}{\end{quote}}
    
  6. \[...\] is equivalent to \begin{displaymath}...\end{displaymath} but very different from \begin{equation}...\end{equation}, because the latter also adds a number to the equation. There's a reason why amsmath defines the equation* environment: it's easier to change an equation from equation to equation* (or conversely) than from equation to displaymath.

  7. Some constructions that one finds in LaTeX documents are actually foreign. Examples are \centerline, \llap, \hbox. A savvy (or macho) LaTeX programmer can profit from them, but it's better to stick with LaTeX's corresponding commands

    \makebox[\columnwidth]{...}
    \makebox[0pt][r]{...}
    \mbox{...}
    

    in a LaTeX document, reserving the lower level commands for packages and using them when one knows what they do, which is not intuitive.

An example. Just a few hours ago I answered a question originating from a strange behavior of a macro a user found on the net. The proposed code used mysterious parameters such as \hoffset; the code I suggested uses normal LaTeX commands, with the exception of \bgroup, \egroup and \dimexpr (these are always in the toolbox of a LaTeX programmer). The difference is between non working and working code. ;-).

share|improve this answer
    
Wait, hbox is a weird one? I see that used all the time... –  Canageek Dec 18 '13 at 0:09
    
So how do to tell which are lower level commands and which I should be using? –  Canageek Dec 18 '13 at 0:10
    
@Canageek Refer to “official” documentation: the manual and the package documentations. –  egreg Dec 18 '13 at 0:16
add comment

The answer is "you don't" but unfortunately the site won't allow short and to the point answers, so a more discursive one...

For example: $x^2$ vs \(^2\); As I understand it, the second example is the more modern version and should be used when possible.

Well not really more modern; \( has been in LaTeX from the start, although $ is a TeX primitive so in a sense is older. \( is intended to give better error diagnostics as the system can tell that \(zzz\( doesn't match up whereas if you miss out a $ things just go out of parity with intended math start becoming math close, and you get weird errors. Unfortunately the standard definition of \( is fragile whereas $ is robust so if you use it in say \caption you get very weird errors. So it's an example of an error detecting mechanism that has generated more errors than it detected. The fixltx2e package makes \( robust, but if people know enough to use that package they don't make so many simple math mode delimiter errors anyway...

Other examples: \it vs the more modern \itshape and the one I'm actually supposed to use \textit{}

There you don't necessarily have a choice, \it is simply not defined in the LaTeX2e format. article and some other classes define

\DeclareOldFontCommand{\bf}{\normalfont\bfseries}{\mathbf}

so you can pretend it's the 1980's again

I've heard enough mention of these that I think I know which one I'm supposed to use; however, there are also things like \begin{center} vs \centering

These do different things: \begin{center} uses \centering internally to do the centering, but it is also a latex display environment (a list) so sets the content off with vertical space. So it depends if you just want to centre something or if you want to make a centred display.

share|improve this answer
    
So I'm hearing there is no rule of thumb to tell if I should be looking on TeX.SX to see if there is a newer version of that command? –  Canageek Dec 17 '13 at 23:24
    
@Canageek There's always a newer version, it doesn't definitely mean it's better or that you you use it. Tikz is newer than pstricks which is newer than the picture environment in latex, but the last of those still have advantages in terms of portability and speed (if not raw power:-) similarly xcolor and enumitem are newer than color and enumerate, but I know the older ones better. –  David Carlisle Dec 17 '13 at 23:54
add comment

In short:

For example: $x^2$ vs (^2); As I understand it, the second example is the more modern version and should be used when possible.

Rather not. The first is safer. But in the case of \[ \] and $$ $$ the first is preferrred.

Other examples: \it vs the more modern \itshape and the one I'm actually supposed to use \textit{}

\textit also makes proper italic correction.

I've heard enough mention of these that I think I know which one I'm supposed to use; however, there are also things like \begin{center} vs \centering

\begin{center} adds additional vertical spacing, \centering - not.

share|improve this answer
    
So I'm hearing there is no rule of thumb to tell if I should be looking on TeX.SX to see if there is a newer version of that command? –  Canageek Dec 17 '13 at 23:25
    
@Canageek If you want information about new version, than rather in documentation of new distributions or on CTAN. But if you want to show your experiments here, near surely you may expect constructive comments. –  Przemysław Scherwentke Dec 18 '13 at 0:53
add comment

For this kind of questions, you can refer to the "An essential guide to LATEX2ε usage" which discusses obsolete commands and packages. Versions of other languages can also be found on CTAN.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.