use strict;
# ##### old intention below
# read file "words.input" from current directory and produce
# "\wordline{<word>}\hline" lines. plus patterns written in lines
# starting with "%" . THe pattern should contain a variable calles
# "$word. It functions as input.
# words.input contains words seperated
# by space, newline or tabular creates or overwrites a file called
# "generated-words.tex"
# the fonts file can be created by this bash line:
# for f in `ls /usr/share/texmf/tex/latex/psnfss/*.sty` ; do f=`basename $f| sed 's/\.sty//'`;echo '\usepackage{'$f'} ::: '$f ; done > fonts.input
########
# conf #
########
my $PDFLATEX_BIN = 'pdflatex';
my $PDFTOTEXT_BIN = 'pdftotext';
#$ENV{'TEXINPUTS'} =$ENV{'TEXINPUTS'}."::".dirname($0);
my $haskell_header =
'{- |
-}
{-
-}
';
########
# main #
########
# syllables (ligatures), letters widely
# used in (Het)CASL
# Split into sections that give the names of the Haskell maps.
my %widths = (); # a table of width from various fonts
# debugging
0 && do {
}
};
}
# a table of sections to table of
# words per section to max width over all fonts
# debugging
1 && do {
foreach my $sec (keys %word_widths) {
print "$sec :\n",
(sort (keys %{$word_widths{$sec}})))),
"\n";
}
};
########
# subs #
########
sub generate_haskell_FM {
my $word_widths = $_[0];
open HASKELL, "> LaTeX_maps.hs" or
die "cannot create Haskell module \"LaTeX_maps.hs\"";
print HASKELL $haskell_header;
my @two_letter_words = ();
foreach my $sec (keys %{$word_widths}) {
# generate a list of pairs for each section named after the section
print HASKELL " [",
')';
}
(@words))),
"]\n";
my $last_word = '';
my @first_letters =
(sort (map {m/^(.)/o;$1} @long_words));
print HASKELL " [",
join(",",map {my $c = &escape_String($_);
"('".$c."',[".
join(",",map {"\"".
&escape_String($_).
"\""}
(grep {m/^$c/}
@long_words)).
}
my $last_word = '';
print HASKELL "\nligatures :: Map String Bool\n",
"ligatures = fromList [",
(sort @two_letter_words)),
"]\n";
}
sub escape_String {
return join("", map {
if (m/^\\$/o) {
"\\$_";
} elsif(m/^"$/o) { # "
"\\$_";
} else {
# substitute ������� with \196\214\220\223\228\246\252
$_ =~ s/�/\\196/o; $_ =~ s/�/\\214/o; $_ =~ s/�/\\220/o;
$_ =~ s/�/\\223/o;
$_ =~ s/�/\\228/o; $_ =~ s/�/\\246/o; $_ =~ s/�/\\252/o;
$_;
}
} split(//o,$_[0]));
}
sub fm_header {
return "\n$map_name :: Map String Int\n$map_name = fromList";
}
sub key_fm_header {
return "\n$map_name :: Map Char [String]\n$map_name = fromList";
}
sub calc_max_width {
my $font_widths = $_[0];
my $words = $_[1];
my @fonts = keys %{$font_widths};
my %max_widths = ();
my %word_max_width = ();
my $width_word_index = 0;
print "$sec: ";
my $max = 0;
#print "$word: ";
}
print STDERR
"\nWarning: max length of $word is undefined or zero\n"
$width_word_index++;
#exit if $width_word_index >= 5;
}
#exit;
}
return %max_widths;
}
sub max {
return (($_[0] >= $_[1]) ? $_[0] : $_[1]);
}
sub process_one_font {
# debugging: print "font: ".join(", ", @{$_[0]})."\n";
# generate two documents one human readable and one for the machine
my $computer_tex_filename =
# &gen_tex('width-table.tex.svmono.templ',
&gen_tex('width-table.tex.templ',
my $human_tex_filename =
# &gen_tex('width-table.tex.svmono.templ',
&gen_tex('width-table.tex.templ',
if ($DO_PDFLATEX) {
}
my $computer_pdf_filename =
}
sub pdflatex {
my $tex_filename = $_[0];
system($PDFLATEX_BIN,$tex_filename);
}
sub get_widths {
my $pdf_filename = $_[0];
my %widths = ();
if ($DO_PDFTOTEXT) {
}
#open WIDTH, "pdftotext $pdf_filename | egrep 'section: |wl: ' |"
# or die "cannot call pdftotext or egrep or cannot fork";
open WIDTH, "< $txt_filename"
or die "cannot read file \"$txt_filename\"";
my $section = '';
my @widths = ();
while (<WIDTH>) {
m/section: (\w+)\+\+\+/o && do {
unless ($section eq '') {
@widths = ();
}
$section = $1;
};
push @widths, $1;
};
}
close WIDTH;
# debugging
0 && do {
}
};
return \%widths;
}
sub gen_tex {
my $output_filename =
my $no_cols = '';
open TEMPL, "< $input_filename";
open OUT, "> $output_filename";
while (<TEMPL>) {
print OUT $_;
}
close TEMPL;
close OUT;
return $output_filename;
}
sub read_fonts {
open FONTS, "< fonts.input"
or die "cannot open file \"fonts.input\" for reading";
my @read_fonts = ();
while (<FONTS>) {
chomp;
my @fnt_descrp = split /\s+:::\s+/;
push @read_fonts, \@fnt_descrp;
}
close FONTS;
return @read_fonts;
}
my $count_words = 0;
sub process_the_words {
my $pat = '%s';
my $line = '';
my @sec_words = ();
my %all_words = ();
my $section = '';
open GENWORDS, "> generated_words.tex"
or die "cannot write to file \"generated_words.tex\"!";
&sep_tabular,next if $line=~ m/^\s*$/o;
if ($line =~ m/^%/o) {
chomp $line;
$line =~ s///o;
#print STDERR "$section : ",join(", ",@sec_words),"\n";
unless ($section eq '') {
#print STDERR "pushed: $section : ",join(", ",@sec_words),"\n";
}
@sec_words = ();
$line =~ s///o;
&sep_tabular("\\newpage\n\\section*{section: $section+++}\n");
} else {
print STDERR "unknown directive: $line\n";
}
} elsif ($line =~ m/^&/o) {
$line =~ s///o;
} elsif ($line =~ m/^~(.*)$/o) {
&sep_tabular($1);
} else {
print GENWORDS "\\wordline{$fpat}\n\\hline\n";
if(++$count_words >= 37) {
}
}
}
}
close WORDS;
close GENWORDS;
return %all_words;
}
sub sep_tabular {
$count_words = 0;
print GENWORDS "\\end{tabular}\n$fill_in\n\\begin{tabular}{l|l}\n\\hline\n";
}