[915] | 1 | #!/bin/ksh |
---|
[1046] | 2 | |
---|
| 3 | #--------------------------------------------------------------------------------# |
---|
[2696] | 4 | # This file is part of the PALM model system. |
---|
[1046] | 5 | # |
---|
| 6 | # PALM is free software: you can redistribute it and/or modify it under the terms |
---|
| 7 | # of the GNU General Public License as published by the Free Software Foundation, |
---|
| 8 | # either version 3 of the License, or (at your option) any later version. |
---|
| 9 | # |
---|
| 10 | # PALM is distributed in the hope that it will be useful, but WITHOUT ANY |
---|
| 11 | # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
---|
| 12 | # A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
---|
| 13 | # |
---|
| 14 | # You should have received a copy of the GNU General Public License along with |
---|
| 15 | # PALM. If not, see <http://www.gnu.org/licenses/>. |
---|
| 16 | # |
---|
[2696] | 17 | # Copyright 1997-2017 Leibniz Universitaet Hannover |
---|
[1046] | 18 | #--------------------------------------------------------------------------------# |
---|
| 19 | # |
---|
[915] | 20 | # Current revisions: |
---|
| 21 | # ----------------- |
---|
[981] | 22 | # |
---|
[915] | 23 | # Former revisions: |
---|
| 24 | # ----------------- |
---|
| 25 | # $Id: compile_tutorial 2696 2017-12-14 17:12:51Z kanani $ |
---|
| 26 | # |
---|
[1047] | 27 | # 1046 2012-11-09 14:38:45Z maronga |
---|
| 28 | # code put under GPL (PALM 3.9) |
---|
| 29 | # |
---|
[982] | 30 | # Typo removed |
---|
| 31 | # 981 2012-08-09 14:57:44Z maronga |
---|
| 32 | # |
---|
[916] | 33 | # 915 2012-05-30 15:11:11Z maronga |
---|
| 34 | # Initial revision |
---|
| 35 | # |
---|
[915] | 36 | # Description: |
---|
| 37 | # ------------ |
---|
| 38 | # This script compiles all LaTeX files that are located in TUTORIAL/SOURCE/. |
---|
| 39 | # Three PDFs are generated for each source file: |
---|
| 40 | # the lecture version has a step-by-step layout, the handout version contains |
---|
| 41 | # lines for notes, the web version can contain additional comments by the |
---|
| 42 | # authors and has no step-by-step layout. |
---|
| 43 | # If a file is given as input parameter, only this file will be compiled. |
---|
| 44 | # |
---|
| 45 | # Execution: |
---|
| 46 | # ---------- |
---|
| 47 | # compile_tutorial --> compiles all *.tex files in directory. |
---|
| 48 | # compile_tutorial -f filename.tex --> compiles filename.tex only. |
---|
| 49 | #------------------------------------------------------------------------------! |
---|
| 50 | |
---|
| 51 | cycles=3 |
---|
| 52 | debug=false |
---|
| 53 | file="" |
---|
| 54 | |
---|
| 55 | full_name=`readlink -f $0` |
---|
| 56 | directory="$(dirname $full_name)/../TUTORIAL/SOURCE" |
---|
| 57 | output_dir="$(dirname $full_name)/../TUTORIAL" |
---|
| 58 | cd $directory |
---|
| 59 | |
---|
| 60 | while getopts :df: option |
---|
| 61 | do |
---|
| 62 | case $option in |
---|
| 63 | (d) debug=true;; |
---|
| 64 | (f) file=$OPTARG;; |
---|
| 65 | (\?) printf "\n +++ unknown option $OPTARG \n" |
---|
| 66 | printf "\n --> type \"$0 ?\" for available options \n" |
---|
| 67 | locat=parameter;exit;; |
---|
| 68 | esac |
---|
| 69 | done |
---|
| 70 | |
---|
| 71 | shift OPTIND-1 |
---|
| 72 | |
---|
| 73 | |
---|
| 74 | # Print help |
---|
| 75 | if [[ "$1" = "?" ]] |
---|
| 76 | then |
---|
| 77 | (printf "\n *** compile_tutorial can be called as follows:\n" |
---|
[980] | 78 | printf "\n compile_tutorial -d -f..\n" |
---|
[915] | 79 | printf "\n Description of available options:\n" |
---|
| 80 | printf "\n Option Description Default-Value" |
---|
| 81 | printf "\n -d show all debug output false" |
---|
| 82 | printf "\n -f Filename (single file compilation mode) \"\"" |
---|
| 83 | printf "\n ? this outline \n\n") | more |
---|
| 84 | exit |
---|
| 85 | fi |
---|
| 86 | |
---|
| 87 | if [[ "$file" != "" ]] then |
---|
| 88 | file_list=`readlink -f $(basename $file)` |
---|
| 89 | else |
---|
| 90 | file_list="$directory/*.tex" |
---|
| 91 | fi |
---|
| 92 | |
---|
| 93 | |
---|
| 94 | if [[ ! -d $output_dir/LECTURE ]] then |
---|
| 95 | printf " $output_dir/LECTURE will be created.\n" |
---|
| 96 | mkdir -p $output_dir/LECTURE |
---|
| 97 | fi |
---|
| 98 | |
---|
| 99 | if [[ ! -d $output_dir/HANDOUT ]] then |
---|
| 100 | printf " $output_dir/HANDOUT will be created.\n" |
---|
| 101 | mkdir -p $output_dir/HANDOUT |
---|
| 102 | fi |
---|
| 103 | |
---|
| 104 | if [[ ! -d $output_dir/WEB ]] then |
---|
| 105 | printf " $output_dir/WEB will be created.\n" |
---|
| 106 | mkdir -p $output_dir/WEB |
---|
| 107 | fi |
---|
| 108 | |
---|
| 109 | for i in $file_list; |
---|
| 110 | do |
---|
| 111 | if [[ "$(echo $(basename $i)|cut -c1-6)" != "header" ]] then |
---|
| 112 | printf "\n Compiling $i.\ Please wait..." |
---|
| 113 | |
---|
| 114 | # Check if file exists |
---|
| 115 | if [[ ! -f "$i" ]] then |
---|
| 116 | printf " error." |
---|
| 117 | printf "\n File $i does not exist. Skipping..." |
---|
| 118 | break |
---|
| 119 | fi |
---|
| 120 | |
---|
| 121 | compiling_type="LECTURE" |
---|
| 122 | for (( j=0; j<=2; j+=1 )) |
---|
| 123 | do |
---|
| 124 | rm -rf tmp_dir |
---|
| 125 | mkdir tmp_dir |
---|
| 126 | cp header_${compiling_type}.tex header_tmp.tex |
---|
| 127 | for (( k=1; k<=$cycles; k+=1 )) |
---|
| 128 | do |
---|
| 129 | if ( $debug ) then |
---|
| 130 | printf "\n pdflatex output:\n\n\n" |
---|
| 131 | pdflatex -halt-on-error -output-directory=tmp_dir $i |
---|
| 132 | if [[ "$?" != "0" ]] |
---|
| 133 | then |
---|
| 134 | printf "\n\n Compilation aborted. Please check your source code.\n" |
---|
| 135 | rm -rf tmp_dir |
---|
| 136 | exit |
---|
| 137 | fi |
---|
| 138 | else |
---|
| 139 | pdflatex -halt-on-error -output-directory=tmp_dir $i 2>&1 > error_file |
---|
| 140 | |
---|
| 141 | if [[ "$?" != "0" ]] |
---|
| 142 | then |
---|
| 143 | printf " error." |
---|
| 144 | printf "\n The following error occured during the compilation:\n\n\n" |
---|
| 145 | cat error_file |grep "Error" |
---|
| 146 | printf "\n\n Compilation aborted. Please check your source code.\n" |
---|
| 147 | rm -rf tmp_dir |
---|
| 148 | rm error_file |
---|
| 149 | exit |
---|
| 150 | fi |
---|
| 151 | fi |
---|
| 152 | mv tmp_dir/*.pdf $output_dir/$compiling_type |
---|
| 153 | done |
---|
| 154 | if [[ "$compiling_type" = "LECTURE" ]] |
---|
| 155 | then |
---|
| 156 | compiling_type="WEB" |
---|
| 157 | elif [[ "$compiling_type" = "WEB" ]] |
---|
| 158 | then |
---|
| 159 | compiling_type="HANDOUT" |
---|
| 160 | fi |
---|
| 161 | done |
---|
| 162 | printf " done." |
---|
| 163 | fi |
---|
| 164 | |
---|
| 165 | # Cleaning up |
---|
| 166 | if [[ -f header_tmp.tex ]] then |
---|
| 167 | rm header_tmp.tex |
---|
| 168 | fi |
---|
| 169 | if [[ -f error_file ]] then |
---|
| 170 | rm error_file |
---|
| 171 | fi |
---|
| 172 | if [[ -d tmp_dir ]] then |
---|
| 173 | rm -rf tmp_dir |
---|
| 174 | fi |
---|
| 175 | |
---|
| 176 | done |
---|
| 177 | |
---|
[981] | 178 | printf "\n\n *** All actions finished.\n" |
---|
[915] | 179 | |
---|
| 180 | exit |
---|