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. -- Bo Peng
Index: lib/scripts/lyxpreview2bitmap.sh =================================================================== RCS file: /cvs/lyx/lyx-devel/lib/scripts/lyxpreview2bitmap.sh,v retrieving revision 1.15 diff -u -r1.15 lyxpreview2bitmap.sh --- lib/scripts/lyxpreview2bitmap.sh 2003/09/03 17:40:56 1.15 +++ lib/scripts/lyxpreview2bitmap.sh 2004/01/06 05:12:22 @@ -128,7 +128,60 @@ cd ${DIR} ${LATEX} ${TEXFILE} || { - BAIL_OUT "Failed: ${LATEX} ${TEXFILE}" + WRONGFORMULAMESSAGE="Formula does not compile" +# if latex fails, try to locate the wrong formulas and +# replace them with \fbox{ $WRONGFORMULAMESSAGE } +# The first snippet, if it is wrong, is identified in $LOGFILE by +# ! + error +# before line +# Preview: Tightpage +# Other wrong snippets are identified by +# Preview Snippet snippet-number numbers +# [snippet-number] +# ! and then error messages. +perl -- <<EOF +undef \$/; # reading the whole file at a time. +open(LOG, "${LOGFILE}") || die "Can not open log file"; +\$_ = <LOG>; +close(LOG); [EMAIL PROTECTED] = (); +# test if the first snippet is wrong. +# QUESTION: Will Tightpage always be there? What does it mean? +if (/^!.*Preview:\s+[^S]/gcms){ + # print "First snippet is wrong.\n"; + push( @badsnippets, 0); +} +# find other wrong formula +while(/^Preview:\s+Snippet\s+(\d+)\s+\d+\s+\d+\s+\d+\s*\[\d+\]\s*!/gcm){ + # print "Snippet \$1 is wrong.\n"; + push( @badsnippets, \$1); +} + +# replace wrong formulas by a message box. +open(TEX, "${TEXFILE}") || die "Can not open tex file."; +\$_ = <TEX>; # get everything. +close(TEX); [EMAIL PROTECTED] = split(/\\\\begin{preview}/, \$_); # separate previews +foreach \$snip (@badsnippets){ + \$PREVIEWS[\$snip+1] = "\n\\\\fbox{$WRONGFORMULAMESSAGE}\n\\\\end{preview}\n\n"; + if( \$snip+2 == @PREVIEWS ){ # if the last one, add \end{document} + \$PREVIEWS[\$snip+1] .= "\n\\\\end{document}\n"; + } +} +# join all the pieces together and write back to $TEXFILE +# QUESTION: Is it a good idea to replace $TEXFILE? Will it be used later? +\$_ = join('\begin{preview}', @PREVIEWS); +open(OUT, ">${TEXFILE}") || die "Can not write to tex file."; +print OUT \$_; +close(OUT); +EOF + + # compile the repaired latex file + ${LATEX} ${TEXFILE} || + { + BAIL_OUT "Failed: ${LATEX} ${TEXFILE} with wrong formula replaced" + } + echo "Wrong formula found" } # Parse ${LOGFILE} to obtain bounding box info to output to