Annotation of loncom/xml/lontexconvert.pm, revision 1.25
1.1 harris41 1: # The LearningOnline Network with CAPA
2: # TeX Conversion Module
3: #
1.25 ! www 4: # $Id: lontexconvert.pm,v 1.24 2003/06/23 21:28:59 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);
1.19 albertel 47: use Apache();
1.1 harris41 48: use Apache::lonmsg;
1.3 www 49: use Apache::lonxml;
1.16 www 50: use Apache::lonmenu;
1.1 harris41 51:
52: # ====================================================================== Header
53:
54: sub header {
55: $errorstring='';
56: my $time=time;
57: if ($ENV{'browser.mathml'}) {
58: &tth::ttminit();
1.13 albertel 59: if ($ENV{'browser.unicode'}) {
60: &tth::ttmoptions('-L -u1');
61: } else {
62: &tth::ttmoptions('-L -u0');
63: }
1.1 harris41 64: } else {
65: &tth::tthinit();
1.13 albertel 66: if ($ENV{'browser.unicode'}) {
67: &tth::tthoptions('-L -u1');
68: } else {
69: &tth::tthoptions('-L -u0');
70: }
1.1 harris41 71: }
1.3 www 72: return &Apache::lonxml::xmlbegin().
73: &Apache::lonxml::fontsettings().
74: "\n<head>\n".
1.16 www 75: &Apache::lonmenu::registerurl(undef,'tex').
1.3 www 76: "\n</head>\n";
1.1 harris41 77: }
78:
79: # ================================================================== Conversion
80:
1.19 albertel 81: $Apache::lontexconvert::messedup=0;
1.1 harris41 82: sub converted {
1.12 www 83: my $texstring=shift;
84: my $xmlstring='[UNDISPLAYABLE]';
1.19 albertel 85: if ($Apache::lontexconvert::messedup) {
1.24 albertel 86: return '[TeX Uncoverted Due To Previous Errors]';
1.19 albertel 87: }
1.12 www 88: eval(<<'ENDCONV');
1.19 albertel 89: {
90: local $SIG{SEGV}=sub { $Apache::lontexconvert::messedup=1; die; };
1.1 harris41 91: if ($ENV{'browser.mathml'}) {
92: $xmlstring=&tth::ttm($$texstring);
93: $xmlstring=~s/\<math\>/\<math xmlns=\"\&mathns\;\"\>/g;
94: $xmlstring=~s/\<br\>/\<br\/\>/g;
95: $xmlstring=~s/\<p\>/\<p\>\<\/p\>/g;
96: $errorstring.=&tth::ttmerror();
1.12 www 97: } else {
1.1 harris41 98: $xmlstring=&tth::tth($$texstring);
99: $errorstring.=&tth::ttherror();
1.12 www 100: }
1.23 albertel 101: $xmlstring=~s/^\s*//;
102: $xmlstring=~s/\s*$//;
1.1 harris41 103: }
1.12 www 104: ENDCONV
1.19 albertel 105: if ($Apache::lontexconvert::messedup || &tth::tthmessedup()) {
106: &Apache::lonnet::logthis("Trying to kill myself");
107: $Apache::lontexconvert::messedup=1;
108: my $request=Apache->request();
109: $request->child_terminate();
110: }
1.1 harris41 111: return $xmlstring;
112: }
113:
114: # ====================================================================== Footer
115:
116: sub footer {
117: my $xmlstring='';
118: if ($ENV{'request.state'} eq 'construct') {
119: $xmlstring.='<address>'.$errorstring.'</address>';
120: } else {
121: &Apache::lonmsg::author_res_msg($ENV{'request.filename'},$errorstring);
122: }
123: # -------------------------------------------------------------------- End Body
1.3 www 124: $xmlstring.=&Apache::lonxml::xmlend();
1.1 harris41 125: return $xmlstring;
1.6 www 126: }
127:
128: # ------------------------------------------------------------ Message display
129:
1.9 albertel 130: sub to_convert {
131: my ($string) = @_;
1.22 www 132: $string=~s/\<br\s*\/?\>/ /gs;
133: $string=~s/\s/ /gs;
1.18 albertel 134: $string=&HTML::Entities::decode($string);
1.9 albertel 135: return &converted(\$string);
136: }
137:
1.20 www 138: sub smiley {
139: my $expression=shift;
140: if ($ENV{'browser.imagesuppress'} eq 'on') { return $expression; }
141: my %smileys=('\:\-*\)' => 'smiley',
142: '8\-*\)' => 'coolsmile',
143: '8\-*I' => 'coolindiff',
144: ':\-*\(' => 'frowny',
145: '\:\-*(o|O|\(\))' => 'shocked',
146: '\;\-*\)' => 'wink',
147: '\:\-*P' => 'baeh',
1.21 www 148: '\:\-(\\\|\\/)' => 'hrrm',
1.20 www 149: '\:\-*D' => 'bigsmile',
150: '\:\-*C' => 'angry',
151: '\:(\'|\`)\-*\(' => 'cry',
152: '\:\-*(X|\#)' => 'lipsrsealed',
153: '\:\-*S' => 'huh');
154: my $iconpath=$Apache::lonnet::perlvar{'lonIconsURL'};
155: foreach (keys %smileys) {
156: $expression=~s/$_/\<img src="$iconpath\/$smileys{$_}.gif" \/\>/gs;
157: }
158: return $expression;
159: }
160:
1.6 www 161: sub msgtexconverted {
162: my $message=shift;
1.9 albertel 163:
1.17 albertel 164: $errorstring='';
1.6 www 165: if ($ENV{'browser.mathml'}) {
1.15 albertel 166: &tth::ttminit();
167: if ($ENV{'browser.unicode'}) {
168: &tth::ttmoptions('-L -u1');
169: } else {
170: &tth::ttmoptions('-L -u0');
171: }
1.6 www 172: } else {
1.15 albertel 173: &tth::tthinit();
174: if ($ENV{'browser.unicode'}) {
175: &tth::tthoptions('-L -u1');
176: } else {
177: &tth::tthoptions('-L -u0');
178: }
1.6 www 179: }
1.25 ! www 180: my $outmessage='';
! 181: my $tex=0;
! 182: foreach (split(/(?:\<\;|\<)\/*m\s*(?:\>\;|\>)/i,$message)) {
! 183: if ($tex) {
! 184: $outmessage.=&to_convert($_); $tex=0;
! 185: } else {
! 186: $outmessage.=&smiley($_); $tex=1;
! 187: }
! 188: }
1.24 albertel 189: if (wantarray) {
1.25 ! www 190: return ($outmessage,$errorstring);
1.24 albertel 191: } else {
1.25 ! www 192: return $outmessage.$errorstring;
1.24 albertel 193: }
1.1 harris41 194: }
195:
196: 1;
197: __END__
198:
199:
200:
201:
202:
203:
204:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>