1
0
mirror of https://github.com/mghansen256/pythontex-wrapper.git synced 2024-10-27 20:34:03 +00:00

Better error reporting and simplified code.

This commit is contained in:
Michael Georg Hansen 2020-10-28 15:58:00 +01:00
parent 388bddd1c8
commit dc3687f5f2

View File

@ -20,35 +20,62 @@ fi
# print some debug information # print some debug information
echo "pythontex-wrapper.sh" echo "pythontex-wrapper.sh"
echo "arguments:" $@ echo "arguments:" $@
logfilename=`basename $1 .tex`.log basefilename=`basename $1 .tex`
logfilename=${basefilename}.log
pytxcodefilename=${basefilename}.pytxcode
echo "Log file: " ${logfilename} echo "Log file: " ${logfilename}
echo "Working directory: " `pwd` echo "Working directory: " `pwd`
echo "Using latex command: " ${latexcommand} echo "Using latex command: " ${latexcommand}
echo "Using pythontex command: " ${pythontexcommand} echo "Using pythontex command: " ${pythontexcommand}
# compile using latex # compile using latex
if ${latexcommand} $@ ; then echo -e "\n\npythontex-wrapper: Calling ${latexcommand}"
# compilation in latex worked, run pythontex3 echo -e "------------------------------------------\n\n"
if ${pythontexcommand} $1 ; then ${latexcommand} $@
# pythontex worked, run latex again lastResult=$?
if ${latexcommand} $@ ; then echo "First latex run: ${lastResult}" >> pythontex-wrapper.log
# compilation in latex worked if [ $lastResult -gt 0 ] ; then
exit 0 # compilation using latex failed
else echo "pythontex-wrapper: This was the first latex run, before pythontex was called!" >> ${logfilename}
# compilation using latex failed echo "pythontex-wrapper: pythontex may have been run previously by lyx, before bibtex was run." >> ${logfilename}
exit 1 echo "pythontex-wrapper: If the problem was due to bad python output and persists after fixing it," >> ${logfilename}
fi echo "pythontex-wrapper: please delete the pythontex-file-${basefilename} folder in the output directory." >> ${logfilename}
else exit 1
# running pythontex failed fi
# lyx expects LaTeX error messages in the log file
# Add a fake latex error message which lyx understands # compilation in latex worked, run pythontex3 if needed
echo "! Undefined control sequence." >>${logfilename} if [ ! -e ${pytxcodefilename} ] ; then
echo "l.17 \\pythontexError" >>${logfilename} echo "pythontex-wrapper: No pytxcode file generated, no need to run pythontex!" | tee -a ${logfilename}
echo "\\Actually there is a pythontex error, see complete log for details." >>${logfilename} exit 0
fi
exit 1
fi echo -e "\n\npythontex-wrapper: Calling ${pythontexcommand}"
else 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 # compilation using latex failed
exit 1 exit 1
fi fi
# compilation in latex worked
exit 0