Below is the script used to transform the raw text into hypertext. Any suggestions regarding optimization or improvements would be greatly appreciated.

#!/bin/perl
open (IN, "originals/Ethics1.html");
open (OUT, ">Ethics1.html");
while ($line = <IN>) {
#Search for and replace propositions
$line =~ m!(Prop\. ) *([^ ]*)!;
&fix_string($2);
$line =~ s!(Prop\. ) *([^ ]*)!<a href=\"\#$1 $end_word_CAPITAL\">$1 $end_word</a>$separator $the_rest!;
#Search for and replace definitions
$line =~ m!(Def\. ) *([^ ]*)!;
&fix_string($2);
$line =~ s!(Def\. ) *([^ ]*)!<a href=\"\#$1 $end_word_CAPITAL\">$1 $end_word</a>$separator $the_rest!;
#Search for and replace axioms
$line =~ m!(Ax\. ) *([^ ]*)!;
&fix_string($2);
$line =~ s!(Ax\. ) *([^ ]*)!<a href=\"\#$1 $end_word_CAPITAL\">$1 $end_word</a>$separator $the_rest!;
#Put proofs and corollaries in bold
$line =~ s!Proof\.!<b>Proof\.</b>!;
$line =~ s!(Corollary) *([^ -]*)!<b>$1 $2</b>!;
# Replace Proposition, Axiom and Definition headers with anchors
$line =~ s!(PROP\.) *([^ ]*)\s!\n<hr>\n<a name=\"Prop. $2\"><b>Prop. $2</b></a> !;
$line =~ s!(AX\.) *([^ ]*)\s!\n<hr>\n<a name=\"Ax. $2\"><b>Ax. $2</b></a> !;
$line =~ s!(DEF\.) *([^ ]*)\s!\n<hr>\n<a name=\"Def. $2\"><b>Def. $2</b></a> !;
$line =~ s!\(\s!\(!g; # Kill "( "
$line =~ s!( ){1,}! !g; # Kill double spaces
print OUT $line;
}
close(OUT);
close(IN);
sub fix_string { # Procedure to fix string after keyword
$the_string = $_[0];
if ($the_string =~ m!\)!) {
$separator = "\)";
$the_rest = "";
($end_word, $the_rest) = split(/\)/, $the_string);
} else {
$separator = "";
$end_word = $the_string;
$the_rest = "";
}
$end_word_CAPITAL = $end_word;
$end_word_CAPITAL =~ s![^a-zA-Z\.]!!g; # Eliminate unwanted characters.
$end_word_CAPITAL =~ s!([a-z\.\s])!\u$&!g; #Convert characters to uppercase
# Above can also be done with tr!a-z!A-Z!
}

[Feedback] [SpinozaWeb] [STG]