summaryrefslogtreecommitdiff
path: root/support/bibtexperllibs/LaTeX-ToUnicode/lib/LaTeX
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2023-11-20 03:04:02 +0000
committerNorbert Preining <norbert@preining.info>2023-11-20 03:04:02 +0000
commit682900f29e7ea9d31046e9541be14fd749b2eb17 (patch)
tree34d06fa9d427e231373629b5cc44517c583c84de /support/bibtexperllibs/LaTeX-ToUnicode/lib/LaTeX
parentaa94b613f51dfa2b65c607585727b66875e765d8 (diff)
CTAN sync 202311200304
Diffstat (limited to 'support/bibtexperllibs/LaTeX-ToUnicode/lib/LaTeX')
-rw-r--r--support/bibtexperllibs/LaTeX-ToUnicode/lib/LaTeX/ToUnicode.pm45
-rw-r--r--support/bibtexperllibs/LaTeX-ToUnicode/lib/LaTeX/ToUnicode/Tables.pm11
2 files changed, 39 insertions, 17 deletions
diff --git a/support/bibtexperllibs/LaTeX-ToUnicode/lib/LaTeX/ToUnicode.pm b/support/bibtexperllibs/LaTeX-ToUnicode/lib/LaTeX/ToUnicode.pm
index 173db38b02..1759a6acd6 100644
--- a/support/bibtexperllibs/LaTeX-ToUnicode/lib/LaTeX/ToUnicode.pm
+++ b/support/bibtexperllibs/LaTeX-ToUnicode/lib/LaTeX/ToUnicode.pm
@@ -2,7 +2,7 @@ use strict;
use warnings;
package LaTeX::ToUnicode;
BEGIN {
- $LaTeX::ToUnicode::VERSION = '0.53';
+ $LaTeX::ToUnicode::VERSION = '0.54';
}
#ABSTRACT: Convert LaTeX commands to Unicode (simplistically)
@@ -22,11 +22,15 @@ our $endcw = qr/(?<=[a-zA-Z])(?=[^a-zA-Z]|$)\s*/;
# all we need for is debugging being on and off. And it's pretty random
# what gets output.
my $debug = 0;
+
sub debuglevel { $debug = shift; }
sub _debug {
return unless $debug;
- my ($pkgname,$filename,$line,$subr) = caller(1);
- warn @_, " at $filename:$line (${pkgname}::$subr)\n";
+ # The backtrace info is split between caller(0) and caller(1), sigh.
+ # We don't need the package name, it's included in $subr in practice.
+ my (undef,$filename,$line,undef) = caller(0);
+ my (undef,undef,undef,$subr) = caller(1);
+ warn @_, " at $filename:$line ($subr)\n";
}
# The main conversion function.
@@ -114,8 +118,17 @@ sub convert {
#
if (! $options{entities}) {
# Convert our \x strings from Tables.pm to the binary characters.
- # Assume no more than four hex digits.
- $string =~ s/\\x\{(.{1,4})\}/ pack('U*', hex($1))/eg;
+
+ # As an extra-special case, we want to preserve the translation of
+ # \{ and \} as 007[bd] entities even if the --entities option is
+ # not give; otherwise they'd get eliminated like all other braces.
+ # Use a temporary cs \xx to keep them marked, and don't use braces
+ # to delimit the argument since they'll get deleted.
+ $string =~ s/\\x\{(007[bd])\}/\\xx($1)/g;
+
+ # Convert all other characters to characters.
+ # Assume exactly four hex digits, since we wrote Tables.pm that way.
+ $string =~ s/\\x\{(....)\}/ pack('U*', hex($1))/eg;
} elsif ($options{entities}) {
# Convert the XML special characters that appeared in the input,
@@ -176,9 +189,15 @@ sub convert {
warn "LaTeX::ToUnicode::convert: please report as bug.\n";
}
- # Drop all braces.
+ # Drop all remaining braces.
$string =~ s/[{}]//g;
+ if (! $options{entities}) {
+ # With all the other braces gone, now we can convert the preserved
+ # brace entities from \{ and \} to actual braces.
+ $string =~ s/\\xx\((007[bd])\)/ pack('U*', hex($1))/eg;
+ }
+
# Backslashes might remain. Don't remove them, as it makes for a
# useful way to find unhandled commands.
@@ -325,7 +344,7 @@ sub _convert_accents {
$string =~ s/(\\(.)\s*(\\?\w{1,1}))/ $tbl{$2}{$3} || $1/eg; # \"a
$string =~ s/(\\(.)\s*\{(\\?\w{1,2})\})/ $tbl{$2}{$3} || $1/eg; # \"{a}
- # second the alphabetic commands, like \c. They have be handled
+ # second the alphabetic commands, like \c. They have to be handled
# differently because \cc is not \c{c}! The only difference in the
# regular expressions is using $endcw instead of just \s*.
#
@@ -413,16 +432,18 @@ sub _convert_markups {
# HTML is different.
return _convert_markups_html($string) if $options->{html};
- # Ok, we'll "convert" to plain text by removing the markup commands.
+
+ # Not HTML, so here we'll "convert" to plain text by removing the
+ # markup commands.
- # we can do all markup commands at once.
+ # we can do all the markup commands at once.
my $markups = join('|', keys %LaTeX::ToUnicode::Tables::MARKUPS);
# Remove \textMARKUP{...}, leaving just the {...}
$string =~ s/\\text($markups)$endcw//g;
- # Similarly remove \MARKUPshape.
- $string =~ s/\\($markups)shape$endcw//g;
+ # Similarly remove \MARKUPshape, plus remove \upshape.
+ $string =~ s/\\($markups|up)shape$endcw//g;
# Remove braces and \command in: {... \MARKUP ...}
$string =~ s/(\{[^{}]+)\\(?:$markups)$endcw([^{}]+\})/$1$2/g;
@@ -516,7 +537,7 @@ LaTeX::ToUnicode - Convert LaTeX commands to Unicode
=head1 VERSION
-version 0.53
+version 0.54
=head1 SYNOPSIS
diff --git a/support/bibtexperllibs/LaTeX-ToUnicode/lib/LaTeX/ToUnicode/Tables.pm b/support/bibtexperllibs/LaTeX-ToUnicode/lib/LaTeX/ToUnicode/Tables.pm
index fd82b3ea7c..dd02926e03 100644
--- a/support/bibtexperllibs/LaTeX-ToUnicode/lib/LaTeX/ToUnicode/Tables.pm
+++ b/support/bibtexperllibs/LaTeX-ToUnicode/lib/LaTeX/ToUnicode/Tables.pm
@@ -1,6 +1,6 @@
package LaTeX::ToUnicode::Tables;
BEGIN {
- $LaTeX::ToUnicode::Tables::VERSION = '0.53';
+ $LaTeX::ToUnicode::Tables::VERSION = '0.54';
}
use strict;
use warnings;
@@ -53,7 +53,7 @@ our %MARKUPS = (
# More commands taking arguments that we want to handle.
#
our %ARGUMENT_COMMANDS = (
- 'emph' => ['\textem{', '}'], # \textem doesn't exist, but is processed
+ 'emph' => ['\textem{', '}'], # \textem doesn't exist, but we handle it
'enquote' => ["`", "'"],
'path' => ['\texttt{', '}'], # ugh, might not be a braced argument
);
@@ -114,6 +114,7 @@ our %CONTROL_WORDS_EMPTY = (
'doi' => '',
'egroup' => '',
'endgroup' => '',
+ 'ensuremath' => '',
'hbox' => '',
'ignorespaces' => '',
'mbox' => '',
@@ -601,7 +602,7 @@ our %GERMAN = ( # for package `german'/`ngerman'
"\"'" => '“',
'"<' => '«',
'">' => '»',
- '"-' => '\x{AD}', # soft hyphen
+ '"-' => '\x{00AD}', # soft hyphen
'""' => '\x{200B}', # zero width space
'"~' => '\x{2011}', # non-breaking hyphen
'"=' => '-',
@@ -625,7 +626,7 @@ LaTeX::ToUnicode::Tables - Character tables for LaTeX::ToUnicode
=head1 VERSION
-version 0.53
+version 0.54
=head1 CONSTANTS
@@ -663,7 +664,7 @@ A hash where the keys are non-alphabetic C<\command>s (without the
backslash), other than accents and special cases. These don't take
arguments. Although some of these have Unicode equivalents, such as the
C<\,> thin space, it seems better to keep the output as simple as
-possible; spacing tweaks in the TeX aren't usually desirable in plain
+possible; small spacing tweaks in TeX aren't usually desirable in plain
text or HTML.
The values are single-quoted strings C<'\x{...}'>, not double-quoted