From dc3687f5f26c5b968606640229e17332564f86ce Mon Sep 17 00:00:00 2001 From: Michael Georg Hansen Date: Wed, 28 Oct 2020 15:58:00 +0100 Subject: [PATCH] Better error reporting and simplified code. --- pythontex-wrapper.sh | 73 ++++++++++++++++++++++++++++++-------------- 1 file changed, 50 insertions(+), 23 deletions(-) diff --git a/pythontex-wrapper.sh b/pythontex-wrapper.sh index e36ac5b..89cd661 100755 --- a/pythontex-wrapper.sh +++ b/pythontex-wrapper.sh @@ -20,35 +20,62 @@ fi # print some debug information echo "pythontex-wrapper.sh" echo "arguments:" $@ -logfilename=`basename $1 .tex`.log +basefilename=`basename $1 .tex` +logfilename=${basefilename}.log +pytxcodefilename=${basefilename}.pytxcode echo "Log file: " ${logfilename} echo "Working directory: " `pwd` echo "Using latex command: " ${latexcommand} echo "Using pythontex command: " ${pythontexcommand} # compile using latex -if ${latexcommand} $@ ; then - # compilation in latex worked, run pythontex3 - if ${pythontexcommand} $1 ; then - # pythontex worked, run latex again - if ${latexcommand} $@ ; then - # compilation in latex worked - exit 0 - else - # compilation using latex failed - exit 1 - fi - else - # running pythontex failed - # lyx expects LaTeX error messages in the log file - # Add a fake latex error message which lyx understands - echo "! Undefined control sequence." >>${logfilename} - echo "l.17 \\pythontexError" >>${logfilename} - echo "\\Actually there is a pythontex error, see complete log for details." >>${logfilename} - - exit 1 - fi -else +echo -e "\n\npythontex-wrapper: Calling ${latexcommand}" +echo -e "------------------------------------------\n\n" +${latexcommand} $@ +lastResult=$? +echo "First latex run: ${lastResult}" >> pythontex-wrapper.log +if [ $lastResult -gt 0 ] ; then # compilation using latex failed + echo "pythontex-wrapper: This was the first latex run, before pythontex was called!" >> ${logfilename} + echo "pythontex-wrapper: pythontex may have been run previously by lyx, before bibtex was run." >> ${logfilename} + echo "pythontex-wrapper: If the problem was due to bad python output and persists after fixing it," >> ${logfilename} + echo "pythontex-wrapper: please delete the pythontex-file-${basefilename} folder in the output directory." >> ${logfilename} exit 1 fi + +# compilation in latex worked, run pythontex3 if needed +if [ ! -e ${pytxcodefilename} ] ; then + echo "pythontex-wrapper: No pytxcode file generated, no need to run pythontex!" | tee -a ${logfilename} + exit 0 +fi + +echo -e "\n\npythontex-wrapper: Calling ${pythontexcommand}" +echo -e "------------------------------------------\n\n" +${pythontexcommand} $1 +lastResult=$? +echo "pythontex run: ${lastResult}" >> pythontex-wrapper.log +if [ ${lastResult} -gt 0 ]; then + # running pythontex failed + # lyx expects LaTeX error messages in the log file + # Add a fake latex error message which lyx understands + echo "! Undefined control sequence." >>${logfilename} + echo "l.17 \\pythontexError" >>${logfilename} + echo "\\Actually there is a pythontex error, see complete log for details." >>${logfilename} + + exit 1 +fi + +# pythontex worked, run latex again +echo -e "\n\npythontex-wrapper: Calling ${latexcommand}" +echo -e "------------------------------------------\n\n" +${latexcommand} $@ +lastResult=$? +echo "Second latex run: ${lastResult}" >> pythontex-wrapper.log +echo "pythontex-wrapper: This was the second latex run, after pythontex was called!" >> ${logfilename} +if [ ${lastResult} -gt 0 ] ; then + # compilation using latex failed + exit 1 +fi + +# compilation in latex worked +exit 0