1# -*- mode: Perl -*- 2# /=====================================================================\ # 3# | inputenc | # 4# | Implementation for LaTeXML | # 5# |=====================================================================| # 6# | Part of LaTeXML: | # 7# | Public domain software, produced as part of work done by the | # 8# | United States Government & not subject to copyright in the US. | # 9# |---------------------------------------------------------------------| # 10# | Bruce Miller <bruce.miller@nist.gov> #_# | # 11# | http://dlmf.nist.gov/LaTeXML/ (o o) | # 12# \=========================================================ooo==U==ooo=/ # 13package LaTeXML::Package::Pool; 14use strict; 15use warnings; 16use LaTeXML::Package; 17use Encode; 18 19#********************************************************************** 20DefPrimitive('\DeclareInputMath {Number} {}', sub { 21 my ($stomach, $code, $expansion) = @_; 22 my $char = pack('C', $code->valueOf); 23 AssignCatcode($char, CC_ACTIVE); 24 DefMacroI(T_ACTIVE($char), undef, $expansion); }); 25 26DefPrimitive('\DeclareInputText {Number} {}', sub { 27 my ($stomach, $code, $expansion) = @_; 28 my $char = pack('C', $code->valueOf); 29 AssignCatcode($char, CC_ACTIVE); 30 DefMacroI(T_ACTIVE($char), undef, $expansion); }); 31 32DefMacro('\IeC{}', '#1'); 33 34DefMacroI('\@inpenc@undefined', undef, sub { 35 Error('unexpected', '<char>', $_[0], 36 "Keyboard character used is undefined in inputencoding " . LookupValue('INPUT_ENCODING')); }); 37 38DefPrimitive('\inputencoding{}', sub { SetInputEncoding(ToString(Expand($_[1]))); }); 39 40DeclareOption(undef, sub { SetInputEncoding(ToString(Expand(T_CS('\CurrentOption')))); }); 41 42ProcessOptions(); 43 44#********************************************************************** 45sub SetInputEncoding { 46 my ($encoding) = @_; 47 # Initially disable all odd & upper half-plane chars 48 foreach my $code ((0 .. 8), 0xB, (0xE .. 0x1E), (128 .. 255)) { 49 my $char = pack('C', $code); 50 AssignCatcode($char, CC_ACTIVE); 51 Let(T_ACTIVE($char), '\@inpenc@undefined'); } 52 AssignValue(PERL_INPUT_ENCODING => undef); # Disable the perl-level decoding, if any. 53 54 # Then load TeX's input encoding definitions. 55 InputDefinitions($encoding, type => 'def'); 56 # NOTE: INPUT_ENCODING is never actually used anywhere! 57 # So, presumably either Perl is magically converting to utf8 58 # or more likely, treating the bytes as (misinterpreted?) utf8? 59 # In latter case, perhaps it doesn't matter as long as we end up with the same bytes in/out??? 60 AssignValue(INPUT_ENCODING => $encoding); 61 DefMacro('\inputencodingname', TokenizeInternal($encoding)); 62 return; } 63 64#********************************************************************** 651; 66