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
- is valid LaTeX and supports if not all then at least most of it
- 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:
- A (TeX or unsafe LaTeX) preamble
- 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?
- 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?)
- Is LaTeX in its standard form context-free?
- 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
\). 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.