-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun_latexml.sh
executable file
·46 lines (40 loc) · 1.8 KB
/
run_latexml.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#! /bin/bash
# Run latexml on the main .tex files under argv[1]
# Sends the Errors to the files latexml_errors_mess.txt
# and the processed file is stored in an xml file with
#the same name as the original .tex file.
#FILE_LIST=($(find $1 -maxdepth 1 -type d '!' -exec test -e "{}/latexml_errors_mess.txt" ';' -print))
#Define the LaTeXML binary file to run by sourcing the config file
# This define the variable latexml_bin
source <(grep ^LATEXML_BIN "$PWD/config.toml")
#echo "latexml_bin file is: $LATEXML_BIN"
COMMENTARY_FILENAME=latexml_commentary.txt
#The maximum amount of time in seconds that LaTeXML is
#allowed to run (seconds)
source <(grep ^MAXT "$PWD/config.toml")
for article_dir in "$@"
do
[ -d $article_dir ] && f=$(perl get_main_tex.pl $article_dir || echo "") ||\
{ echo $article_dir "seems to not exist"; exit 0; }
if [ -z $f ] #check if $f is string of length zero
then
COMMENTARY_FILE=$article_dir/$COMMENTARY_FILENAME
echo "Could not find the main tex file in:" $article_dir
[ -f "$COMMENTARY_FILE" ] && echo "Main TeX file not found" >> $COMMENTARY_FILE
else
echo "Running LaTeXML on the file " $f
COMMENTARY_FILE=${f%/*}/$COMMENTARY_FILENAME
echo "main .tex file" $(basename $f) >> $COMMENTARY_FILE
timeout --kill-after=60 $MAXT $LATEXML_BIN $f --noparse 2>${f%/*}/latexml_errors_mess.txt > ${f%.*}.xml
RETURN_CODE=$?
if [ $RETURN_CODE -eq 124 ]; then
echo "Timeout Occured with file $f"
echo "Timeout of $MAXT seconds occured" >> $COMMENTARY_FILE
elif [ $RETURN_CODE -eq 137 ]; then
echo "Had to kill the file $f"
echo "Timeout of $MAXT seconds occured And the process had to be KILLED" >> $COMMENTARY_FILE
else
echo "Finished in less than $MAXT seconds" >> $COMMENTARY_FILE
fi
fi
done