[HN Gopher] Is there a BNF grammar of the TeX language? (2010)
       ___________________________________________________________________
        
       Is there a BNF grammar of the TeX language? (2010)
        
       Author : nequo
       Score  : 53 points
       Date   : 2024-06-06 22:08 UTC (3 days ago)
        
 (HTM) web link (tex.stackexchange.com)
 (TXT) w3m dump (tex.stackexchange.com)
        
       | ginko wrote:
       | No wonder Knuth hasn't gotten around to writing the parsing
       | chapter of TAOCP.
        
       | choeger wrote:
       | It's a shame that TeX the great typesetting system comes with TeX
       | the ungodly complex language. There's literally no chance to
       | create good tooling for TeX because of this. There's very little
       | chance to optimize rendering of large documents because of it
       | (e.g., by automatic parallelization). Finally, there's never
       | going to be a readable error message from TeX.
       | 
       | TeX the language is the prime example of gatekeeping.
       | 
       | OTOH, no one has ever succeeded in creating and popularizing a
       | context-free language that compiles to TeX.
        
         | SassyBird wrote:
         | _> Finally, there 's never going to be a readable error message
         | from LaTeX._
         | 
         | FTFY. If you learn TeX from Knuth's TeX book, along with the
         | typographical concepts it works with, the error messages
         | generated by documents written in raw TeX are understandable.
         | 
         | LaTeX on the other hand is what the metaprogramming-heavy
         | Boost/STL libraries are to C or C++. Abandon all hope.
        
           | breck wrote:
           | > If you learn TeX from Knuth's TeX book
           | 
           | https://visualmatheditor.equatheque.net/doc/texbook.pdf
           | 
           | +1 on this.
           | 
           | That book is fantastic, one of my favorites. It's been a
           | couple of years since I last read it, and your comment
           | reminded me that I should probably skim again.
        
             | WillAdams wrote:
             | Except that PDF shouldn't exist since it was generated in
             | flagrant disregard for the copyright/comment:
             | % This manual is copyright (C) 1984 by the American
             | Mathematical Society.         % All rights are reserved!
             | % The file is distributed only for people to see its
             | examples of TeX input,         % not for use in the
             | preparation of books like The TeXbook.         % Permission
             | for any other use of this file must be obtained in writing
             | % from the copyright holder and also from the publisher
             | (Addison-Wesley).         \loop\iftrue
             | \errmessage{This manual is copyrighted and should not be
             | TeXed}\repeat
             | 
             | If you want a free PDF on TeX try _TeX for the Impatient_:
             | 
             | https://tug.ctan.org/info/impatient/book.pdf
             | 
             | If you want a copy of _The TeXbook_, buy it.
        
               | wrs wrote:
               | I love the subtle humor in misusing "copyright" as a verb
               | and then misusing "TeX" the same way.
        
           | dunham wrote:
           | Yeah, I always used plain TeX back in the day because I could
           | understand it. LaTeX always seemed unnecessarily complex.
        
         | dhosek wrote:
         | One of the things I decided to do with finl was to formalize on
         | LaTeX's syntax. No more shifting category codes, Separating out
         | the lexer definition of commands from their meaning also means
         | that tooling becomes simpler. Throw in proper variables so
         | there's no longer the need for redefining macros to emulate
         | variables and it becomes a little more tractable.
         | 
         | That said, even with these restrictions, writing a good
         | lexer/parser of a LaTeX-like syntax is still a challenge (and
         | made all the slower by the needs to earn money, spend time with
         | my kids and have other joys in life).
        
         | breck wrote:
         | > It's a shame that TeX the great typesetting system comes with
         | TeX the ungodly complex language
         | 
         | You hit the nail on the head. Brilliant design of the
         | typesetting system, not an ergonomic language.
         | 
         | I think over the next few years Scroll (https://scroll.pub/)
         | will become the language all academics use to publish
         | papers.(Or another markdown like alternative, but ours will be
         | _very_, _very_ good)
         | 
         | You are always in an ergonomic, simple, fun, forgiving high
         | level language (Scroll), but then you can dip down into TeX
         | whenever you want for its beautiful 2D math rendering (thanks
         | to KaTeX library).
         | 
         | We don't have great automatic whole document PDF generation yet
         | (you still have to manually save as PDF from your web browser),
         | but we will get there.
         | 
         | If anyone really wants this please shoot me an email--fun to
         | get more passionate beta users that can help us steer
         | priorities and build something free and great for paper writers
         | all across the globe.
        
           | me_vinayakakv wrote:
           | Typst[1] is another tool which implements document generation
           | from the ground up.
           | 
           | Zerodha had a great article [2] how they migrated from LaTeX
           | based pdf generation to Typst, which ended up saving time and
           | compute.
           | 
           | [1]: https://typst.app/ [2]:
           | https://zerodha.tech/blog/1-5-million-pdfs-in-25-minutes/
        
         | jjmarr wrote:
         | People say TeX doesn't have good tooling but I can't think of
         | any other language where I can seamlessly intermix circuit
         | diagrams with equations and plots. It's really nice to be able
         | to draw on an axis coordinate system (pgfplots with TikZ), as
         | an example.
         | 
         | The language itself is horrible and the skill floor is too high
         | but the Turing completeness enables a ton of wacky features
         | that would never be allowed in something like Mathematica.
        
           | g15jv2dp wrote:
           | I think you're misunderstanding what "tooling" means here.
           | Even determining what line (or even file!) in your document
           | is the source of an error or warning is sometimes a
           | nightmare.
        
         | omoikane wrote:
         | I don't think a language is complex just because it's not
         | context free, since any language that supports syntactic macros
         | of some sort are not context free. Neither M4 nor C++ are
         | context free, but C++ is usually considered more complex than
         | M4.
         | 
         | Still, multiple parsers and great tooling exist for C++, and
         | the error messages have gotten much better in recent years.
         | This is probably because companies needed them for different
         | reasons, and they have the resources to build alternatives.
        
         | graycat wrote:
         | > TeX the ungodly complex language
         | 
         | A friend, although he is a good mathematician, kept criticizing
         | TeX, so I explained one view of it: TeX was not intended to be
         | some new big steps forward in interactive user interface, to
         | replace Microsoft's Word, HTML or Mathematica, or for making
         | images or movies. Instead, TeX was, first, for something he
         | knew well -- the journal of the AMS (American Mathematical
         | Society). For doing the word processing for the AMS, TeX was a
         | nice step forward from what went before.
         | 
         | TeX seems fine to me, just the way it is. Started with Knuth's
         | book and also got his file of TeX _source_ his book. The book
         | is easier to read, but with my favorite text editor KEDIT
         | sometimes the file is easier to search.
         | 
         | Also with the TeX software have the Windows program to display
         | the formatted output on a screen and the program to write the
         | output to a PDF file. Both work fine.
         | 
         | It appears that Knuth made commendable efforts to get any bugs
         | out of TeX.
         | 
         | Wrote some macros for TeX: The main collection has, just
         | checked, 86 macros. Also have macros for some special purposes,
         | e.g., foils, inserting images, _verbatim_ , business cards,
         | etc.
         | 
         | Use TeX for business letters; used TeX for the last paper I
         | published: The paper had a lot of tricky math notation, and TeX
         | handled that well. The journal seemed quite pleased to get the
         | TeX input with my macros; then they were able to format the
         | paper right away.
         | 
         | When rusty with TeX, my old papers, letters, etc. and macro
         | collections get me productive again quickly.
         | 
         | Since I like TeX so much and since the _philosophy_ of LaTeX
         | seems different, never used LaTeX.
         | 
         | Knuth's book shows that it's possible to write _long_ documents
         | with TeX.
        
       | twoodfin wrote:
       | If you were willing to live with a Turing-complete grammar in a
       | general purpose language, I wonder how it would ideally work and
       | what you'd be able to gain in trade.
       | 
       | Sort of a supercharged version of Lisp reader macros.
        
         | samatman wrote:
         | We already have that: Forth.
         | 
         | The above sentence can be a Forth program. This? Another Forth
         | program.
         | 
         | What does my post do? Run it to find out!
         | 
         | > OK
        
           | MaxBarraclough wrote:
           | I'm a Forth dabbler too, but its opposite number in the Lisp
           | world also deserves a mention: _Racket_. Like Forth, Racket
           | can be extended to describe languages radically different
           | from the  'starting point' language.
           | 
           | https://en.wikipedia.org/wiki/Racket_(programming_language)#.
           | ..
        
       | wslh wrote:
       | If it would be LaTeX, tree-sitter includes a paraer for it [1].
       | Not BNF though.
       | 
       | [1] https://tree-sitter.github.io/tree-sitter/
        
       | thiagoharry wrote:
       | METAFONT is another macro language where everything is context
       | sensitive because macros redefine everything. But METAFONT has a
       | BNF grammar that describes the language after the macro
       | expansion. Perhaps the problem with TeX are the catcodes, that
       | redefine at runtime how every future token is interpreted even
       | after macro expansion?
        
       | tylerneylon wrote:
       | I'm a fan of most of what Knuth has done, and in particular I
       | love the high quality _output_ of the TeX family. But TeX's
       | language is extremely difficult to use. I suspect this is true
       | for any macro-expansion-like language.
       | 
       | If you like deep dives, I suggest two follow-up tools for
       | mathematical typesetting:
       | 
       | 1. LuaTeX, which is TeX + Lua scripting support. (luatex.org) An
       | example:
       | 
       | https://tex.stackexchange.com/questions/70/what-is-a-simple-...
       | 
       | This has become my default, and I enjoy it. (I use lualatex.)
       | 
       | 2. A friend of mine was inspired to write a modern macOS app for
       | math typesetting. It's called MadHat:
       | 
       | https://madhat.design/
       | 
       | One of the coolest features is "no compilation," which I view as
       | a slight exaggeration, but what's true is that it can work
       | quickly and incrementally so you don't have a compile-and-wait
       | cycle, even on long documents.
        
         | leephillips wrote:
         | few examples of things you can do with LuaTeX, and a tutorial:
         | https://lwn.net/Articles/731581/
        
       ___________________________________________________________________
       (page generated 2024-06-09 23:01 UTC)