7

I faced these questions when I was searching for an intelligent Windows TeX editor:

Specially, in the second question, in the selected answer, it has been claimed that writing such an editor means a background-running editor! If it is surprisingly the case, what is the intrinsic difference between Java and TeX which makes this difference?


Note: In programs like Eclipse, you see the compile errors as you write them, in real time.

13
  • 6
    It would probably be a good idea to explain what Eclipse and Netbeans do for Java programmers: for those of us who are not 'real' programmers it's not immediately obvious. We have a big list of editors which cover what is available for TeX users in the 'specialist editor' area.
    – Joseph Wright
    May 16, 2015 at 8:39
  • 1
    I don't know why you put a ! on the suggestion of running tex in the background, any implementation of what you ask will surely do that. Also I don't understand your reference to Java, surely you don't run your java program as you type it that sounds very dangerous. May 16, 2015 at 8:41
  • @DavidCarlisle Of course it is not a run-time run but it is a run-time compile
    – hossayni
    May 16, 2015 at 8:44
  • @hossayni well then the intrinsic difference is that tex is not a compiler. There is no separate compile and run step. May 16, 2015 at 8:46
  • 3
    Their is a bit stuff that tries real-time timestting. It is annoying. Typing a caption and actually thinking a bit about it will trigger a compilation error because the brace isn't close. It doesn't take long till the cursing starts.
    – Johannes_B
    May 16, 2015 at 16:52

3 Answers 3

24

The main difference is that Java is a language with a fixed grammar and a compiler separate from execution.

TeX has neither of those things, there is no fixed grammar, even the lexical analysis and tokenisation depends on the run time behaviour.

So a Java editor can use a java compiler, or (more likely) its own inbuilt implementation of the Java syntax grammar and report errors but that is not possible with TeX.

An editor can (and usually does) report simple things like mis-matched brackets but even that results in false error reports

$(1,2]$ 

is perfectly legal as is

\catcode`?=2
\mbox{aaa?

For bracket matching the simple check is probably right often enough that it is worth doing but if you try to do more then you will get false reports of syntax errors more often than not so it is not helpful.

What you can do, and some systems do, is run tex in the background and update the preview whenever there is a result to be previewed.

2
  • 6
    The $(1,2]$ example is particularly salient. In a programming language, that would be a syntax error but TeX needs to be able to typeset whatever text the user wants it to typset, even if it's nonsense: forbidding $(1,2]$ would be the same as forbidding Colourless green ideas sleep furiouslyadkjhf. (And $(1,2]$ isn't even nonsense: it refers to the set of real numbers x such that 1<x<=2.) May 16, 2015 at 12:47
  • 1
    "So a Java editor can use a java compiler, or (more likely) its own inbuilt implementation of the Java syntax grammar and report errors but that is not possible with TeX." In addition to syntax checking that can be based on textual analysis, very many many IDEs do perform incremental compilation behind the scenes. That's different from running the resulting program, but Eclipse, for instance, will be using a java compiler continually behind the scenes (unless instructed not to). May 16, 2015 at 14:16
1

It is possible, in fact a few seconds searching brought up one example. Disclaimer: I have not used that plugin.


The first thing to ask is: what is Eclipse, exactly? What does it provide?

Eclipse is an IDE. It provides frameworks which can be leveraged by plugins which run in the IDE. It is best-known for being a Java IDE, and the Java plugin is one of the oldest and most mature available for Eclipse. But you can do anything in Eclipse: you could even implement a database, photo editor, or video game if you wanted to. In fact there is an entire RCP framework for building arbitrary (non-development, even) applications.


What does the Eclipse Java plugin (JDT) do?

JDT includes two components relevant to this question: a Java editor and a Java compiler. The two work together to provide those red squigglies (their real name is "error markers" but I prefer squigglies). In the background, as you edit Java source code, the JDT compiler is building an AST (abstract syntax tree) that is basically a data structure that represents the partially-compiled code in memory. Its purpose, in this context, is to identify regions of your code: variables, method names, class declarations, etc. This is how JDT can tell you "missing }": the AST is broken, and it expected a } but you did not provide one. This is also how if you select a method reference you can hit F3 to go to its definition.


How would a LaTeX editor in Eclipse work?

Now we get to the core of your question. Clearly, a LaTeX editor would not work the same as a Java editor because LaTeX has no "compiler." Java and LaTeX are just different. But is there any way to correlate them?

You would need something similar to the background compiler in JDT, but not a compiler. Some process that runs as you edit your document, checking for errors. This is more difficult as David Carlisle mentions because LaTeX has a more complex grammar. Java (and most programming languages) was built to have a grammar that is easy to parse, making the compiler easier to write with the side effect of making the language more programmer-friendly.

LaTeX is a lot older, it has evolved differently from programming languages, and its grammar was not designed the same way a programming language grammar would be. But clearly it can be parsed, because we have programs that consume LaTeX.


Specially, in the second question, in the selected answer, it has been claimed that writing such an editor means a background-running editor! If it is surprisingly the case, what is the intrinsic difference between Java and TeX which makes this difference?

I hope my explanation above demonstrates that there is no difference. JDT has a "background editor" if you will (actually an editor and a background compiler working together). A "smart" LaTeX editor would need an editor... and a background syntax checker. But in the context of an editor, the JDT compiler is basically performing the exact same role.

2
  • 1
    It's often said that only TeX can (properly) parse TeX: there is no fixed grammar as we can always redefine a macro/primitive or change some catcodes. (For the classic example see xii.tex.)
    – Joseph Wright
    May 16, 2015 at 19:52
  • It has a grammar as any language does, but it is extraordinarily complex. I never said parsing it and giving real-time feedback would be easy, only that it would be possible.
    – user78338
    May 16, 2015 at 19:55
1

TeXlipse does some recognition of syntax in Eclipse. It struggles with huge files though... Very slow on my file of over 2000 lines.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.