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.

I use LaTeX daily to write my papers, and while I find it a very nice tool to make documents in, some things about the system outright bother me; such as the very inconsistent macro system.

A few examples:

Many, but not all block macros/commands look like this:

\begin{lstlisting}
...
\end{lstlisting}

except for math blocks which look like this:

\[ ... \]

Inline macros usually look like this:

\footnote{...}

Except when they suddenly look like this:

{\em ...} % I'm aware that \emph{...} also exits

Or like this:

\lstinline|...|

Or even like this:

$ ... $

So why is it that LaTeX is so inconsistently designed? It seems that for every package I add, there's a new way of writing it, which makes the learning curve of LaTeX insanely steep, why not just keep it all consistent and uniform?

share|improve this question
21  
Instead of \[ and \] you can use \begin{displaymath} and \end{displaymath}. Instead of {\em ...} you can use \emph{...}. Instead of $...$ you can use \begin{math}...\end{math}. –  Heiko Oberdiek Jun 11 at 9:39
14  
The lack of uniformity in verbatim-like inline commands is a necessary feature: it allows you to determine the delimiter of the verbatim content yourself so you can use a delim that is not contained in the content. –  Bordaigorl Jun 11 at 9:41
5  
I think a bigger bigger disconnect can be felt by comparing packages/classes that offer a key-val interface and packages/classes that don't. An example: beamer vs moderncv –  Bordaigorl Jun 11 at 9:44
2  
@ElectricCoffee: The multitude of features of some commands needs varying interfaces –  Christian Hupfer Jun 11 at 9:45
4  
"So why is it that LaTeX is so inconsistently designed?" -- has it been designed? Arguably, a system that can rewrite its own lexer and has no (enforced/-able) standards and few conventions (as far as I can tell) can hardly be called "designed", as far as syntax goes. –  Raphael Jun 12 at 6:03

3 Answers 3

up vote 44 down vote accepted

One of the main aims of LaTeX is to give a consistent syntax over the wildly inconsistent syntax of the TeX primitives, so

\frac{a}{b} not {a \over b}

\makebox[3pt]{foo} not \hbox to 3pt{foo}

\begin{math} x \end{math} as an alias for $ x $

The distinction between environments and commands with arguments is slightly arbitrary but generally works reasonably well, using an environment body for large chunks of text. You see similar things in most document markup systems, e.g. the distinction between attributes and elements in HTML or XML <p> xxx </p> but href=....

Most two letter font commands (\bf etc) have been deprecated, partly for this reason since LaTeX2e was released. (\em is a bit different as noted in comments.)

Your other examples related to listings and verbatim, they necessarily have a different syntax, compare XML where the similar construct isn't an element or an attribute but <![CDATA[....]]>

share|improve this answer
1  
Erm, \em isn't deprecated (uniquely amongst the two-letter font change commands) –  Joseph Wright Jun 11 at 10:50
1  
@T.Verron \em isn't the same as \textit: it does the 'emphasis on and off' business for nesting correctly. Try {\em Some {\em text}} and contrast {\textit Some {\textit text}}. It's not just a command to make stuff italic. –  Joseph Wright Jun 11 at 11:53
7  
@T.Verron In addition to Joseph's comment, there's no alternative declaration to \em. (\bf should be replaced with \bfseries, \it should be replaced with \itshape, etc.) With emphasis, you only have a choice of the text-block command \emph{text} or the declaration \em. –  Nicola Talbot Jun 11 at 11:58
5  
@DavidCarlisle Yes, but that's because it's not actually a shape or anything: it's a flexible higher-level concept ('do something to make this stand out'). I'm not sure there is a better name than \em: it's just unfortunate that it looks like other two-letter commands. –  Joseph Wright Jun 11 at 12:06
2  
@T.Verron the symmetries within latex are there, but they're sometimes tricky to spot. not “higgs boson” tricky, but “study everything in enormous detail before trying to give an answer” tricky. believe me, a lot of the stuff described in these comments was simply “not there” before the advent of latex2e in 1994. –  wasteofspace Jun 11 at 12:47

In addition to David Carlisle's answer, I would quote the Zen of Python on this one:

Special cases aren't special enough to break the rules.
Although practicality beats purity.

As David pointed out, there are ways to write these commands in a standard style. But if I'm writing a paper, I don't want it to be littered with

Then substitute
\begin{math}
  x^2
\end{math}
for
\begin{math}
  y
\end{math}
in \ref{eq:foo}.

when

Then substitute $x^2$ for $y$ in \ref{eq:foo}.

would suffice.

This is one major case where practicality breaks purity. Sure, the first version is purer. But the purity is simply not worth it.

share|improve this answer
    
And we pay for it with often useless error messages -- extra/missing $ is a particular pain in the ass. –  Raphael Jun 12 at 6:07
5  
@Raphael — If you want (slightly) better error messages, use \(...\) instead of $...$. –  Will Robertson Jun 12 at 6:08
    
@WillRobertson: Yup, those enable more robust matching. Unfortunately, they are a pain to type -- there's a trade-off for you. –  Raphael Jun 12 at 6:13
1  
I would go as far as to say that if you care about purity that much to write a document in the first style, then go all the way and use XML as an input format. That has an additional advantage that you can easily verify that the input conforms to a schema –  Aditya Jun 12 at 14:52
1  
@David in practice yes, but \eqref is part of amsmath, so for MWE purposes I left it out. –  WChargin Jun 13 at 6:11

Without getting into a discussion about which syntax is how useful, reasonable and established, there is one fundamental reason.

(La)TeX does not have a (static) syntax. The lexer may be redefined at any point during interpretation, even by the end user (i.e. in document code).

That enables every package and document author to develop their own syntax, however clever or ill-advised. Come a few decades of (re)development, you are stuck with buckloads of (legacy) stuff, barely cobbled together by a few brave conventions.

share|improve this answer
    
After a while, one understands the syntax of LaTeX itself, and it even begins to make sense. However, you always need several packages to do what you want, and that's really when things get ugly. ConTeXt does a much better job in this respect, and usually needs no external packages. I committed myself to ConTeXt for a year, but gave it up because no one else in math/science uses it. LaTeX was amazing when it was new, and is still amazing today. It really needs an overhaul. But given the huge user base, a change in the "API" would be a difficult sell. –  garyp Jun 13 at 2:12

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.