source: palm/trunk/SCRIPTS/compile_tutorial @ 4459

Last change on this file since 4459 was 2718, checked in by maronga, 7 years ago

deleting of deprecated files; headers updated where needed

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