source: palm/trunk/SCRIPTS/compile_tutorial @ 1046

Last change on this file since 1046 was 1046, checked in by maronga, 11 years ago

put scripts and utilities under GPL

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