Hacker News new | ask | show | jobs
by rrgok 821 days ago
I still wonder why anyone would create such awful grammar for a programming language. Considering LaTeX's initial release was 40 years ago, there were certainly other programming languages from which to draw inspiration.

And I certainly don't believe that LaTeX DSL was the most suitable solution for solving typesetting problems.

5 comments

LaTeX grammar makes much more sense when you spend some time using raw TeX with no macros at all - it's surprisingly capable on its own and the LaTeX becomes much more obviously "slight improvements".

Many things people think of as LaTeX are actually just TeX.

I would say that the TeX language was designed for the final user to add the "last mile", not for piling layers of macrosubstitution on top of something akin to lambda calculus. As amazing a feat of engineering LaTeX is, it has abused the TeX language beyond its natural limits. The price paid in complexity for abstraction was high. But the TeX language itself is a tiny elegant language.
LaTeX grammar is actually very good to type and quite powerful and compact. It's not a programming grammar, it's a markup language.

The problem with LaTeX was always the lack of underlying proper programming language and data model. The syntax always has been excellent.

The syntax is full of inconsistencies and it generally user-unfriendly: why is _ allowed only in math mode? Why can't macros have numbers in their names? Why does a simple thing like bolding text require a \textbf?

LaTeX is powerful and I use it every day, but let's not pretend it's got qualities it doesn't.

> why is _ allowed only in math mode?

Because it has different meaning in different context. It's a nice shorthand for subscript in math mode and you still need it as an underscore when you write code or normal text.

> Why can't macros have numbers in their names?

I give you that. That's due to underlying lack of proper programming language.

> Why does a simple thing like bolding text require a \textbf?

What else do you want there? The markdowns * has famously bitten me multiple times when it interfered with my multiplication in math (math + mathjax). Or when the bold needs to cover a full paragraph. I don't have a better suggestion. I'll be happy to hear another one.

Having studied a lot of the TeX source code and re-implemented portions of it, my theory is that it's the result of the TeX language evolving organically in a software development environment in which large scale refactoring is impossible. (Knuth didn't have source control, or unit tests, and the language he wrote TeX in has little-to-no support for meaningful abstractions. All of these make refactoring safely hard or impossible.) If you can't refactor, but still want to add a new feature, your only option is to implement things in a hacky way on top of existing features. This then bleeds into the TeX language itself.
I would say that the TeX language was designed for the final user to add the "last mile", not for piling layers of macrosubstitution on top of something akin to lambda calculus. As amazing a feat of engineering LaTeX is, it has abused the TeX language beyond its natural limits. The price paid in complexity for abstraction was high.