File:  [LON-CAPA] / loncom / xml / lontex.pm
Revision 1.14: download - view: text, annotated - select for diffs
Fri Dec 22 13:38:01 2023 UTC (4 months, 1 week ago) by raeburn
Branches: MAIN
CVS tags: version_2_12_X, version_2_11_4_msu, HEAD
- .tex file in Resource Space or uploaded to Main Content area:
  - texdisplay parameter can determine whether TtH of MathJax is used for
    conversion (web context)
  - values in effect for contentopen, contentclose, and acc params honored

    1: # The LearningOnline Network with CAPA
    2: # TeX Content Handler
    3: #
    4: # $Id: lontex.pm,v 1.14 2023/12/22 13:38:01 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 tth;
   50: 
   51: # ================================================================ Main Handler
   52: 
   53: sub footer {
   54:     my ($errorstring) = @_;
   55:     my $xmlstring='';
   56:     if ($env{'request.state'} eq 'construct') {
   57: 	$xmlstring.='<address>'.
   58: 	    $Apache::lontexconvert::errorstring.'</address>';
   59:     } else {
   60: 	&Apache::lonmsg::author_res_msg($env{'request.filename'},
   61: 					$Apache::lonxml::errorstring);
   62:     }
   63: # -------------------------------------------------------------------- End Body
   64:     $xmlstring.=&Apache::loncommon::end_page({'discussion' => 1});
   65:     return $xmlstring;
   66: }
   67: 
   68: sub handler {
   69:   my ($r)= @_;
   70:   my @texcontents;
   71:   my $texstring;
   72: 
   73: # ----------------------------------------------------------- Set document type
   74: 
   75:   if ($env{'browser.mathml'}) {
   76:       &Apache::loncommon::content_type($r,'text/xml');
   77:   } else {
   78:       &Apache::loncommon::content_type($r,'text/html');
   79:   }
   80:   $r->send_http_header;
   81: 
   82:   return OK if $r->header_only;
   83: 
   84: # ------------------------------------------------------------------- Read file
   85: 
   86:   {
   87:     my $fh=Apache::File->new($r->filename);
   88:     @texcontents=<$fh>;
   89:   }
   90: 
   91:   $texstring=join("\n",@texcontents);
   92: 
   93: # --------------------------------------------------------------- Render Output
   94:   
   95:   &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
   96: 					  ['texengine','inhibitmenu']);
   97: 
   98: 
   99:   $r->print(&Apache::loncommon::start_page(undef,undef,
  100: 					   {'bgcolor'        => '#FFFFFF',
  101: 					    'force_register' => 1,
  102: 					    'only_body'      =>
  103: 						($env{'form.inhibitmenu'} 
  104: 						 eq 'yes'), }));
  105: 
  106:   my $displaymode;
  107:   if (&Apache::lonnet::EXT('resource.0.texdisplay') =~ /^(tth|mathjax)$/i) {
  108:       $displaymode = $1;
  109:   }
  110:   if ($env{'form.texengine'} =~ /^(tth|mathjax)$/i) {
  111:       $displaymode = $1;
  112:   }
  113:   $r->print(&Apache::lontexconvert::converted(\$texstring,
  114: 					      $displaymode));
  115:   $r->print(&footer());
  116: 
  117:   return OK;
  118: }
  119: 
  120: 1;
  121: __END__
  122: 
  123: =pod
  124: 
  125: =head1 NAME
  126: 
  127: Apache::lontex.pm
  128: 
  129: =head1 SYNOPSIS
  130: 
  131: Handler for tex files (somewhere in modules)
  132: 
  133: This is part of the LearningOnline Network with CAPA project
  134: described at http://www.lon-capa.org.
  135: 
  136: 
  137: =head1 SUBROUTINES
  138: 
  139: =over
  140: 
  141: =item footer()
  142: 
  143: Main Handler
  144: 
  145: =back
  146: 
  147: =cut
  148: 
  149: 
  150: 
  151: 
  152: 
  153: 
  154: 

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