Skip to content

Commit

Permalink
#35 escape_tex()
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Jun 30, 2023
1 parent cd4efd8 commit 7355a7c
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions bibcop.pl
Original file line number Diff line number Diff line change
Expand Up @@ -752,11 +752,18 @@ sub listed_tags {
return '(' . join(', ', @sorted) . ')';
}

# Make sure the text can safely be rendered in TeX.
sub escape_tex {
my ($tex) = @_;
$tex =~ s/[^a-zA-Z0-9-.+)(:; ]/?/g;
return $tex;
}

# Print ERROR message to the console and die.
sub error {
my ($txt) = @_;
if (exists $args{'--latex'}) {
print "\\PackageError{bibcop}{$txt}{}\n";
print "\\PackageError{bibcop}{" . escape_tex($txt). "}{}\n";
} else {
print STDERR $txt . "\n";
}
Expand All @@ -768,7 +775,7 @@ sub debug {
my ($txt) = @_;
if (exists $args{'--verbose'}) {
if (exists $args{'--latex'}) {
print "\\message{bibcop: $txt^^J}\n";
print "\\message{bibcop: " . escape_tex($txt) . "^^J}\n";
} else {
print $txt . "\n";
}
Expand Down

0 comments on commit 7355a7c

Please sign in to comment.