Bo Peng wrote: > I have updated my previous patch. It now can: > > 1. If a wrong formula is entered, a 'formula does not compile' box > will > be displayed rather than the orginal lyx math box. > 2. If a file with wrong formula(s) is opened, the perl script will > locate the wrong formula(s) and replace them with 'formula does > not compile' box. Instant preview will continue to work. > > You can test this script by entering wrong formulas such as > $\text{\alpha}$, $\eee$, save file and reopen. > > The script works on my redhat 9 + tetex 1.0.7 + lyx 1.4.0 cvs/lyx > 1.3.3 stable. I hope that it works on other platforms as well.
Goodness! I really opened a can of worms by encouraging you, didn't I ;-) A question for you: Does Latex stop when it encounters the first error, or does it try and compile the whole file? If it stops, then shouldn't we implement while (true) do compile latex check log file if (no errors) break replace flagged formulae with $WRONGFORMULAMESSAGE done Answers to your questions: # QUESTION: Will Tightpage always be there? What does it mean? The "Tightpage" and "Snippet" lines are added to the log file by the preview-latex package. I use them to ascertain how to place the image on the screen. See 'setAscentFractions' in src/graphics/PreviewLoader.C for the gory details. # QUESTION: Is it a good idea to replace $TEXFILE? # Will it be used later? It might be more elegant to use ${BASE}_retry.tex, but I don't think that it really matters. Comments on your code: * That was clever of you to use the snippet counters output by preview-latex to identify the snippets that should be 'repaired'. This looks suspicious: +# QUESTION: Will Tightpage always be there? What does it mean? +if (/^!.*Preview:\s+[^S]/gcms){ In fact, if I understand you correctly, you're using this regex to identify the line "Preview: Tightpage...", no? I think that if the line doesn't exist, then you should just abort. +if (!/Preview:\s+Tightpage/gcms){ // bail out (I've forgotten what all those 'gcms' commands mean --- if I ever knew.) * Grammatical point: don't call them 'wrong formulas'. Call them 'incorrrect formulas', or even 'incorrect formulae'. I'm very impressed! Kind regards, Angus -- Angus