10

I am in constant search for an alternative to LaTeX, but it seems I am stuck for it for a long time, and I am trying to see the bright side of it.

The other day one thought struck me, I think, LaTeX is missing many reasonable defaults, especially math environment. For example, it is very unlikely that you have three variables named l, o and g at the same time, and you are writing product of those three variables in that order. But still you have to write \log to indicate you meant the function log(). In other words, when someone writes log, they (almost) always mean the log function.

Same is true for parentheses and braces, in math environment when one uses a parenthesis again they most probably mean a \left(. I know, I can introduce my own \( commands but again they are not by default.

Because I am using LaTeX mostly for math typesetting, I am only aware of those kind of non-defaults. My question is why are the things are not designed such that these most basic, fundamental things are not handled by default? I read that Knuth is considered math typesetting specialist, he should have noticed these burdens while he is using TeX in my opinion.

user202729
  • 7,143
nimcap
  • 5,135
  • 10
    In programming languages where the string log is interpreted as "the logarithmic function", you probably have to say l*o*g to denote the product of three variables. Generally ( should not be \left(; if you're used to this, you're on a wrong direction. – egreg Jan 25 '12 at 21:18
  • 34
    Why should TeX go through all the trouble to check if a character sequence like "l" "o" "g" correspond to some "default"? Do you know how much more complex this would make a compiler? TeX is from the early 80s where computer resources where limited. What's the big problem to add a simple \\ in front of it? I'm really sometimes shocked about the laziness of some modern computer users. – Martin Scharrer Jan 25 '12 at 21:19
  • 11
    @MartinScharrer: Totally agree with you about complexity, but I don't think it is laziness, just a normal frustration when one is learning things. It is natural to try to wonder why things don't just work as you would expect, and I think it is an important part of learning to try to understand why. – Peter Grill Jan 25 '12 at 21:30
  • 4
    This seems more like a rant than a genuine question. – DQdlM Jan 26 '12 at 01:20
  • 2
    Do you program? If so, you might be familiar with the computer's tendency to "do what I say" rather than "do what I mean". You're the one who has to be smart on behalf of your electronic slave. – Ryan Reich Jan 26 '12 at 04:57
  • 1
    @MartinScharrer: That tiny little \ introduces mental friction for me. When there are many of them the code looks far from elegant and hard to grasp at once. – nimcap Jan 26 '12 at 08:58
  • 3
    @Martin I disagree that a compiler shouldn’t make the effort to provide such a default if it were really meaningful. Math could conceivably be parsed this way (but yes, it would be way less efficient). But TeX’ way of consistently parsing math is simply superior. For instance, nimcap’s request is not good because it doesn’t scale and limits generality (two important design principles in computer languages, cf. Eric Lippert). – Konrad Rudolph Jan 26 '12 at 10:09
  • 9
    The TeX SE is a very friendly crowd, but you are likely to be treated as hostile when you frame your question argumentatively. If you're interested in why TeX's parser requires backslashes, that's a good question. But you've presumed that your feature request is "basic" and "fundamental" and so "reasonable" that it should already be implemented, and that puts everyone on the defensive. – Matthew Leingang Jan 26 '12 at 14:02
  • 3
    egreg, just out of curiosity, where do you really need ( more often than \left(? – Joey Jan 27 '12 at 08:21
  • 1
    @Joey: As is explained in this answer, there are more differences between ( and \left( than one might think. nimcap: See also this answer of mine which explains why automatic replacement of ( with \left( is not a good idea. – Hendrik Vogt Jun 23 '12 at 12:13

7 Answers7

51

Well, to answer your question. The behaviour is reasonable, because it is consistent. I use, besides \log, the functions \det, \tr, \tg, \inv, \abs, etc. If you made the "most-used" ones "backslash-less", then you don't know which ones have backslash and which don't. As well, some of us generate automated LaTeX codes and such exceptions would change our work to a true hell.

For parentheses, you get into serious troubles with things like [0,1[ for semi-open intervals, or even [0,1) for that.

Remember, LaTeX is good because it is consistent hence predictable, once you learn the basics.

yo'
  • 51,322
  • Word has no problem parsing [0, 1) the correct way, though you need a \right to get the same effect with [0, 1[. Still, an actual opening-closing pair is trivial (once you have Unicode, of course, which TeX didn't know anything about until recently). And you still need \operatorname{foo} for those that LaTeX doesn't have an own command. – Joey Jan 27 '12 at 08:19
  • 1
    @Joey \operatorname is not a good command for general use, better put \DeclareMathOperator{\foo}{foo} in the preamble. – yo' Jan 27 '12 at 16:30
  • @tohecz You are right when there is a symbol used several times; however, occasionally there is a unique occurrence and then I prefer \operatorname. Actually \DeclareMathOperator invokes \operatorname. – marczellm Jan 18 '13 at 21:33
17

When designing something for general purpose use it does not make sense to assume that you want log to be upright roman, as opposed to the default italics that are used in math mode. If that were the case, then someone else would need a method to specify the product of l, o, and g. There are also just way too many functions and new ones are added now and then.

It is more important to have defined rules and be consistent rather than having too many special cases. While you probably mean left( when you write (, probaably is not enough to assume that is what you mean. Again, this assumption would necessitate having to say something like \paren when one just wanted a regular (, and someone else would complain that why can't a ( just be a (.

Basically it comes down to specify what you really mean, so as to minimize confusion when TeX does its job.

Peter Grill
  • 223,288
17

Playing devil's advocate, the opposite could also be expected down the line: What if you actually had three variables l, o and g that you want separated and (La)TeX required you use use them as \separate{l}\separate{o}\separate{g}? Of course, I'm exaggerating the use of some "really special" function \separate. The same goes for not always wanting \left( when you type (, for whatever reason.

As such, nothing is assumed, giving the end user freedom over manipulation down to the highest detail.

The nath package is an example that might be in favour of your "assume some basic defaults" notion. As stated in the package description on CTAN,

[nath] delivers a particular context-dependent presentation on the basis of a rather coarse context-independent notation. Highlighted features [include]: depending on the context, the command \frac produces either built-up or case or solidus fractions, with parentheses added whenever required for preservation of the mathematical meaning; delimiters adapt their size to the material enclosed, rendering \left and \right almost obsolete.

So, it provides some "assumptions" in your mathematical use so you don't have to worry or think about it anymore. But it may not always be perfect, and what then?

Werner
  • 603,163
  • 3
    You could just use l o g, similar to what the eqn preprocessor for troff uses. – Aditya Jan 25 '12 at 21:20
  • 1
    btw: my two cents: I don't like the output of $$(\sum_{i=1}^n x^i)$$ and $$(\int\limits_{i=1}^n x^i)$$ with the nath package, I would prefer some horizontal space and a bit larger parentheses :-/ To get a professional output, you have to put a bit more effort to the code, and LaTeX is about being professional. – yo' Jan 25 '12 at 21:22
  • @Aditya: As mentioned, I used some exaggeration to illustrate the alternative viewpoint... – Werner Jan 25 '12 at 21:23
  • @tohecz: Agreed. I have not used nath since I prefer making my own decisions on delimiter (and other) usage, spacing, etc. – Werner Jan 25 '12 at 21:24
  • 3
    @tohecz: Nath goes to considerable efforts to make sure that the parenthesis are smaller. In \left\sum_{i=1}^n x^i \right), the parenthesis are too large and look ugly. – Aditya Jan 25 '12 at 21:26
  • Nobody should use \left( often, let alone always! Aditya's comment shows a reason why. – egreg Jan 25 '12 at 21:27
  • @egreg: I can't agree. You get good results in a lot of cases, as far as what I've met. – yo' Jan 25 '12 at 21:34
  • @Aditya: I know and of course I don't use \left with \sum and \int. I just wanted to say that making non-consistent "defaults" is a lot a matter of *ense of the typesetter, and not a matter of "good standards". – yo' Jan 25 '12 at 21:35
  • 1
    @tohecz See this answer, for example. – egreg Jan 25 '12 at 21:37
  • @egreg: ok guys, you've caught me, I wasn't aware of this solution to that problem. – yo' Jan 25 '12 at 21:46
14

With ConTeXt MkIV, you can use the calcmath module to use such shortcuts. For example:

\usemodule[calcmath]

\starttext                                                                 
\calcmath{log(x/(1+x))}
\stoptext

gives

enter image description here

Aditya
  • 62,301
10

In the initial TEXDR.AFT that Knuth wrote to describe the new system he was proposing, he did not use back slashes for “keywords”, but relied on them being “chosen so that match English words, since they can appear intermixed with normal text.” In the next draft, TEX.ONE slash was introduced as an escape character “to indicate control mode rather than text mode”, this change was not explained (though the next draft has a note to forget the first the first draft if you have seen it), presumably he found the idea of reserved keywords not so good, but at least we know he didn’t overlook it :)

  • 2
    In a language used for typesetting, reserved words should never appear as ones that a user would like to typeset; or one has to confine the "strings to be typeset" mostly like Postscript does. – egreg Jan 18 '13 at 22:49
  • 1
    +1, This is the only answer here that actually addresses the question historically. It is worth noting that Bell Labs's eqn (which predates TeX (the CACM article is dated June 1976) and which definitely had an influence in TeX's design) actually allows you to use such keywords like sup and sin without any backslashes. – ShreevatsaR Sep 13 '16 at 00:52
6

There are several good answers here already, but it's worth adding that some of Donald Knuth's thoughts on this are set out in an article that appeared in the Bulletin of the AMS in 1979.

Ian Thompson
  • 43,767
0

This can also be manually redefined with enough effort.

\documentclass{article}
\usepackage{amsmath}
\usepackage{luacode}
\begin{document}

\begin{luacode} cmdname_blacklist={relax=1, undefined_cs=1} function preprocessFormula(formula, before, after) tex.print(before .. ( formula:gsub('%a+', function(s) if #s>1 and not cmdname_blacklist[token.create(s).cmdname] then return '\'..s..' ' else return s end end)) .. after) end \end{luacode}

\makeatletter

\def@preprocessFormulaAdvanced#1#2#3{\directlua{preprocessFormula( "\luaescapestring{\unexpanded{#1}}", "\luaescapestring{\unexpanded{#2}}", "\luaescapestring{\unexpanded{#3}}" )}} \def@preprocessFormula#1{@preprocessFormulaAdvanced{#1}{}{}}

\NewCommandCopy\oldOpenBracket[ \NewCommandCopy\oldOpenParen( \def[#1]{\oldOpenBracket@preprocessFormula{#1}]} \def(#1){\oldOpenParen@preprocessFormula{#1})}

\ExplSyntaxOn \NewDocumentCommand \NewEnvironmentCopy {mm} { % https://tex.stackexchange.com/a/680717/250119 \expandafter \NewCommandCopy \csname#1\expandafter\endcsname \csname#2\endcsname \expandafter \NewCommandCopy \csname end#1\expandafter\endcsname \csname end#2\endcsname } \ExplSyntaxOff

\NewEnvironmentCopy{oldalign}{align} \RenewDocumentEnvironment{align}{b}{% @preprocessFormulaAdvanced{#1}% {\begin{oldalign}}% {\end{oldalign*}}% }{}

% redefine the dollar: https://tex.stackexchange.com/a/60395/250119 \catcode`$=\active \protected\def${@ifnextchar$@doubledollar@singledollar} \def@doubledollar$#1$${[#1]} \def@singledollar#1${(#1)}

\makeatother

\begin{align} sum_{x=1}^{10} x^2 &> int_{x=1}^9 x^2 , dx \end{align}

$a+b=b+a$

$$a-b ne b-a$$

[a-b ne b-a]

$sin x+cos y=tan theta$

$Pr[x=a wedge y=b]$

$undefined multiple characters$

\end{document}

Basically for each multi-letter word it checks whether the control sequence is "defined" and replace it with the control sequence.

output

For \left( ... \right) it's a bit more complicated to implement, but in theory it's also implementable, see https://tex.stackexchange.com/a/31529/250119 for an example.

user202729
  • 7,143