#!/bin/bash
###############################################################################
#                                                                             #
#                                  ShLaTeX                                    #
#                                                                             #
###############################################################################
#                                                                             #
# Author:           Mael Hill�reau                                            #
# Mail:             [email protected]                                    #
# Web:              http://mael.hillereau.free.fr                             #
# Creation :        06/03/2003                                                #
# Last modif.:      21/08/2003                                                #
# Version:          1.2a-en                                                   #
# Description:      LaTeX compilation script for Linux                        #
#                                                                             #
###############################################################################
#                                                                             #
# ShLaTeX -- LaTeX compilation script for Linux.                              #
# Copyright (C) 2003  Mael Hill�reau                                          #
#                                                                             #
# This program is free software; you can redistribute it and/or               #
# modify it under the terms of the GNU General Public License                 #
# as published by the Free Software Foundation; either version 2              #
# of the License, or (at your option) any later version.                      #
#                                                                             #
# This program is distributed in the hope that it will be useful,             #
# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
# GNU General Public License for more details.                                #
#                                                                             #
# You should have received a copy of the GNU General Public License           #
# along with this program; if not, write to the Free Software                 #
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. #
#                                                                             #
###############################################################################

nomshell=`expr match "$0" '.*/\([^-\]*\).*'`;
version="1.2b-en";

## envoi du code de retour appropri�
function fin() {
       echo -ne "done.\n\n";
       if [ $errindex -eq 1 ]
       then
               exit 3;
       else
               if [ $errbib -eq 1 ]
               then
                       exit 2;
               else
                       if [ $errcompil -eq 1 ]
                       then
                               exit 1;
                       else
                               exit 0;
                       fi
               fi
       fi
}

## suppression des temporaires
function suppressionTemp() {
       if [ $tmp -eq 0 ]
       then
               echo "deletion of latex temporary files...";
               rm -fr ./"$f".ShLaTeX
       fi
}

## fct de rappel pour CTRL^C
function ctrlc() {
       echo -ne "\n> Cancel!\n";
       if [ ! "$f" == "-" ]
       then
               repCourant=`pwd`;
               repCourant=`expr match "$repCourant" '.*/\(.*\)'`
               if [ "$repCourant" == "$f".ShLaTeX  ]
               then
                       cd ..;
               fi
               suppressionTemp;
       fi
       fin;
}

## d�claration des variables globales

# nom du fichier
f="-";

# codes d'erreur
errindex=0;
errcompil=0;
errbib=0;

# options pr�f�rencielles
P_dvipdf=-1;
P_pdflatex=-1;
P_dvips=-1;
P_pstopdf=-1;
P_dvi=-1;
P_idx=-1;
P_no_idx=-1;
P_idx_file="-";
P_bib=-1;
P_no_bib=-1;
P_bib_file="-";
P_toc=-1;
P_no_toc=-1;
P_tmp=-1;
P_no_tmp=-1;
P_z=-1;
P_no_z=-1;
P_un=-1;
P_deux=-1;
P_quatre=-1;
P_sep=-1;
P_no_sep=-1;
P_m=-1;
P_no_m=-1;
P_view=-1;
P_no_view=-1;
P_sept=-1;
P_huit=-1;
P_v_ps="-";
P_v_pdf="-";
P_v_dvi="-";

# options de la ligne de commande
L_dvipdf=-1;
L_pdflatex=-1;
L_dvips=-1;
L_pstopdf=-1;
L_dvi=-1;
L_idx=-1;
L_no_idx=-1;
L_idx_file="-";
L_bib=-1;
L_no_bib=-1;
L_bib_file="-";
L_toc=-1;
L_no_toc=-1;
L_tmp=-1;
L_no_tmp=-1;
L_z=-1;
L_no_z=-1;
L_un=-1;
L_deux=-1;
L_quatre=-1;
L_sep=-1;
L_no_sep=-1;
L_m=-1;
L_no_m=-1;
L_view=-1;
L_no_view=-1;
L_sept=-1;
L_huit=-1;
L_v_ps="-";
L_v_pdf="-";
L_v_dvi="-";

## options d'�x�cution
mode="dvi";
idx=0;
idx_file="-";
bib=0;
bib_file="-";
toc=1;
tmp=0;
z=0;
ppf=1;
sep=0;
m=0;
view=1;
ascii=7;
v_ps="gv";
v_pdf="gv";
v_dvi="xdvi";

## capture des CTRL^C
trap "ctrlc" SIGINT

## affiche une aide rapide
function aideRapide() {
       echo -ne "> Usage :\n";
       echo -ne "\n";
       echo -ne "    $nomshell [options] <file.tex>\n";
       echo -ne "\n";
       echo -ne "    hit \"man shlatex\" or \"$nomshell -?\" for more help.\n";
       echo -ne "\n";
}

## affiche une aide compl�te
function aideComplete() {
echo ".TH \\fBShLaTeX\\fP 1 \"August 2003\" \"version 1.2b\" \"User Manual\"

SH NAME
\\fBShLaTeX\\fP \\- Compilation script for documents written in LaTeX language.

SH SYNOPSIS
\\fBShLaTeX\\fP [options] \\fIsourceFile.tex\\fP

SH DESCRIPTION
PP
 This script allows to centralize the many program calls necessary to
completely compile a LaTeX document. In particular, the multiple calls of the
\\fBlatex\\fP command necessary in order to create a table of contents, a
bibliography or an index are carried out automatically. Are also managed the
call of the programs \\fBbibtex\\fP and \\fBmakeindex\\fP as well as the
vizualisation of the resulting file (in DVI, PostScript or PDF format) by
calling an external program.
PP
 It is possible to compile documents wich use the \\fB\\input\\fP and
\\fB\\include\\fP commands to make references to some external files and that in a
transparent way by compiling only the main source file.
PP
 Once compilation done, the temporary files are erased (option \\fB-no-tmp\\fP)
or preserved (option \\fB-tmp\\fP). The DVI file generated by LaTeX can then
directly be converted to the PostScript or PDF formats.
PP
 This script also provides the stressing of the French characters by the
intermediary of an external C program (named \\fBtex8to7\\fP) and provided with
the script. It also manages the C cedilla as well as the replacement of the
quotation marks by the \\fB\\\\og\\fP and \\fB\\\\fg\\fP commands (supposing that the
quotation marks are coupled). The quotation marks may be imbricated by using
accodances for distinguishing the different quotation mark couples. For example,
the text :
PP
 The quotation marks \"may be {\"imbricated\"} by using accodances\".
PP
 is a correct example.
PP
 The default options (preferences) are saved in the personal directory of the
user, in the file \\fB~/.shlatex\\fP. See section FILES to know the synthax of
this file.
SH OPTIONS
IP \"\\fB\\-dvipdf\\fP\"
Select a PDF format instead of the DVI format for the resulting file. The
program \\fBdvipdf\\fP is used for converting.
IP \"\\fB\\-pdflatex\\fP\"
Select a PDF format instead of the DVI format for the resulting file. The
program \\fBpdflatex\\fP is directly used to create the resulting file.
IP \"\\fB-dvips\\fP\"
Select a PostScript format instead of the DVI format for the resulting file. The
program \\fBdvips\\fP is used for converting.
IP \"\\fB-ps2pdf\\fP\"
Select a PDF format instead of the PaostScript format for the resulting file.
This option uses the \\fB-dvips\\fP option. The programs \\fBdvips\\fP and
\\fBps2pdf\\fP are successively used for conversion and the PostScript file is
keeped after conversion.
IP \"\\fB-dvi\\fP\"
Select a DVI format for the resulting file.
IP \"\\fB-idx\\fP \\fI[style.ist]\\fP or \\fB--index\\fP \\fI[style.ist]\\fP\"
Enable the creation of the index (using the \\fImakeidx\\fP latex module). The
optionnal file \\fIstyle.ist\\fP is a style file for \\fBmakeindex\\fP.
IP \"\\fB-no-idx\\fP or \\fB--no-index\\fP\"
Disable the creation of the index.
IP \"\\fB-bib\\fP \\fI[file.bib]\\fP or \\fB--bibliography\\fP \\fI[file.bib]\\fP\"
Enable the creation of the bibliography with \\fBbibtex\\fP being based on
\\fIfichier.bib\\fP. If no file is present, the file with the \".bib\" extension
must have the same name as \\fIsourceFile\\fP.tex.
IP \"\\fB-no-bib\\fP or \\fB--no-bibliography\\fP\"
Disable the creation of the bibliography.
IP \"\\fB-toc\\fP or \\fB--table-of-contents\\fP\"
Enable the additional compilation for the construction of a table of contents, a
table of figures, a list of figures and all LaTeX references
(\\fB\\\\label{...}\\fP).
IP \"\\fB-no-toc\\fP or \\fB--no-table-of-contents\\fP\"
Disnable the additional compilation for the construction of a table of contents,
a table of figures, a list of figures and all LaTeX references
(\\fB\\\\label{...}\\fP).
IP \"\\fB-tmp\\fP or \\fB--temporary\\fP\"
Once compilation performed, keep the temporary files created by LaTeX.
IP \"\\fB-no-tmp\\fP or \\fB--no-temporary\\fP\"
Once compilation performed, delete the temporary files created by LaTeX.
IP \"\\fB-z\\fP or \\fB--gzip\\fP\"
Compress the PsotScript files with the program \\fBgzip\\fP. The files have then
the extension \".ps.gz\".
IP \"\\fB-no-z\\fP or \\fB--no-gzip\\fP\"
Disable compression of the PsotScript files with the program \\fBgzip\\fP.
IP \"\\fB-1\\fP or \\fB--1page\\fP\"
Generate PostScript files having 1 page per a4 sheet.
IP \"\\fB-2\\fP or \\fB--2pages\\fP\"
Generate PostScript files having 2 pages per a4 sheet.
IP \"\\fB-4\\fP or \\fB--4pages\\fP\"
Generate PostScript files having 4 pages per a4 sheet.
IP \"\\fB-sep\\fP or \\fB--separator\\fP\"
Use this option in conjunction with the options \\fB-2\\fP or \\fB-4\\fP. Draw a
separating line between the different pages of a single sheet.
IP \"\\fB-no-sep\\fP or \\fB--no-separator\\fP\"
Use this option in conjunction with the options \\fB-2\\fP or \\fB-4\\fP. Disable
drawing a separating line between the different pages of a single sheet.
IP \"\\fB-m\\fP or \\fB--messages\\fP\"
Always show the LaTeX messages in the terminal (see also the section COMPILATION
ERRORS).
IP \"\\fB-no-m\\fP or \\fB--no-messages\\fP\"
If this option is used, the LaTeX messages only appear if there is some errors
(see also the section COMPILATION ERRORS).
IP \"\\fB-view\\fP or \\fB--viewer\\fP\"
Enable the final vizualisation.
IP \"\\fB-no-view\\fP or \\fB--no-viewer\\fP\"
Disable the final vizualisation.
IP \"\\fB-7\\fP or \\fB--7bits\\fP\"
Disable the sressing of the LaTeX source file. The source file must then use 7
bits ascii codes.
IP \"\\fB-8\\fP or \\fB--8bits\\fP\"
Enable the sressing of the LaTeX source file. The source file may then use 8
bits ascii codes.
IP \"\\fB-v-ps\\fP \\fIviewer\\fP or \\fB--view-ps-with\\fP \\fIviewer\\fP\"
Use the program \\fIviewer\\fP for the final vizualisation of the PostScript
files.
IP \"\\fB-v-pdf\\fP \\fIviewer\\fP or \\fB--view-pdf-with\\fP \\fIviewer\\fP\"
Use the program \\fIviewer\\fP for the final vizualisation of the PDF files.
IP \"\\fB-v-dvi\\fP \\fIviewer\\fP or \\fB--view-dvi-with\\fP \\fIviewer\\fP\"
Use the program \\fIviewer\\fP for the final vizualisation of the DVI files.
IP \"\\fB-v\\fP or \\fB--version\\fP\"
Print version and exit.
IP \"\\fB-?\\fP, \\fB-h\\fP or \\fB--help\\fP\"
Print some help.

IP \"\\fINote\\fP :\"
When using the option \\fB\\-view\\fP, the resulting file format choosen (DVI,
PostScript or PDF) must be compatible with the program \\fIviewer\\fP in order to
make the vizualisation running correctly. By default, the programs used are
\\fBxdvi\\fP for the DVI files and \\fBgv\\fP for the PostScript and PDF files.

SH \"COMPILATION ERRORS\"
PP
 If option \\fB-no-m\\fP is used, if LaTeX compilation error occurs, the script
seems to get stuck. One can stop it by typing command line options (\"x\" for
ignore, \"q\" for quit, ...) without viewing the messages, or by typing \"Ctrl^C\".
In the two cases, the error messages will be shown afterwards. This imperfection
is due to the choice of not printing the \\fBlatex\\fP program messages by
default. However, the problem exists only if the interaction mode allows LaTeX
to stop on errors (wich is not the case, for instance if the \\fB\\\\nonstopmode\\fP
command is used).
PP
 Anyway, it is possible to force display of the \\fBlatex\\fP messages by using
the option \\fB-m\\fP instead of the option \\fB-no-m\\fP.

SH \"FILES\"
PP
 The file \\fB~/.shlatex\\fP contains the user's preferences. It can be modified
in order to use custom default values for the script's options, but the synthax of
the script must be respected :
PP
 Each line of the file must hold a single option. All the options are allowed
excepting \\fB-v\\fP and \\fB-?\\fP which wouldn't have any sence in this file. For
the options which need a parameter, as in the shell, they will be placed after
their respective option but the separator have to be a single space character
('\\ '). The order of the options doesn't matter.
PP
 If some inconstancies appear during execution of the script, some warnings
will be displayed.
PP
 If while running the script for the first time, the file \\fB~/.shlatex\\fP
doesn't exist, it will be created automatically with the following content :
RS 5
IP \"-dvips\"
IP \"-view\"
IP \"-no-idx\"
IP \"-no-bib\"
IP \"-toc\"
IP \"-no-tmp\"
IP \"-no-z\"
IP \"-1\"
IP \"-no-sep\"
IP \"-no-m\"
IP \"-8\"
IP \"-v-ps gv\"
IP \"-v-pdf gv\"
IP \"-v-dvi xdvi\"

SH \"KNOWN PROBLEMS\"
SS \"BoundingBox\"
PP
 While inserting an image with the command \\fB\\\\includegraphics\\fP, it is
necessary to specify the \"boundingbox\" as argument of the command, unless
compilation doesn't work. Here is an exemple :
PP
 \\\\includegraphics[bb=0 0 100 200]{image.eps}
SS \"External files\"
 If you want external file inclusion to work properly, you have to put the
\\fB\\\\input\\fP and \\fB\\\\include\\fP commands on a single line in the file
\\fIsourceFile.tex\\fP.

SH \"SEE ALSO\"
BR latex (1),
BR pdflatex (1),
BR dvips (1),
BR ps2pdf (1),
BR dvipdf (1),
BR xdvi (1),
BR gv (1),
BR gzip (1)

SH \"BUGS\"
PP
Thanks for reporting bugs by sending an email to the AUTHOR section adress.

SH \"LICENCE\"
PP
 This script and all its relative files (including this manual) are released
under the terms of the GNU General Public Licence. The GNU GPL is provided with
the script (file /usr/share/shlatex/GPL.TXT) and is also available at the adress
http://www.gnu.org/licenses/gpl.html.

SH \"AUTHOR\"
PP
Copyright (C) 2003 Mael Hill�reau
PP
\\fIcontact\\fP : [email protected]
PP
\\fIweb\\fP : http://mael.hillereau.free.fr

" > ~/ShLaTeX_"$version".tmp;
man ~/ShLaTeX_"$version".tmp
rm -f ~/ShLaTeX_"$version".tmp
}

## affiche un message d'erreur
function erreur() {
       echo -ne "\n";
       echo -ne "> Error :\n";
       echo -ne "    $1\n";
       echo -ne "\n";
       if [ $# -eq 2 ]
       then
               if [ $2 == "-?" ]
               then
                       aideRapide;
               fi
       fi
}

## affiche un message d'avertissement
function avertissement() {
       echo -ne "\n";
       echo -ne "> Warning :\n";
       echo -ne "    $1\n";
       echo -ne "\n";
}

## affiche la version et sort
function version() {
       echo -ne "$nomshell version $version - LaTeX compilation script for Linux.\nCopyright (C) 2003 Mael Hill�reau\n";
       exit 0;
}

## recherche les fichiers externes (1 seul par ligne dans le source LaTeX !)
function fichiersExternes() {
       fExt="";
       lignes=`grep -e "^[ |\t]*\input{" $1`;
       lignes=`echo $lignes | grep -v -E "^[ |\t]*%.*"`
       for l in $lignes
       do
               fExt="$fExt `expr match $l '.*\input{\(.*\)}'`";
       done
       lignes=`grep -e "^[ |\t]*\include{" $1`;
       lignes=`echo $lignes | grep -v -E "^[ |\t]*%.*"`
       for l in $lignes
       do
               fExt="$fExt `expr match $l '.*\include{\(.*\)}'`";
       done
       lignes=`grep -e "^[ |\t]*\in\(put\|clude\) " $1`;
       lignes=`echo $lignes | grep -v -E "^[ |\t]*%.*"`
       for l in $lignes
       do
               if [ ! $l == "\input" -a ! $l == "\include" ]
               then
                       fExt="$fExt $l";
               fi
       done
       fTemp="";
       for l in $fExt
       do
               cTemp=`expr match $l '[ |\t]*\(.*\)\.tex'`;
               if [[ $cTemp == "" ]]
               then
                       fTemp="$fTemp $l";
               else
                       fTemp="$fTemp $cTemp";
               fi
       done
       fExt=$fTemp;
}

## remplace les fichiers externes nomm�s $1 par $2 dans le fichier $3
function rplcExtFich() {
       if [ -f $3 ]
       then
               lignes=`cat $3 | grep -n "\input $1" | tr " " "@"`;
               lignes="`cat $3 | grep -n \input{$1}` $lignes";
               for ligne in $lignes
               do
                       ligne=`echo $ligne | tr "@" " "`;
                       nblignes=`wc -l $3 | tr -s " " ":" | cut -f 2 -d ":"`;
                       nligne=`echo $ligne | cut -f 1 -d ":"`;
                       nligne=`expr $nligne - 1`;
                       fin=`expr $nblignes - $nligne - 1`;
                       head -$nligne "$3" > "$3".tmp
                       echo "\input{$2}" >> "$3.tmp"
                       tail -n $fin "$3" >> "$3".tmp
                       mv -f "$3".tmp "$3"
               done
               lignes=`cat $3 | grep -n "\include $1" | tr " " "@"`;
               lignes="`cat $3 | grep -n \include{$1}` $lignes";
               for ligne in $lignes
               do
                       ligne=`echo $ligne | tr "@" " "`;
                       nblignes=`wc -l $3 | tr -s " " ":" | cut -f 2 -d ":"`;
                       nligne=`echo $ligne | cut -f 1 -d ":"`;
                       nligne=`expr $nligne - 1`;
                       fin=`expr $nblignes - $nligne - 1`;
                       head -$nligne "$3" > "$3".tmp
                       echo "\include{$2}" >> "$3.tmp"
                       tail -n $fin "$3" >> "$3".tmp
                       mv -f "$3".tmp "$3"
               done
       fi
}

## v�rifie que le fichier fourni est accessible et �x�cutable
function estExec() {
       for rep in `echo $PATH | tr ":" " "`
       do
               if [ -x $rep/$1 ]
               then
                       return 1;
               fi
       done
       return 0;
}

## v�rifie qu'au plus un seul des arguments entiers a �t� initialis�
function verifInit() {
       i=0;
       for a
       do
               if [ $a -ne -1 ]
               then
                       i=`expr $i + 1`;
               fi
       done
       return $i;
}

## charge les pr�f�rences � partir du fichier ~/.shlatex (une option par ligne)
function preferences() {
       for ligne in `grep -e "^-.*" ~/.shlatex | tr " " "="`
       do
               opt=`expr match $ligne '[:space:]*\(-[-a-z0-9]*\)=*.*'`;
               paramopt="";
               paramopt=`expr match $ligne '[:space:]*-[-a-z0-9]*=\(.*\)'`;
               case $opt in
                       "-dvipdf" )
                               P_dvipdf=1;;
                       "-pdflatex" )
                               P_pdflatex=1;;
                       "-ps2pdf" )
                               P_pstopdf=1;;
                       "-dvips" )
                               P_dvips=1;;
                       "-dvi" )
                               P_dvi=1;;
                       "-idx" | "--index" )
                               P_idx=1;
                               if [ ! $paramopt == "" ]
                               then
                                       P_idx_file=$paramopt;
                               fi ;;
                       "-no-idx" | "--no-index" )
                               P_no_idx=1;
                               ;;
                       "-bib" | "--bibliography" )
                               P_bib=1;
                               if [ ! $paramopt == "" ]
                               then
                                       P_bib_file=`expr match $paramopt '\(.*\)\.bib'`;
                               fi ;;
                       "-no-bib" | "--no-bibliography" )
                               P_no_bib=1;;
                       "-toc" | "--table-of-contents" )
                               P_toc=1;;
                       "-no-toc" | "--no-table-of-contents" )
                               P_no_toc=1;;
                       "-tmp" | "--temporary" )
                               P_tmp=1;;
                       "-no-tmp" | "--no-temporary" )
                               P_no_tmp=1;;
                       "-z" | "--gzip" )
                               P_z=1;;
                       "-no-z" | "--no-gzip" )
                               P_no_z=1;;
                       "-1" | "--1page" )
                               P_un=1;;
                       "-2" | "--2pages" )
                               P_deux=1;;
                       "-4" | "--4pages" )
                               P_quatre=1;;
                       "-sep" | "--separator" )
                               P_sep=1;;
                       "-no-sep" | "--no-separator" )
                               P_no_sep=1;;
                       "-m" | "--messages" )
                               P_m=1;;
                       "-no-m" | "--no-messages" )
                               P_no_m=1;;
                       "-view" | "--viewer" )
                               P_view=1;;
                       "-no-view" | "--no-viewer" )
                               P_no_view=1;;
                       "-7" )
                               P_sept=1;;
                       "-8" )
                               P_huit=1;;
                       "-v-ps" | "--view-ps-with" )
                               if [ ! $paramopt == "" ]
                               then
                                       P_v_ps=$paramopt;
                               else
                                       avertissement "file \"$HOME/.shalatex\" -- option \"$opt\" ignored, missing argument!";
                               fi ;;
                       "-v-pdf" | "--view-pdf-with" )
                               if [ ! $paramopt == "" ]
                               then
                                       P_v_pdf=$paramopt;
                               else
                                       avertissement "file \"$HOME/.shalatex\" -- option \"$opt\" ignored, missing argument!";
                               fi ;;
                       "-v-dvi" | "--view-dvi-with" )
                               if [ ! $paramopt == "" ]
                               then
                                       P_v_dvi=$paramopt;
                               else
                                       avertissement "file \"$HOME/.shalatex\" -- option \"$opt\" ignored, missing argument!";
                               fi ;;
                       * )
                               avertissement "file \"$HOME/.shlatex\" -- option \"$opt\" ignored ; this option doesn't exist or isn't supported in preferences file";;
               esac
       done
       ## v�rification des options des pr�f�rences
       # mode
       verifInit $P_pstopdf $P_dvips $P_dvipdf $P_pdflatex $P_dvi;
       if [ $? -gt 1 ]
       then
               avertissement "file \"$HOME/.shlatex\" -- options -dvipdf, -dvips, -pdflatex, -ps2pdf and -dvi are mutually exclusive!";
       fi
       # index
       verifInit $P_idx $P_no_idx;
       if [ $? -gt 1 ]
       then
               avertissement "file \"$HOME/.shlatex\" -- options -idx and -no-idx are mutually exclusive!";
       fi
       # bibliography
       verifInit $P_bib $P_no_bib;
       if [ $? -gt 1 ]
       then
               avertissement "file \"$HOME/.shlatex\" -- options -bib and -no-bib are mutually exclusive!";
       fi
       # table of contents
       verifInit $P_toc $P_no_toc;
       if [ $? -gt 1 ]
       then
               avertissement "file \"$HOME/.shlatex\" -- options -toc and -no-toc are mutually exclusive!";
       fi
       # temporary
       verifInit $P_tmp $P_no_tmp;
       if [ $? -gt 1 ]
       then
               avertissement "file \"$HOME/.shlatex\" -- options -tmp and -no-tmp are mutually exclusive!";
       fi
       # gzip
       verifInit $P_z $P_no_z;
       if [ $? -gt 1 ]
       then
               avertissement "file \"$HOME/.shlatex\" -- options -z and -no-z are mutually exclusive!";
       fi
       # 1, 2, 4
       verifInit $P_un $P_deux $P_quatre;
       if [ $? -gt 1 ]
       then
               avertissement "file \"$HOME/.shlatex\" -- options -1, -2 and -4 are mutually exclusive!";
       fi
       # separator
       verifInit $P_sep $P_no_sep;
       if [ $? -gt 1 ]
       then
               avertissement "file \"$HOME/.shlatex\" -- options -sep and -no-sep are mutually exclusive!";
       fi
       # messages
       verifInit $P_m $P_no_m;
       if [ $? -gt 1 ]
       then
               avertissement "file \"$HOME/.shlatex\" -- options -m and -no-m are mutually exclusive!";
       fi
       # view
       verifInit $P_view $P_no_view;
       if [ $? -gt 1 ]
       then
               avertissement "file \"$HOME/.shlatex\" -- options -view and -no-view are mutually exclusive!";
       fi
       # 7, 8
       verifInit $P_sept $P_huit;
       if [ $? -gt 1 ]
       then
               avertissement "file \"$HOME/.shlatex\" -- options -7 and -8 are mutually exclusive!";
       fi
}

## si il n'y a pas de fichier de pr�f�rences, on le cr�e avec des valeurs par d�faut
if [ ! -f ~/.shlatex ]
then
       echo -ne "-dvips\n-view\n-no-idx\n-no-bib\n-toc\n-no-tmp\n-no-z\n-1\n-no-sep\n-no-m\n-8\n-v-ps gv\n-v-pdf gv\n-v-dvi xdvi\n" > ~/.shlatex
fi

## chargement des pr�f�rences
preferences;

## v�rification du nombre d'arguments et r�cup�ration des options
if [ $# -lt 2 ]
then
       if [ $# -eq 1 ]
       then
               if [ $1 == "-?" -o $1 == "-h" -o $1 == "--help" ]
               then
                       aideComplete;
                       exit 0;
               elif [ $1 == "-v" -o $1 == "--version" ]
               then
                       version
                       exit 0;
               fi
       else
               erreur "bad number of arguments!" -?;
               exit 1;
       fi
else
       noshift=0;
       while [ $# -gt 1 ]
       do
               case $1 in
                       "-dvipdf" )
                               L_dvipdf=1;;
                       "-pdflatex" )
                               L_pdflatex=1;;
                       "-ps2pdf" )
                               L_pstopdf=1;;
                       "-dvips" )
                               L_dvips=1;;
                       "-dvi" )
                               L_dvi=1;;
                       "-idx" | "--index" )
                               L_idx=1;
                               if [ $# -gt 2 ]
                               then
                                       shift;
                                       if [ ! ${1:0:1} == "-" ]
                                       then
                                               L_idx_file=$1;
                                       else
                                               noshift=1;
                                       fi
                               fi ;;
                       "-no-idx" | "--no-index" )
                               L_no_idx=1;;
                       "-bib" | "--bibliography" )
                               L_bib=1;
                               if [ $# -gt 2 ]
                               then
                                       shift;
                                       if [ ! ${1:0:1} == "-" ]
                                       then
                                               if [ -f $1 ]
                                               then
                                                       L_bib_file=`expr match "$1" '\(.*\)\.bib'`;
                                               else
                                                       erreur "the bibliography file \"$1\" doesn't exists!" -?;
                                                       exit 1;
                                               fi
                                       else
                                               noshift=1;
                                       fi
                               fi ;;
                       "-no-bib" | "--no-bibliography" )
                               L_no_bib=1;;
                       "-toc" | "--table-of-contents" )
                               L_toc=1;;
                       "-no-toc" | "--no-table-of-contents" )
                               L_no_toc=1;;
                       "-tmp" | "--temporary" )
                               L_tmp=1;;
                       "-no-tmp" | "--no-temporary" )
                               L_no_tmp=1;;
                       "-z" | "--gzip" )
                               L_z=1;;
                       "-no-z" | "--no-gzip" )
                               L_no_z=1;;
                       "-1" | "--1page" )
                               L_un=1;;
                       "-2" | "--2pages" )
                               L_deux=1;;
                       "-4" | "--4pages" )
                               L_quatre=1;;
                       "-sep" | "--separator" )
                               L_sep=1;;
                       "-no-sep" | "--no-separator" )
                               L_no_sep=1;;
                       "-m" | "--messages" )
                               L_m=1;;
                       "-no-m" | "--no-messages" )
                               L_no_m=1;;
                       "-view" | "--viewer" )
                               L_view=1;;
                       "-no-view" | "--no-viewer" )
                               L_no_view=1;;
                       "-7" )
                               L_sept=1;;
                       "-8" )
                               L_huit=1;;
                       "-v-ps" | "--view-ps-with" )
                               if [ $# -gt 2 ]
                               then
                                       shift;
                                       if [ ! ${1:0:1} == "-" ]
                                       then
                                               estExec $1;
                                               if [ $? -eq 1 ]
                                               then
                                                       L_v_ps=$1;
                                               else
                                                       erreur "the file \"$1\" isn't accessible or isn't runable on the command line!";
                                                       exit 1;
                                               fi
                                       else
                                               noshift=1;
                                       fi
                               else
                                       erreur "the option $1 needs a parameter!" -?;
                                       exit 1;
                               fi ;;
                       "-v-pdf" | "--view-pdf-with" )
                               if [ $# -gt 2 ]
                               then
                                       shift;
                                       if [ ! ${1:0:1} == "-" ]
                                       then
                                               estExec $1;
                                               if [ $? -eq 1 ]
                                               then
                                                       L_v_pdf=$1;
                                               else
                                                       erreur "the file \"$1\" isn't accessible or isn't runable on the command line!";
                                                       exit 1;
                                               fi
                                       else
                                               noshift=1;
                                       fi
                               else
                                       erreur "the option $1 needs a parameter!" -?;
                                       exit 1;
                               fi ;;
                       "-v-dvi" | "--view-dvi-with" )
                               if [ $# -gt 2 ]
                               then
                                       shift;
                                       if [ ! ${1:0:1} == "-" ]
                                       then
                                               estExec $1;
                                               if [ $? -eq 1 ]
                                               then
                                                       L_v_dvi=$1;
                                               else
                                                       erreur "the file \"$1\" isn't accessible or isn't runable on the command line!";
                                                       exit 1;
                                               fi
                                       else
                                               noshift=1;
                                       fi
                               else
                                       erreur "the option $1 needs a parameter!" -?;
                                       exit 1;
                               fi ;;
                       "-?" | "-h" | "--help" )
                               aideRapide;
                               exit 0;;
                       "-v" | "--version" )
                               version;;
                       * )
                               erreur "the option \"$1\" is incorrect!" -?;
                               exit 1;;
               esac
               if [ $noshift -eq 0 ]
               then
                       shift;
               else
                       noshift=0;
               fi
       done
fi

# v�rification de l'existence d'un nom pour le fichier source LaTeX
if [ $# -ne 1 ]
then
       erreur "LaTeX source file missing!" -?;
       exit 1;
fi

# v�rification de l'existence du fichier source LaTeX
if [ ! -f $1 ]
then
       erreur "unable to find the file \"$1\"!" -?;
       exit 1;
fi

# nom du fichier source
fich=$1;

# nom du fichier source sans son extension ".tex"
f=`expr match "$fich" '\(.*\)\.[a-zA-Z]*'`;

## v�rification des options de la ligne de commande
# mode
verifInit $L_pstopdf $L_dvips $L_dvipdf $L_pdflatex $L_dvi;
iopt=$?;
if [ $iopt -gt 1 ]
then
       erreur "options -dvipdf, -dvips, -pdflatex, -ps2pdf and -dvi are mutually exclusive!";
       exit 1;
elif [ $iopt -eq 1 ]
then
       # ligne de commande
       if [ $L_dvipdf -eq 1 ]
       then
               mode="dvipdf";
       elif [ $L_dvips -eq 1 ]
       then
               mode="dvips";
       elif [ $L_pdflatex -eq 1 ]
       then
               mode="pdflatex";
       elif [ $L_pstopdf -eq 1 ]
       then
               mode="ps2pdf";
       elif [ $L_dvi -eq 1 ]
       then
               mode="dvi";
       fi
else
       # pr�f�rences
       if [ $P_dvipdf -eq 1 ]
       then
               mode="dvipdf";
       elif [ $P_dvips -eq 1 ]
       then
               mode="dvips";
       elif [ $P_pdflatex -eq 1 ]
       then
               mode="pdflatex";
       elif [ $P_pstopdf -eq 1 ]
       then
               mode="ps2pdf";
       elif [ $P_dvi -eq 1 ]
       then
               mode="dvi";
       fi
fi
# index
verifInit $L_idx $L_no_idx;
iopt=$?;
if [ $iopt -gt 1 ]
then
       erreur "options -idx and -no-idx are mutually exclusive!";
       exit 1;
elif [ $iopt -eq 1 ]
then
       # ligne de commande
       if [ $L_idx -eq 1 ]
       then
               idx=1;
       else
               idx=0;
       fi
else
       # pr�f�rences
       if [ $P_idx -eq 1 ]
       then
               idx=1;
       else
               idx=0;
       fi
fi
if [ ! $L_idx_file == "-" ]
then
       idx_file=$L_idx_file;
elif [ ! $P_idx_file == "-" ]
then
       idx_file=$P_idx_file;
fi
# bibliography
verifInit $L_bib $L_no_bib;
iopt=$?;
if [ $iopt -gt 1 ]
then
       erreur "options -bib and -no-bib are mutually exclusive!";
       exit 1;
elif [ $iopt -eq 1 ]
then
       # ligne de commande
       if [ $L_bib -eq 1 ]
       then
               bib=1;
       else
               bib=0;
       fi
else
       # pr�f�rences
       if [ $P_bib -eq 1 ]
       then
               bib=1;
       else
               bib=0;
       fi
fi
if [ ! $L_bib_file == "-" ]
then
       bib_file=$L_bib_file;
elif [ ! $P_bib_file == "-" ]
then
       bib_file=$P_bib_file;
fi
# table of contents
verifInit $L_toc $L_no_toc;
iopt=$?;
if [ $iopt -gt 1 ]
then
       erreur "options -toc and -no-toc are mutually exclusive!";
       exit 1;
elif [ $iopt -eq 1 ]
then
       # ligne de commande
       if [ $L_toc -eq 1 ]
       then
               toc=1;
       else
               toc=0;
       fi
else
       # pr�f�rences
       if [ $P_toc -eq 1 ]
       then
               toc=1;
       else
               toc=0;
       fi
fi
# temporary
verifInit $L_tmp $L_no_tmp;
iopt=$?;
if [ $iopt -gt 1 ]
then
       erreur "options -tmp and -no-tmp are mutually exclusive!";
       exit 1;
elif [ $iopt -eq 1 ]
then
       # ligne de commande
       if [ $L_tmp -eq 1 ]
       then
               tmp=1;
       else
               tmp=0;
       fi
else
       # pr�f�rences
       if [ $P_tmp -eq 1 ]
       then
               tmp=1;
       else
               tmp=0;
       fi
fi
# gzip
verifInit $L_z $L_no_z;
iopt=$?;
if [ $iopt -gt 1 ]
then
       erreur "options -z and -no-z are mutually exclusive!";
       exit 1;
elif [ $mode == "dvips" -o $mode == "ps2pdf" ]
then
       if [ $iopt -eq 1 ]
       then
               # ligne de commande
               if [ $L_z -eq 1 ]
               then
                       z=1;
               else
                       z=0;
               fi
       else
               # pr�f�rences
               if [ $P_z -eq 1 ]
               then
                       z=1;
               else
                       z=0;
               fi
       fi
elif [ $iopt -eq 1 ]
then
       avertissement "option -z ignored -- option -z doesn't concern PostScript files!";
fi
# 1, 2, 4
verifInit $L_un $L_deux $L_quatre;
iopt=$?;
if [ $iopt -gt 1 ]
then
       erreur "options -1, -2 and -4 are mutually exclusive!";
       exit 1;
elif [ $mode == "dvips" -o $mode == "ps2pdf" ]
then
       if [ $iopt -eq 1 ]
       then
               # ligne de commande
               if [ $L_un -eq 1 ]
               then
                       ppf=1;
               elif [ $L_deux -eq 1 ]
               then
                       ppf=2;
               else
                       ppf=4;
               fi
       else
               # pr�f�rences
               if [ $P_un -eq 1 ]
               then
                       ppf=1;
               elif [ $P_deux -eq 1 ]
               then
                       ppf=2;
               else
                       ppf=4;
               fi
       fi
elif [ $iopt -eq 1 ]
then
       if [ $L_un -eq 1 ]
       then
               avertissement "option -1 ignored -- options -1, -2 and -4 only concern PostScript files!";
       elif [ $L_deux -eq 1 ]
       then
               avertissement "option -2 ignored -- options -1, -2 and -4 only concern PostScript files!";
       else
               avertissement "option -4 ignored -- options -1, -2 and -4 only concern PostScript files!";
       fi
fi
# separator
verifInit $L_sep $L_no_sep;
iopt=$?;
if [ $iopt -gt 1 ]
then
       erreur "options -sep and -no-sep are mutually exclusive!";
       exit 1;
elif [ $ppf -gt 1 ]
then
       if [ $iopt -eq 1 ]
       then
               # ligne de commande
               if [ $L_sep -eq 1 ]
               then
                       sep=1;
               else
                       sep=0;
               fi
       else
               # pr�f�rences
               if [ $P_sep -eq 1 ]
               then
                       sep=1;
               else
                       sep=0;
               fi
       fi
elif [ $iopt -eq 1 ]
then
       avertissement "option -sep ignored -- option -sep must be used with options -2 and -4!";
fi
# messages
verifInit $L_m $L_no_m;
iopt=$?;
if [ $iopt -gt 1 ]
then
       erreur "options -m and -no-m are mutually exclusive!";
       exit 1;
elif [ $iopt -eq 1 ]
then
       # ligne de commande
       if [ $L_m -eq 1 ]
       then
               m=1;
       else
               m=0;
       fi
else
       # pr�f�rences
       if [ $P_m -eq 1 ]
       then
               m=1;
       else
               m=0;
       fi
fi
# view
verifInit $L_view $L_no_view;
iopt=$?;
if [ $iopt -gt 1 ]
then
       erreur "options -view and -no-view are mutually exclusive!";
       exit 1;
elif [ $iopt -eq 1 ]
then
       # ligne de commande
       if [ $L_view -eq 1 ]
       then
               view=1;
       else
               view=0;
       fi
else
       # pr�f�rences
       if [ $P_view -eq 1 ]
       then
               view=1;
       else
               view=0;
       fi
fi
# 7, 8
verifInit $L_sept $L_huit;
iopt=$?;
if [ $iopt -gt 1 ]
then
       erreur "options -7 and -8 are mutually exclusive!";
       exit 1;
elif [ $iopt -eq 1 ]
then
       # ligne de commande
       if [ $L_sept -eq 1 ]
       then
               ascii=7;
       else
               ascii=8;
       fi
else
       # pr�f�rences
       if [ $P_sept -eq 1 ]
       then
               ascii=7;
       else
               ascii=8;
       fi
fi
# v_dvi
if [ ! $L_v_dvi == "-" ]
then
       # lige de commande
       v_dvi=$L_v_dvi;
elif [ ! $P_v_dvi == "-" ]
then
       # pr�f�rences
       v_dvi=$P_v_dvi;
fi
# v_ps
if [ ! $L_v_ps == "-" ]
then
       # lige de commande
       v_ps=$L_v_ps;
elif [ ! $P_v_ps == "-" ]
then
       # pr�f�rences
       v_ps=$P_v_ps;
fi
# v_pdf
if [ ! $L_v_pdf == "-" ]
then
       # lige de commande
       v_pdf=$L_v_pdf;
elif [ ! $P_v_pdf == "-" ]
then
       # pr�f�rences
       v_pdf=$P_v_pdf;
fi


## test de l'existance du fichier de bibliographie
if [ $bib -eq 1 -a $bib_file == "-" ]
then
       if [ ! -f "$f".bib ]
       then
               erreur "you have used option -bib and the file \"$f.bib\" doesn't exists!" -?;
               exit 1;
       fi
fi


## affichage d'un petit message de version
echo -ne "\n$nomshell version $version - LaTeX compilation script for Linux.\nCopyright (C) 2003 Mael Hill�reau\n\n";


## cr�ation d'un r�pertoire de travail
if [ ! -d "$f".ShLaTeX ]
then
       mkdir "$f".ShLaTeX
fi


## recherche (non r�cursive) des fichiers externes
fichiersExternes $fich


## copie du fichier latex source principal
cp "$f".tex "$f".ShLaTeX

## copie des fichiers latex source externes
fExtTmp="";
for fe in $fExt
do
       if [ -f "$fe".tex ]
       then
               cp "$fe".tex "$f".ShLaTeX
               # �limination du chemin relatif dans le fichier source
               sansChemin=`expr match "/$fe" '.*/\(.*\)'`;
               rplcExtFich "$fe.tex" "$sansChemin.tex" "$f".ShLaTeX/"$f".tex
               fExtTmp="$sansChemin $fExtTmp";
       else
               avertissement "the external file \"$fe.tex\" referenced in \"$fich\" is unavailable!";
       fi
done
fExt=$fExtTmp;

## copie du fichier de bibliographie
if [ $bib -eq 1 ]
then
       if [ $bib_file == "-" ]
       then
               bib_file=$f;
       fi
       cp "$bib_file".bib "$f".ShLaTeX
fi

## copie du fichier de style d'index
if [ ! $idx_file == "-" ]
then
       if [ -f $idx_file ]
       then
               cp $idx_file "$f".ShLaTeX
       fi
fi

## on passe dans le r�pertoire de travail
cd "$f".ShLaTeX

## accentuation
if [ $ascii -eq 8 ]
then
       ## accentuation du fichier latex source
       echo "> Stressing in progress...";
       echo -ne "<$fich>"
       tex8to7 $fich > /dev/null 2>&1

       ## �crasement du fichier latex source
       mv -f "$fich"7 $fich

       ## accentuation et �crasement des fichier latex source externes
       for fe in $fExt
       do
               if [ -f "$fe".tex ]
               then
                       echo -ne "<$fe.tex>"
                       tex8to7 "$fe".tex > /dev/null 2>&1
                       mv -f "$fe".tex7 "$fe".tex
               fi
       done
       echo ""
fi

## compilation du fichier latex source accuentu�
echo "> Begining latex compilation...";
reslatex=0;
echo "> Compilation (ShLaTeX)" >latex.log
if [ ! $mode == "pdflatex" ]
then
       if [ $m -eq 1 ]
       then
               latex $fich
       else
               latex $fich >>latex.log 2>&1
       fi
       reslatex=$?;
else
       if [ $m -eq 1 ]
       then
               pdflatex $fich
       else
               pdflatex $fich >>latex.log 2>&1
       fi
       reslatex=$?;
fi
if [ $reslatex -ne 0 ]
then
       errcompil=1;
else
       echo "first compilation successfull.";
fi

## cr�ation de la biliographie et deuxi�me compilation
if [ $bib -eq 1 -a $errcompil -ne 1 ]
then
       echo "> Creation of the bibliography...";
       bib_file=`expr match "/$bib_file" '.*/\(.*\)'`;
       if [ $ascii -eq 8 ]
       then
               echo "> Stressing the file \""$bib_file".bib\"...";
               tex8to7 "$bib_file".bib > /dev/null 2>&1
               echo "<$bib_file.bib>"
               mv -f "$bib_file".bib7 "$bib_file".bib
       fi
       bibtex "$f" > bibtex.log 2>&1
       if [ $? -eq 0 ]
       then
               if [ ! $mode == "pdflatex" ]
               then
                       echo "> Compilation (ShLaTeX)" >>latex.log
                       latex $fich >>latex.log 2>&1
                       reslatex=$?;
               else
                       echo "> Compilation (ShLaTeX)" >>latex.log
                       pdflatex $fich >>latex.log 2>&1
                       reslatex=$?;
               fi
               if [ $reslatex -ne 0 ]
               then
                       errcompil=1;
               else
                       echo "second compilation successfull.";
               fi
       else
               echo -ne "\n";
               cat bibtex.log
               erreur "problem while creating the bibliography!";
               errbib=1;
       fi
fi

## cr�ation d'un index
if [ $idx -eq 1 -a $errcompil -ne 1 -a $errbib -ne 1 ]
then
       echo "> Creation of the index...";
       if [ $idx_file == "-" ]
       then
               makeindex "$f".idx > makeindex.log 2>&1
       else
               makeindex -s $idx_file "$f".idx > makeindex.log 2>&1
       fi
       if [ $? -ne 0 ]
       then
               echo -ne "\n";
               cat makeindex.log
               cat "$f".ilg 2>/dev/null
               erreur "problem while creating the index!";
               errindex=1;
       else
               errindex=0;
               echo "index successfully created.";
       fi
fi

## deuxi�me ou troisi�me compilation pour l'index et la table des mati�res
if [ $toc -eq 1 -a $errbib -ne 1 -a $errindex -ne 1 -a $errcompil -ne 1 ]
then
       if [ ! $mode == "pdflatex" ]
       then
               echo "> Compilation (ShLaTeX)" >>latex.log
               latex $fich >>latex.log 2>&1
               reslatex=$?;
       else
               echo "> Compilation (ShLaTeX)" >>latex.log
               pdflatex $fich >>latex.log 2>&1
               reslatex=$?;
       fi
       if [ $reslatex -ne 0 ]
       then
               errcompil=1;
       else
               if [ $bib -eq 1 ]
               then
                       echo "third compilation successfull.";
               else
                       echo "second compilation successfull.";
               fi
       fi
fi

## d�placement du fichier dvi ou pdf
if [ $mode == "pdflatex" ]
then
       mv "$f".pdf ..
else
       mv "$f".dvi ..
fi

## on sort du r�pertoire de travail
cd ..

## conversion du fichier dvi
errconvert=0;
if [ $errbib -ne 1 -a $errindex -ne 1 -a $errcompil -ne 1 -a ! $mode == "pdflatex" -a ! $mode == "dvi" ]
then
       echo "> Conversion in progress...";
       if [ $mode == "dvipdf" ]
       then
               dvipdf "$f".dvi "$f".pdf >> ./"$f".ShLaTeX/dvipdf.log 2>&1
               if [ $? -ne 0 ]
               then
                       echo -ne "\n";
                       cat ./"$f".ShLaTeX/dvipdf.log
                       erreur "problem while converting in PDF!";
                       errconvert=1;
               fi
       elif [ $mode == "dvips" -o $mode == "ps2pdf" ]
       then
               dvips -Ppdf "$f".dvi -o "$f".ps >> ./"$f".ShLaTeX/dvips.log 2>&1
               if [ $? -ne 0 ]
               then
                       echo -ne "\n";
                       cat ./"$f".ShLaTeX/dvips.log
                       erreur "problem while converting in PostScript!";
                       errconvert=1;
               fi
               if [ $errconvert -ne 1 ]
               then
                       optpstops="";
                       if [ $sep -eq 1 ]
                       then
                               optpstops="-d";
                       fi
                       if [ $ppf -eq 2 ]
                       then
                               pstops $optpstops "2:[email protected](21cm,0cm)[email protected](21cm,14.85cm)" "$f".ps "$f".2ppf.ps >/dev/null 2>&1
                               mv "$f".2ppf.ps "$f".ps
                       elif [ $ppf -eq 4 ]
                       then
                               pstops $optpstops "4:[email protected](0cm,14.85cm)[email protected](10.5cm,14.85cm)[email protected](0cm,0cm)[email protected](10.5cm,0cm)" "$f".ps "$f".4ppf.ps >/dev/null 2>&1
                               mv "$f".4ppf.ps "$f".ps
                       fi
                       if [ $mode == "ps2pdf" ]
                       then
                               ps2pdf "$f".ps "$f".pdf >> ./"$f".ShLaTeX/ps2pdf.log 2>&1
                               if [ $? -ne 0 ]
                               then
                                       echo -ne "\n";
                                       cat ./"$f".ShLaTeX/ps2pdf.log
                                       erreur "problem while converting in PDF!";
                                       errconvert=1;
                               fi
                       fi
                       if [ $z -eq 1 ]
                       then
                               rm -f "$f".ps.gz
                               gzip "$f".ps > /dev/null 2>&1
                       fi
               fi
       fi
       rm -f "$f".dvi
fi

## visualisation du fichier dvi, ps ou pdf
if [ $errconvert -ne 1 -a $errbib -ne 1 -a $errindex -ne 1 -a $errcompil -ne 1 -a $view -eq 1 ]
then
       echo "> Launching viewer.";
       case $mode in
               "dvi" )
                       $v_dvi "$f".dvi >/dev/null 2>&1 & ;;
               "dvips" )
                       if [ $z -eq 1 ]
                       then
                               $v_ps "$f".ps.gz >/dev/null 2>&1 &
                       else
                               $v_ps "$f".ps >/dev/null 2>&1 &
                       fi ;;
               "ps2pdf" | "dvipdf" | "pdflatex" )
                       $v_pdf "$f".pdf >/dev/null 2>&1 & ;;
       esac
fi

## affichage des messages d'erreur de compilation
if [ $errcompil -eq 1 ]
then
       if [ $m -eq 0 ]
       then
               echo -ne "\n";
               cat ./"$f".ShLaTeX/latex.log
       fi
       erreur "problem during compilation!";
fi

## suppression des temporaires et sortie
suppressionTemp;
fin;