1: # The LearningOnline Network with CAPA
2: # TeX Conversion Module
3: #
4: # $Id: lontexconvert.pm,v 1.12 2002/10/28 20:40:25 www 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: # 05/03/2001 Scott Harrison
41: # 5/4 Gerd Kortemeyer
42:
43: package Apache::lontexconvert;
44:
45: use strict;
46: use tth;
47: use vars qw($errorstring);
48: use Apache::lonmsg;
49: use Apache::lonxml;
50:
51: # ====================================================================== Header
52:
53: sub header {
54: $errorstring='';
55: my $time=time;
56: if ($ENV{'browser.mathml'}) {
57: &tth::ttminit();
58: } else {
59: &tth::tthinit();
60: }
61: return &Apache::lonxml::xmlbegin().
62: &Apache::lonxml::fontsettings().
63: "\n<head>\n".
64: &Apache::lonxml::registerurl(undef,'tex').
65: "\n</head>\n";
66: }
67:
68: # ================================================================== Conversion
69:
70: sub converted {
71: my $texstring=shift;
72: my $xmlstring='[UNDISPLAYABLE]';
73: eval(<<'ENDCONV');
74: {
75: local $SIG{SEGV}=sub { die; };
76: if ($ENV{'browser.mathml'}) {
77: $xmlstring=&tth::ttm($$texstring);
78: $xmlstring=~s/\<math\>/\<math xmlns=\"\&mathns\;\"\>/g;
79: $xmlstring=~s/\<br\>/\<br\/\>/g;
80: $xmlstring=~s/\<p\>/\<p\>\<\/p\>/g;
81: $errorstring.=&tth::ttmerror();
82: } else {
83: $xmlstring=&tth::tth($$texstring);
84: $errorstring.=&tth::ttherror();
85: }
86: }
87: ENDCONV
88: return $xmlstring;
89: }
90:
91: # ====================================================================== Footer
92:
93: sub footer {
94: my $xmlstring='';
95: if ($ENV{'request.state'} eq 'construct') {
96: $xmlstring.='<address>'.$errorstring.'</address>';
97: } else {
98: &Apache::lonmsg::author_res_msg($ENV{'request.filename'},$errorstring);
99: }
100: # -------------------------------------------------------------------- End Body
101: $xmlstring.=&Apache::lonxml::xmlend();
102: return $xmlstring;
103: }
104:
105: # ------------------------------------------------------------ Message display
106:
107: sub to_convert {
108: my ($string) = @_;
109: $string=~s/\<br\s*\/?\>/ /g;
110: return &converted(\$string);
111: }
112:
113: sub msgtexconverted {
114: my $message=shift;
115:
116: #FIXME this crap needs to go but right now the -L option might be
117: #ignored if this isn;t the first time the tth engine is used
118: #thus the \\document class crap, it makes sure we init the LaTeX stuff
119: if ($ENV{'browser.mathml'}) {
120: &tth::ttminit();
121: &tth::ttmoptions("-L");
122: } else {
123: &tth::tthinit();
124: &tth::tthoptions("-L");
125: }
126: $message=~s/(\$\$.+?\$\$)/&to_convert("\\documentclass{article}".$1)/ge;
127: $message=~s/(\$.+?\$)/&to_convert("\\documentclass{article}".$1)/ge;
128: $message=~s/(\\\(.+?\\\))/&to_convert("\\documentclass{article}".$1)/ge;
129: $message=~s/(\\\[.+?\\\])/&to_convert("\\documentclass{article}".$1)/ge;
130: return $message.$errorstring;
131: }
132:
133: 1;
134: __END__
135:
136:
137:
138:
139:
140:
141:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>