LaTeX-ToUnicode-0.54/0000755000076700000240000000000014526042361014206 5ustar bveytsmanstaffLaTeX-ToUnicode-0.54/LICENSE0000644000076700000240000004344214526036644015231 0ustar bveytsmanstaffCopyright 2010-2023 Gerhard Gossen, Boris Veytsman, Karl Berry This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2010 by Gerhard Gossen. This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End LaTeX-ToUnicode-0.54/Changes0000644000076700000240000000134514526036761015513 0ustar bveytsmanstaffChanges for LaTeX::ToUnicode 0.54 2023-11-17 Better handling of \{ \}. New release 0.53 2023-08-20 Tests fixed, new release 0.52 2022-11-07 Support many more control sequences, \kern removal, \, etc. Add ltxunitxt script to access functionality from command line. 0.11 2020-12-12 Updates and cleaing 0.05 2016-11-23 02:28:35+00:00 Compatibility with perl 5.25 (Alexandr Ciornii) 0.04 2015-12-25 19:16:41+00:00 Macrons are handled properly 0.03 2010-10-18 18:04:14 Specify minimal perl version (5.8.0) for UTF-8 support 0.02 2010/07/09 Handle accents with \i Add script used to generate accents table 0.01 2010/07/09 First release. LaTeX-ToUnicode-0.54/MANIFEST0000644000076700000240000000065014526042361015340 0ustar bveytsmanstaffLICENSE Changes MANIFEST t/release-pod-coverage.t t/release-pod-syntax.t t/convert.t t/release-synopsis.t README script/ltx2unitxt script/convert.pl lib/LaTeX/ToUnicode/Tables.pm lib/LaTeX/ToUnicode.pm Makefile.PL head.ltx Makefile.TDS weaver.ini dist.ini META.yml Module YAML meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) LaTeX-ToUnicode-0.54/t/0000755000076700000240000000000014526042361014451 5ustar bveytsmanstaffLaTeX-ToUnicode-0.54/t/release-pod-coverage.t0000644000076700000240000000076514470510772020643 0ustar bveytsmanstaff#!perl BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } use Test::More; eval "use Test::Pod::Coverage 1.08"; plan skip_all => "Test::Pod::Coverage 1.08 required for testing POD coverage" if $@; eval "use Pod::Coverage::TrustPod"; plan skip_all => "Pod::Coverage::TrustPod required for testing POD coverage" if $@; all_pod_coverage_ok({ coverage_class => 'Pod::Coverage::TrustPod' }); LaTeX-ToUnicode-0.54/t/release-pod-syntax.t0000644000076700000240000000045014470510772020365 0ustar bveytsmanstaff#!perl BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } use Test::More; eval "use Test::Pod 1.41"; plan skip_all => "Test::Pod 1.41 required for testing POD" if $@; all_pod_files_ok(); LaTeX-ToUnicode-0.54/t/convert.t0000644000076700000240000000364614526036514016332 0ustar bveytsmanstaffuse strict; use warnings; use Test::More; use utf8; BEGIN{ use_ok( 'LaTeX::ToUnicode', qw( convert ) ); } binmode( STDOUT, ':utf8' ); my @tests = ( [ '\LaTeX' => 'LaTeX' ], [ '\$ \% \& \_ \{ \} \#' => '$ % & _ { } #' ], [ '{\"{a}}' => 'ä' ], [ '{\"a}' => 'ä' ], [ '{\`{a}}' => 'à' ], [ '{\`a}' => 'à' ], [ '\ae' => 'æ' ], [ '\L' => 'Ł' ], [ "{\\'e}" => 'é'], ['\={a}' => 'ā'], ['{\=a}' => 'ā'], ); foreach my $test ( @tests ) { is( convert( $test->[0] ), $test->[1], "Convert $test->[0]" ); } my @german_tests = ( [ '"a' => 'ä' ], ['"`' => '„' ], ["\"'" => '“' ], ); foreach my $test ( @german_tests ) { is( convert( $test->[0], german => 1 ), $test->[1], "Convert $test->[0], german => 1" ); } binmode( DATA, ':utf8' ); while () { chomp; my ( $tex, $result ) = split /\t/; is( convert( $tex ), $result, "Convert $tex" ); } close DATA; done_testing; __DATA__ \& & {\`a} à {\^a} â {\~a} ã {\'a} á {\'{a}} á {\"a} ä {\`A} À {\'A} Á {\"A} Ä {\aa} å {\AA} Å {\ae} æ {\bf 12} 12 {\'c} ć {\cal P} P {\c{c}} ç {\c{C}} Ç {\c{e}} ȩ {\c{s}} ş {\c{S}} Ş {\c{t}} ţ {\-d} d {\`e} è {\^e} ê {\'e} é {\"e} ë {\'E} É {\em bits} bits {\H{o}} ő {\`i} ì {\^i} î {\i} ı {\`i} ì {\'i} í {\"i} ï {\`\i} ì {\'\i} í {\"\i} ï {\`{\i}} ì {\'{\i}} í {\"{\i}} ï {\it Note} Note {\k{e}} ę {\l} ł {\-l} l {\log} log {\~n} ñ {\'n} ń {\^o} ô {\o} ø {\'o} ó {\"o} ö {\"{o}} ö {\'O} Ó {\"O} Ö {\"{O}} Ö {\rm always} always {\-s} s {\'s} ś {\sc JoiN} JoiN {\sl bit\/ \bf 7} bit 7 {\sl L'Informatique Nouvelle} L’Informatique Nouvelle {\small and} and {\ss} ß {\TeX} TeX {\TM} ™ {\tt awk} awk {\^u} û {\'u} ú {\"u} ü {\"{u}} ü {\'U} Ú {\"U} Ü {\u{a}} ă {\u{g}} ğ {\v{c}} č {\v{C}} Č {\v{e}} ě {\v{n}} ň {\v{r}} ř {\v{s}} š {\v{S}} Š {\v{z}} ž {\v{Z}} Ž {\'y} ý {\.{z}} ż Herv{\`e} Br{\"o}nnimann Hervè Brönnimann LaTeX-ToUnicode-0.54/t/release-synopsis.t0000644000076700000240000000046314470510772020152 0ustar bveytsmanstaff#!perl BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } use Test::More; eval "use Test::Synopsis"; plan skip_all => "Test::Synopsis required for testing synopses" if $@; all_synopsis_ok('lib'); LaTeX-ToUnicode-0.54/README0000644000076700000240000000066414470510772015100 0ustar bveytsmanstaffThis is the LaTeX::ToUnicode Perl package: Convert LaTeX source fragments to Unicode plain text or simple html Dev sources, bug tracker: https://github.com/borisveytsman/bibtexperllibs Releases: https://ctan.org/pkg/bibtexperllibs Copyright 2010-2022 Gerhard Gossen, Boris Veytsman, Karl Berry This is free software; you can redistribute it and/or modify it under the same terms as the Perl5 programming language system itself. LaTeX-ToUnicode-0.54/script/0000755000076700000240000000000014526042361015512 5ustar bveytsmanstaffLaTeX-ToUnicode-0.54/script/ltx2unitxt0000755000076700000240000001270714470510772017620 0ustar bveytsmanstaff#!/usr/bin/env perl # Use the LaTeX::ToUnicode module (also in the bibtexperllibs # repository/package, like this script) to convert LaTeX to Unicode. # # We work on fragments of text, not whole documents, the goal being to # replace LaTeX commands and syntax with obvious plain text equivalents, # or remove them. use strict; use warnings; use Cwd; use File::Basename; use File::Spec; BEGIN { # find files relative to our installed location within TeX Live chomp(my $TLMaster = `kpsewhich -var-value=SELFAUTOPARENT`); # TL root if (length($TLMaster)) { unshift @INC, "$TLMaster/texmf-dist/scripts/bibtexperllibs"; } # find development bibtexperllibs in sibling checkout to this script, # even if $0 is a symlink. Irrelevant when using from an installation. my $real0 = Cwd::abs_path($0); my $scriptdir = File::Basename::dirname($real0); my $dev_btxperllibs = Cwd::abs_path("$scriptdir/../.."); # we need the lib/ subdirectories inside ... unshift (@INC, glob ("$dev_btxperllibs/*/lib")) if -d $dev_btxperllibs; } use LaTeX::ToUnicode; our %opts; local *OUT; # output filehandle exit(main()); sub main { init(); # by paragraph? while (<>) { print OUT (convert($_)); } return 0; } sub convert { my ($in) = @_; my @args = (); # what we'll pass to the convert() fn. # if (defined(&{"LaTeX_ToUnicode_convert_hook"})) { push (@args, "hook" => \&LaTeX_ToUnicode_convert_hook); } if ($opts{e}) { push (@args, "entities" => 1); } if ($opts{g}) { push (@args, "german" => 1); } if ($opts{h}) { push (@args, "html" => 1); } LaTeX::ToUnicode::debuglevel($opts{v}); my $out = LaTeX::ToUnicode::convert($in, @args); #warn "out=$out"; return $out; } # Command line options, etc. # sub init { my $USAGE = < \($opts{c}), "entities|e" => \($opts{e}), "german|g" => \($opts{g}), "html|h" => \($opts{h}), "output|o=s" => \($opts{o}), "verbose|v" => \($opts{v}), "version|V" => \($opts{V}), "help|?" => \($opts{help})) || die "Try $0 --help for more information.\n"; if ($opts{help}) { print "$USAGE\n$VERSION"; exit 0; } if ($opts{V}) { print $VERSION; exit 0; } binmode(STDOUT, ":utf8"); *OUT = *STDOUT; if (defined($opts{o})) { open(OUT, ">$opts{o}") || die "open(>$opts{o}) failed: $!\n"; binmode(OUT, ":utf8") } if ($opts{c}) { if (-r $opts{c}) { # if config arg is absolute, fine; if not, prepend "./" as slightly # less troublesome than putting "." in the @INC path. my $rel = (File::Spec->file_name_is_absolute($opts{c}) ? "" : "./"); my $cnffile = "$rel$opts{c}"; verbose("requiring config file: $cnffile"); require $cnffile; } else { die "open config file ($opts{c}) for reading failed: $!\n"; } } } sub verbose { print @_ if $::opts{v}; } LaTeX-ToUnicode-0.54/script/convert.pl0000644000076700000240000000727714470510772017550 0ustar bveytsmanstaff#!/usr/bin/perl use strict; use warnings; use utf8; use feature 'say'; use FindBin; my $UNICODE_DATA_URL = "http://www.unicode.org/Public/UNIDATA/UnicodeData.txt"; my $stream; if ( -f "$FindBin::Bin/UnicodeData.txt" ) { open $stream, "<", "$FindBin::Bin/UnicodeData.txt" or die; } else { open $stream, "-|", "curl $UNICODE_DATA_URL" or die; } my %data; my %chars = ( 'ACUTE' => "'", 'ACUTE AND DOT ABOVE' => '', 'BAR' => '', 'BELT' => '', 'BREVE' => 'u', 'BREVE AND ACUTE' => '', 'BREVE AND DOT BELOW' => '', 'BREVE AND GRAVE' => '', 'BREVE AND HOOK ABOVE' => '', 'BREVE AND TILDE' => '', 'BREVE BELOW' => '', 'CARON' => 'v', 'CARON AND DOT ABOVE' => '', 'CEDILLA' => 'c', 'CEDILLA AND ACUTE' => '', 'CEDILLA AND BREVE' => '', 'CIRCUMFLEX' => '^', 'CIRCUMFLEX AND ACUTE' => '', 'CIRCUMFLEX AND DOT BELOW' => '', 'CIRCUMFLEX AND GRAVE' => '', 'CIRCUMFLEX AND HOOK ABOVE' => '', 'CIRCUMFLEX AND TILDE' => '', 'CIRCUMFLEX BELOW' => '', 'COMMA' => '', 'COMMA BELOW' => '', 'CROSSED-TAIL' => '', 'CURL' => '', 'DESCENDER' => '', 'DIAERESIS' => '"', 'DIAERESIS AND ACUTE' => '', 'DIAERESIS AND CARON' => '', 'DIAERESIS AND GRAVE' => '', 'DIAERESIS AND MACRON' => '', 'DIAERESIS BELOW' => '', 'DIAGONAL STROKE' => '', 'DOT ABOVE' => '.', 'DOT ABOVE AND MACRON' => '', 'DOT BELOW' => 'd', 'DOT BELOW AND DOT ABOVE' => '', 'DOT BELOW AND MACRON' => '', 'DOUBLE ACUTE' => 'H', 'DOUBLE BAR' => '', 'DOUBLE GRAVE' => '', 'FISHHOOK' => '', 'FISHHOOK AND MIDDLE TILDE' => '', 'FLOURISH' => '', 'GRAVE' => '`', 'HIGH STROKE' => '', 'HOOK' => '', 'HOOK ABOVE' => 'h', 'HOOK AND TAIL' => '', 'HOOK TAIL' => '', 'HORIZONTAL BAR' => '', 'HORN' => '', 'HORN AND ACUTE' => '', 'HORN AND DOT BELOW' => '', 'HORN AND GRAVE' => '', 'HORN AND HOOK ABOVE' => '', 'HORN AND TILDE' => '', 'INVERTED BREVE' => '', 'LEFT HOOK' => '', 'LINE BELOW' => '', 'LONG LEG' => '', 'LONG RIGHT LEG' => '', 'LONG STROKE OVERLAY' => '', 'LOOP' => '', 'LOW RING INSIDE' => '', 'MACRON' => '=', 'MACRON AND ACUTE' => '', 'MACRON AND DIAERESIS' => '', 'MACRON AND GRAVE' => '', 'MIDDLE DOT' => '', 'MIDDLE TILDE' => '', 'NOTCH' => '', 'OGONEK' => 'k', 'OGONEK AND MACRON' => '', 'PALATAL HOOK' => '', 'RETROFLEX HOOK' => '', 'RIGHT HALF RING' => '', 'RIGHT HOOK' => '', 'RING ABOVE' => 'r', 'RING ABOVE AND ACUTE' => '', 'RING BELOW' => '', 'SMALL LETTER J' => '', 'SMALL LETTER Z' => '', 'SMALL LETTER Z WITH CARON' => '', 'SQUIRREL TAIL' => '', 'STRIKETHROUGH' => '', 'STROKE' => '', 'STROKE AND ACUTE' => '', 'STROKE AND DIAGONAL STROKE' => '', 'STROKE THROUGH DESCENDER' => '', 'SWASH TAIL' => '', 'TAIL' => '', 'TILDE' => '~', 'TILDE AND ACUTE' => '', 'TILDE AND DIAERESIS' => '', 'TILDE AND MACRON' => '', 'TILDE BELOW' => '', 'TOPBAR' => '', ); my %missing; while(<$stream>) { chomp; my @F = split /;/; my $hex = $F[0]; if ( $F[1] =~ /LATIN (SMALL|CAPITAL) LETTER ((?:\w+ )*\w{1,2}) WITH (.+)$/ ) { my $case = $1; my $letter = $2; my $accent = $3; if ( $case eq 'SMALL' ) { $letter = lc $letter; } if ( $chars{$accent} && $letter !~ / / ) { my $char = chr( eval "0x$hex" ); $data{ $chars{$accent} }->{ $letter } = $char; if ( lc( $letter ) eq 'i' ) { my $additional_letter = "\\$letter"; $data{ $chars{$accent} }->{ $additional_letter } = $char; } } else { push @{ $missing{$accent} }, $letter; } } } use Data::Dumper::Concise; binmode(STDOUT, ":utf8"); say Dumper( \%data ); #say Dumper( \%missing ); LaTeX-ToUnicode-0.54/META.yml0000644000076700000240000000115214526042361015456 0ustar bveytsmanstaff--- abstract: 'Convert LaTeX commands to Unicode' author: - 'Gerhard Gossen and Boris Veytsman and Karl Berry ' build_requires: {} configure_requires: ExtUtils::MakeMaker: '6.31' dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 7.34, CPAN::Meta::Converter version 2.150010' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: LaTeX-ToUnicode no_index: directory: - t - inc requires: {} version: '0.54' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' LaTeX-ToUnicode-0.54/lib/0000755000076700000240000000000014526042361014754 5ustar bveytsmanstaffLaTeX-ToUnicode-0.54/lib/LaTeX/0000755000076700000240000000000014526042361015731 5ustar bveytsmanstaffLaTeX-ToUnicode-0.54/lib/LaTeX/ToUnicode/0000755000076700000240000000000014526042361017622 5ustar bveytsmanstaffLaTeX-ToUnicode-0.54/lib/LaTeX/ToUnicode/Tables.pm0000644000076700000240000004506514526037117021407 0ustar bveytsmanstaffpackage LaTeX::ToUnicode::Tables; BEGIN { $LaTeX::ToUnicode::Tables::VERSION = '0.54'; } use strict; use warnings; #ABSTRACT: Character tables for LaTeX::ToUnicode use utf8; # just for the german support # Technically not all of these are ligatures, but close enough. # Order is important, so has to be a list, not a hash. # our @LIGATURES = ( "---" => '\x{2014}', # em dash "--" => '\x{2013}', # en dash "!`" => '\x{00A1}', # inverted exclam "?`" => '\x{00A1}', # inverted question "``" => '\x{201c}', # left double "''" => '\x{201d}', # right double "`" => '\x{2018}', # left single "'" => '\x{2019}', # right single ); # test text: em---dash, en--dash, exc!`am, quest?`ion, ``ld, rd'', `ls, rs'. # # Some additional ligatures supported in T1 encoding, but we won't (from # tex-text.map): # U+002C U+002C <> U+201E ; ,, -> DOUBLE LOW-9 QUOTATION MARK # U+003C U+003C <> U+00AB ; << -> LEFT POINTING GUILLEMET # U+003E U+003E <> U+00BB ; >> -> RIGHT POINTING GUILLEMET # for {\MARKUP(shape) ...} and \textMARKUP{...}; although not all # command names are defined in LaTeX for all markups, we translate them # anyway. Also, LaTeX has more font axes not included here: md, ulc, sw, # ssc, etc. See ltfntcmd.dtx and ltfssaxes.dtx if we ever want to try # for completeness. # our %MARKUPS = ( 'bf' => 'b', 'cal' => '', 'em' => 'em', 'it' => 'i', 'rm' => '', 'sc' => '', # qqq should uppercasify 'sf' => '', 'sl' => 'i', 'small' => '', 'subscript' => 'sub', 'superscript' => 'sup', 'tt' => 'tt', ); # More commands taking arguments that we want to handle. # our %ARGUMENT_COMMANDS = ( 'emph' => ['\textem{', '}'], # \textem doesn't exist, but we handle it 'enquote' => ["`", "'"], 'path' => ['\texttt{', '}'], # ugh, might not be a braced argument ); # Non-alphabetic \COMMANDs, other than accents and special cases. # our %CONTROL_SYMBOLS = ( ' ' => ' ', # control space "\t" => ' ', # control space "\n" => '\x{0020}', # control space; use entity to avoid being trimmed '!' => '', # negative thin space # " umlaut '#' => '#', # sharp sign '$' => '$', # dollar sign '%' => '%', # percent sign '&' => '\x{0026}', # ampersand, entity to avoid html conflict # ' acute accent '(' => '', # start inline math ')' => '', # end inline math '*' => '', # discretionary multiplication '+' => '', # tabbing: tab stop to right ',' => '', # thin space '-' => '', # discretionary hyphenation # . overdot accent '/' => '', # italic correction # 0..9 undefined ':' => '', # medium space ';' => ' ', # thick space '<' => '', # tabbing: text to left of margin # = macron accent '>' => '', # tabbing: next tab stop # ? undefined '@' => '#', # end of sentence # A..Z control words, not symbols '[' => '', # start display math '\\' => ' ', # line break ']' => '', # end display math # ^ circumflex accent '_' => '_', # underscore # ` grave accent # a..z control words, not symbols '{' => '\x{007b}', # lbrace '|' => '\x{2225}', # parallel '}' => '\x{007d}', # rbrace # ~ tilde accent ); # Alphabetic \COMMANDs that map to nothing. This is simply # interpolated into %CONTROL_WORDS (next), not used directly, so we # redundantly specify the '' on every line. # our %CONTROL_WORDS_EMPTY = ( 'begingroup' => '', 'bgroup' => '', 'checkcomma' => '', #'cite' => '', # keep \cite undefined since it needs manual work 'clearpage' => '', 'doi' => '', 'egroup' => '', 'endgroup' => '', 'ensuremath' => '', 'hbox' => '', 'ignorespaces' => '', 'mbox' => '', 'medspace' => '', 'negmedspace' => '', 'negthickspace' => '', 'negthinspace' => '', 'newblock' => '', 'newpage' => '', 'noindent' => '', 'nolinkurl' => '', 'oldstylenums' => '', 'pagebreak' => '', 'protect' => '', 'raggedright' => '', 'relax' => '', 'thinspace' => '', 'unskip' => '', 'urlprefix' => '', ); # Alphabetic commands, that expand to nothing (above) and to # something (below). # our %CONTROL_WORDS = ( %CONTROL_WORDS_EMPTY, 'BibLaTeX' => 'BibLaTeX', 'BibTeX' => 'BibTeX', 'LaTeX' => 'LaTeX', 'LuaLaTeX' => 'LuaLaTeX', 'LuaTeX' => 'LuaTeX', 'MF' => 'Metafont', 'MP' => 'MetaPost', 'Omega' => '\x{03A9}', 'TeX' => 'TeX', 'XeLaTeX' => 'XeLaTeX', 'XeTeX' => 'XeTeX', 'bullet' => '\x{2022}', 'dag' => '\x{2020}', 'ddag' => '\x{2021}', 'dots' => '\x{2026}', 'epsilon' => '\x{03F5}', 'hookrightarrow' => '\x{2194}', 'ldots' => '\x{2026}', 'log' => 'log', 'omega' => '\x{03C9}', 'par' => "\n\n", 'qquad' => ' ', # 2em space 'quad' => ' ', # em space 'textbackslash' => '\x{005C}', # entities so \ in output indicates # untranslated TeX source 'textbraceleft' => '\x{007B}', # entities so our bare-brace removal 'textbraceright' => '\x{007D}', # skips them 'textgreater' => '\x{003E}', 'textless' => '\x{003C}', 'textquotedbl' => '"', 'thickspace' => ' ', 'varepsilon' => '\x{03B5}', ); # Control words (not symbols) that generate various non-English # letters and symbols. Lots more could be added. # our %SYMBOLS = ( # Table 3.2 in Lamport, plus more 'AA' => '\x{00C5}', # A with ring 'aa' => '\x{00E5}', 'AE' => '\x{00C6}', # AE 'ae' => '\x{00E6}', 'DH' => '\x{00D0}', # ETH 'dh' => '\x{00F0}', 'DJ' => '\x{0110}', # D with stroke 'dj' => '\x{0111}', 'i' => '\x{0131}', # small dotless i 'L' => '\x{0141}', # L with stroke 'l' => '\x{0142}', 'NG' => '\x{014A}', # ENG 'ng' => '\x{014B}', 'OE' => '\x{0152}', # OE 'oe' => '\x{0153}', 'O' => '\x{00D8}', # O with stroke 'o' => '\x{00F8}', 'SS' => 'SS', # lately also U+1E9E, but SS seems good enough 'ss' => '\x{00DF}', 'TH' => '\x{00DE}', # THORN 'textordfeminine' => '\x{00AA}', 'textordmasculine' => '\x{00BA}', 'textregistered' => '\x{00AE}', 'th' => '\x{00FE}', 'TM' => '\x{2122}', # trade mark sign ); # Accent commands that are not alphabetic. # our %ACCENT_SYMBOLS = ( "\"" => { # with diaresis A => '\x{00C4}', E => '\x{00CB}', H => '\x{1E26}', I => '\x{00CF}', O => '\x{00D6}', U => '\x{00DC}', W => '\x{1E84}', X => '\x{1E8c}', Y => '\x{0178}', "\\I" => '\x{00CF}', "\\i" => '\x{00EF}', a => '\x{00E4}', e => '\x{00EB}', h => '\x{1E27}', i => '\x{00EF}', o => '\x{00F6}', t => '\x{1E97}', u => '\x{00FC}', w => '\x{1E85}', x => '\x{1E8d}', y => '\x{00FF}', }, "'" => { # with acute A => '\x{00C1}', AE => '\x{01FC}', C => '\x{0106}', E => '\x{00C9}', G => '\x{01F4}', I => '\x{00CD}', K => '\x{1E30}', L => '\x{0139}', M => '\x{1E3E}', N => '\x{0143}', O => '\x{00D3}', P => '\x{1E54}', R => '\x{0154}', S => '\x{015A}', U => '\x{00DA}', W => '\x{1E82}', Y => '\x{00DD}', Z => '\x{0179}', "\\I" => '\x{00CD}', "\\i" => '\x{00ED}', a => '\x{00E1}', ae => '\x{01FD}', c => '\x{0107}', e => '\x{00E9}', g => '\x{01F5}', i => '\x{00ED}', k => '\x{1E31}', l => '\x{013A}', m => '\x{1E3f}', n => '\x{0144}', o => '\x{00F3}', p => '\x{1E55}', r => '\x{0155}', s => '\x{015B}', u => '\x{00FA}', w => '\x{1E83}', y => '\x{00FD}', z => '\x{017A}', }, "^" => { # with circumflex A => '\x{00C2}', C => '\x{0108}', E => '\x{00CA}', G => '\x{011C}', H => '\x{0124}', I => '\x{00CE}', J => '\x{0134}', O => '\x{00D4}', R => 'R\x{0302}', S => '\x{015C}', U => '\x{00DB}', W => '\x{0174}', Y => '\x{0176}', Z => '\x{1E90}', "\\I" => '\x{00CE}', "\\J" => '\x{0134}', "\\i" => '\x{00EE}', "\\j" => '\x{0135}', a => '\x{00E2}', c => '\x{0109}', e => '\x{00EA}', g => '\x{011D}', h => '\x{0125}', i => '\x{00EE}', j => '\x{0135}', o => '\x{00F4}', s => '\x{015D}', u => '\x{00FB}', w => '\x{0175}', y => '\x{0177}', z => '\x{1E91}', }, "`" => { # with grave A => '\x{00C0}', E => '\x{00C8}', I => '\x{00CC}', N => '\x{01F8}', O => '\x{00D2}', U => '\x{00D9}', W => '\x{1E80}', Y => '\x{1Ef2}', "\\I" => '\x{00CC}', "\\i" => '\x{00EC}', a => '\x{00E0}', e => '\x{00E8}', i => '\x{00EC}', n => '\x{01F9}', o => '\x{00F2}', u => '\x{00F9}', w => '\x{1E81}', y => '\x{1EF3}', }, "." => { # with dot above A => '\x{0226}', B => '\x{1E02}', C => '\x{010A}', D => '\x{1E0A}', E => '\x{0116}', F => '\x{1E1E}', G => '\x{0120}', H => '\x{1E22}', I => '\x{0130}', M => '\x{1E40}', N => '\x{1E44}', O => '\x{022E}', P => '\x{1E56}', R => '\x{1E58}', S => '\x{1E60}', T => '\x{1E6a}', W => '\x{1E86}', X => '\x{1E8A}', Y => '\x{1E8E}', Z => '\x{017B}', "\\I" => '\x{0130}', a => '\x{0227}', b => '\x{1E03}', c => '\x{010B}', d => '\x{1E0B}', e => '\x{0117}', f => '\x{1e1f}', g => '\x{0121}', h => '\x{1E23}', m => '\x{1E41}', n => '\x{1E45}', o => '\x{022F}', p => '\x{1E57}', r => '\x{1E59}', s => '\x{1E61}', t => '\x{1E6b}', w => '\x{1E87}', x => '\x{1E8b}', y => '\x{1E8f}', z => '\x{017C}', }, '=' => { # with macron A => '\x{0100}', AE => '\x{01E2}', E => '\x{0112}', G => '\x{1E20}', I => '\x{012A}', O => '\x{014C}', U => '\x{016A}', Y => '\x{0232}', "\\I" => '\x{012A}', "\\i" => '\x{012B}', a => '\x{0101}', ae => '\x{01E3}', e => '\x{0113}', g => '\x{1E21}', i => '\x{012B}', o => '\x{014D}', u => '\x{016B}', y => '\x{0233}', }, "~" => { # with tilde A => '\x{00C3}', E => '\x{1EBC}', I => '\x{0128}', N => '\x{00D1}', O => '\x{00D5}', U => '\x{0168}', V => '\x{1E7C}', Y => '\x{1EF8}', "\\I" => '\x{0128}', "\\i" => '\x{0129}', a => '\x{00E3}', e => '\x{1EBD}', i => '\x{0129}', n => '\x{00F1}', o => '\x{00F5}', u => '\x{0169}', v => '\x{1E7D}', y => '\x{1EF9}', }, ); # Accent commands that are alphabetic. # our %ACCENT_LETTERS = ( "H" => { # with double acute O => '\x{0150}', U => '\x{0170}', o => '\x{0151}', u => '\x{0171}', }, "c" => { # with cedilla C => '\x{00C7}', D => '\x{1E10}', E => '\x{0228}', G => '\x{0122}', H => '\x{1E28}', K => '\x{0136}', L => '\x{013B}', N => '\x{0145}', R => '\x{0156}', S => '\x{015E}', T => '\x{0162}', c => '\x{00E7}', d => '\x{1E11}', e => '\x{0229}', g => '\x{0123}', h => '\x{1E29}', k => '\x{0137}', l => '\x{013C}', n => '\x{0146}', r => '\x{0157}', s => '\x{015F}', t => '\x{0163}', }, "d" => { # with dot below A => '\x{1EA0}', B => '\x{1E04}', D => '\x{1E0C}', E => '\x{1EB8}', H => '\x{1E24}', I => '\x{1ECA}', K => '\x{1E32}', L => '\x{1E36}', M => '\x{1E42}', N => '\x{1E46}', O => '\x{1ECC}', R => '\x{1E5A}', S => '\x{1E62}', T => '\x{1E6C}', U => '\x{1EE4}', V => '\x{1E7E}', W => '\x{1E88}', Y => '\x{1Ef4}', Z => '\x{1E92}', "\\I" => '\x{1ECA}', "\\i" => '\x{1ECB}', a => '\x{1EA1}', b => '\x{1E05}', d => '\x{1E0D}', e => '\x{1EB9}', h => '\x{1E25}', i => '\x{1ECB}', k => '\x{1E33}', l => '\x{1E37}', m => '\x{1E43}', n => '\x{1E47}', o => '\x{1ECD}', r => '\x{1E5b}', s => '\x{1E63}', t => '\x{1E6D}', u => '\x{1EE5}', v => '\x{1E7F}', w => '\x{1E89}', y => '\x{1EF5}', z => '\x{1E93}', }, "h" => { # with hook above A => '\x{1EA2}', E => '\x{1EBA}', I => '\x{1EC8}', O => '\x{1ECe}', U => '\x{1EE6}', Y => '\x{1EF6}', "\\I" => '\x{1EC8}', "\\i" => '\x{1EC9}', a => '\x{1EA3}', e => '\x{1EBB}', i => '\x{1EC9}', o => '\x{1ECF}', u => '\x{1EE7}', y => '\x{1EF7}', }, "k" => { # with ogonek A => '\x{0104}', E => '\x{0118}', I => '\x{012E}', O => '\x{01EA}', U => '\x{0172}', "\\I" => '\x{012E}', "\\i" => '\x{012F}', a => '\x{0105}', e => '\x{0119}', i => '\x{012F}', o => '\x{01EB}', u => '\x{0173}', }, "r" => { # with ring above A => '\x{00C5}', U => '\x{016E}', a => '\x{00E5}', u => '\x{016F}', w => '\x{1E98}', y => '\x{1E99}', }, "u" => { # with breve A => '\x{0102}', E => '\x{0114}', G => '\x{011E}', I => '\x{012C}', O => '\x{014E}', U => '\x{016C}', "\\I" => '\x{012C}', "\\i" => '\x{012D}', a => '\x{0103}', e => '\x{0115}', g => '\x{011F}', i => '\x{012D}', o => '\x{014F}', u => '\x{016D}', }, "v" => { # with caron A => '\x{01CD}', C => '\x{010C}', D => '\x{010E}', DZ => '\x{01C4}', E => '\x{011A}', G => '\x{01E6}', H => '\x{021E}', I => '\x{01CF}', K => '\x{01E8}', L => '\x{013D}', N => '\x{0147}', O => '\x{01D1}', R => '\x{0158}', S => '\x{0160}', T => '\x{0164}', U => '\x{01D3}', Z => '\x{017D}', "\\I" => '\x{01CF}', "\\i" => '\x{01D0}', "\\j" => '\x{01F0}', a => '\x{01CE}', c => '\x{010D}', d => '\x{010F}', dz => '\x{01C6}', e => '\x{011B}', g => '\x{01E7}', h => '\x{021F}', i => '\x{01D0}', j => '\x{01F0}', k => '\x{01E9}', l => '\x{013E}', n => '\x{0148}', o => '\x{01D2}', r => '\x{0159}', s => '\x{0161}', t => '\x{0165}', u => '\x{01D4}', z => '\x{017E}', }, ); # our %GERMAN = ( # for package `german'/`ngerman' '"a' => 'ä', '"A' => 'Ä', '"e' => 'ë', '"E' => 'Ë', '"i' => 'ï', '"I' => 'Ï', '"o' => 'ö', '"O' => 'Ö', '"u' => 'ü', '"U' => 'Ü', '"s' => 'ß', '"S' => 'SS', '"z' => 'ß', '"Z' => 'SZ', '"ck' => 'ck', # old spelling: ck -> k-k '"ff' => 'ff', # old spelling: ff -> ff-f '"`' => '„', "\"'" => '“', '"<' => '«', '">' => '»', '"-' => '\x{00AD}', # soft hyphen '""' => '\x{200B}', # zero width space '"~' => '\x{2011}', # non-breaking hyphen '"=' => '-', '\glq' => '‚', # left german single quote '\grq' => '‘', # right german single quote '\flqq' => '«', '\frqq' => '»', '\dq' => '"', ); 1; __END__ =pod =encoding UTF-8 =head1 NAME LaTeX::ToUnicode::Tables - Character tables for LaTeX::ToUnicode =head1 VERSION version 0.54 =head1 CONSTANTS =head2 @LIGATURES Standard TeX character sequences (not \commands) which need to be replaced: C<---> with U+2014 (em dash), etc. Includes: em dash, en dash, inverted exclamation, inverted question, left double quote, right double quote, left single quote, right single quote. They are replaced in that order. =head2 %MARKUPS Hash where keys are the names of formatting commands like C<\tt>, without the backslash, namely: C. Values are the obvious HTML equivalent where one exists, given as the tag name without the angle brackets: C. Otherwise the value is the empty string. =head2 %ARGUMENT_COMMANDS Hash where keys are the names of TeX commands taking arguments that we handle, without the backslash, such as C. Each value is a reference to a list of two strings, the first being the text to insert before the argument, the second being the text to insert after. For example, for C the value is C<["`", "'"]>. The inserted text is subject to further replacements. Only three such commands are currently handled: C<\emph>, C<\enquote>, and C<\path>. =head2 %CONTROL_SYMBOLS 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; 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 literal characters <"\x{...}">, to ease future parsing of the TeX/text/HTML. This hash is necessary because TeX's parsing rules for control symbols are different from control words: no space or other token is needed to terminate control symbols. =head2 %CONTROL_WORDS Keys are names of argument-less commands, such as C<\LaTeX> (without the backslash). Values are the replacements, often the empty string. =head2 %SYMBOLS Keys are the commands for extended characters, such as C<\AA> (without the backslash.) =head2 %ACCENT_SYMBOLS Two-level hash of accented characters like C<\'{a}>. The keys of this hash are the accent symbols (without the backslash), such as C<`> and C<'>. The corresponding values are hash references where the keys are the base letters and the values are single-quoted C<'\x{....}'> strings. =head2 %ACCENT_LETTERS Same as %ACCENT_SYMBOLS, except the keys are accents that are alphabetic, such as C<\c> (without the backslash as always). As with control sequences, it's necessary to distinguish symbols and alphabetic commands because of the different parsing rules. =head2 %GERMAN Character sequences (not necessarily commands) as defined by the package `german'/`ngerman', e.g. C<"a> (a with umlaut), C<"s> (german sharp s) or C<"`"> (german left quote). Note the missing backslash. The keys of this hash are the literal character sequences. =head1 AUTHOR Gerhard Gossen , Boris Veytsman , Karl Berry L =head1 COPYRIGHT AND LICENSE Copyright 2010-2023 Gerhard Gossen, Boris Veytsman, Karl Berry This is free software; you can redistribute it and/or modify it under the same terms as the Perl5 programming language system itself. =cut LaTeX-ToUnicode-0.54/lib/LaTeX/ToUnicode.pm0000644000076700000240000006762114526037103020172 0ustar bveytsmanstaffuse strict; use warnings; package LaTeX::ToUnicode; BEGIN { $LaTeX::ToUnicode::VERSION = '0.54'; } #ABSTRACT: Convert LaTeX commands to Unicode (simplistically) require Exporter; our @ISA = qw(Exporter); our @EXPORT_OK = qw( convert debuglevel $endcw ); use utf8; use Encode; use LaTeX::ToUnicode::Tables; # Terminating a control word (not symbol) the way TeX does: at the # boundary between a letter (lookbehind) and a nonletter (lookahead), # and then ignore any following whitespace. 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; # 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. # sub convert { my ($string, %options) = @_; #warn debug_hash_as_string("starting with: $string", %options); # First, remove leading and trailing horizontal whitespace # on each line of the possibly-multiline string we're given. $string =~ s/^[ \t]*//m; $string =~ s/[ \t]*$//m; # For HTML output, must convert special characters that were in the # TeX text (&<>) to their entities to avoid misparsing. We want to # do this first, because conversion of the markup commands might # output HTML tags like , and we don't want to convert those <>. # Although <tt> works, better to keep the output HTML as # human-readable as we can. # if ($options{html}) { $string =~ s/([^\\]|^)&/$1&/g; $string =~ s//>/g; } my $user_hook = $options{hook}; if ($user_hook) { $string = &$user_hook($string, \%options); _debug("after user hook: $string"); } # Convert general commands that take arguments, since (1) they might # insert TeX commands that need to be converted, and (2) because # their arguments could well contain constructs that will map to a # Perl string \x{nnnn} for Unicode character nnnn; those Perl braces # for the \x will confuse further parsing of the TeX. # $string = _convert_commands_with_arg($string); _debug("after commands with arg: $string"); # Convert markups (\texttt, etc.); they have the same brace-parsing issue. $string = _convert_markups($string, \%options); _debug("after markups: $string"); # And urls, a special case of commands with arguments. $string = _convert_urls($string, \%options); _debug("after urls: $string"); $string = _convert_control_words($string); _debug("after control words: $string"); $string = _convert_control_symbols($string); _debug("after control symbols: $string"); $string = _convert_accents($string); $string = _convert_german($string) if $options{german}; $string = _convert_symbols($string); $string = _convert_ligatures($string); # Let's handle ties here, after all the other conversions, since # they don't fit well with any of the tables. # # /~, or ~ at the beginning of a line, is probably part of a url or # path, not a tie. Otherwise, consider it a space, since a no-break # spot in TeX is most likely fine to break in text or HTML. # $string =~ s,([^/])~,$1 ,g; # Remove kerns. Clearly needs generalizing/sharpening to recognize # dimens better, and plenty of other commands could use it. #_debug("before kern: $string"); my $dimen_re = qr/[-+]?[0-9., ]+[a-z][a-z]\s*/; $string =~ s!\\kern${endcw}${dimen_re}!!g; # What the heck, let's do \hfuzz and \vfuzz too. They come up pretty # often and practically the same thing (plus ignore optional =).. $string =~ s!\\[hv]fuzz${endcw}=?\s*${dimen_re}!!g; # After all the conversions, $string contains \x{....} constructs # (Perl Unicode characters) where translations have happened. Change # those to the desired output format. Thus we assume that the # Unicode \x{....}'s are not themselves involved in further # translations, which is, so far, true. # if (! $options{entities}) { # Convert our \x strings from Tables.pm to the binary characters. # 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, # e.g., from a TeX \&. Unless we're generating HTML output, in # which case they have already been converted. if (! $options{html}) { $string =~ s/&/&/g; $string =~ s//>/g; } # Our values in Tables.pm are simple ASCII strings \x{....}, # so we can replace them with hex entities with no trouble. # Fortunately TeX does not have a standard \x control sequence. $string =~ s/\\x\{(....)\}/&#x$1;/g; # The rest of the job is about binary Unicode characters in the # input. We want to transform them into entities also. As always # in Perl, there's more than one way to do it, and several are # described here, just for the fun of it. my $ret = ""; # # decode_utf8 is described in https://perldoc.perl.org/Encode. # Without the decode_utf8, all of these methods output each byte # separately; apparently $string is a byte string at this point, # not a Unicode string. I don't know why that is. $ret = decode_utf8($string); # # Transform everything that's not printable ASCII or newline into # entities. $ret =~ s/([^ -~\n])/ sprintf("&#x%04x;", ord($1)) /eg; # # This method leaves control characters as literal; doesn't matter # for XML output, since control characters aren't allowed, but # let's use the regexp method anyway. #$ret = encode("ascii", decode_utf8($string), Encode::FB_XMLCREF); # # The nice_string function from perluniintro also works. # # This fails, just outputs numbers (that is, ord values): # foreach my $c (unpack("U*", $ret)) { # # Without the decode_utf8, outputs each byte separately. # With the decode_utf8, works, but the above seems cleaner. #foreach my $c (split(//, $ret)) { # if (ord($c) <= 31 || ord($c) >= 128) { # $ret .= sprintf("&#x%04x;", ord($c)); # } else { # $ret .= $c; # } #} # $string = $ret; # assigned from above. } if ($string =~ /\\x\{/) { warn "LaTeX::ToUnicode::convert: untranslated \\x remains: $string\n"; warn "LaTeX::ToUnicode::convert: please report as bug.\n"; } # 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. # leave newlines alone, but trim spaces and tabs. $string =~ s/^[ \t]+//s; # remove leading whitespace $string =~ s/[ \t]+$//s; # remove trailing whitespace $string =~ s/[ \t]+/ /gs; # collapse all remaining whitespace to one space $string; } # Convert commands that take a single braced argument. The table # defines text we're supposed to insert before and after the argument. # We let future processing handle conversion of both the inserted text # and the argument. # sub _convert_commands_with_arg { my $string = shift; foreach my $cmd ( keys %LaTeX::ToUnicode::Tables::ARGUMENT_COMMANDS ) { my $repl = $LaTeX::ToUnicode::Tables::ARGUMENT_COMMANDS{$cmd}; my $lft = $repl->[0]; # ref to two-element list my $rht = $repl->[1]; # \cmd{foo} -> LFT foo RHT $string =~ s/\\$cmd${endcw}\{(.*?)\}/$lft$1$rht/g; #warn "replaced arg $cmd, yielding $string\n"; } $string; } # Convert url commands in STRING. This is a special case of commands # with arguments: \url{u} and \href{u}{desc text}. The HTML output # (generated if $OPTIONS{html} is set) is just too special to be handled # in a table; further, \href is the only two-argument command we are # currently handling. # sub _convert_urls { my ($string,$options) = @_; if ($options->{html}) { # HTML output. # \url{URL} -> URL $string =~ s,\\url$endcw\{([^}]*)\} ,$1,gx; # # \href{URL}{TEXT} -> TEXT $string =~ s,\\href$endcw\{([^}]*)\}\s*\{([^}]*)\} ,$2,gx; } else { # plain text output. # \url{URL} -> URL $string =~ s/\\url$endcw\{([^}]*)\}/$1/g; # # \href{URL}{TEXT} -> TEXT (URL) # but, as a special case, if URL ends with TEXT, just output URL, # as in: # \href{https://doi.org/10/fjzzc8}{10/fjzzc8} # -> # https://doi.org/10/fjzzc8 # # Yet more specialness: the TEXT might have extra braces, as in # \href{https://doi.org/10/fjzzc8}{{10/fjzzc8}} # left over from previous markup commands (\path) which got # removed. We want to accept and ignore such extra braces, # hence the \{+ ... \}+ in recognizing TEXT. # #warn "txt url: starting with $string\n"; if ($string =~ m/\\href$endcw\{([^}]*)\}\s*\{+([^}]*)\}+/) { my $url = $1; my $text = $2; #warn " url: $url\n"; #warn " text: $text\n"; my $repl = ($url =~ m!$text$!) ? $url : "$text ($url)"; #warn " repl: $repl\n"; $string =~ s/\\href$endcw\{([^}]*)\}\s*\{+([^}]*)\}+/$repl/; #warn " str: $string\n"; } } $string; } # Convert control words (not symbols), that is, a backslash and an # alphabetic sequence of characters terminated by a non-alphabetic # character. Following whitespace is ignored. # sub _convert_control_words { my $string = shift; foreach my $command ( keys %LaTeX::ToUnicode::Tables::CONTROL_WORDS ) { my $repl = $LaTeX::ToUnicode::Tables::CONTROL_WORDS{$command}; # replace {\CMD}, whitespace ignored after \CMD. $string =~ s/\{\\$command$endcw\}/$repl/g; # replace \CMD, preceded by not-consumed non-backslash. $string =~ s/(?<=[^\\])\\$command$endcw/$repl/g; # replace \CMD at beginning of whole string, which otherwise # wouldn't be matched. Two separate regexps to avoid # variable-length lookbehind. $string =~ s/^\\$command$endcw/$repl/g; } $string; } # Convert control symbols, other than accents. Much simpler than # control words, since are self-delimiting, don't take arguments, and # don't consume any following text. # sub _convert_control_symbols { my $string = shift; foreach my $symbol ( keys %LaTeX::ToUnicode::Tables::CONTROL_SYMBOLS ) { my $repl = $LaTeX::ToUnicode::Tables::CONTROL_SYMBOLS{$symbol}; # because these are not alphabetic, we can quotemeta them, # and we need to because "\" is one of the symbols. my $rx = quotemeta($symbol); # the preceding character must not be a backslash, else "\\ " # could have the "\ " seen first as a control space, leaving # a spurious \ behind. Don't consume the preceding. # Or it could be at the beginning of a line. # $string =~ s/(^|(?<=[^\\]))\\$rx/$repl/g; #warn "after sym $symbol (\\$rx -> $repl), have: $string\n"; } $string; } # Convert accents. # sub _convert_accents { my $string = shift; # first the non-alphabetic accent commands, like \". my %tbl = %LaTeX::ToUnicode::Tables::ACCENT_SYMBOLS; $string =~ s/(\{\\(.)\s*\{(\\?\w{1,2})\}\})/$tbl{$2}{$3} || $1/eg; #{\"{a}} $string =~ s/(\{\\(.)\s*(\\?\w{1,2})\})/ $tbl{$2}{$3} || $1/eg; # {\"a} $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 to be handled # differently because \cc is not \c{c}! The only difference in the # regular expressions is using $endcw instead of just \s*. # %tbl = %LaTeX::ToUnicode::Tables::ACCENT_LETTERS; $string =~ s/(\{\\(.)$endcw\{(\\?\w{1,2})\}\})/$tbl{$2}{$3} || $1/eg; #{\"{a}} $string =~ s/(\{\\(.)$endcw(\\?\w{1,2})\})/ $tbl{$2}{$3} || $1/eg; # {\"a} $string =~ s/(\\(.)$endcw(\\?\w{1,1}))/ $tbl{$2}{$3} || $1/eg; # \"a $string =~ s/(\\(.)$endcw\{(\\?\w{1,2})\})/ $tbl{$2}{$3} || $1/eg; # \"{a} # The argument is just one \w character for the \"a case, not two, # because otherwise we might consume a following character that is # not part of the accent, e.g., a backslash (\"a\'e). # # Others can be two because of the \t tie-after accent. Even {\t oo} is ok. # # Allow whitespace after the \CMD in all cases, e.g., "\c c". Even # for the control symbols, it turns out spaces are ignored there # (as in \" o), unlike the usual syntax. # # Some non-word constituents would work, but in practice we hope # everyone just uses letters. $string; } # For the [n]german package. sub _convert_german { my $string = shift; foreach my $symbol ( keys %LaTeX::ToUnicode::Tables::GERMAN ) { $string =~ s/\Q$symbol\E/$LaTeX::ToUnicode::Tables::GERMAN{$symbol}/g; } $string; } # Control words that produce printed symbols (and letters in languages # other than English), that is. # sub _convert_symbols { my $string = shift; foreach my $symbol ( keys %LaTeX::ToUnicode::Tables::SYMBOLS ) { my $repl = $LaTeX::ToUnicode::Tables::SYMBOLS{$symbol}; # preceded by a (non-consumed) non-backslash, # usual termination for a control word. # These commands don't take arguments. $string =~ s/(?<=[^\\])\\$symbol$endcw/$repl/g; # or the beginning of the whole string: $string =~ s/^\\$symbol$endcw/$repl/g; } $string; } # Special character sequences, not \commands. They aren't all # technically ligatures, but no matter. # sub _convert_ligatures { my $string = shift; # have to convert these in order specified. my @ligs = @LaTeX::ToUnicode::Tables::LIGATURES; for (my $i = 0; $i < @ligs; $i+=2) { my $in = $ligs[$i]; my $out = $ligs[$i+1]; $string =~ s/\Q$in\E/$out/g; } $string; } # # Convert LaTeX markup commands in STRING like \textbf{...} and # {\bfshape ...} and {\bf ...}. # # If we're aiming for plain text output, they are just cleared away (the # braces are not removed). # # If we're generating HTML output ("html" key is set in $OPTIONS hash # ref), we use the value in the hash, so that \textbf{foo} becomes # foo. Nested markup doesn't work. # sub _convert_markups { my ($string, $options) = @_; # HTML is different. return _convert_markups_html($string) if $options->{html}; # Not HTML, so here we'll "convert" to plain text by removing the # markup commands. # 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, plus remove \upshape. $string =~ s/\\($markups|up)shape$endcw//g; # Remove braces and \command in: {... \MARKUP ...} $string =~ s/(\{[^{}]+)\\(?:$markups)$endcw([^{}]+\})/$1$2/g; # Remove braces and \command in: {\MARKUP ...} $string =~ s/\{\\(?:$markups)$endcw([^{}]*)\}/$1/g; # Remove: {\MARKUP # Although this will leave unmatched } chars behind, there's no # alternative without full parsing, since the bib entry will often # look like: {\em {The TeX{}book}}. Also might, in principle, be # at the end of a line. $string =~ s/\{\\(?:$markups)$endcw//g; # Ultimately we remove all braces in ltx2crossrefxml SanitizeText fns, # so the unmatched braces don't matter ... that code should be moved. $string; } # Convert \markup in STRING to html. We can't always figure out where to # put the end tag, but we always put it somewhere. We don't even attempt # to handle nested markup. # sub _convert_markups_html { my ($string) = @_; my %MARKUPS = %LaTeX::ToUnicode::Tables::MARKUPS; # have to consider each markup \command separately. for my $markup (keys %MARKUPS) { my $hcmd = $MARKUPS{$markup}; # some TeX commands don't translate my $tag = $hcmd ? "<$hcmd>" : ""; my $end_tag = $hcmd ? "" : ""; # The easy one: \textMARKUP{...} $string =~ s/\\text$markup$endcw\{(.*?)\}/$tag$1$end_tag/g; # {x\MARKUP(shape) y} -> xy (leave out braces) $string =~ s/\{([^{}]+)\\$markup(shape)?$endcw([^{}]+)\} /$1$tag$3$end_tag/gx; # {\MARKUP(shape) y} -> y. Same as previous but without # the x part. Could do it in one regex but this seems clearer. $string =~ s/\{\\$markup(shape)?$endcw([^{}]+)\} /$tag$2$end_tag/gx; # for {\MARKUP(shape) ... with no matching brace, we don't know # where to put the end tag, so seems best to do nothing. } $string; } ############################################################## # debug_hash_as_string($LABEL, HASH) # # Return LABEL followed by HASH elements, followed by a newline, as a # single string. If HASH is a reference, it is followed (but no recursive # derefencing). ############################################################### sub debug_hash_as_string { my ($label) = shift; my (%hash) = (ref $_[0] && $_[0] =~ /.*HASH.*/) ? %{$_[0]} : @_; my $str = "$label: {"; my @items = (); for my $key (sort keys %hash) { my $val = $hash{$key}; $val = ".undef" if ! defined $val; $key =~ s/\n/\\n/g; $val =~ s/\n/\\n/g; push (@items, "$key:$val"); } $str .= join (",", @items); $str .= "}"; return "$str\n"; } 1; __END__ =pod =encoding UTF-8 =head1 NAME LaTeX::ToUnicode - Convert LaTeX commands to Unicode =head1 VERSION version 0.54 =head1 SYNOPSIS use LaTeX::ToUnicode qw( convert debuglevel $endcw ); # simple examples: convert( '{\"a}' ) eq 'ä'; # true convert( '{\"a}', entities=>1 ) eq '�EF;'; # true convert( '"a', german=>1 ) eq 'ä'; # true, `german' package syntax convert( '"a', ) eq '"a'; # false, not enabled by default # more generally: my $latexstr; my $unistr = convert($latexstr); # get literal (binary) Unicode characters my $entstr = convert($latexstr, entities=>1); # get &#xUUUU; my $htmstr = convert($latexstr, entities=>1, html=>1); # also html markup my $unistr = convert($latexstr, hook=>\&my_hook); # user-defined hook # if nonzero, dumps various info; perhaps other levels in the future. LaTeX::ToUnicode::debuglevel($verbose); # regexp for terminating TeX control words, e.g., in hooks. my $endcw = $LaTeX::ToUnicode::endcw; $string =~ s/\\newline$endcw/ /g; # translate \newline to space =head1 DESCRIPTION This module provides a method to convert LaTeX markups for accents etc. into their Unicode equivalents. It translates some commands for special characters or accents into their Unicode (or HTML) equivalents and removes formatting commands. It is not at all bulletproof or complete. This module is intended to convert fragments of LaTeX source, such as bibliography entries and abstracts, into plain text (or, optionally, simplistic HTML). It is not a document conversion system. Math, tables, figures, sectioning, etc., are not handled in any way, and mostly left in their TeX form in the output. The translations assume standard LaTeX meanings for characters and control sequences; macros in the input are not considered. The aim for all the output is utter simplicity and minimalism, not faithful translation. For example, although Unicode has a code point for a thin space, the LaTeX C<\thinspace> (etc.) command is translated to the empty string; such spacing refinements desirable in the TeX output are, in our experience, generally not desired in the HTML output from this tool. As another example, TeX C<%> comments are not removed, even on lines by themselves, because they may be inside verbatim blocks, and we don't attempt to keep any such context. In practice, TeX comments are rare in the text fragments intended to be handled, so removing them in advance has not been a great burden. As another example, LaTeX ties, C<~> characters, are replaced with normal spaces (exception: unless they follow a C character or at the beginning of a line, when they're assumed to be part of a url or a pathname), rather than a no-break space character, because in our experience most ties intended for the TeX output would just cause trouble in plain text or HTML. Regarding normal whitespace: all leading and trailing horizontal whitespace (that is, SPC and TAB) is removed. All internal horizontal whitespace sequences are collapsed to a single space. After the conversions, all brace characters (C<{}>) are simply removed from the returned string. This turns out to be a significant convenience in practice, since many LaTeX commands which take arguments don't need to do anything for our purposes except output the argument. On the other hand, backslashes are not removed. This is so the caller can check for C<\\> and thus discover untranslated commands. Of course there are many other constructs that might not be translated, or translated wrongly. There is no escaping the need to carefully look at the output. Suggestions and bug reports are welcome for practical needs; we know full well that there are hundreds of commands not handled that could be. Virtually all the behavior mentioned here would be easily made customizable, if there is a need to do so. =head1 FUNCTIONS =head2 convert( $latex_string, %options ) Convert the text in C<$latex_string> into a plain(er) Unicode string. Escape sequences for accented and special characters (e.g., C<\i>, C<\"a>, ...) are converted. A few basic formatting commands (e.g., C<{\it ...}>) are removed. See the L submodule for the full conversion tables. These keys are recognized in C<%options>: =over =item C Output C<&#xUUUU;> entities (valid in XML); in this case, also convert the E, E, C<&> metacharacters to entities. Recognized non-ASCII Unicode characters in the original input are also converted to entities, not only the translations from TeX commands. The default is to output literal (binary) Unicode characters, and not change any metacharacters. =item C If this option is set, the commands introduced by the package `german' (e.g. C<"a> eq C<ä>, note the missing backslash) are also handled. =item C If this option is set, the output is simplistic html rather than plain text. This affects only a few things: S<1) the> output of urls from C<\url> and C<\href>; S<2) the> output of markup commands like C<\textbf> (but nested markup commands don't work); S<3) two> other random commands, C<\enquote> and C<\path>, because they are needed. =item C The value must be a function that takes two arguments and returns a string. The first argument is the incoming string (may be multiple lines), and the second argument is a hash reference of options, exactly what was passed to this C function. Thus the hook can detect whether html is needed. The hook is called (almost) right away, before any of the other conversions have taken place. That way the hook can make use of the predefined conversions instead of repeating them. The only changes made to the input string before the hook is called are trivial: leading and trailing whitespace (space and tab) on each line are removed, and, for HTML output, incoming ampersand, less-than, and greater-than characters are replaced with their entities. Any substitutions that result in Unicode code points must use C<\\x{nnnn}> on the right hand side: that's two backslashes and a four-digit hex number. As an example, here is a skeleton of the hook function for TUGboat: sub LaTeX_ToUnicode_convert_hook { my ($string,$options) = @_; my $endcw = $LaTeX::ToUnicode::endcw; die "no endcw regexp in LaTeX::ToUnicode??" if ! $endcw; ... $string =~ s/\\newline$endcw/ /g; # TUB's \acro{} takes an argument, but we do nothing with it. # The braces will be removed by convert(). $string =~ s/\\acro$endcw//g; ... $string =~ s/\\CTAN$endcw/CTAN/g; $string =~ s/\\Dash$endcw/\\x{2014}/g; # em dash; replacement is string ... # ignore \begin{abstract} and \end{abstract} commands. $string =~ s,\\(begin|end)$endcw\{abstract\}\s*,,g; # Output for our url abbreviations, and other commands, depends on # whether we're generating plain text or HTML. if ($options->{html}) { # HTML. # \tbsurl{URLBASE} -> URLBASE $string =~ s,\\tbsurl$endcw\{([^}]*)\} ,$1,gx; ... # varepsilon, and no line break at hyphen. $string =~ s,\\eTeX$endcw,\\x{03B5}-TeX,g; } else { # for plain text, we can just prepend the protocol://. $string =~ s,\\tbsurl$endcw,https://,g; ... $string =~ s,\\eTeX$endcw,\\x{03B5}-TeX,g; } ... return $string; } As shown here for C<\eTeX> (an abbreviation macro defined in the TUGboat style files), if markup is desired in the output, the substitutions must be different for HTML and plain text. Otherwise, the desired HTML markup is transliterated as if it were plain text. Or else the translations must be extended so that TeX markup can be used on the rhs to be replaced with the desired HTML (C<<nobr>> in this case). For the full definition (and plenty of additional information), see the file C in the TUGboat source repository at . The hook function is specified in the C call like this: LaTeX::ToUnicode::convert(..., { hook => \&LaTeX_ToUnicode_convert_hook }) =back =head2 debuglevel( $level ) Output debugging information if C<$level> is nonzero. =head2 $endcw A predefined regexp for terminating TeX control words (not control symbols!). Can be used in, for example, hook functions: my $endcw = $LaTeX::ToUnicode::endcw; $string =~ s/\\newline$endcw/ /g; # translate \newline to space It's defined as follows: our $endcw = qr/(?<=[a-zA-Z])(?=[^a-zA-Z]|$)\s*/; That is, look behind for an alphabetic character, then look ahead for a non-alphabetic character (or end of line), then consume whitespace. Fingers crossed. =head1 AUTHOR Gerhard Gossen , Boris Veytsman , Karl Berry L =head1 COPYRIGHT AND LICENSE Copyright 2010-2023 Gerhard Gossen, Boris Veytsman, Karl Berry This is free software; you can redistribute it and/or modify it under the same terms as the Perl5 programming language system itself. =cut LaTeX-ToUnicode-0.54/Makefile.PL0000644000076700000240000000220114526040641016152 0ustar bveytsmanstaff use strict; use warnings; BEGIN { require 5.8.0; } use ExtUtils::MakeMaker 6.31; my %WriteMakefileArgs = ( 'ABSTRACT' => 'Convert LaTeX commands to Unicode', 'AUTHOR' => 'Gerhard Gossen and Boris Veytsman and Karl Berry ', 'BUILD_REQUIRES' => { 'Pod-LaTeX' => '0.61' }, 'CONFIGURE_REQUIRES' => { 'ExtUtils::MakeMaker' => '6.31' }, 'DISTNAME' => 'LaTeX-ToUnicode', 'EXE_FILES' => ['script/ltx2unitxt'], 'LICENSE' => 'perl', 'NAME' => 'LaTeX::ToUnicode', 'PREREQ_PM' => {}, 'VERSION_FROM' => 'lib/LaTeX/ToUnicode.pm', 'test' => { 'TESTS' => 't/*.t' } ); unless ( eval { ExtUtils::MakeMaker->VERSION(6.56) } ) { my $br = delete $WriteMakefileArgs{BUILD_REQUIRES}; my $pp = $WriteMakefileArgs{PREREQ_PM}; for my $mod ( keys %$br ) { if ( exists $pp->{$mod} ) { $pp->{$mod} = $br->{$mod} if $br->{$mod} > $pp->{$mod}; } else { $pp->{$mod} = $br->{$mod}; } } } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); LaTeX-ToUnicode-0.54/head.ltx0000644000076700000240000000147514470510772015653 0ustar bveytsmanstaff% documentation for LaTeX::ToUnicode. % head.ltx file public domain. % \documentclass[11pt]{article} \usepackage{fullpage,pdfpages} \usepackage[hidelinks]{hyperref} \let\printindex=\empty % index is not useful \sloppy \hbadness=3000 % not aiming for good typesetting % Silence useless font warning about braces in cmsy instead of cmtt: \makeatletter\def\@font@warning#1{}\makeatother % https://tex.stackexchange.com/questions/68272 \newcommand\invisiblesection[1]{% \refstepcounter{section}% \addcontentsline{toc}{section}{\protect\numberline{\thesection}#1}% \sectionmark{#1}% } \begin{document} \title{\texttt{LaTeX::ToUnicode} documentation} \author{Boris Veytsman\thanks{borisv@lk.net}} \maketitle \tableofcontents \invisiblesection{ltx2unitxt---convert \LaTeX\ source fragments} \includepdf[pages=-]{ltx2unitxt} LaTeX-ToUnicode-0.54/Makefile.TDS0000644000076700000240000000255514526042134016304 0ustar bveytsmanstaff# # This is Makefile for TDS-compliant TeX distributions # Written by Boris Veytsman, boris@varphi.com # # This file is in public domain # PREFIX = /usr/local LIBDIR = $(PREFIX)/scripts/bibtexperllibs DOCDIR = $(PREFIX)/doc/bibtex/bibtexperllibs DOCS = latex-tounicode.pdf ltx2unitxt.pdf ltx2unitxt.1 all: docs: $(DOCS) latex-tounicode.pdf: latex-tounicode.tex ltx2unitxt.pdf texfot pdflatex $< || { rm -f $@; exit 1; } ToUnicode = lib/LaTeX/ToUnicode latex-tounicode.tex: $(ToUnicode).pm $(ToUnicode)/Tables.pm pod2latex -modify -full -prefile head.ltx -out $@ $^ latex-tounicode.tex: head.ltx # unfortunately pod2latex doesn't recognize =encoding, so there # are two warnings of "Command encoding not recognised ...". Oh well. ltx2unitxt.1: script/ltx2unitxt # don't run --version since the --help message includes --version output. help2man --no-info --version-string=" " \ --name="convert LaTeX source fragment to plain (Unicode) text or simple html" \ $< >$@ \ || { rm -f $@; exit 1; } ltx2unitxt.pdf: ltx2unitxt.1 sed 's/^Releases:/\nReleases:/' $< | groff -man -t -rS11 - | ps2pdf - $@ force: install: all docs mkdir -p $(LIBDIR) cp -r lib/* $(LIBDIR) mkdir -p $(DOCDIR) cp -r man/man3/* $(DOCDIR) cp -r latex-tounicode.pdf ltx2unitxt.pdf ltx2unitxt.1 $(DOCDIR) clean: $(RM) *.log *.aux *.out *.toc latex-tounicode.tex distclean: clean $(RM) $(DOCS)LaTeX-ToUnicode-0.54/weaver.ini0000644000076700000240000000040514470510772016203 0ustar bveytsmanstaff[-Encoding] [@CorePrep] [Name] [Version] [Region / prelude] [Generic / SYNOPSIS] [Generic / DESCRIPTION] [Generic / OVERVIEW] [Collect / ATTRIBUTES] command = attr [Collect / METHODS] command = method [Leftovers] [Region / postlude] [Authors] [Legal] LaTeX-ToUnicode-0.54/META.json0000644000076700000240000000165414526042361015635 0ustar bveytsmanstaff{ "abstract" : "Convert LaTeX commands to Unicode", "author" : [ "Gerhard Gossen and Boris Veytsman and Karl Berry " ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 7.34, CPAN::Meta::Converter version 2.150010", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "LaTeX-ToUnicode", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : {} }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "6.31" } }, "runtime" : { "requires" : {} } }, "release_status" : "stable", "version" : "0.54", "x_serialization_backend" : "JSON::PP version 4.02" } LaTeX-ToUnicode-0.54/dist.ini0000644000076700000240000000063014526037675015665 0ustar bveytsmanstaffname = LaTeX-ToUnicode author = Gerhard Gossen and Boris Veytsman and Karl Berry license = Perl_5 copyright_holder = Gerhard Gossen and Boris Veytsman copyright_year = 2010-2023 version = 0.53 [@Classic] [Prereqs] perl = 5.8.0 [NextRelease] format = %-7v %{yyyy-MM-dd HH:mm:ss}d [PodWeaver] [Repository] [@Git] [SynopsisTests]