[915] | 1 | #!/bin/ksh |
---|
| 2 | #------------------------------------------------------------------------------! |
---|
| 3 | # Current revisions: |
---|
| 4 | # ----------------- |
---|
| 5 | # |
---|
| 6 | # Former revisions: |
---|
| 7 | # ----------------- |
---|
| 8 | # $Id: compile_tutorial 916 2012-05-30 15:24:21Z fricke $ |
---|
| 9 | # |
---|
[916] | 10 | # 915 2012-05-30 15:11:11Z maronga |
---|
| 11 | # Initial revision |
---|
| 12 | # |
---|
[915] | 13 | # Description: |
---|
| 14 | # ------------ |
---|
| 15 | # This script compiles all LaTeX files that are located in TUTORIAL/SOURCE/. |
---|
| 16 | # Three PDFs are generated for each source file: |
---|
| 17 | # the lecture version has a step-by-step layout, the handout version contains |
---|
| 18 | # lines for notes, the web version can contain additional comments by the |
---|
| 19 | # authors and has no step-by-step layout. |
---|
| 20 | # If a file is given as input parameter, only this file will be compiled. |
---|
| 21 | # |
---|
| 22 | # Execution: |
---|
| 23 | # ---------- |
---|
| 24 | # compile_tutorial --> compiles all *.tex files in directory. |
---|
| 25 | # compile_tutorial -f filename.tex --> compiles filename.tex only. |
---|
| 26 | #------------------------------------------------------------------------------! |
---|
| 27 | |
---|
| 28 | cycles=3 |
---|
| 29 | debug=false |
---|
| 30 | file="" |
---|
| 31 | |
---|
| 32 | full_name=`readlink -f $0` |
---|
| 33 | directory="$(dirname $full_name)/../TUTORIAL/SOURCE" |
---|
| 34 | output_dir="$(dirname $full_name)/../TUTORIAL" |
---|
| 35 | cd $directory |
---|
| 36 | |
---|
| 37 | while getopts :df: option |
---|
| 38 | do |
---|
| 39 | case $option in |
---|
| 40 | (d) debug=true;; |
---|
| 41 | (f) file=$OPTARG;; |
---|
| 42 | (\?) printf "\n +++ unknown option $OPTARG \n" |
---|
| 43 | printf "\n --> type \"$0 ?\" for available options \n" |
---|
| 44 | locat=parameter;exit;; |
---|
| 45 | esac |
---|
| 46 | done |
---|
| 47 | |
---|
| 48 | shift OPTIND-1 |
---|
| 49 | |
---|
| 50 | |
---|
| 51 | # Print help |
---|
| 52 | if [[ "$1" = "?" ]] |
---|
| 53 | then |
---|
| 54 | (printf "\n *** compile_tutorial can be called as follows:\n" |
---|
| 55 | printf "\n compile -d -f..\n" |
---|
| 56 | printf "\n Description of available options:\n" |
---|
| 57 | printf "\n Option Description Default-Value" |
---|
| 58 | printf "\n -d show all debug output false" |
---|
| 59 | printf "\n -f Filename (single file compilation mode) \"\"" |
---|
| 60 | printf "\n ? this outline \n\n") | more |
---|
| 61 | exit |
---|
| 62 | fi |
---|
| 63 | |
---|
| 64 | if [[ "$file" != "" ]] then |
---|
| 65 | file_list=`readlink -f $(basename $file)` |
---|
| 66 | else |
---|
| 67 | file_list="$directory/*.tex" |
---|
| 68 | fi |
---|
| 69 | |
---|
| 70 | |
---|
| 71 | if [[ ! -d $output_dir/LECTURE ]] then |
---|
| 72 | printf " $output_dir/LECTURE will be created.\n" |
---|
| 73 | mkdir -p $output_dir/LECTURE |
---|
| 74 | fi |
---|
| 75 | |
---|
| 76 | if [[ ! -d $output_dir/HANDOUT ]] then |
---|
| 77 | printf " $output_dir/HANDOUT will be created.\n" |
---|
| 78 | mkdir -p $output_dir/HANDOUT |
---|
| 79 | fi |
---|
| 80 | |
---|
| 81 | if [[ ! -d $output_dir/WEB ]] then |
---|
| 82 | printf " $output_dir/WEB will be created.\n" |
---|
| 83 | mkdir -p $output_dir/WEB |
---|
| 84 | fi |
---|
| 85 | |
---|
| 86 | for i in $file_list; |
---|
| 87 | do |
---|
| 88 | if [[ "$(echo $(basename $i)|cut -c1-6)" != "header" ]] then |
---|
| 89 | printf "\n Compiling $i.\ Please wait..." |
---|
| 90 | |
---|
| 91 | # Check if file exists |
---|
| 92 | if [[ ! -f "$i" ]] then |
---|
| 93 | printf " error." |
---|
| 94 | printf "\n File $i does not exist. Skipping..." |
---|
| 95 | break |
---|
| 96 | fi |
---|
| 97 | |
---|
| 98 | compiling_type="LECTURE" |
---|
| 99 | for (( j=0; j<=2; j+=1 )) |
---|
| 100 | do |
---|
| 101 | rm -rf tmp_dir |
---|
| 102 | mkdir tmp_dir |
---|
| 103 | cp header_${compiling_type}.tex header_tmp.tex |
---|
| 104 | for (( k=1; k<=$cycles; k+=1 )) |
---|
| 105 | do |
---|
| 106 | if ( $debug ) then |
---|
| 107 | printf "\n pdflatex output:\n\n\n" |
---|
| 108 | pdflatex -halt-on-error -output-directory=tmp_dir $i |
---|
| 109 | if [[ "$?" != "0" ]] |
---|
| 110 | then |
---|
| 111 | printf "\n\n Compilation aborted. Please check your source code.\n" |
---|
| 112 | rm -rf tmp_dir |
---|
| 113 | exit |
---|
| 114 | fi |
---|
| 115 | else |
---|
| 116 | pdflatex -halt-on-error -output-directory=tmp_dir $i 2>&1 > error_file |
---|
| 117 | |
---|
| 118 | if [[ "$?" != "0" ]] |
---|
| 119 | then |
---|
| 120 | printf " error." |
---|
| 121 | printf "\n The following error occured during the compilation:\n\n\n" |
---|
| 122 | cat error_file |grep "Error" |
---|
| 123 | printf "\n\n Compilation aborted. Please check your source code.\n" |
---|
| 124 | rm -rf tmp_dir |
---|
| 125 | rm error_file |
---|
| 126 | exit |
---|
| 127 | fi |
---|
| 128 | fi |
---|
| 129 | mv tmp_dir/*.pdf $output_dir/$compiling_type |
---|
| 130 | done |
---|
| 131 | if [[ "$compiling_type" = "LECTURE" ]] |
---|
| 132 | then |
---|
| 133 | compiling_type="WEB" |
---|
| 134 | elif [[ "$compiling_type" = "WEB" ]] |
---|
| 135 | then |
---|
| 136 | compiling_type="HANDOUT" |
---|
| 137 | fi |
---|
| 138 | done |
---|
| 139 | printf " done." |
---|
| 140 | fi |
---|
| 141 | |
---|
| 142 | # Cleaning up |
---|
| 143 | if [[ -f header_tmp.tex ]] then |
---|
| 144 | rm header_tmp.tex |
---|
| 145 | fi |
---|
| 146 | if [[ -f error_file ]] then |
---|
| 147 | rm error_file |
---|
| 148 | fi |
---|
| 149 | if [[ -d tmp_dir ]] then |
---|
| 150 | rm -rf tmp_dir |
---|
| 151 | fi |
---|
| 152 | |
---|
| 153 | done |
---|
| 154 | |
---|
| 155 | printf "\n\n +++ All actions finished.\n" |
---|
| 156 | |
---|
| 157 | exit |
---|