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 \( 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.
\macroname[<optional>]...{<mandatory>}? But, of course, that need not be the case even for LaTeX. And if you useexpl3, you don't even need\defor similar to create commands with arbitrary syntax. [But probably I've misunderstood your question.] – cfr Oct 25 '16 at 11:54<>arguments and so it goes.... – David Carlisle Oct 25 '16 at 12:08<>but tikz (or keyval, or array) introduce new micro syntax within existing arguments so as long as you are prepared to skip[]arguments as a single unit you don't need to parse[width=3em, rotate=90]as two settings. – David Carlisle Oct 25 '16 at 15:37