0

Apparently, Parsing TeX is Turing-complete. I however, do not write TeX but LaTeX. In that process, I profit from assistance by editor plugins like Auctex et.al. These plugins rely on a syntactic model of my writing (hence, they need to parse it). I assume they could be confused by running certain TeX commands directly.

Hence, I wonder, if one could create a context free syntax, that

  1. is valid LaTeX and supports if not all then at least most of it
  2. is guaranteed to not contain any syntax-changing commands

Documents written in that syntax are considered "safe". I guess 1. is relatively simple (is it not?). In order to fulfill 2., I propose to structure each document as follows:

  1. A (TeX or unsafe LaTeX) preamble
  2. One or more safe documents

One could check the documents using the following approach: 1. create a custom format from the preamble 2. inspect the effect on the syntax that have occured 3. Reject the compilation if any such modifications are in place

Is this a reasonable approach?

  1. Is it technically sound (i.e. given the state of a tex interpreter as a format file, is it possible to detect that the accepted syntax has been changed?)
  2. Is LaTeX in its standard form context-free?
  3. How complete is this approach (i.e. which widely used features would not work)?

edit: One simple example is the TeX math delimiter $. It is much harder to track down missing closing $ than it is for a pair of \( and \). As long as no other character was set up to take the place of $, however, a simple scanner could detect any use of it and report an error.

  • 1
    Since the underlying TeX is fully available for access from LaTeX, it would be hard to envision developing a way to prevent user-directed syntax changes. However, menu-driven approaches like Scientific Workplace might come close, or perhaps (I don't use them) LaTeX emulators. – Steven B. Segletes Oct 25 '16 at 11:43
  • Of course, tex is available, but couldn't one syntactically differentiate between a valid LaTeX command and an invalid one from TeX? – choeger Oct 25 '16 at 11:44
  • 1
    Are you talking about things like the standard syntax being \macroname[<optional>]...{<mandatory>}? But, of course, that need not be the case even for LaTeX. And if you use expl3, you don't even need \def or similar to create commands with arbitrary syntax. [But probably I've misunderstood your question.] – cfr Oct 25 '16 at 11:54
  • Yes, that is what I consider the standard syntax. Standard syntax is what tex parses by default (i.e. without any commands that affect this behavior) changed by whatever LaTex puts on top of this by default. – choeger Oct 25 '16 at 11:58
  • 1
    the trouble is any package can install any parser tikz for example embeds a whole new grammar, beamer has <> arguments and so it goes.... – David Carlisle Oct 25 '16 at 12:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.