1: # The LearningOnline Network with CAPA
2: # TeX Conversion Module
3: #
4: # $Id: lontexconvert.pm,v 1.15 2003/02/05 22:50:44 albertel Exp $
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: #
39: # 05/29/00,05/30,10/11,10/20 Gerd Kortemeyer
40: # 5/4 Gerd Kortemeyer
41:
42: package Apache::lontexconvert;
43:
44: use strict;
45: use tth;
46: use vars qw($errorstring);
47: use Apache::lonmsg;
48: use Apache::lonxml;
49:
50: # ====================================================================== Header
51:
52: sub header {
53: $errorstring='';
54: my $time=time;
55: if ($ENV{'browser.mathml'}) {
56: &tth::ttminit();
57: if ($ENV{'browser.unicode'}) {
58: &tth::ttmoptions('-L -u1');
59: } else {
60: &tth::ttmoptions('-L -u0');
61: }
62: } else {
63: &tth::tthinit();
64: if ($ENV{'browser.unicode'}) {
65: &tth::tthoptions('-L -u1');
66: } else {
67: &tth::tthoptions('-L -u0');
68: }
69: }
70: return &Apache::lonxml::xmlbegin().
71: &Apache::lonxml::fontsettings().
72: "\n<head>\n".
73: &Apache::lonxml::registerurl(undef,'tex').
74: "\n</head>\n";
75: }
76:
77: # ================================================================== Conversion
78:
79: sub converted {
80: my $texstring=shift;
81: my $xmlstring='[UNDISPLAYABLE]';
82: eval(<<'ENDCONV');
83: {
84: local $SIG{SEGV}=sub { die; };
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();
91: } else {
92: $xmlstring=&tth::tth($$texstring);
93: $errorstring.=&tth::ttherror();
94: }
95: }
96: ENDCONV
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
110: $xmlstring.=&Apache::lonxml::xmlend();
111: return $xmlstring;
112: }
113:
114: # ------------------------------------------------------------ Message display
115:
116: sub to_convert {
117: my ($string) = @_;
118: $string=~s/\<br\s*\/?\>/ /g;
119: return &converted(\$string);
120: }
121:
122: sub msgtexconverted {
123: my $message=shift;
124:
125: if ($ENV{'browser.mathml'}) {
126: &tth::ttminit();
127: if ($ENV{'browser.unicode'}) {
128: &tth::ttmoptions('-L -u1');
129: } else {
130: &tth::ttmoptions('-L -u0');
131: }
132: } else {
133: &tth::tthinit();
134: if ($ENV{'browser.unicode'}) {
135: &tth::tthoptions('-L -u1');
136: } else {
137: &tth::tthoptions('-L -u0');
138: }
139: }
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;
144: return $message.$errorstring;
145: }
146:
147: 1;
148: __END__
149:
150:
151:
152:
153:
154:
155:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>