summaryrefslogtreecommitdiff
path: root/support/shlatex/en/ShLaTeX
blob: f0ea2855d90fba96f265ea3b307575146c2e1283 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
#!/bin/bash
###############################################################################
#                                                                             #
#                                  ShLaTeX                                    #
#                                                                             #
###############################################################################
#                                                                             #
# Author:           Mael Hilléreau                                            #
# Mail:             mael.hillereau@free.fr                                    #
# 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 : mael.hillereau@free.fr
.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:0L@.7(21cm,0cm)+1L@.7(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:0@.5(0cm,14.85cm)+1@.5(10.5cm,14.85cm)+2@.5(0cm,0cm)+3@.5(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;