forked from latex2html/latex2html
-
Notifications
You must be signed in to change notification settings - Fork 0
/
latex2html.pin
executable file
·18215 lines (16455 loc) · 612 KB
/
latex2html.pin
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
#- -*- perl -*-
#
# Comprises patches and revisions by various authors:
# See Changes, the log file of LaTeX2HTML.
#
# Original Copyright notice:
#
# LaTeX2HTML by Nikos Drakos <[email protected]>
# ****************************************************************
# LaTeX To HTML Translation **************************************
# ****************************************************************
# LaTeX2HTML is a Perl program that translates LaTeX source
# files into HTML (HyperText Markup Language). For each source
# file given as an argument the translator will create a
# directory containing the corresponding HTML files.
#
# The man page for this program is included at the end of this file
# and can be viewed using "perldoc latex2html"
#
# For more information on this program and some examples of its
# capabilities visit
#
# http://www.latex2html.org/
#
# or see the accompanying documentation in the docs/ directory
#
# Original code written by Nikos Drakos, July 1993.
#
# Address: Computer Based Learning Unit
# University of Leeds
# Leeds, LS2 9JT
#
# Copyright (c) 1993-95. All rights reserved.
#
#
# Extensively modified by Ross Moore, Herb Swan and others
#
# Address: Mathematics Department
# Macquarie University
# Sydney, Australia, 2109
#
# Copyright (c) 1996-2001. All rights reserved.
#
# See general license in the LICENSE file.
#
##########################################################################
use 5.003; # refuse to work with old and buggy perl version
#use strict;
#use diagnostics;
# include some perl packages; these come with the standard distribution
use Getopt::Long;
use Fcntl;
use AnyDBM_File;
use POSIX; # for ceil()
use Encode qw(decode_utf8 encode_utf8); # for russian UTF-8 hack
# The following are global variables that also appear in some modules
use vars qw($LATEX2HTMLDIR $LATEX2HTMLPLATDIR $SCRIPT
%Month %used_icons $inside_tabbing $TABLE_attribs
%mathentities $date_name $outer_math $TABLE__CELLPADDING_rx);
#- NOTE: This file contains a sort of preprocessor information, similar
#- to C's #define statement, so please be careful when removing comments!
#-
#- The (texlive) wrapper sets these values
#- or it is stored in the enviroment
#-
#unless @wrapper@ || @texlive@
BEGIN {
# print "scanning for l2hdir\n";
if($ENV{'LATEX2HTMLDIR'}) {
$LATEX2HTMLDIR = $ENV{'LATEX2HTMLDIR'};
} else {
$ENV{'LATEX2HTMLDIR'} = $LATEX2HTMLDIR = '@LATEX2HTMLDIR@';
}
if($ENV{'LATEX2HTMLPLATDIR'}) {
$LATEX2HTMLPLATDIR = $ENV{'LATEX2HTMLPLATDIR'};
} else {
$LATEX2HTMLPLATDIR = '@LATEX2HTMLPLATDIR@'||$LATEX2HTMLDIR;
$ENV{'LATEX2HTMLPLATDIR'} = $LATEX2HTMLPLATDIR;
}
if(-d $LATEX2HTMLPLATDIR) {
push(@INC,$LATEX2HTMLPLATDIR);
}
if(-d $LATEX2HTMLDIR) {
push(@INC,$LATEX2HTMLDIR);
} else {
die qq{Fatal: Directory "$LATEX2HTMLDIR" does not exist.\n};
}
}
#fi
use L2hos; # Operating system dependent routines
# $^W = 1; # turn on warnings
my $RELEASE = '@distver@';
my $REVISION = '@release_date@';
# The key, which delimts expressions defined in the environment
# depends on the operating system.
$envkey = L2hos->pathd();
# $dd is the directory delimiter character
$dd = L2hos->dd();
# make sure the $LATEX2HTMLDIR is on the search-path for forked processes
if($ENV{'PERL5LIB'}) {
$ENV{'PERL5LIB'} .= "$envkey$LATEX2HTMLDIR"
unless($ENV{'PERL5LIB'} =~ m|\Q$LATEX2HTMLDIR\E|o);
} else {
$ENV{'PERL5LIB'} = $LATEX2HTMLDIR;
}
# Local configuration, read at runtime
# Read the $CONFIG_FILE (usually l2hconf.pm )
if($ENV{'L2HCONFIG'}) {
require $ENV{'L2HCONFIG'} ||
die "Fatal (require $ENV{'L2HCONFIG'}): $!";
} else {
eval 'use l2hconf';
if($@) {
die "Fatal (use l2hconf): $@\n";
}
}
# MRO: Changed this to global value in config/config.pl
# change these whenever you do a patch to this program and then
# name the resulting patch file accordingly
# $TVERSION = "@distver@";
#$TPATCHLEVEL = " beta";
#$TPATCHLEVEL = " release";
#$RELDATE = "(March 30, 1999)";
#$TEX2HTMLV_SHORT = $TVERSION . $TPATCHLEVEL;
$TEX2HTMLV_SHORT = $RELEASE;
$TEX2HTMLVERSION = "$TEX2HTMLV_SHORT ($REVISION)";
$TEX2HTMLADDRESS = "http://www.latex2html.org/";
# Set $HOME to what the system considers the home directory
$HOME = L2hos->home();
push(@INC,$HOME);
# flush stdout with every print -- gives better feedback during
# long computations
$| = 1;
# set Perl's subscript separator to LaTeX's illegal character.
# (quite defensive but why not)
$; = "\000";
# No arguments!!
unless(@ARGV) {
die "Error: No files to process!\n";
}
# Image prefix
#if @texlive@
$IMAGE_PREFIX = L2hos->plat() eq 'dos' ? 'ps' : '_image';
#else
#if @plat@ eq 'dos'
$IMAGE_PREFIX = 'ps';
#else
$IMAGE_PREFIX = '_image';
#fi
#fi - texlive
# Partition prefix
$PARTITION_PREFIX = 'part_' unless $PARTITION_PREFIX;
# Author address - contains user name and date - not used by default
@address_data = &address_data('ISO');
$ADDRESS = "";
# ensure non-zero defaults
$MAX_SPLIT_DEPTH = 4 unless ($MAX_SPLIT_DEPTH);
$MAX_LINK_DEPTH = 4 unless ($MAX_LINK_DEPTH);
$TOC_DEPTH = 4 unless ($TOC_DEPTH);
# A global value may already be set in the $CONFIG_FILE
$INIT_FILE_NAME = $ENV{'L2HINIT_NAME'} || '.latex2html-init'
unless $INIT_FILE_NAME;
# Read the $HOME/$INIT_FILE_NAME if one is found
if (-f "$HOME$dd$INIT_FILE_NAME" && -r _) {
print "Note: Loading $HOME$dd$INIT_FILE_NAME\n";
require("$HOME$dd$INIT_FILE_NAME");
$INIT_FILE = "$HOME$dd$INIT_FILE_NAME";
# _MRO_TODO_: Introduce a version to be checked?
die "Error: You have an out-of-date " . $HOME .
"$dd$INIT_FILE_NAME file.\nPlease update or delete it.\n"
if ($DESTDIR eq '.');
}
# Read the $INIT_FILE_NAME file if one is found in current directory
if ( L2hos->Cwd() ne $HOME && -f ".$dd$INIT_FILE_NAME" && -r _) {
$INIT_FILE = ".$dd$INIT_FILE_NAME";
print "Note: Loading $INIT_FILE\n";
require($INIT_FILE);
}
die "Error: '.' is an incorrect setting for DESTDIR.\n" .
"Please check your $INIT_FILE_NAME file.\n"
if ($DESTDIR eq '.');
# User home substitutions
$LATEX2HTMLSTYLES =~ s/~([$dd$dd$envkey]|$)/$HOME$1/go;
# the next line fails utterly on non-UNIX systems
$LATEX2HTMLSTYLES =~ s/~([^$dd$dd$envkey]+)/L2hos->home($1)/geo;
#absolutise the paths
$LATEX2HTMLSTYLES = join($envkey,
map(L2hos->Make_directory_absolute($_),
split(/$envkey/o, $LATEX2HTMLSTYLES)));
#HWS: That was the last reference to HOME. Now set HOME to $LATEX2HTMLDIR,
# to enable dvips to see that version of .dvipsrc! But only if we
# have DVIPS_MODE not set - yes - this is a horrible nasty kludge
# MRO: The file has to be updated by configure _MRO_TODO_
if ($PK_GENERATION && ! $DVIPS_MODE) {
$ENV{HOME} = $LATEX2HTMLDIR;
delete $ENV{PRINTER}; # Overrides .dvipsrc
}
# language of the DTD specified in the <DOCTYPE...> tag
$ISO_LANGUAGE = 'en' unless $ISO_LANGUAGE;
# Save the command line arguments, quote where necessary
$argv = join(' ', map {/[\s#*!\$%]/ ? "'$_'" : $_ } @ARGV);
# Pre-process the command line for backward compatibility
foreach(@ARGV) {
s/^--?no_/-no/; # replace e.g. no_fork by nofork
# s/^[+](\d+)$/$1/; # remove + in front of integers
}
# Process command line options
my %opt;
unless(GetOptions(\%opt, # all non-linked options go into %opt
# option linkage (optional)
'help|h',
'version|V',
'split=s',
'link=s',
'toc_depth=i', \$TOC_DEPTH,
'toc_stars!', \$TOC_STARS,
'short_extn!', \$SHORTEXTN,
'iso_language=s', \$ISO_LANGUAGE,
'validate!', \$HTML_VALIDATE,
'latex!',
'djgpp!', \$DJGPP,
'fork!', \$CAN_FORK,
'external_images!', \$EXTERNAL_IMAGES,
'ascii_mode!', \$ASCII_MODE,
'lcase_tags!', \$LOWER_CASE_TAGS,
'ps_images!', \$PS_IMAGES,
'font_size=s', \$FONT_SIZE,
'tex_defs!', \$TEXDEFS,
'navigation!',
'top_navigation!', \$TOP_NAVIGATION,
'bottom_navigation!', \$BOTTOM_NAVIGATION,
'auto_navigation!', \$AUTO_NAVIGATION,
'index_in_navigation!', \$INDEX_IN_NAVIGATION,
'contents_in_navigation!', \$CONTENTS_IN_NAVIGATION,
'next_page_in_navigation!', \$NEXT_PAGE_IN_NAVIGATION,
'previous_page_in_navigation!', \$PREVIOUS_PAGE_IN_NAVIGATION,
'footnode!',
'numbered_footnotes!', \$NUMBERED_FOOTNOTES,
'prefix=s', \$PREFIX,
'auto_prefix!', \$AUTO_PREFIX,
'long_titles=i', \$LONG_TITLES,
'custom_titles!', \$CUSTOM_TITLES,
'title|t=s', \$TITLE,
'rooted!', \$ROOTED,
'rootdir=s',
'dir=s', \$FIXEDDIR,
'mkdir', \$MKDIR,
'use_dvipng!', \$USE_DVIPNG,
'dvipng_dpi=s', \$DVIPNG_DPI,
'use_pdftex!', \$USE_PDFTEX,
'use_luatex!', \$USE_LUATEX,
'use_luadvi!', \$USE_LUADVI,
'address=s', \$ADDRESS,
'noaddress',
'subdir!',
'info=s', \$INFO,
'noinfo',
'auto_link!',
'reuse=i', \$REUSE,
'noreuse',
'antialias_text!', \$ANTI_ALIAS_TEXT,
'antialias!', \$ANTI_ALIAS,
'transparent!', \$TRANSPARENT_FIGURES,
'white!', \$WHITE_BACKGROUND,
'discard!', \$DISCARD_PS,
'image_type=s', \$IMAGE_TYPE,
'images!',
'accent_images=s', \$ACCENT_IMAGES,
'noaccent_images',
'style=s', \$STYLESHEET,
'parbox_images!',
'math!',
'math_parsing!',
'latin!',
'entities!', \$USE_ENTITY_NAMES,
'local_icons!', \$LOCAL_ICONS,
'scalable_fonts!', \$SCALABLE_FONTS,
'images_only!', \$IMAGES_ONLY,
'cut_ref_num!', \$CUT_REF_NUM,
'add_ref_name!', \$ADD_REF_NAME,
'show_section_numbers!',\$SHOW_SECTION_NUMBERS,
'show_init!', \$SHOW_INIT_FILE,
'init_file=s', \$INIT_FILE,
'up_url=s', \$EXTERNAL_UP_LINK,
'up_title=s', \$EXTERNAL_UP_TITLE,
'down_url=s', \$EXTERNAL_DOWN_LINK,
'down_title=s', \$EXTERNAL_DOWN_TITLE,
'prev_url=s', \$EXTERNAL_PREV_LINK,
'prev_title=s', \$EXTERNAL_PREV_TITLE,
'index=s', \$EXTERNAL_INDEX,
'biblio=s', \$EXTERNAL_BIBLIO,
'contents=s', \$EXTERNAL_CONTENTS,
'external_file=s', \$EXTERNAL_FILE,
'short_index!', \$SHORT_INDEX,
'unsegment!', \$UNSEGMENT,
'debug!', \$DEBUG,
'tmp=s', \$TMP,
'ldump!', \$LATEX_DUMP,
'timing!', \$TIMING,
'verbosity=i', \$VERBOSITY,
'html_version=s', \$HTML_VERSION,
'strict!', \$STRICT_HTML,
'xbit!', \$XBIT_HACK,
'ssi!', \$ALLOW_SSI,
'php!', \$ALLOW_PHP,
'test_mode!' # undocumented switch
)) {
&usage();
exit 1;
}
# interpret options, check option consistency
if(defined $opt{'split'}) {
if ($opt{'split'} =~ /^(\+?)(\d+)$/) {
$MAX_SPLIT_DEPTH = $2;
if ($1) { $MAX_SPLIT_DEPTH *= -1; $REL_DEPTH = 1; }
} else {
&usage;
die "Error: Unrecognised value for -split: $opt{'split'}\n";
}
}
if(defined $opt{'link'}) {
if ($opt{'link'} =~ /^(\+?)(\d+)$/) {
$MAX_LINK_DEPTH = $2;
if ($1) { $MAX_LINK_DEPTH *= -1 }
} else {
&usage;
die "Error: Unrecognised value for -link: $opt{'link'}\n";
}
}
if ($HTML_VALIDATE && !$HTML_VALIDATOR) {
die "Error: Need a HTML_VALIDATOR when -validate is specified.\n";
}
&set_if_false($NOLATEX,$opt{latex}); # negate the option...
if ($ASCII_MODE || $PS_IMAGES) {
$EXTERNAL_IMAGES = 1;
}
if ($FONT_SIZE && $FONT_SIZE !~ /^\d+pt$/) {
die "Error: Font size (-font_size) must end with 'pt': $FONT_SIZE\n"
}
&set_if_false($NO_NAVIGATION,$opt{navigation});
&set_if_false($NO_FOOTNODE,$opt{footnode});
if (defined $TITLE && !length($TITLE)) {
die "Error: Empty title (-title).\n";
}
$LONG_LINKPOINT = $TITLE if (defined $TITLE && $LONG_TITLES && $LINKPOINT);
if ($opt{rootdir}) {
$ROOTED = 1;
$FIXEDDIR = $opt{rootdir};
}
if ($FIXEDDIR && !-d $FIXEDDIR) {
if ($MKDIR) {
print "\n *** creating directory: $FIXEDDIR ";
die "Failed: $!\n" unless (mkdir($FIXEDDIR, 0755));
# _TODO_ use File::Path to create a series of directories
} else {
&usage;
die "Error: Specified directory (-rootdir, -dir) does not exist.\n";
}
}
&set_if_false($NO_SUBDIR, $opt{subdir});
&set_if_false($NO_AUTO_LINK, $opt{auto_link});
if ($opt{noreuse}) {
$REUSE = 0;
}
unless(grep(/^\Q$IMAGE_TYPE\E$/o, @IMAGE_TYPES)) {
die <<"EOF";
Error: No such image type '$IMAGE_TYPE'.
This installation supports (first is default): @IMAGE_TYPES
EOF
}
&set_if_false($NO_IMAGES, $opt{images});
if ($opt{noaccent_images}) {
$ACCENT_IMAGES = '';
}
if($opt{noaddress}) {
$ADDRESS = '';
}
if($opt{noinfo}) {
$INFO = 0;
}
if($ACCENT_IMAGES && $ACCENT_IMAGES !~ /^[a-zA-Z,]+$/) {
die "Error: Single word or comma-list of style words needed for -accent_images, not: $_\n";
}
&set_if_false($NO_PARBOX_IMAGES, $opt{parbox_images});
&set_if_false($NO_SIMPLE_MATH, $opt{math});
if (defined $opt{math_parsing}) {
$NO_MATH_PARSING = !$opt{math_parsing};
$NO_SIMPLE_MATH = !$opt{math_parsing} unless(defined $opt{math});
}
&set_if_false($NO_ISOLATIN, $opt{latin});
if ($INIT_FILE) {
# if ($INIT_FILE !~ /^[.$dd$dd]/) { # should start with / or .
# 2019-12-18 shige: 2-43)
if ($INIT_FILE !~ /^\./ && !L2hos->is_absolute_path($INIT_FILE)) {
$INIT_FILE = ".$dd$INIT_FILE"; # so that value of @INC has no effect
}
if (-f $INIT_FILE && -r _) {
print "Note: Initialising with file: $INIT_FILE\n"
if ($DEBUG || $VERBOSITY);
require($INIT_FILE);
} else {
die "Error: Could not find file (-init_file): $INIT_FILE\n";
}
}
foreach($EXTERNAL_UP_LINK, $EXTERNAL_DOWN_LINK, $EXTERNAL_PREV_LINK,
$EXTERNAL_INDEX, $EXTERNAL_BIBLIO, $EXTERNAL_CONTENTS) {
$_ ||= ''; # initialize
s/~/~/g; # protect `~'
}
if($TMP && !(-d $TMP && -w _)) {
die "Error: '$TMP' not usable as temporary directory.\n";
}
if ($opt{help}) {
L2hos->perldoc($SCRIPT);
exit 0;
}
if ($opt{version}) {
&banner();
exit 0;
}
if ($opt{test_mode}) {
$TITLE = 'LaTeX2HTML Test Document';
$TEXEXPAND = "$PERL @srcdir@${dd}texexpand@scriptext@";
$PSTOIMG = "$PERL @srcdir@${dd}pstoimg@scriptext@";
$ICONSERVER = L2hos->path2URL("@srcdir@${dd}icons");
$TEST_MODE = 1;
$RGBCOLORFILE = "@srcdir@${dd}styles${dd}rgb.txt";
$CRAYOLAFILE = "@srcdir@${dd}styles${dd}crayola.txt";
}
if (!$ICONSERVER) { # if we don't have a url to find icons on the web,
$LOCAL_ICONS = 1; # copy them into the directory for this document
}
if($DEBUG) {
# make the OS-dependent functions more chatty, too
$L2hos::Verbose = 1;
}
undef %opt; # not needed any more
#unless @have_images@
print "Warning: This system does not support generation of images\n"
unless($NO_IMAGES);
$NO_IMAGES = 1;
#fi
$FIXEDDIR = $FIXEDDIR || $DESTDIR || ''; # for backward compatibility
if ($EXTERNAL_UP_TITLE xor $EXTERNAL_UP_LINK) {
warn "Warning (-up_url, -up_title): Need to specify both a parent URL and a parent title!\n";
$EXTERNAL_UP_TITLE = $EXTERNAL_UP_LINK = "";
}
if ($EXTERNAL_DOWN_TITLE xor $EXTERNAL_DOWN_LINK) {
warn "Warning (-down_url, -down_title): Need to specify both a parent URL and a parent title!\n";
$EXTERNAL_DOWN_TITLE = $EXTERNAL_DOWN_LINK = "";
}
# $NO_NAVIGATION = 1 unless $MAX_SPLIT_DEPTH; # Martin Wilck
if ($MAX_SPLIT_DEPTH && $MAX_SPLIT_DEPTH < 0) {
$MAX_SPLIT_DEPTH *= -1; $REL_DEPTH = 1;
}
if ($MAX_LINK_DEPTH && $MAX_LINK_DEPTH < 0) {
$MAX_LINK_DEPTH *= -1; $LEAF_LINKS = 1;
}
$FOOT_FILENAME = 'footnode' unless ($FOOT_FILENAME);
$NO_FOOTNODE = 1 unless ($MAX_SPLIT_DEPTH || $NO_FOOTNODE);
$NO_SPLIT = 1 unless $MAX_SPLIT_DEPTH; # _MRO_TODO_: is this needed at all?
$SEGMENT = $SEGMENTED = 0;
$NO_MATH_MARKUP = 1;
# specify the filename extension to use with the generated HTML files
if ($SHORTEXTN) { $EXTN = ".htm"; } # for HTML files on CDROM
elsif ($ALLOW_PHP) { $EXTN = ".php"; } # has PHP dynamic includes
# with server-side includes (SSI) :
elsif ($ALLOW_SSI && !$XBIT_HACK) { $EXTN = ".shtml"; }
# ordinary names, valid also for SSI with XBit hack :
else { $EXTN = ".html"; }
$NODE_NAME = 'node' unless (defined $NODE_NAME);
# space for temporary files
# different to the $TMPDIR for image-generation
# MRO: No directory should end with $dd!
$TMP_ = "TMP";
$TMP_PREFIX = "l2h" unless ($TMP_PREFIX);
# This can be set to 1 when using a version of dvips that is safe
# from the "dot-in-name" bug.
# _TODO_ this should be determined by configure
$DVIPS_SAFE = 1;
$CHARSET = $charset || 'utf-8';
# This will be set to 1 by polyglossia.perl to mark its own presence
$POLYGLOSSIA = 0;
$DVIPNG_DPI=200 unless $DVIPNG_DPI;
####################################################################
#
# If possible, use icons of the same type as generated images
#
if ($IMAGE_TYPE && %{"icons_$IMAGE_TYPE"}) {
%icons = %{"icons_$IMAGE_TYPE"};
}
####################################################################
#
# Figure out what options we need to pass to DVIPS and store that in
# the $DVIPSOPT variable. Also, scaling is taken care of at the
# dvips level if PK_GENERATION is set to 1, so adjust SCALE_FACTORs
# accordingly.
#
if ($SCALABLE_FONTS) {
$PK_GENERATION = 0;
$DVIPS_MODE = '';
}
if ($PK_GENERATION) {
if ($MATH_SCALE_FACTOR <= 0) { $MATH_SCALE_FACTOR = 1; }
if ($FIGURE_SCALE_FACTOR <= 0) { $FIGURE_SCALE_FACTOR = 1; }
my $saveMSF = $MATH_SCALE_FACTOR;
my $saveFSF = $FIGURE_SCALE_FACTOR;
my $desired_dpi = int($MATH_SCALE_FACTOR*75);
$FIGURE_SCALE_FACTOR = ($METAFONT_DPI / 72) *
($FIGURE_SCALE_FACTOR / $MATH_SCALE_FACTOR) ;
$MATH_SCALE_FACTOR = $METAFONT_DPI / 72;
$dvi_mag = int(1000 * $desired_dpi / $METAFONT_DPI);
if ($dvi_mag > 1000) {
&write_warnings(
"WARNING: Your SCALE FACTOR is too large for PK_GENERATION.\n" .
" See $CONFIG_FILE for more information.\n");
}
# RRM: over-sized scaling, using dvi-magnification
if ($EXTRA_IMAGE_SCALE) {
print "\n *** Images at $EXTRA_IMAGE_SCALE times resolution of displayed size ***\n";
$desired_dpi = int($EXTRA_IMAGE_SCALE * $desired_dpi+.5);
print " desired_dpi = $desired_dpi METAFONT_DPI = $METAFONT_DPI\n"
if $DEBUG;
$dvi_mag = int(1000 * $desired_dpi / $METAFONT_DPI);
$MATH_SCALE_FACTOR = $saveMSF;
$FIGURE_SCALE_FACTOR = $saveFSF;
}
# no space after "-y", "-D", "-e" --- required by DVIPS under DOS !
my $mode_switch = "-mode $DVIPS_MODE" if $DVIPS_MODE;
$DVIPSOPT .= " -y$dvi_mag -D$METAFONT_DPI $mode_switch -e5 ";
} else { # no PK_GENERATION
# if ($EXTRA_IMAGE_SCALE) {
# &write_warnings(
# "the \$EXTRA_IMAGE_SCALE feature requires either \$PK_GENERATION=1"
# . " or the '-scalable_fonts' option");
# $EXTRA_IMAGE_SCALE = '';
# }
# MRO: shifted to l2hconf
#$DVIPSOPT .= ' -M';
} # end PK_GENERATION
# The mapping from numbers to accents.
# These are required to process the \accent command, which is found in
# tables of contents whenever there is an accented character in a
# caption or section title. Processing the \accent command makes
# $encoded_*_number work properly (see &extract_captions) with
# captions that contain accented characters.
# I got the numbers from the plain.tex file, version 3.141.
# Missing entries should be looked up by a native speaker.
# Have a look at generate_accent_commands and $iso_8859_1_character_map.
# MEH: added more accent types
# MRO: only uppercase needed!
%accent_type = (
'18' => 'grave', # \`
'19' => 'acute', # `'
'20' => 'caron', # \v
'21' => 'breve', # \u
'22' => 'macr', # \=
'23' => 'ring', #
'24' => 'cedil', # \c
'94' => 'circ', # \^
'95' => 'dot', # \.
'7D' => 'dblac', # \H
'7E' => 'tilde', # \~
'7F' => 'uml', # \"
);
&driver;
exit 0; # clean exit, no errors
############################ Subroutines ##################################
#check that $TMP is writable, if so create a subdirectory
sub make_tmp_dir {
&close_dbm_database if $DJGPP; # to save file-handles
#if @texlive@
$TMP = "$DESTDIR$dd$TMP_";
unless(-d $TMP) {
mkdir($TMP,0755);
}
#fi
# determine a suitable temporary path
#
$TMPDIR = '';
my @tmp_try = ();
push(@tmp_try, $TMP) if($TMP);
push(@tmp_try, "$DESTDIR$dd$TMP_") if($TMP_);
push(@tmp_try, $DESTDIR) if($DESTDIR);
push(@tmp_try, L2hos->Cwd());
my $try;
TempTry: foreach $try (@tmp_try) {
next unless(-d $try && -w _);
my $tmp = "$try$dd$TMP_PREFIX$$";
if(mkdir($tmp,0755)) {
$TMPDIR=$tmp;
last TempTry;
} else {
warn "Warning: Cannot create temporary directory '$tmp': $!\n";
}
}
$dvips_warning = <<"EOF";
Warning: There is a '.' in \$TMPDIR, $DVIPS will probably fail.
Set \$TMP to use a /tmp directory, or rename the working directory.
EOF
die ($dvips_warning . "\n\$TMPDIR=$TMPDIR ***\n\n")
if ($TMPDIR =~ /\./ && $DVIPS =~ /dvips/ && !$DVIPS_SAFE);
&open_dbm_database if $DJGPP;
}
# MRO: set first parameter to the opposite of the second if second parameter is defined
sub set_if_false {
$_[0] = !$_[1] if(defined $_[1]);
}
sub check_for_dots {
local($file) = @_;
if ($file =~ /\.[^.]*\./ && !$DVIPS_SAFE) {
die "\n\n\n *** Fatal Error --- but easy to fix ***\n"
. "\nCannot have '.' in file-name prefix, else dvips fails on images"
. "\nChange the name from $file and try again.\n\n";
}
}
# Process each file ...
sub driver {
local($FILE, $orig_cwd, %unknown_commands, %dependent, %depends_on
, %styleID, %env_style, $bbl_cnt, $dbg, %numbered_section);
# MRO: $texfilepath has to be global!
local(%styles_loaded);
$orig_cwd = L2hos->Cwd();
print "\n *** initialise *** " if ($VERBOSITY > 1);
&initialise; # Initialise some global variables
print "\n *** check modes *** " if ($VERBOSITY > 1);
&ascii_mode if $ASCII_MODE; # Must come after initialization
&titles_language($TITLES_LANGUAGE);
&make_numbered_footnotes if ($NUMBERED_FOOTNOTES);
$dbg = $DEBUG ? "-debug" : "";
$dbg .= (($VERBOSITY>2) ? " -verbose" : "");
#use the same hashes for all files in a batch
local(%cached_env_img, %id_map, %symbolic_labels, %latex_labels)
if ($FIXEDDIR && $NO_SUBDIR);
local($MULTIPLE_FILES,$THIS_FILE);
$MULTIPLE_FILES = 1+$#ARGV if $ROOTED;
print "\n *** $MULTIPLE_FILES file".($MULTIPLE_FILES ? 's: ' : ': ')
. join(',',@ARGV) . " *** " if ($VERBOSITY > 1);
local(%section_info, %toc_section_info, %cite_info, %ref_files);
foreach $FILE (@ARGV) {
&check_for_dots($FILE) unless $DVIPS_SAFE;
++$THIS_FILE if $MULTIPLE_FILES;
do {
%section_info = ();
%toc_section_info = ();
%cite_info = ();
%ref_files = ();
} unless $MULTIPLE_FILES;
local($bbl_nr) = 1;
# The number of reused images and those in images.tex
local($global_page_num) = (0) unless($FIXEDDIR && $NO_SUBDIR);
# The number of images in images.tex
local($new_page_num) = (0); # unless($FIXEDDIR && $NO_SUBDIR);
local($pid, $sections_rx,
, $outermost_level, %latex_body, $latex_body
, %encoded_section_number
, %verbatim, %new_command, %new_environment
, %provide_command, %renew_command, %new_theorem
, $preamble, $aux_preamble, $prelatex, @preamble);
# must retain these when all files are in the same directory
# else the images.pl and labels.pl files get clobbered
unless ($FIXEDDIR && $NO_SUBDIR) {
print "\nResetting image-cache" if ($#ARGV);
local(%cached_env_img, %id_map, %symbolic_labels, %latex_labels)
}
## AYS: Allow extension other than .tex and make it optional
if ($FILE =~ /.*(\.[^\.]*)$/) {
$EXT = $1;
} elsif (-f "$FILE.tex") {
$EXT = ".tex";
$FILE =~ s/$/.tex/;
} else {
$EXT = '';
}
#RRM: allow user-customisation, dependent on file-name
# e.g. add directories to $TEXINPUTS named for the file
# --- idea due to Fred Drake <[email protected]>
&custom_driver_hook($FILE) if (defined &custom_driver_hook);
# JCL(jcl-dir)
# We need absolute paths for TEXINPUTS here, because
# we change the directory
if ($orig_cwd eq $texfilepath) {
&deal_with_texinputs($orig_cwd);
} else {
&deal_with_texinputs($orig_cwd, $texfilepath);
}
($texfilepath, $FILE) = &get_full_path($FILE);
$texfilepath = '.' unless($texfilepath);
die "Cannot read $texfilepath$dd$FILE \n"
unless (-r "$texfilepath$dd$FILE");
# Tell texexpand which files we *don't* want to look at.
$ENV{'TEXE_DONT_INCLUDE'} = $DONT_INCLUDE if $DONT_INCLUDE;
# Tell texexpand which files we *do* want to look at, e.g.
# home-brew style files
$ENV{'TEXE_DO_INCLUDE'} = $DO_INCLUDE if $DO_INCLUDE;
$FILE =~ s/\.[^\.]*$//; ## AYS
$DESTDIR = ''; # start at empty
if ($FIXEDDIR) {
$DESTDIR = $FIXEDDIR unless ($FIXEDDIR eq '.');
if (($ROOTED)&&!($texfilepath eq $orig_cwd)) {
$DESTDIR .= $dd . $FILE unless $NO_SUBDIR;
};
} elsif ($texfilepath eq $orig_cwd) {
$DESTDIR = ($NO_SUBDIR ? '.' : $FILE);
} else {
$DESTDIR = $ROOTED ? '.' : $texfilepath;
$DESTDIR .= $dd . $FILE unless $NO_SUBDIR;
}
$PREFIX = "$FILE-" if $AUTO_PREFIX;
print "\nOPENING $texfilepath$dd$FILE$EXT \n"; ## AYS
next unless (&new_dir($DESTDIR,''));
# establish absolute path to $DESTDIR
$DESTDIR = L2hos->Make_directory_absolute($DESTDIR);
# &make_tmp_dir;
# print "\nNote: Working directory is $DESTDIR\n";
# print "Note: Images will be generated in $TMPDIR\n\n";
# Need to clean up a bit in case there's garbage left
# from former runs.
if ($DESTDIR) { chdir($DESTDIR) || die "$!\n"; }
if (opendir (TMP,$TMP_)) {
foreach (readdir TMP) {
L2hos->Unlink("TMP_$dd$_") unless (/^\.\.?$/);
}
closedir TMP;
}
&cleanup(1);
&make_tmp_dir;
print "\nNote: Working directory is $DESTDIR\n";
print "Note: Images will be generated in $TMPDIR\n\n";
unless(-d $TMP_) {
mkdir($TMP_, 0755) ||
die "Cannot create directory '$TMP_': $!\n";
}
chdir($orig_cwd);
# RRM 14/5/98 moved this to occur earlier
## JCL(jcl-dir)
## We need absolute paths for TEXINPUTS here, because
## we change the directory
# if ($orig_cwd eq $texfilepath) {
# &deal_with_texinputs($orig_cwd);
# } else {
# &deal_with_texinputs($orig_cwd, $texfilepath);
# }
# This needs $DESTDIR to have been created ...
print " *** calling `texexpand' ***" if ($VERBOSITY > 1);
local($unseg) = ($UNSEGMENT ? "-unsegment " : "");
# does DOS need to check these here ?
# die "File $TEXEXPAND does not exist or is not executable\n"
# unless (-x $TEXEXPAND);
L2hos->syswait("$TEXEXPAND $dbg -auto_exclude $unseg"
. "-save_styles \"$DESTDIR$dd$TMP_${dd}styles\" "
. ($TEXINPUTS ? "-texinputs \"$TEXINPUTS\" " : '' )
. (($VERBOSITY >2) ? "-verbose " : '' )
. "-out \"$DESTDIR$dd$TMP_$dd$FILE\" "
. "\"$texfilepath$dd$FILE$EXT\"")
&& die " texexpand failed: $!\n";
print STDOUT "\n *** `texexpand' done ***\n" if ($VERBOSITY > 1);
chdir($DESTDIR) if $DESTDIR;
$SIG{'INT'} = 'handler';
&open_dbm_database;
&initialise_sections;
print STDOUT "\n *** database open ***\n" if ($VERBOSITY > 1);
if ($IMAGES_ONLY) {
&make_off_line_images;
} else {
&rename_image_files;
&load_style_file_translations;
&make_language_rx;
&make_raw_arg_cmd_rx;
# &make_isolatin1_rx unless ($NO_ISOLATIN);
&translate_titles;
&make_sections_rx;
print "\nReading ...";
if ($SHORT_FILENAME) {
L2hos->Rename ("$TMP_$dd$FILE" ,"$TMP_$dd$SHORT_FILENAME" );
&slurp_input_and_partition_and_pre_process(
"$TMP_$dd$SHORT_FILENAME");
} else {
&slurp_input_and_partition_and_pre_process("$TMP_$dd$FILE");
}
&add_preamble_head;
# Create a regular expressions
&set_depth_levels;
&make_sections_rx;
&make_order_sensitive_rx;
&add_document_info_page if ($INFO && !(/\\htmlinfo/));
&add_bbl_and_idx_dummy_commands;
&translate; # Destructive!
}
&style_sheet;
&close_dbm_database;
&cleanup();
#JCL: read warnings from file to $warnings
local($warnings) = &get_warnings;
print "\n\n*********** WARNINGS *********** \n$warnings"
if ($warnings || $NO_IMAGES || $IMAGES_ONLY);
&image_cache_message if ($NO_IMAGES || $IMAGES_ONLY);
&image_message if ($warnings =~ /Failed to convert/io);
undef $warnings;
# JCL - generate directory index entry.
# Yet, a hard link, cause Perl lacks symlink() on some systems.
do {
local($EXTN) = $EXTN;
$EXTN =~ s/_\w+(\.html?)/$1/ if ($frame_main_name);
local($from,$to) = (eval($LINKPOINT),eval($LINKNAME));
$from = &make_long_title($LONG_LINKPOINT) . $EXTN
if ($LONG_TITLES && $LONG_LINKPOINT);
if (length($from) && length($to) && ($from ne $to)) {
#frames may have altered $EXTN
$from =~ s/$frame_main_name(\.html?)/$1/ if ($frame_main_name);
$to =~ s/$frame_main_name(\.html?)/$1/ if ($frame_main_name);
L2hos->Unlink($to);
L2hos->Link($from,$to);
}
} unless ($NO_AUTO_LINK || !($LINKPOINT) || !($LINKNAME));
&html_validate if ($HTML_VALIDATE && $HTML_VALIDATOR);
# Go back to the source directory
chdir($orig_cwd);
$TEST_MODE = $DESTDIR if($TEST_MODE); # save path
$DESTDIR = '';
$OUT_NODE = 0 unless $FIXEDDIR;
$STYLESHEET = '' if ($STYLESHEET =~ /^\Q$FILE./);
}
print "\nUnknown commands: " . join(" ", sort keys %unknown_commands)
if %unknown_commands;
###MEH -- math support
print "\nMath commands outside math: " .
join(" ", sort keys %commands_outside_math) .
"\n Output may look weird or may be faulty!\n"
if %commands_outside_math;
print "\nDone.\n";
if($TEST_MODE) {
$TEST_MODE =~ s:[$dd$dd]+$::;
print "\nTo view the results, point your browser at:\n",
L2hos->path2URL(L2hos->Make_directory_absolute($TEST_MODE).$dd.
"index$EXTN"),"\n";
}
$end_time = time;
$total_time = $end_time - $start_time;
print STDOUT join(' ',"Timing:",$total_time,"seconds\n")
if ($TIMING||$DEBUG||($VERBOSITY > 2));
$_;
}
sub open_dbm_database {
# These are DBM (unix DataBase Management) arrays which are actually
# stored in external files. They are used for communication between
# the main process and forked child processes;
print STDOUT "\n"; # this mysteriously prevents a core dump !
dbmopen(%verb, "$TMP_${dd}verb",0755);
# dbmopen(%verbatim, "$TMP_${dd}verbatim",0755);
dbmopen(%verb_delim, "$TMP_${dd}verb_delim",0755);
dbmopen(%verb_lstopt, "$TMP_${dd}verb_lstopt",0755);
dbmopen(%expanded,"$TMP_${dd}expanded",0755);
# Holds max_id, verb_counter, verbatim_counter, eqn_number
dbmopen(%global, "$TMP_${dd}global",0755);
# Hold style sheet information
dbmopen(%env_style, "$TMP_${dd}envstyles",0755);
dbmopen(%txt_style, "$TMP_${dd}txtstyles",0755);
dbmopen(%styleID, "$TMP_${dd}styleIDs",0755);
# These next two are used during off-line image conversion
# %new_id_map maps image id's to page_numbers of the images in images.tex
# %image_params maps image_ids to conversion parameters for that image
dbmopen(%new_id_map, "$TMP_${dd}ID_MAP",0755);
dbmopen(%img_params, "$TMP_${dd}IMG_PARAMS",0755);
dbmopen(%orig_name_map, "$TMP_${dd}ORIG_MAP",0755);
$global{'max_id'} = ($global{'max_id'} | 0);
&read_mydb(\%verbatim, "verbatim");
$global{'verb_counter'} = ($global{'verb_counter'} | 0);
$global{'verbatim_counter'} = ($global{'verbatim_counter'} | 0);
&read_mydb(\%new_command, "new_command");
&read_mydb(\%renew_command, "renew_command");
&read_mydb(\%provide_command, "provide_command");
&read_mydb(\%new_theorem, "new_theorem");
&read_mydb(\%new_environment, "new_environment");
&read_mydb(\%dependent, "dependent");
# &read_mydb(\%env_style, "env_style");
# &read_mydb(\%styleID, "styleID");
# MRO: Why should we use read_mydb instead of catfile?
$preamble = &catfile(&_dbname("preamble"),1) || '';
$prelatex = &catfile(&_dbname("prelatex"),1) || '';
$aux_preamble = &catfile(&_dbname("aux_preamble"),1) || '';
&restore_critical_variables;
}
sub close_dbm_database {
&save_critical_variables;
dbmclose(%verb); undef %verb;
# dbmclose(%verbatim); undef %verbatim;
dbmclose(%verb_delim); undef %verb_delim;
dbmclose(%verb_lstopt); undef %verb_lstopt;
dbmclose(%expanded); undef %expanded;
dbmclose(%global); undef %global;
dbmclose(%env_style); undef %env_style;
dbmclose(%style_id); undef %style_id;
dbmclose(%new_id_map); undef %new_id_map;