source: palm/trunk/SCRIPTS/compile_tutorial @ 982

Last change on this file since 982 was 982, checked in by maronga, 12 years ago

last commit documented

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