--- loncom/xml/lontexconvert.pm 2001/05/04 17:38:22 1.3
+++ loncom/xml/lontexconvert.pm 2019/02/15 20:56:22 1.122
@@ -1,73 +1,693 @@
# The LearningOnline Network with CAPA
# TeX Conversion Module
#
-# 05/29/00,05/30,10/11,10/20 Gerd Kortemeyer
-# 05/03/2001 Scott Harrison
-# 5/4 Gerd Kortemeyer
+# $Id: lontexconvert.pm,v 1.122 2019/02/15 20:56:22 raeburn Exp $
+#
+# Copyright Michigan State University Board of Trustees
+#
+# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
+#
+# LON-CAPA 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 2 of the License, or
+# (at your option) any later version.
+#
+# LON-CAPA 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 LON-CAPA; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# /home/httpd/html/adm/gpl.txt
+#
+# http://www.lon-capa.org/
+#
+# Copyright for TtHfunc and TtMfunc by Ian Hutchinson.
+# TtHfunc and TtMfunc (the "Code") may be compiled and linked into
+# binary executable programs or libraries distributed by the
+# Michigan State University (the "Licensee"), but any binaries so
+# distributed are hereby licensed only for use in the context
+# of a program or computational system for which the Licensee is the
+# primary author or distributor, and which performs substantial
+# additional tasks beyond the translation of (La)TeX into HTML.
+# The C source of the Code may not be distributed by the Licensee
+# to any other parties under any circumstances.
+#
package Apache::lontexconvert;
use strict;
-use tth;
+use tth();
use vars qw($errorstring);
-use Apache::lonmsg;
-use Apache::lonxml;
+#use Apache::lonxml();
+use Apache::lonlocal;
+use Apache::lonnet;
+use lib '/home/httpd/lib/perl/';
+use LONCAPA;
+use URI::Escape;
+use IO::Socket::INET;
+
+
+#
+# Table of substitutions to unicode characters.
+#
+
+my %unicode_harpoons = (
+ '\rightleftharpoons' => 0x21cc,
+ );
+
+my %unicode_translations = (
+
+# Brackets - unicode for browsers/OS which support it.
+
+ '' => 0x23a1,
+ '' => 0x23a2,
+ '' => 0x23a3,
+ '' => 0x23a4,
+ '' => 0x23a5,
+ '' => 0x23a6,
+
+# Parens - unicode for browsers/OS which support it
+
+ '' => 0x239b,
+ '' => 0x239c,
+ '' => 0x239d,
+ '' => 0x239e,
+ '' => 0x239f,
+ '' => 0x23a0,
+
+);
+
+my %ascii_8bit_translations = (
+
+# Brackets - pure 8-bit ascii ugliness for browsers/OS which can't handle unicode
+
+ '' => 0x5b,
+ '' => 0x5b, # '['
+ '' => 0x5b,
+ '' => 0x5d, # ']'
+ '' => 0x5d,
+ '' => 0x5d,
+
+# Parens - pure 8-bit ascii ugliness for browsers/OS which can't handle unicode
+
+ '' => 0x28,
+ '' => 0x28, # '('
+ '' => 0x28,
+ '' => 0x29,
+ '' => 0x29, # '('
+ '' => 0x29,
+
+);
+
+##
+# Utility to convert elements of a string to unicode:
+#
+# @param input - Input string
+# @param pattern - Pattern to convert
+# @param unicode - Unicode to substitute for pattern.
+#
+# @return string - resulting string.
+#
+sub unicode_subst {
+ my ($input, $pattern, $unicode) = @_;
+
+ my $char = pack('U', $unicode);
+
+ $input =~ s/$pattern/$char/g;
+
+ return $input;
+}
# ====================================================================== Header
-sub header {
- $errorstring='';
- my $time=time;
- if ($ENV{'browser.mathml'}) {
- &tth::ttminit();
- } else {
- &tth::tthinit();
- }
- return &Apache::lonxml::xmlbegin().
- &Apache::lonxml::fontsettings().
- "\n
\n".
- &Apache::lonxml::registerurl().
- "\n\n";
+sub init_tth {
+ my $options=$env{'course.'.$env{'request.course.id'}.'.tthoptions'};
+ if ($options =~ /\S/) {
+ $options = ' '.$options;
+ } else {
+ undef($options);
+ }
+ if ($env{'browser.mathml'}) {
+ &tth::ttminit();
+ if ($env{'browser.unicode'}) {
+ &tth::ttmoptions('-L -u1'.$options);
+ } else {
+ &tth::ttmoptions('-L -u0'.$options);
+ }
+ } else {
+ &tth::tthinit();
+ if ($env{'browser.unicode'}) {
+ &tth::tthoptions('-L -u1'.$options);
+ } else {
+ &tth::tthoptions('-L -u0'.$options);
+ }
+ }
}
# ================================================================== Conversion
-sub converted {
+$Apache::lontexconvert::messedup=0;
+
+
+sub convert_real {
+ my ($texstring)=@_;
+ my ($xmlstring,$errorstring);
+ local $SIG{SEGV}=sub { $Apache::lontexconvert::messedup=1; die; };
+ local $SIG{ALRM}=sub {
+ &Apache::lonnet::logthis("ALRM");
+ $xmlstring='['.&mt("TeX unconverted due to errors").']';
+ $Apache::lontexconvert::messedup=1;
+ die &mt("TeX unconverted due to errors");
+ };
+ &Apache::lonxml::start_alarm();
+ if ($env{'browser.mathml'}) {
+ $xmlstring=&tth::ttm($$texstring);
+ $xmlstring=~s/\