while (<>) {
$environ = undef;
if (/\\(begin|end){(\w+)}/) {
- $environ = $2;
+ $environ=$2;
$begin=$1 eq "begin";
if ($environ eq 'verbatim') {
$verbatim=$begin;
if ($begin) {
pushsection("poem",undef);
} else {
- flushsection('poem');
+ add_to_section(tag($buffer,'stanza')."\n") if $buffer;
+ $buffer="";
+ flushsection('poem');
}
$poetry = $begin;
- } elsif($environ = 'document' && $begin) {
+ } elsif($environ eq 'document' && $begin) {
$header=0;
}
}
next LINE if $header;
if ((/^$/ || $environ) && $buffer) {
#output on empty line (p or stanza) depending on poetry mode
- add_to_section(tag($buffer,$poetry?"stanza":"p"));
+ add_to_section(tag($buffer,$poetry?"stanza":"p")."\n");
$buffer="";
}
next LINE if $environ;
add_to_section("<empty-line />");
next LINE;
}
+next LINE if /\\pagebreak\b/;
#normal mode:
if (!$verbatim) {
#strip TeX comments
s/\\sloppy\s+//g;
s/\\sloppy{}//g;
s/\\sloppy([^\w])/$1/g;
+# strip extra space
+s/^\s+//;
+s/\s+$//;
+s/(\s)\s+/$1/g;
#replace TeX ligatures ~ --- << >> \% with appropriate unicode symbols
s/~/\xA0/g;
s/---/-/g;
if ($poetry) {
chomp;
- $buffer.=tag($_,'v');
+ s/\s*\\\\$//;
+ $buffer.=tag($_,'v')."\n";
} elsif ($verbatim) {
add_to_section(tag(tag($_,"code"),"p"));
} else {
- $buffer.=$_;
+ $buffer.=" ".$_;
}
}
if ($buffer) {
}
$content .= $str->{data};
if ($#sections >=0) {
- add_to_section(tag($content,$tag));
+ add_to_section(tag($content,$tag)."\n");
} else {
print tag($content,$tag);
}
sub tag {
my ($content,$name) = @_;
- return "" if ($content eq "\n");
+ return "" if $content =~ /^\s*$/s;
return "<$name>$content</$name>";
}