File:  [LON-CAPA] / loncom / xml / lontex.pm
Revision 1.16: download - view: text, annotated - select for diffs
Thu Feb 20 03:46:11 2025 UTC (2 days, 4 hours ago) by raeburn
Branches: MAIN
CVS tags: version_2_12_X, HEAD
- Remove p tag wrapping error message because loncommon::simple_error_page()
  already provides it.

    1: # The LearningOnline Network with CAPA
    2: # TeX Content Handler
    3: #
    4: # $Id: lontex.pm,v 1.16 2025/02/20 03:46:11 raeburn 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: #
   29: # Copyright for TtHfunc and TtMfunc by Ian Hutchinson. 
   30: # TtHfunc and TtMfunc (the "Code") may be compiled and linked into 
   31: # binary executable programs or libraries distributed by the 
   32: # Michigan State University (the "Licensee"), but any binaries so 
   33: # distributed are hereby licensed only for use in the context
   34: # of a program or computational system for which the Licensee is the 
   35: # primary author or distributor, and which performs substantial 
   36: # additional tasks beyond the translation of (La)TeX into HTML.
   37: # The C source of the Code may not be distributed by the Licensee
   38: # to any other parties under any circumstances.
   39: #
   40: # 05/29/00,05/30,10/11 Gerd Kortemeyer
   41: 
   42: package Apache::lontex;
   43: 
   44: use strict;
   45: use Apache::File;
   46: use Apache::lontexconvert;
   47: use Apache::Constants qw(:common);
   48: use Apache::lonnet;
   49: use Apache::loncommon;
   50: use Apache::lonmsg;
   51: use Apache::lonlocal;
   52: use tth;
   53: 
   54: # ================================================================ Main Handler
   55: 
   56: sub footer {
   57:     my $xmlstring='';
   58:     if ($env{'request.state'} eq 'construct') {
   59: 	$xmlstring.='<address>'.
   60: 	    $Apache::lontexconvert::errorstring.'</address>';
   61:     } else {
   62: 	&Apache::lonmsg::author_res_msg($env{'request.filename'},
   63: 					$Apache::lonxml::errorstring);
   64:     }
   65: # -------------------------------------------------------------------- End Body
   66:     $xmlstring.=&Apache::loncommon::end_page({'discussion' => 1});
   67:     return $xmlstring;
   68: }
   69: 
   70: sub handler {
   71:   my ($r)= @_;
   72:   my @texcontents;
   73:   my $texstring;
   74: 
   75: # ----------------------------------------------------------- Set document type
   76: 
   77:   if ($env{'browser.mathml'}) {
   78:       &Apache::loncommon::content_type($r,'text/xml');
   79:   } else {
   80:       &Apache::loncommon::content_type($r,'text/html');
   81:   }
   82:   $r->send_http_header;
   83: 
   84:   return OK if $r->header_only;
   85: 
   86: # ------------------------------------------------------------------- Read file
   87: 
   88:   {
   89:       if (-e $r->filename) {
   90:           my $fh=Apache::File->new($r->filename);
   91:           @texcontents=<$fh>;
   92:           close($fh);
   93:       } else {
   94:             my $filename=(split('/',$r->filename))[-1];
   95:             my $error = &mt('Unable to find [_1]',
   96:                             '<span class="LC_filename">'.$filename.'</span>');
   97:             &Apache::loncommon::simple_error_page($r,'Not available',
   98:                                                   $error,{'no_auto_mt_msg' => 1});
   99:             return OK;
  100:       }
  101:   }
  102: 
  103:   $texstring=join("\n",@texcontents);
  104: 
  105: # --------------------------------------------------------------- Render Output
  106:   
  107:   &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
  108: 					  ['texengine','inhibitmenu']);
  109: 
  110: 
  111:   $r->print(&Apache::loncommon::start_page(undef,undef,
  112: 					   {'bgcolor'        => '#FFFFFF',
  113: 					    'force_register' => 1,
  114: 					    'only_body'      =>
  115: 						($env{'form.inhibitmenu'} 
  116: 						 eq 'yes'), }));
  117: 
  118:   my $displaymode;
  119:   if (&Apache::lonnet::EXT('resource.0.texdisplay') =~ /^(tth|mathjax)$/i) {
  120:       $displaymode = $1;
  121:   }
  122:   if ($env{'form.texengine'} =~ /^(tth|mathjax)$/i) {
  123:       $displaymode = $1;
  124:   }
  125:   $r->print(&Apache::lontexconvert::converted(\$texstring,
  126: 					      $displaymode));
  127:   $r->print(&footer());
  128: 
  129:   return OK;
  130: }
  131: 
  132: 1;
  133: __END__
  134: 
  135: =pod
  136: 
  137: =head1 NAME
  138: 
  139: Apache::lontex.pm
  140: 
  141: =head1 SYNOPSIS
  142: 
  143: Handler for tex files (somewhere in modules)
  144: 
  145: This is part of the LearningOnline Network with CAPA project
  146: described at http://www.lon-capa.org.
  147: 
  148: 
  149: =head1 SUBROUTINES
  150: 
  151: =over
  152: 
  153: =item footer()
  154: 
  155: Main Handler
  156: 
  157: =back
  158: 
  159: =cut
  160: 
  161: 
  162: 
  163: 
  164: 
  165: 
  166: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>