File:
[LON-CAPA] /
loncom /
interface /
lonhelp.pm
Revision
1.15:
download - view:
text,
annotated -
select for diffs
Mon May 17 22:08:56 2004 UTC (20 years, 3 months ago) by
albertel
Branches:
MAIN
CVS tags:
version_1_3_X,
version_1_3_3,
version_1_3_2,
version_1_3_1,
version_1_3_0,
version_1_2_X,
version_1_2_99_1,
version_1_2_99_0,
version_1_2_1,
version_1_2_0,
version_1_1_99_5,
version_1_1_99_4,
version_1_1_99_3,
version_1_1_99_2,
version_1_1_99_1,
version_1_1_99_0,
HEAD
- add missing \label
- add errormessage generation to lonhelp.pm in case it does not find a label for
the reference
- This should fix #3016, and make it easier to find these errors in the fututre
1: # The LearningOnline Network with CAPA
2: # .tex help system web server handler
3: #
4: # Copyright Michigan State University Board of Trustees
5: #
6: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
7: #
8: # LON-CAPA is free software; you can redistribute it and/or modify
9: # it under the terms of the GNU General Public License as published by
10: # the Free Software Foundation; either version 2 of the License, or
11: # (at your option) any later version.
12: #
13: # LON-CAPA is distributed in the hope that it will be useful,
14: # but WITHOUT ANY WARRANTY; without even the implied warranty of
15: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16: # GNU General Public License for more details.
17: #
18: # You should have received a copy of the GNU General Public License
19: # along with LON-CAPA; if not, write to the Free Software
20: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21: #
22: # /home/httpd/html/adm/gpl.txt
23: #
24: # http://www.lon-capa.org/
25: #
26: # .tex file help handler
27: # YEAR=2002
28: # 7/4 Jeremy Bowers
29:
30: package Apache::lonhelp;
31:
32: use strict;
33: use Apache::Constants qw(:common :http);
34: use Apache::File();
35: use Apache::loncommon();
36: use Apache::lonacc();
37: use Apache::lontexconvert();
38: use Apache::lonnavmaps; # for advancedUser
39: use Apache::lonlocal;
40: use tth();
41: use GDBM_File();
42:
43: # This sub takes the name of a label in, and converts it to something
44: # that is a valid anchor name.
45: sub processLabelName
46: {
47: my ($name) = @_;
48: $name =~ tr/a-zA-Z0-9/_/cs;
49: return $name;
50: }
51:
52: # Serve out the Tex
53: sub serveTex
54: {
55: my ($tex, $r) = @_;
56: my $bugs=&Apache::loncommon::help_open_bug('Documentation');
57: my $header=&mt('LON-CAPA Help');
58: my $footer=&mt('About LON-CAPA help and More Help');
59: $r->print(<<HEADER);
60: <html>
61: <head>
62: <title>LON-CAPA Help</title>
63: </head>
64: <body bgcolor="#FFFFFF">
65: <h3 style="font: sans-serif"><img align="right"
66: src="/adm/help/gif/lonhelpheader.gif"/>$header<hr />$bugs</h3>
67: <!-- BEGIN -->
68: HEADER
69:
70: $r->print($tex);
71:
72: if (Apache::lonnavmaps::advancedUser()) {
73: $r->print(<<FOOTER);
74: <!-- END -->
75: <hr />
76: <center><font size="-1"><a href="/adm/help/abouthelp.html">$footer</a></font></center>
77: </body>
78: </html>
79: FOOTER
80: } else {
81: $r->print(<<FOOTER);
82: <!-- END -->
83: </body>
84: </html>
85: FOOTER
86: }
87: }
88:
89: # Render takes a tex fragment, transforms it for TtH, and returns the
90: # HTML equivalent
91: sub render
92: {
93: my ($tex, $docroot, $serverroot) = @_;
94: tie (my %fragmentLabels, 'GDBM_File', $docroot . '/adm/help/fragmentLabels.gdbm', 0, 0);
95:
96: # This tells TtH what to do with captions, labels, and other
97: # things
98: $tex = "\\documentclass{article}\n" . $tex;
99:
100: # We process these ourselves because TtH can't handle then without
101: # LaTeX .aux files
102: # absolute paths for use with help.loncapa.org
103: $tex =~ s| \\ref\{([^}]*)\}
104: |
105: if (not(exists($fragmentLabels{$1}))) {
106: &Apache::lonnet::logthis("ERROR: $1 not a valid help label");
107: };
108: '\\begin{html}<a href="http://' . $serverroot ."/adm/help/".
109: substr($fragmentLabels{$1}, 0, -4) .
110: '.hlp#' . processLabelName($1) .
111: '"><img src="http://' . $serverroot . '/adm/help/gif/smallHelp.gif" border="0" /></a>' .
112: '\\end{html}'
113: |gxe;
114:
115: # Backslashes
116: $tex =~ s|\\textbackslash|###BACKSLASH###|g;
117:
118: # Figures leftover without captions
119: $tex =~ s| \\includegraphics(\[[^]]*\])*\{([^}]*)\}
120: | '\\begin{html}<img src="http://' . $serverroot . '/adm/help/gif/' . $2 . '.gif" border="2"'.
121: ' bordercolor="#000000"/>\\end{html}'
122: |gxe;
123:
124:
125: $tex=&Apache::lontexconvert::converted(\$tex);
126:
127: # Finish backslashes
128: $tex =~ s/###BACKSLASH###/'\\'/ge;
129:
130: # Fix the pretty quotes
131: $tex =~ s/('')|(``)/"/g; #" to get emacs syntax highlighter happy
132:
133: # For some reason all captions come out as "Figure 0:", so
134: # just duck the issue...
135:
136: $tex =~ s/Figure 0://g;
137: $tex.=$Apache::lontexconvert::errorstring;
138: untie %fragmentLabels;
139:
140: return $tex;
141: }
142:
143: sub handler
144: {
145: my $r = shift;
146:
147: my $docroot = $r->dir_config('lonDocRoot');
148: my $serverroot = $ENV{'HTTP_HOST'};
149:
150: my $filenames = &Apache::lonnet::unescape(substr ($ENV{'REQUEST_URI'} ,
151: rindex($ENV{'REQUEST_URI'}, '/') + 1, -4));
152:
153: # Security check on the file; the whole filename must consist
154: # of nothing but alphanums, ' ,, or ., or the file
155: # will be "not found", no matter what.
156:
157: return HTTP_NOT_FOUND if ($filenames !~ /\A[-0-9a-zA-z_'',:.]+\Z/);
158:
159: &Apache::lonlocal::get_language_handle($r);
160:
161: # Join together the tex files, return HTTP_NOT_FOUND if any of
162: # them are not found
163: my $tex = '';
164: # Since in insertlist.tab I want to specify multiple files,
165: # and insertlist.tab also uses commas, I need something else
166: # so replace : with ,
167: $filenames =~ s/:/,/g;
168: my @files = split(/,/, $filenames);
169:
170: for my $filename (@files) {
171: if (-e $docroot.'/adm/help/tex/'.
172: &Apache::lonlocal::current_language().'/'.
173: $filename.'.tex') {
174: $filename=&Apache::lonlocal::current_language().'/'.$filename;
175: }
176: (my $file = Apache::File->new($docroot
177: . '/adm/help/tex/'.$filename.'.tex'))
178: or return HTTP_NOT_FOUND;
179: $tex .= join('', <$file>);
180: }
181:
182: if ($ENV{'browser.mathml'}) {
183: &Apache::loncommon::content_type($r,'text/xml');
184: &tth::ttminit();
185: if ($ENV{'browser.unicode'}) {
186: &tth::ttmoptions('-L -u1');
187: } else {
188: &tth::ttmoptions('-L -u0');
189: }
190: } else {
191: &Apache::loncommon::content_type($r,"text/html");
192: &tth::tthinit();
193: if ($ENV{'browser.unicode'}) {
194: &tth::tthoptions('-L -u1');
195: } else {
196: &tth::tthoptions('-L -u0');
197: }
198: }
199:
200: $r->send_http_header;
201: $tex = render($tex, $docroot, $serverroot);
202: serveTex($tex, $r);
203:
204: return OK;
205: }
206:
207: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>