so I'm currently working on a little application which basically consists of an editor and a preview. One writes LaTeX in the editor and the idea is that you get a live preview while you type. Like here in stackoverflow. For doing that, I have to compile the TeX input at some point (because I need an image/pdf for displaying a preview) and since it isn't just some normal text, I better do it while there won't be any compiling errors.
So my question is: Using PyQT5, can I somehow keep checking the syntax and somehow know when the current Tex input could be compiled successfully?
It is possible that you could compile the LaTeX code in the background whenever an edit is made, and only show the result based on if there were no errors from the compile. You could even keep the previous successful compile in the preview until the next point that will compile is reached. In this way, you would not have to check that the syntax itself was correct and ready to be displayed, but rather your viewer would only display useful previews.
I imagine this could be done by parsing the output files, or even just checking their modification times. There are many points during the writing of LaTeX code where it may not compile, as well as a large variety of packages one could use, so it seems like an ambitious project to employ a complete syntax checker. Additionally, you could even display compiler messages in real-time in the previewer while still providing a useful compiled view to work off of. I could see both as being very useful to any LaTeX user.
I apologize if some of this seems better suited to a comment, but I am not yet able to on this site despite being able to on TeX.SX where this may also be relevant. I do hope, however, that it is a useful idea.
TeX syntax is very complex, and it's very hard to predict if it will compile successfully. I'm not aware of any previewers that try it.
Instead, they try to compile the source. If it fails, they quit and keep the previously-generated PDF. After some input, they try again. Or, they allow the user to trigger rendering with a key shortcut.
Some things you may or may not want to be aware of: QTeXEngine; KLFBackend; and PyLaTeX.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With