Annotation of loncom/xml/lontexconvert.pm, revision 1.15
1.1 harris41 1: # The LearningOnline Network with CAPA
2: # TeX Conversion Module
3: #
1.15 ! albertel 4: # $Id: lontexconvert.pm,v 1.14 2003/02/03 18:03:53 harris41 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.1 harris41 49:
50: # ====================================================================== Header
51:
52: sub header {
53: $errorstring='';
54: my $time=time;
55: if ($ENV{'browser.mathml'}) {
56: &tth::ttminit();
1.13 albertel 57: if ($ENV{'browser.unicode'}) {
58: &tth::ttmoptions('-L -u1');
59: } else {
60: &tth::ttmoptions('-L -u0');
61: }
1.1 harris41 62: } else {
63: &tth::tthinit();
1.13 albertel 64: if ($ENV{'browser.unicode'}) {
65: &tth::tthoptions('-L -u1');
66: } else {
67: &tth::tthoptions('-L -u0');
68: }
1.1 harris41 69: }
1.3 www 70: return &Apache::lonxml::xmlbegin().
71: &Apache::lonxml::fontsettings().
72: "\n<head>\n".
1.5 matthew 73: &Apache::lonxml::registerurl(undef,'tex').
1.3 www 74: "\n</head>\n";
1.1 harris41 75: }
76:
77: # ================================================================== Conversion
78:
79: sub converted {
1.12 www 80: my $texstring=shift;
81: my $xmlstring='[UNDISPLAYABLE]';
82: eval(<<'ENDCONV');
83: {
84: local $SIG{SEGV}=sub { die; };
1.1 harris41 85: if ($ENV{'browser.mathml'}) {
86: $xmlstring=&tth::ttm($$texstring);
87: $xmlstring=~s/\<math\>/\<math xmlns=\"\&mathns\;\"\>/g;
88: $xmlstring=~s/\<br\>/\<br\/\>/g;
89: $xmlstring=~s/\<p\>/\<p\>\<\/p\>/g;
90: $errorstring.=&tth::ttmerror();
1.12 www 91: } else {
1.1 harris41 92: $xmlstring=&tth::tth($$texstring);
93: $errorstring.=&tth::ttherror();
1.12 www 94: }
1.1 harris41 95: }
1.12 www 96: ENDCONV
1.1 harris41 97: return $xmlstring;
98: }
99:
100: # ====================================================================== Footer
101:
102: sub footer {
103: my $xmlstring='';
104: if ($ENV{'request.state'} eq 'construct') {
105: $xmlstring.='<address>'.$errorstring.'</address>';
106: } else {
107: &Apache::lonmsg::author_res_msg($ENV{'request.filename'},$errorstring);
108: }
109: # -------------------------------------------------------------------- End Body
1.3 www 110: $xmlstring.=&Apache::lonxml::xmlend();
1.1 harris41 111: return $xmlstring;
1.6 www 112: }
113:
114: # ------------------------------------------------------------ Message display
115:
1.9 albertel 116: sub to_convert {
117: my ($string) = @_;
1.11 www 118: $string=~s/\<br\s*\/?\>/ /g;
1.9 albertel 119: return &converted(\$string);
120: }
121:
1.6 www 122: sub msgtexconverted {
123: my $message=shift;
1.9 albertel 124:
1.6 www 125: if ($ENV{'browser.mathml'}) {
1.15 ! albertel 126: &tth::ttminit();
! 127: if ($ENV{'browser.unicode'}) {
! 128: &tth::ttmoptions('-L -u1');
! 129: } else {
! 130: &tth::ttmoptions('-L -u0');
! 131: }
1.6 www 132: } else {
1.15 ! albertel 133: &tth::tthinit();
! 134: if ($ENV{'browser.unicode'}) {
! 135: &tth::tthoptions('-L -u1');
! 136: } else {
! 137: &tth::tthoptions('-L -u0');
! 138: }
1.6 www 139: }
1.15 ! albertel 140: $message=~s/(\$\$.+?\$\$)/&to_convert($1)/ge;
! 141: $message=~s/(\$.+?\$)/&to_convert($1)/ge;
! 142: $message=~s/(\\\(.+?\\\))/&to_convert($1)/ge;
! 143: $message=~s/(\\\[.+?\\\])/&to_convert($1)/ge;
1.8 albertel 144: return $message.$errorstring;
1.1 harris41 145: }
146:
147: 1;
148: __END__
149:
150:
151:
152:
153:
154:
155:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>