Annotation of loncom/xml/lontexconvert.pm, revision 1.18
1.1 harris41 1: # The LearningOnline Network with CAPA
2: # TeX Conversion Module
3: #
1.18 ! albertel 4: # $Id: lontexconvert.pm,v 1.17 2003/02/25 22:50:11 albertel Exp $
1.4 www 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: # Copyright for TtHfunc and TtMfunc by Ian Hutchinson.
29: # TtHfunc and TtMfunc (the "Code") may be compiled and linked into
30: # binary executable programs or libraries distributed by the
31: # Michigan State University (the "Licensee"), but any binaries so
32: # distributed are hereby licensed only for use in the context
33: # of a program or computational system for which the Licensee is the
34: # primary author or distributor, and which performs substantial
35: # additional tasks beyond the translation of (La)TeX into HTML.
36: # The C source of the Code may not be distributed by the Licensee
37: # to any other parties under any circumstances.
38: #
1.1 harris41 39: # 05/29/00,05/30,10/11,10/20 Gerd Kortemeyer
1.3 www 40: # 5/4 Gerd Kortemeyer
1.1 harris41 41:
42: package Apache::lontexconvert;
43:
44: use strict;
45: use tth;
46: use vars qw($errorstring);
47: use Apache::lonmsg;
1.3 www 48: use Apache::lonxml;
1.16 www 49: use Apache::lonmenu;
1.1 harris41 50:
51: # ====================================================================== Header
52:
53: sub header {
54: $errorstring='';
55: my $time=time;
56: if ($ENV{'browser.mathml'}) {
57: &tth::ttminit();
1.13 albertel 58: if ($ENV{'browser.unicode'}) {
59: &tth::ttmoptions('-L -u1');
60: } else {
61: &tth::ttmoptions('-L -u0');
62: }
1.1 harris41 63: } else {
64: &tth::tthinit();
1.13 albertel 65: if ($ENV{'browser.unicode'}) {
66: &tth::tthoptions('-L -u1');
67: } else {
68: &tth::tthoptions('-L -u0');
69: }
1.1 harris41 70: }
1.3 www 71: return &Apache::lonxml::xmlbegin().
72: &Apache::lonxml::fontsettings().
73: "\n<head>\n".
1.16 www 74: &Apache::lonmenu::registerurl(undef,'tex').
1.3 www 75: "\n</head>\n";
1.1 harris41 76: }
77:
78: # ================================================================== Conversion
79:
80: sub converted {
1.12 www 81: my $texstring=shift;
82: my $xmlstring='[UNDISPLAYABLE]';
83: eval(<<'ENDCONV');
84: {
85: local $SIG{SEGV}=sub { die; };
1.1 harris41 86: if ($ENV{'browser.mathml'}) {
87: $xmlstring=&tth::ttm($$texstring);
88: $xmlstring=~s/\<math\>/\<math xmlns=\"\&mathns\;\"\>/g;
89: $xmlstring=~s/\<br\>/\<br\/\>/g;
90: $xmlstring=~s/\<p\>/\<p\>\<\/p\>/g;
91: $errorstring.=&tth::ttmerror();
1.12 www 92: } else {
1.1 harris41 93: $xmlstring=&tth::tth($$texstring);
94: $errorstring.=&tth::ttherror();
1.12 www 95: }
1.1 harris41 96: }
1.12 www 97: ENDCONV
1.1 harris41 98: return $xmlstring;
99: }
100:
101: # ====================================================================== Footer
102:
103: sub footer {
104: my $xmlstring='';
105: if ($ENV{'request.state'} eq 'construct') {
106: $xmlstring.='<address>'.$errorstring.'</address>';
107: } else {
108: &Apache::lonmsg::author_res_msg($ENV{'request.filename'},$errorstring);
109: }
110: # -------------------------------------------------------------------- End Body
1.3 www 111: $xmlstring.=&Apache::lonxml::xmlend();
1.1 harris41 112: return $xmlstring;
1.6 www 113: }
114:
115: # ------------------------------------------------------------ Message display
116:
1.9 albertel 117: sub to_convert {
118: my ($string) = @_;
1.11 www 119: $string=~s/\<br\s*\/?\>/ /g;
1.18 ! albertel 120: $string=&HTML::Entities::decode($string);
1.9 albertel 121: return &converted(\$string);
122: }
123:
1.6 www 124: sub msgtexconverted {
125: my $message=shift;
1.9 albertel 126:
1.17 albertel 127: $errorstring='';
1.6 www 128: if ($ENV{'browser.mathml'}) {
1.15 albertel 129: &tth::ttminit();
130: if ($ENV{'browser.unicode'}) {
131: &tth::ttmoptions('-L -u1');
132: } else {
133: &tth::ttmoptions('-L -u0');
134: }
1.6 www 135: } else {
1.15 albertel 136: &tth::tthinit();
137: if ($ENV{'browser.unicode'}) {
138: &tth::tthoptions('-L -u1');
139: } else {
140: &tth::tthoptions('-L -u0');
141: }
1.6 www 142: }
1.15 albertel 143: $message=~s/(\$\$.+?\$\$)/&to_convert($1)/ge;
144: $message=~s/(\$.+?\$)/&to_convert($1)/ge;
145: $message=~s/(\\\(.+?\\\))/&to_convert($1)/ge;
146: $message=~s/(\\\[.+?\\\])/&to_convert($1)/ge;
1.8 albertel 147: return $message.$errorstring;
1.1 harris41 148: }
149:
150: 1;
151: __END__
152:
153:
154:
155:
156:
157:
158:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>