From 682900f29e7ea9d31046e9541be14fd749b2eb17 Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Mon, 20 Nov 2023 03:04:02 +0000 Subject: CTAN sync 202311200304 --- .../LaTeX-ToUnicode/lib/LaTeX/ToUnicode.pm | 45 ++++++++++++++++------ .../LaTeX-ToUnicode/lib/LaTeX/ToUnicode/Tables.pm | 11 +++--- 2 files changed, 39 insertions(+), 17 deletions(-) (limited to 'support/bibtexperllibs/LaTeX-ToUnicode/lib/LaTeX') 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 -- cgit v1.2.3