r39580 - in /branches/upstream/libtex-encode-perl: ./ current/ current/debug/ current/lib/ current/lib/TeX/ current/t/

jawnsy-guest at users.alioth.debian.org jawnsy-guest at users.alioth.debian.org
Thu Jul 9 20:38:58 UTC 2009


Author: jawnsy-guest
Date: Thu Jul  9 20:38:50 2009
New Revision: 39580

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=39580
Log:
[svn-inject] Installing original source of libtex-encode-perl

Added:
    branches/upstream/libtex-encode-perl/
    branches/upstream/libtex-encode-perl/current/
    branches/upstream/libtex-encode-perl/current/Changes
    branches/upstream/libtex-encode-perl/current/MANIFEST
    branches/upstream/libtex-encode-perl/current/MANIFEST.SKIP
    branches/upstream/libtex-encode-perl/current/META.yml
    branches/upstream/libtex-encode-perl/current/Makefile.PL
    branches/upstream/libtex-encode-perl/current/README
    branches/upstream/libtex-encode-perl/current/debug/
    branches/upstream/libtex-encode-perl/current/debug/debug.pl   (with props)
    branches/upstream/libtex-encode-perl/current/lib/
    branches/upstream/libtex-encode-perl/current/lib/TeX/
    branches/upstream/libtex-encode-perl/current/lib/TeX/Encode.pm
    branches/upstream/libtex-encode-perl/current/t/
    branches/upstream/libtex-encode-perl/current/t/01ltgt.t
    branches/upstream/libtex-encode-perl/current/t/Encode-LaTeX.t

Added: branches/upstream/libtex-encode-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtex-encode-perl/current/Changes?rev=39580&op=file
==============================================================================
--- branches/upstream/libtex-encode-perl/current/Changes (added)
+++ branches/upstream/libtex-encode-perl/current/Changes Thu Jul  9 20:38:50 2009
@@ -1,0 +1,51 @@
+Revision history for Perl extension Encode::LaTeX.
+
+1.1
+	- Added support for \ensuremath{}
+	- Wrap greek letters in \ensuremath{} to fix a typesetting problem
+	  (reported by Mark Muldoon)
+
+1.0
+	- CPAN thinks 0.10 is less than 0.9
+
+0.10
+	- Remove empty braces e.g. $\sim{}200$
+
+0.9
+	- Removed autoloader: this isn't an xs module
+	- Added LaTeX 'special characters'
+	- Changed decode behaviour to decode mathmode first, then other macros
+	- Modified decode to use a single regexp for other macros
+	- Searches for longest named macro first
+
+0.7
+	- Fixed bug: Wasn't actually eating paired braces at all
+	- math** and text** now map to span classes of the same name in htmlise
+	- Added encoding of TeX reserved characters
+
+0.6
+	- Fixed incompatibility with HTML::Parser 1.35
+	- Upped the required versions of Pod::LaTeX and HTML::Entities to ones I know
+		work
+
+0.5
+	- Fixed an incorrect quoting bug in MathMode
+	- Added a couple of tests for quote bug and escaping
+	- Now unescapes any singular character (\\ => \, \x => x, etc), this may be
+		too broad and need casing?
+
+0.4
+	- Support for Latex braces (e.g. {\rm \sigma})
+	- Support for fractions (still off-set though)
+
+0.3
+	- Moved namespace to TeX::Encode, as this isn't really
+	character encoding per-se (more character escaping)
+
+0.2
+	- Added support for decoding mathematical symbols
+
+0.1  Tue Aug 16 12:58:54 2005
+	- original version; created by h2xs 1.23 with options
+		-X -v 0.1 -b 5.8.0 -n Encode::LaTeX
+

Added: branches/upstream/libtex-encode-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtex-encode-perl/current/MANIFEST?rev=39580&op=file
==============================================================================
--- branches/upstream/libtex-encode-perl/current/MANIFEST (added)
+++ branches/upstream/libtex-encode-perl/current/MANIFEST Thu Jul  9 20:38:50 2009
@@ -1,0 +1,10 @@
+Changes
+debug/debug.pl
+lib/TeX/Encode.pm
+Makefile.PL
+MANIFEST
+MANIFEST.SKIP
+META.yml			Module meta-data (added by MakeMaker)
+README
+t/01ltgt.t
+t/Encode-LaTeX.t

Added: branches/upstream/libtex-encode-perl/current/MANIFEST.SKIP
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtex-encode-perl/current/MANIFEST.SKIP?rev=39580&op=file
==============================================================================
--- branches/upstream/libtex-encode-perl/current/MANIFEST.SKIP (added)
+++ branches/upstream/libtex-encode-perl/current/MANIFEST.SKIP Thu Jul  9 20:38:50 2009
@@ -1,0 +1,9 @@
+MANIFEST.bak
+Makefile.old
+Makefile$
+examples/robots.db
+tar.gz$
+^blib
+^pm_to_blib
+.svn/
+CVS/

Added: branches/upstream/libtex-encode-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtex-encode-perl/current/META.yml?rev=39580&op=file
==============================================================================
--- branches/upstream/libtex-encode-perl/current/META.yml (added)
+++ branches/upstream/libtex-encode-perl/current/META.yml Thu Jul  9 20:38:50 2009
@@ -1,0 +1,15 @@
+# http://module-build.sourceforge.net/META-spec.html
+#XXXXXXX This is a prototype!!!  It will change in the future!!! XXXXX#
+name:         TeX-Encode
+version:      1.1
+version_from: lib/TeX/Encode.pm
+installdirs:  site
+requires:
+    Encode::Encoding:              0.1
+    HTML::Entities:                1.27
+    HTML::Parser:                  3.35
+    Pod::LaTeX:                    0.56
+    Test::More:                    0.1
+
+distribution_type: module
+generated_by: ExtUtils::MakeMaker version 6.17

Added: branches/upstream/libtex-encode-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtex-encode-perl/current/Makefile.PL?rev=39580&op=file
==============================================================================
--- branches/upstream/libtex-encode-perl/current/Makefile.PL (added)
+++ branches/upstream/libtex-encode-perl/current/Makefile.PL Thu Jul  9 20:38:50 2009
@@ -1,0 +1,19 @@
+use 5.008;
+use ExtUtils::MakeMaker;
+# See lib/ExtUtils/MakeMaker.pm for details of how to influence
+# the contents of the Makefile that is written.
+WriteMakefile(
+    NAME              => 'TeX::Encode',
+    VERSION_FROM      => 'lib/TeX/Encode.pm', # finds $VERSION
+    PREREQ_PM         => {
+		Pod::LaTeX => 0.56,
+		HTML::Parser => 3.35,
+		HTML::Entities => 1.27,
+		Test::More => 0.1,
+		Encode::Encoding => 0.1,
+	}, # e.g., Module::Name => 1.1
+    ($] >= 5.005 ?     ## Add these new keywords supported since 5.005
+      (ABSTRACT_FROM  => 'lib/TeX/Encode.pm', # retrieve abstract from module
+       AUTHOR         => 'Timothy D Brody <tdb01r at ecs.soton.ac.uk>') : ()),
+	dist		=> { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
+);

Added: branches/upstream/libtex-encode-perl/current/README
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtex-encode-perl/current/README?rev=39580&op=file
==============================================================================
--- branches/upstream/libtex-encode-perl/current/README (added)
+++ branches/upstream/libtex-encode-perl/current/README Thu Jul  9 20:38:50 2009
@@ -1,0 +1,37 @@
+Encode-LaTeX version 0.1
+========================
+
+This module provides encoding to LaTeX escapes from utf8 using mapping tables
+in L<Pod::LaTeX> and L<HTML::Entities>. This covers only a subset of the
+Unicode character table (undef warnings will occur for non-mapped chars).
+
+Mileage will vary when decoding (converting LaTeX to utf8), as LaTeX is in
+essence a programming language, and this module does not implement LaTeX.
+
+INSTALLATION
+
+To install this module type the following:
+
+   perl Makefile.PL
+   make
+   make test
+   make install
+
+DEPENDENCIES
+
+This module requires these other modules and libraries:
+
+	Pod::LaTeX
+	HTML::Entities
+
+COPYRIGHT AND LICENCE
+
+Put the correct copyright and licence information here.
+
+Copyright (C) 2005 by Timothy D Brody
+
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself, either Perl version 5.8.7 or,
+at your option, any later version of Perl 5 you may have available.
+
+

Added: branches/upstream/libtex-encode-perl/current/debug/debug.pl
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtex-encode-perl/current/debug/debug.pl?rev=39580&op=file
==============================================================================
--- branches/upstream/libtex-encode-perl/current/debug/debug.pl (added)
+++ branches/upstream/libtex-encode-perl/current/debug/debug.pl Thu Jul  9 20:38:50 2009
@@ -1,0 +1,19 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use lib 'lib';
+
+use TeX::Encode;
+
+warn "Requires UTF-8 Support in Terminal (CTRL+C now to exit)!\n";
+
+binmode(STDOUT,":utf8");
+
+my @terms = split '\|', $TeX::Encode::LATEX_Math_mode_re;
+print "LATEX_Math_mode_re:\n",
+	join("\n", map { join("\t", $_, ord($TeX::Encode::LATEX_Math_mode{$_}), $TeX::Encode::LATEX_Math_mode{$_}) } keys %TeX::Encode::LATEX_Math_mode), "\n";
+
+print "LATEX_Escapes:\n",
+	join("\n", map { join("\t", $_, sprintf("0x%x", ord($_)), $TeX::Encode::LATEX_Escapes{$_}, $TeX::Encode::LATEX_Escapes_inv{substr($TeX::Encode::LATEX_Escapes{$_},1)}||'') } sort { ord($a) <=> ord($b) } keys %TeX::Encode::LATEX_Escapes), "\n";

Propchange: branches/upstream/libtex-encode-perl/current/debug/debug.pl
------------------------------------------------------------------------------
    svn:executable = 

Added: branches/upstream/libtex-encode-perl/current/lib/TeX/Encode.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtex-encode-perl/current/lib/TeX/Encode.pm?rev=39580&op=file
==============================================================================
--- branches/upstream/libtex-encode-perl/current/lib/TeX/Encode.pm (added)
+++ branches/upstream/libtex-encode-perl/current/lib/TeX/Encode.pm Thu Jul  9 20:38:50 2009
@@ -1,0 +1,319 @@
+package TeX::Encode;
+
+use 5.008;
+use strict;
+use warnings;
+
+#use AutoLoader qw(AUTOLOAD);
+
+use Encode::Encoding;
+use Pod::LaTeX;
+use HTML::Entities;
+use Carp;
+
+our @ISA = qw(Encode::Encoding);
+
+our $VERSION = '1.1';
+
+use constant ENCODE_CHRS => '<>&"';
+
+__PACKAGE__->Define(qw(LaTeX BibTeX latex bibtex));
+
+use vars qw( %LATEX_Escapes %LATEX_Escapes_inv $LATEX_Escapes_inv_re %LATEX_Math_mode $LATEX_Math_mode_re $LATEX_Reserved );
+
+# Missing entities in HTML::Entities?
+ at HTML::Entities::entity2char{qw(sol verbar)} = qw(\textfractionsolidus{} |);
+
+# Use the mapping from Pod::LaTeX, but we use HTML::Entities
+# to get the Unicode character
+while( my ($entity,$tex) = each %Pod::LaTeX::HTML_Escapes ) {
+	# HTML::Entities changed entity2char somewhere between 1.27 and 1.35: in 1.35
+	# there are semi-colons on all the keys in the $] > 5.007 group (#260)
+	# Regardless, using the public method is probably better karma
+	my $c = decode_entities( sprintf( "&%s;", $entity ));
+	
+	# 1.27 used UTF-8 in the source, which requires decoding
+	utf8::decode($c) if $HTML::Entities::VERSION < 1.35;
+	
+	$tex =~ s/\{\}$//; # Strip the trailing {}
+	$LATEX_Escapes{$c} = $tex;
+	if( $tex =~ s/^\$\\(.+)\$/$1/ ) {
+		$LATEX_Math_mode{$tex} = $c;
+#		warn "MM: ", quotemeta($tex), " => ", $c, "\n";
+	} elsif( $tex =~ s/^\\// ) {
+		$LATEX_Escapes_inv{$tex} = $c;
+#		warn quotemeta($tex), " => ", $c, "\n";
+	}
+}
+
+### Additional Supported Characters ###
+
+{
+	# Greek letters
+	my $i = 0;
+	for(qw( alpha beta gamma delta epsilon zeta eta theta iota kappa lamda mu nu xi omicron pi rho final_sigma sigma tau upsilon phi chi psi omega )) {
+		$LATEX_Escapes{$LATEX_Escapes_inv{$_} = chr(0x3b1+$i)} = "\\ensuremath{\\$_}";
+		$LATEX_Escapes{$LATEX_Escapes_inv{"\u$_"} = chr(0x391+$i)} = "\\ensuremath{\\\u$_}";
+		$i++;
+	}
+	# Spelling mistake in LaTeX/charmap?
+	$LATEX_Escapes{
+		$LATEX_Escapes_inv{'lambda'} = $LATEX_Escapes_inv{'lamda'}
+	} = "\\lambda";	
+	$LATEX_Escapes{
+		$LATEX_Escapes_inv{'Lambda'} = $LATEX_Escapes_inv{'Lamda'}
+	} = "\\Lambda";
+	# Special Characters from
+	# http://www.cs.wm.edu/~mliskov/texsymbols.pdf
+	my %euro = (
+		chr(0x2020) => 'dag', # Dagger
+		chr(0x2021) => 'ddag', # Double-dagger
+		chr(0xa7) => 'S', # Section mark
+		chr(0xb6) => 'P', # Paragraph
+		chr(0xdf) => 'ss', # German sharp S
+		chr(0x152) => 'OE', # French ligature OE
+		chr(0x153) => 'oe', # French ligature oe
+		chr(0x141) => 'L', # Polish suppressed-l
+		chr(0x142) => 'l', # Polish suppressed-L
+		chr(0xd8) => 'O', # Scandinavian O-with-slash
+		chr(0xf8) => 'o', # Scandinavian o-with-slash
+		chr(0xc5) => 'AA', # Scandinavian A-with-circle
+		chr(0xe5) => 'aa', # Scandinavian a-with-circle
+		chr(0x131) => 'i', # dotless i
+		chr(0x237) => 'j', # dotless j
+	);
+	while(my($c,$tex) = each %euro)
+	{
+		$LATEX_Escapes{$LATEX_Escapes_inv{$tex} = $c} = "\\$tex";
+	}
+}
+# Build a single regexp for LaTeX macros
+$LATEX_Escapes_inv_re =
+	join '|',
+	map { quotemeta($_) }
+	sort { length($b) <=> length($a) }
+	keys %LATEX_Escapes_inv;
+
+# Math-mode sequences
+%LATEX_Math_mode = (
+	%LATEX_Math_mode,
+	'AA' => chr(0xc5), # &aring; Angstrom
+	'sin' => 'sin', # sin (should be romanised), other trigonometric functions???
+	'to' => chr(0x2192), # -->
+	'leftarrow' => chr(0x2190), # <--
+	'rightarrow' => chr(0x2192), # -->
+	'approx' => chr(0x2248), # &asymp; Approximately equal to
+	'lesssim' => chr(0x2272), # May not exist!
+	'gtrsim' => chr(0x2273), # May not exist!
+	'simeq' => chr(0x2243),
+	'leq' => chr(0x2264),
+	'pm' => chr(0xb1), # &plusmn; Plus-minus
+	'times' => chr(0xd7), # &times; Times
+	'odot' => chr(0x2299), # odot
+	'int' => chr(0x222b), # integral
+	# Sets, http://www.unicode.org/charts/PDF/Unicode-4.1/U41-2100.pdf
+	'N' => chr(0x2115),
+	'R' => chr(0x211d),
+	'Z' => chr(0x2124),
+);
+# Build a single regexp for math mode macros
+$LATEX_Math_mode_re =
+	join '|',
+	map { quotemeta($_) }
+	sort { length($b) <=> length($a) }
+	keys %LATEX_Math_mode;
+# TODO
+# e.g. \acute{e} => \'e
+# Math-mode accents: hat, acute, bar, dot, breve, check, grave, vec, ddot, tilde
+
+# Based on http://www.aps.org/meet/abstracts/latex.cfm
+$LATEX_Reserved = quotemeta('#$%&~_^{}\\');
+
+# encode($string [,$check])
+sub encode
+{
+	use utf8;
+	my ($self,$str,$check) = @_;
+	$str =~ s/([$LATEX_Reserved])/\\$1/sog;
+	$str =~ s/([<>])/\$$1\$/sog;
+	$str =~ s/([^\x00-\x80])(?![A-Za-z0-9])/$LATEX_Escapes{$1}/sg;
+	$str =~ s/([^\x00-\x80])/$LATEX_Escapes{$1}\{\}/sg;
+	return $str;
+}
+
+# decode($octets [,$check])
+sub decode
+{
+	my ($self,$str,$check) = @_;
+
+	# Convert mathmode macros to unicode
+	$str =~ s/\$([^\$]+?)\$/'$'.&_mathmode($1).'$'/seg;
+
+	# Convert standard macros to chars
+	$str =~ s/\\($LATEX_Escapes_inv_re)/$LATEX_Escapes_inv{$1}/sg;
+	
+	# $str = encode_entities($str,'<>&"');
+	# Convert some LaTeX macros into HTML equivalents
+	return _htmlise(\$str);
+}
+
+# Math-mode symbols
+sub _mathmode
+{
+	my $str = shift;
+	$str =~ s/\\($LATEX_Math_mode_re)/$LATEX_Math_mode{$1}/sog;
+	$str;
+}
+
+# Superscript/subscript
+# sqrt
+# Overline for /bar
+# LaTeX
+sub _htmlise
+{
+	my $str = shift;
+	my $out = '';
+	while(length($$str) > 0) {
+		if( $$str =~ s/^\$([^\$]+)\$// ) {
+			my $s = $1;
+			$out .= "<span class='mathrm'>" . _htmlise(\$s) . "</span>";
+		} elsif( $$str =~ s/^\^// ) {
+			$out .= '<sup>' . _atom($str) . '</sup>';
+		} elsif( $$str =~ s/^_// ) {
+			$out .= '<sub>' . _atom($str) . '</sub>';
+		} elsif( $$str =~ s/^\\sqrt/\\bar/ ) {
+			$out .= chr(0x221a);
+		} elsif( $$str =~ s/^\\frac\s*// ) {
+			$out .= "<sup style='text-decoration: underline'>" . _atom($str) . '</sup>';
+			$$str =~ s/^\s*//;
+			$out .= "<sub>" . _atom($str) . '</sub>';
+		} elsif( $$str =~ s/^\\(?:bar|overline)\s*// ) {
+			$out .= "<span style='text-decoration: overline'>" . _atom($str) . "</span>";
+		} elsif( $$str =~ s/^\\((?:math|text)\w{2,3})\s*// ) {
+			$out .= "<span class='$1'>" . _atom($str) . "</span>";
+		} elsif( $$str =~ s/^\\ensuremath// ) {
+			$out .= "<span class='mathrm'>" . _atom($str) . "</span>";
+		} elsif( $$str =~ s/^LaTeX// ) {
+			$out .= "L<sup>A<\/sup>T<small>E<\/small>X";
+		} elsif( $$str =~ s/^([^\^_\\\{\$]+)// ) {
+			$out .= encode_entities($1,ENCODE_CHRS);
+		} else {
+			$out .= _atom($str);
+		}
+	}
+	return $out;
+}
+
+sub _atom
+{
+	my $str = shift;
+	if( $$str =~ s/^\{\\(cal|rm)(?:[^\w])/\{/ ) {
+		return "<span class='" . ($1 eq 'cal' ? 'textcal' : 'textrm') . "'>" . _atom($str) . "</span>";
+	} elsif( $$str =~ s/^\\\\// ) { # Newline
+		return "<br />";
+	} elsif( $$str =~ s/^\\(.)// ) { # Escaped character
+		return $1;
+	} elsif( $$str =~ s/^\{([^\{\}]*)\}// ) {
+		my $sstr = $1;
+		return _htmlise(\$sstr);
+	} elsif( $$str =~ s/^\{// ) {
+		# Find the closing tag
+		my $i = 1;
+		pos($$str) = 0;
+		while( $i > 0 && pos($$str) < (length($$str)-1) ) {
+			if( $$str =~ /[^\}]*\{/cg ) {
+				$i++;
+			} elsif( $$str =~ /[^\{]*\}/cg ) {
+				$i--;
+			} else {
+				last;
+			}
+		}
+		return '' if pos($$str) == 0;
+		my $sstr = substr($$str,0,pos($$str)-1);
+		$$str = substr($$str,pos($$str));
+		return _htmlise(\$sstr);
+	} elsif( $$str =~ s/^(.)// ) {
+		return encode_entities($1,ENCODE_CHRS);
+	}
+	return '';
+}
+
+sub perlio_ok { 0 }
+
+# Autoload methods go after =cut, and are processed by the autosplit program.
+
+1;
+__END__
+
+=head1 NAME
+
+TeX::Encode - Encode/decode Perl utf-8 strings into TeX
+
+=head1 SYNOPSIS
+
+  use TeX::Encode;
+  use Encode;
+
+  $tex = encode('latex', "This will encode an e-acute (".chr(0xe9).") as \'e");
+  $str = decode('latex', $tex); # Will decode the \'e too!
+
+=head1 DESCRIPTION
+
+This module provides encoding to LaTeX escapes from utf8 using mapping tables in L<Pod::LaTeX> and L<HTML::Entities>. This covers only a subset of the Unicode character table (undef warnings will occur for non-mapped chars). This module is intentionally vague about what it will handle, see Caveats below.
+
+Mileage will vary when decoding (converting TeX to utf8), as TeX is in essence a programming language, and this module does not implement TeX.
+
+I use this module to encode author names in BibTeX and to do a rough job at presenting LaTeX abstracts in HTML. Using decode rather than seeing $\sqrt{\Omega^2\zeta_n}$ you get something that looks like the formula.
+
+The next logical step for this module is to integrate some level of TeX grammar to improve the decoding, in particular to handle fractions and font changes (which should probably be dropped).
+
+=head1 METHODS
+
+=over 4
+
+=item TeX::Encode::encode STRING [, CHECK]
+
+Encodes a utf8 string into TeX. CHECK isn't implemented.
+
+=item TeX::Encode::decode STRING [, CHECK]
+
+Decodes a TeX string into utf8. CHECK isn't implemented.
+
+=item TeX::Encode::perlio_ok
+
+Returns 0. PerlIO isn't implemented.
+
+=back
+
+=head1 CAVEATS
+
+Proper Encode checking is not implemented.
+
+LaTeX comments (% ...) are ignored because chopping a lot of text may not be what you actually want.
+
+=head2 encode()
+
+Converts non-ASCII Unicode characters to their equivalent TeX symbols (unTeXable characters will result in undef warnings).
+
+=head2 decode()
+
+Attempts to convert TeX symbols (e.g. \ae) to Unicode characters. As an experimental feature this also handles Math-mode TeX by inserting HTML into the resulting string (so you end up with an HTML approximation of the maths - NOT MathML).
+
+=head1 SEE ALSO
+
+L<Encode::Encoding>, L<Pod::LaTeX>, L<Encode>
+
+=head1 AUTHOR
+
+Timothy D Brody, E<lt>tdb01r at ecs.soton.ac.ukE<gt>
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright (C) 2005-2007 by Timothy D Brody
+
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself, either Perl version 5.8.7 or,
+at your option, any later version of Perl 5 you may have available.
+
+=cut

Added: branches/upstream/libtex-encode-perl/current/t/01ltgt.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtex-encode-perl/current/t/01ltgt.t?rev=39580&op=file
==============================================================================
--- branches/upstream/libtex-encode-perl/current/t/01ltgt.t (added)
+++ branches/upstream/libtex-encode-perl/current/t/01ltgt.t Thu Jul  9 20:38:50 2009
@@ -1,0 +1,21 @@
+# Before `make install' is performed this script should be runnable with
+# `make test'. After `make install' it should work as `perl Encode-LaTeX.t'
+
+#########################
+
+# change 'tests => 1' to 'tests => last_test_to_print';
+
+use Test::More tests => 3;
+use Encode;
+BEGIN { use_ok('TeX::Encode') };
+
+#########################
+
+# Insert your test code below, the Test::More module is use()ed here so read
+# its man page ( perldoc Test::More ) for help writing this test script.
+
+my $str = "begin \$d_<=x/2\$ between \$d_>=3x/2\$ end";
+
+is(decode('latex', $str), "begin <span class='mathrm'>d<sub>&lt;</sub>=x/2</span> between <span class='mathrm'>d<sub>&gt;</sub>=3x/2</span> end");
+
+ok(1);

Added: branches/upstream/libtex-encode-perl/current/t/Encode-LaTeX.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtex-encode-perl/current/t/Encode-LaTeX.t?rev=39580&op=file
==============================================================================
--- branches/upstream/libtex-encode-perl/current/t/Encode-LaTeX.t (added)
+++ branches/upstream/libtex-encode-perl/current/t/Encode-LaTeX.t Thu Jul  9 20:38:50 2009
@@ -1,0 +1,73 @@
+# Before `make install' is performed this script should be runnable with
+# `make test'. After `make install' it should work as `perl Encode-LaTeX.t'
+
+#########################
+
+# change 'tests => 1' to 'tests => last_test_to_print';
+
+use Test::More tests => 24;
+use Encode;
+BEGIN { use_ok('TeX::Encode') };
+
+#########################
+
+# Insert your test code below, the Test::More module is use()ed here so read
+# its man page ( perldoc Test::More ) for help writing this test script.
+
+# decode of an encode should be equivalent
+my $str = "eacute = '" . chr(0xe9) . "'";
+is(encode('LaTeX', $str), "eacute = '\\'e'", "eacute => '\\'e'");
+is(decode('latex', "eacute = '\\'e'"), $str, $str);
+
+# General decode tests
+my %DECODE_TESTS = (
+	'\\sqrt{2}' => (chr(0x221a) . "<span style='text-decoration: overline'>2<\/span>"),
+	'hyper-K\\"ahler background' => ('hyper-K'.chr(0xe4).'hler background'),
+	'$0<\\sigma\\leq{}2$' => ('<span class=\'mathrm\'>0&lt;'.chr(0x3c3).chr(0x2264).'2</span>'),
+	'foo \\{ bar' => 'foo { bar', # Unescaping Tex escapes
+	'foo \\\\ bar' => 'foo <br /> bar', # Tex newline
+	'foo $mathrm$ bar' => 'foo <span class=\'mathrm\'>mathrm</span> bar', # Math mode test (strictly should eat spaces inside math mode too)
+	'{\\L}' => chr(0x141), # Polish suppressed-L
+	'\\ss' => chr(0xdf), # German sharp S
+	'\\oe' => chr(0x153), # French oe
+	'\\OE' => chr(0x152), # French OE
+	'\\ae' => chr(0xe6), # Scandinavian ligature ae
+"consist of \$\\sim{}260,000\$ of subprobes \$\\sim{}4\%\$ of in \$2.92\\cdot{}10^{8}\$ years. to \$1.52\\cdot{}10^{7}\$ years." =>
+"consist of <span class='mathrm'>".chr(0x223c)."260,000</span> of subprobes <span class='mathrm'>".chr(0x223c)."4%</span> of in <span class='mathrm'>2.92".chr(0x22c5)."10<sup>8</sup></span> years. to <span class='mathrm'>1.52".chr(0x22c5)."10<sup>7</sup></span> years.", # Should remove empty braces too
+	'\\ensuremath{\\alpha}' => ('<span class=\'mathrm\'>'.chr(0x3b1).'</span>'), # Math mode by ensuremath
+);
+
+# General encode tests
+my %ENCODE_TESTS = (
+	'underscores _ should be escaped' => "underscores \\_ should be escaped",
+	'#$%&~_^{}><\\' => '\\#\\$\\%\\&\\~\\_\\^\\{\\}$>$$<$\\\\',
+	chr(0xe6) => '\\ae',
+	chr(0xe6).'foo' => '\\ae{}foo',
+	chr(0x3b1) => '\\ensuremath{\\alpha}',
+);
+
+while( my( $in, $out ) = each %DECODE_TESTS ) {
+	is( decode('latex', $in), $out );
+}
+
+while( my( $in, $out ) = each %ENCODE_TESTS ) {
+	is( encode('latex', $in), $out );
+}
+
+# Check misquoting of tex strings ({})
+SKIP: {
+	skip "Pod::LaTeX::HTML_Escapes doesn't have mathrm{E}", 1 unless exists($TeX::Encode::LATEX_Math_mode{'mathrm{E}'});
+	
+	$str = 'mathrm $\\mathrm{E}$';
+	is(decode('latex', $str), 'mathrm <span class=\'mathrm\'>'.chr(917).'</span>');
+};
+
+# Unsupported
+TODO: {
+	local $TODO = "No support yet for macro-based text twiddles";
+
+	my $str = "blah \$\\acute{e}\$ blah";
+	is(decode('latex',$str), "blah <i>".chr(0xe9)."</i> blah", $str);
+}
+
+ok(1);




More information about the Pkg-perl-cvs-commits mailing list