<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl -w
$/ = "";

use File::Basename;

$kl = $ARGV[0]; 
if ($kl &amp;&amp; ($kl =~ /-h|-\?/)) {&amp;message(); exit(1);}

$file = @ARGV;
if ($file &lt; 1) {&amp;message(); exit(1);} 

$a = $ARGV[0];
open(VCHOD, "$a") || die "Sorry, I cannot open $a: $!\n";

print STDERR "Making reference tags... \n";

&amp;hesh_stup(); 

while(&lt;VCHOD&gt;){

	&amp;format1();
	&amp;name_href();
	&amp;format2();
	print;
}

sub hesh_stup {
	$schet_stup = 0;
	while(&lt;VCHOD&gt;){
		if (/\\TEZA{(\w\w)}/) {$schet_stup++; $stup{"$1"} = "$schet_stup";}
		if (/\\STEZA{(\w\w)}{(\w\w)}/) {$schet_stup++; $stup{"$1"} = "$schet_stup";}
	}
	seek (VCHOD, 0, 0);
}

END {
	close (VCHOD);
}

sub format1 {
	s@&lt;!--(.*)--&gt;@$1@g;
	s@(\\TEZA{\w\w})@&lt;span class="TEZA"&gt;$1\.&lt;/span&gt;@gi;
	s@(\\STEZA{\w\w}{\w\w})@&lt;span class="STEZA"&gt;$1\.&lt;/span&gt;@gi;
	s@(\\SSYLKA{\w\w})@ ... &lt;span class="SSYLKA"&gt;$1\.&lt;/span&gt;@gi;
}

sub name_href {
	s@\\TEZA{(\w\w)}@&lt;a name=\"$1\"&gt;$stup{$1}&lt;\/a&gt;@g;
	s@\\STEZA{(\w\w)}{(\w\w)}@&lt;a name=\"$1\"&gt;$stup{$1}&lt;\/a&gt;\(&lt;a href=\"#$2\"&gt;$stup{$2}&lt;\/a&gt;\)@g;
	s@\\SSYLKA{(\w\w)}@&lt;a href=\"#$1\"&gt;$stup{$1}&lt;\/a&gt;@g;
}

sub format2 {
	s@\\documentclass.*@@gi;
	s@\\usepackage.*@@gi;
	s@\\begin.*@@gi;
	s@\\end.*@@gi;
	s@&lt;p&gt;%@@gi;
	s@\\i *{}@i@gsi;
	s@\$\\times\$@&amp;times\;@gi;
	s@\\#@-@gi;
	s@\\&lt;|&lt;&lt;@&amp;laquo\;@g;
	s@\\&gt;|&gt;&gt;@&amp;raquo\;@g;
	s@~@&amp;nbsp\;@gi;
	s@---|\\---@&amp;mdash;@gi;
	s@(\\T+?)(.*?)\n\n@ ... 
		&lt;!--&lt;a href=""&gt;--&gt;&lt;span class="SP"&gt;$2&lt;/span&gt;&lt;!--&lt;/a&gt;--&gt;\n\n@gsi;
	s@\\KN (.+?) @&lt;em&gt;$1&lt;/em&gt; @gsi;
	s@\\NN (.+?) (.+?) @&lt;em&gt;$1 $2&lt;/em&gt; @gsi;
	s@\\K *{(.+?)}@&lt;em&gt;$1&lt;/em&gt;@gsi;
	s@\\J *{(.+?)}@&lt;strong&gt;$1&lt;/strong&gt;@gsi;
	s@\\textit *{(.+?)}@&lt;em&gt;$1&lt;/em&gt;@gsi;
	s@\\textbf *{(.+?)}@&lt;strong&gt;$1&lt;/strong&gt;@gsi;
	s@&lt;p&gt;\\FK@&lt;p class="FK"&gt;@sgi;
	s@&lt;p&gt;@&lt;p class="ST"&gt;@sgi;
	s@\\AN@&amp;ndash;@gi;
	s@\\AAN|\\AAAN@=@gi;
	s@  +?@ @sgi;
	s@\\'@@sgi;
	s@\\i{}@@sgi;
}

sub message {
$Me = basename($0);
print &lt;&lt;END_OF_MESSAGE
USAGE: $Me [-h|-?] File1 [&gt;File2]
END_OF_MESSAGE
}
#</pre></body></html>