source: palm/trunk/SCRIPTS/compile_tutorial @ 915

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

added first LaTeX source code for the new tutorial

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