version 1.326, 2006/04/11 18:42:43
|
version 1.356, 2007/03/09 00:08:02
|
Line 48 use Apache::lonmenu();
|
Line 48 use Apache::lonmenu();
|
use Apache::lonmeta(); |
use Apache::lonmeta(); |
use Apache::Constants qw(:common); |
use Apache::Constants qw(:common); |
use File::Basename; |
use File::Basename; |
|
use LONCAPA(); |
# use Data::Dumper; |
# use Data::Dumper; |
|
|
BEGIN { |
BEGIN { |
Line 79 sub initialize_londefdef {
|
Line 80 sub initialize_londefdef {
|
@Apache::londefdef::DT=(0); |
@Apache::londefdef::DT=(0); |
@Apache::londefdef::seenDT=(0); |
@Apache::londefdef::seenDT=(0); |
$Apache::londefdef::list_index=0; |
$Apache::londefdef::list_index=0; |
|
undef($Apache::londefdef::head); |
|
undef($Apache::londefdef::title); |
} |
} |
|
|
#======================= TAG SUBROUTINES ===================== |
#======================= TAG SUBROUTINES ===================== |
Line 178 sub end_tthoption {
|
Line 181 sub end_tthoption {
|
sub start_html { |
sub start_html { |
my ($target,$token) = @_; |
my ($target,$token) = @_; |
my $currentstring = ''; |
my $currentstring = ''; |
my $options=$env{'course.'.$env{'request.course.id'}.'.tthoptions'}; |
|
&Apache::lontexconvert::init_tth(); |
|
if ($target eq 'web' || $target eq 'edit' || $target eq 'webgrade' ) { |
if ($target eq 'web' || $target eq 'edit' || $target eq 'webgrade' ) { |
$currentstring = &Apache::lonxml::xmlbegin(); |
# start_body() takes care of emitting the <html> |
} elsif ($target eq 'tex') { |
} elsif ($target eq 'tex') { |
$currentstring .= '\documentclass[letterpaper,twoside]{article}'; |
$currentstring .= |
|
'\documentclass[letterpaper,twoside]{article}\raggedbottom'; |
if (($env{'form.latex_type'}=~'batchmode') || |
if (($env{'form.latex_type'}=~'batchmode') || |
(!$env{'request.role.adv'})) {$currentstring .='\batchmode';} |
(!$env{'request.role.adv'})) {$currentstring .='\batchmode';} |
$currentstring .= '\newcommand{\keephidden}[1]{}'. |
$currentstring .= '\newcommand{\keephidden}[1]{}'. |
Line 212 sub end_html {
|
Line 214 sub end_html {
|
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; |
my $currentstring = ''; |
my $currentstring = ''; |
if ($target eq 'web' || $target eq 'webgrade') { |
if ($target eq 'web' || $target eq 'webgrade') { |
$currentstring = '</html>'; |
# end_body takes care of the </html> |
} |
} |
return $currentstring; |
return $currentstring; |
} |
} |
Line 222 sub start_head {
|
Line 224 sub start_head {
|
my ($target,$token) = @_; |
my ($target,$token) = @_; |
my $currentstring = ''; |
my $currentstring = ''; |
if ($target eq 'web' || $target eq 'webgrade') { |
if ($target eq 'web' || $target eq 'webgrade') { |
$currentstring = $token->[4].&Apache::lonxml::fontsettings(); |
&Apache::lonxml::startredirection(); |
} |
} |
return $currentstring; |
return $currentstring; |
} |
} |
Line 232 sub end_head {
|
Line 234 sub end_head {
|
my $currentstring = ''; |
my $currentstring = ''; |
if (($target eq 'web' && $env{'request.state'} eq 'published') || |
if (($target eq 'web' && $env{'request.state'} eq 'published') || |
($target eq 'webgrade' && $env{'request.state'} eq 'published')) { |
($target eq 'webgrade' && $env{'request.state'} eq 'published')) { |
$currentstring = &Apache::lonmenu::registerurl(undef,$target). |
# in case there is a </head> but no <head> |
$token->[2]; |
if ($Apache::lonxml::redirection) { |
|
$Apache::londefdef::head = &Apache::lonxml::endredirection(); |
|
} |
} |
} |
return $currentstring; |
return $currentstring; |
} |
} |
Line 365 sub end_form {
|
Line 369 sub end_form {
|
|
|
#-- <title> tag (end tag required) |
#-- <title> tag (end tag required) |
sub start_title { |
sub start_title { |
my ($target,$token) = @_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_; |
my $currentstring = ''; |
my $currentstring = ''; |
if ($target eq 'web' || $target eq 'webgrade') { |
if ($target eq 'web' || $target eq 'webgrade') { |
$currentstring = $token->[4]; |
$Apache::londefdef::title = |
|
&Apache::lonxml::get_all_text('/title',$parser,$style); |
} elsif ($target eq 'tex') { |
} elsif ($target eq 'tex') { |
$currentstring .= '\keephidden{Title of the document: ' |
$currentstring .= '\keephidden{Title of the document: ' |
} |
} |
Line 383 sub end_title {
|
Line 388 sub end_title {
|
my ($target,$token) = @_; |
my ($target,$token) = @_; |
my $currentstring = ''; |
my $currentstring = ''; |
if ($target eq 'web' || $target eq 'webgrade') { |
if ($target eq 'web' || $target eq 'webgrade') { |
$currentstring = $token->[2]; |
# start_title takes care of swallowing the title |
} elsif ($target eq 'tex') { |
} elsif ($target eq 'tex') { |
$currentstring .= '}'; |
$currentstring .= '}'; |
} |
} |
Line 518 sub start_body {
|
Line 523 sub start_body {
|
&Apache::lonxml::warning("<body> tag found inside of <problem> tag this can cause problems."); |
&Apache::lonxml::warning("<body> tag found inside of <problem> tag this can cause problems."); |
return ''; |
return ''; |
} |
} |
if (!$Apache::lonxml::registered && |
|
$env{'request.state'} eq 'published') { |
|
$currentstring.='<head>'. |
|
&Apache::lonmenu::registerurl(undef,$target).'</head>'; |
|
} |
|
# Accessibility |
|
if ($env{'browser.imagesuppress'} eq 'on') { |
|
delete($token->[2]->{'background'}); |
|
} |
|
if ($env{'browser.fontenhance'} eq 'on') { |
|
my $style=''; |
|
foreach my $key (keys(%{$token->[2]})) { |
|
if ($key =~ /^style$/i) { |
|
$style.=$token->[2]->{$key}.';'; |
|
delete($token->[2]->{$key}); |
|
} |
|
} |
|
$token->[2]->{'style'}=$style.'; font-size: x-large;'; |
|
} |
|
if ($env{'browser.blackwhite'} eq 'on') { |
|
delete($token->[2]->{'font'}); |
|
delete($token->[2]->{'link'}); |
|
delete($token->[2]->{'alink'}); |
|
delete($token->[2]->{'vlink'}); |
|
delete($token->[2]->{'bgcolor'}); |
|
delete($token->[2]->{'background'}); |
|
} |
|
# Overload loads |
|
my $onLoad=''; |
|
foreach my $key (keys(%{$token->[2]})) { |
|
if ($key =~ /^onload$/i) { |
|
$onLoad.=$token->[2]->{$key}.';'; |
|
delete($token->[2]->{$key}); |
|
} |
|
} |
|
$token->[2]->{'onload'}=&Apache::lonmenu::loadevents().';'.$onLoad; |
|
my $onUnload=''; |
|
foreach my $key (keys(%{$token->[2]})) { |
|
if ($key =~ /^onunload$/i) { |
|
$onUnload.=$token->[2]->{$key}.';'; |
|
delete($token->[2]->{$key}); |
|
} |
|
} |
|
$token->[2]->{'onunload'}=&Apache::lonmenu::unloadevents(). |
|
';'.$onUnload; |
|
|
|
$currentstring .= '<'.$token->[1]; |
if (&is_inside_of($tagstack, "head")) { |
foreach (keys %{$token->[2]}) { |
&end_head(@_); |
$currentstring.=' '.$_.'="'.$token->[2]->{$_}.'"'; |
|
} |
} |
$currentstring.='>'; |
$currentstring = |
$currentstring.=&Apache::lontexconvert::init_math_support(); |
&Apache::loncommon::start_page($Apache::londefdef::title, |
|
$Apache::londefdef::head, |
|
{'add_entries' => $token->[2], |
|
'no_title' => 1, |
|
'force_register' => 1}); |
|
|
if ($env{'request.state'} ne 'published') { |
if ($env{'request.state'} ne 'published') { |
if ($env{'environment.remote'} eq 'off') { |
$currentstring.=&Apache::lonmenu::constspaceform(); |
$currentstring.= |
|
&Apache::lonmenu::constspaceform(). |
|
&Apache::lonmenu::menubuttons(1,'web',1); |
|
} |
|
$currentstring.=(<<EDITBUTTON); |
$currentstring.=(<<EDITBUTTON); |
<form method="post"> |
<form method="post"> |
<input type="submit" name="editmode" accesskey="e" value="Edit" /> |
<input type="submit" name="editmode" accesskey="e" value="Edit" /> |
</form> |
</form> |
|
<br /> |
EDITBUTTON |
EDITBUTTON |
} else { |
|
$currentstring.=&Apache::lonmenu::menubuttons(undef,$target,1); |
|
} |
} |
$currentstring.=&Apache::lonxml::message_location(); |
$currentstring.=&Apache::lonxml::message_location(); |
} elsif ($target eq 'tex') { |
} elsif ($target eq 'tex') { |
Line 595 sub end_body {
|
Line 554 sub end_body {
|
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; |
my $currentstring = &end_p(); # Close off unclosed <p> |
my $currentstring = &end_p(); # Close off unclosed <p> |
if ($target eq 'web' || $target eq 'webgrade') { |
if ($target eq 'web' || $target eq 'webgrade') { |
$currentstring .= &Apache::lonxml::xmlend($target,$parser); |
$currentstring .= &Apache::loncommon::end_page({'discussion' => 1}); |
} elsif ($target eq 'tex') { |
} elsif ($target eq 'tex') { |
$currentstring .= '\strut\newline\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}\newline\noindent \end{document}'; |
$currentstring .= '\strut\newline\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}\newline\noindent \end{document}'; |
} |
} |
Line 603 sub end_body {
|
Line 562 sub end_body {
|
} |
} |
|
|
# \begin{center} causes a new paragprah spacing that looks odd inside |
# \begin{center} causes a new paragprah spacing that looks odd inside |
# of a table cell |
# of a table cell. Same at the end of a \center but with a slightly |
sub center_correction { return '\vspace*{-6 mm}'; } |
# larger space .. hence center_correction and center_end_correction. |
|
# |
|
sub center_correction { return '\vspace*{-6 mm}'; } |
|
sub center_end_correction { return '\vspace*{-7 mm}'; } |
|
|
#-- <center> tag (end tag required) |
#-- <center> tag (end tag required) |
sub start_center { |
sub start_center { |
my ($target,$token,$tagstack) = @_; |
my ($target,$token,$tagstack) = @_; |
Line 627 sub end_center {
|
Line 590 sub end_center {
|
$currentstring = $token->[2]; |
$currentstring = $token->[2]; |
} elsif ($target eq 'tex') { |
} elsif ($target eq 'tex') { |
$currentstring = '\end{center}'; |
$currentstring = '\end{center}'; |
|
if (&is_inside_of($tagstack, "table")) { |
|
$currentstring .= ¢er_end_correction(); |
|
} |
} |
} |
return $currentstring; |
return $currentstring; |
} |
} |
Line 1196 sub start_p {
|
Line 1162 sub start_p {
|
$currentstring .= &end_p(); # close off prior para if in progress. |
$currentstring .= &end_p(); # close off prior para if in progress. |
my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1); |
my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1); |
if ($align eq 'center') { |
if ($align eq 'center') { |
$currentstring .='\begin{center}\par'; |
$currentstring .='\begin{center}\par '; |
$closing_string = '\end{center}'; |
$closing_string = '\end{center}'; |
if (&is_inside_of($tagstack, "table")) { |
if (&is_inside_of($tagstack, "table")) { |
$currentstring = ¢er_correction().$currentstring; |
$currentstring = ¢er_correction().$currentstring; |
Line 1252 sub start_br {
|
Line 1218 sub start_br {
|
# |
# |
for (my $i=$#tempo;$i>=0;$i--) { |
for (my $i=$#tempo;$i>=0;$i--) { |
if (($tempo[$i] eq 'b') || ($tempo[$i] eq 'strong') || |
if (($tempo[$i] eq 'b') || ($tempo[$i] eq 'strong') || |
($tempo[$i] eq 'ol') || ($tempo[$i] eq 'ul') || |
($tempo[$i] eq 'ol') || ($tempo[$i] eq 'ul')) { |
($tempo[$i] eq 'td') || ($tempo[$i] eq 'th')) { |
|
$signal=1; |
$signal=1; |
last; |
} |
|
if (($tempo[$i] eq 'td') || ($tempo[$i] eq 'th')) { |
|
$signal = 1; |
} |
} |
} |
} |
if ($signal) { |
if ($signal eq 1) { |
$currentstring .= ' \vskip 0 mm '; |
$currentstring .= ' \vskip 0 mm '; |
} elsif ($$tagstack[-2] ne 'sub' && $$tagstack[-2] ne 'sup') { |
} else { |
$currentstring .= '\strut \\\\ \strut '; |
$currentstring .= '\strut \\\\ \strut '; |
} |
} |
|
|
} |
} |
return $currentstring; |
return $currentstring; |
} |
} |
Line 1444 sub start_sub {
|
Line 1412 sub start_sub {
|
if ($target eq 'web' || $target eq 'webgrade') { |
if ($target eq 'web' || $target eq 'webgrade') { |
$currentstring .= $token->[4]; |
$currentstring .= $token->[4]; |
} elsif ($target eq 'tex') { |
} elsif ($target eq 'tex') { |
$currentstring .= '\ensuremath{_{'; |
$currentstring .= '\raisebox{-\smallskipamount}{\scriptsize{'; |
} |
} |
return $currentstring; |
return $currentstring; |
} |
} |
Line 1467 sub start_sup {
|
Line 1435 sub start_sup {
|
if ($target eq 'web' || $target eq 'webgrade') { |
if ($target eq 'web' || $target eq 'webgrade') { |
$currentstring .= $token->[4]; |
$currentstring .= $token->[4]; |
} elsif ($target eq 'tex') { |
} elsif ($target eq 'tex') { |
$currentstring .= '\ensuremath{^{'; |
$currentstring .= '\raisebox{\smallskipamount}{\scriptsize{'; |
} |
} |
return $currentstring; |
return $currentstring; |
} |
} |
Line 1590 sub start_a {
|
Line 1558 sub start_a {
|
my $href=&Apache::lonxml::get_param('href',$parstack,$safeeval, |
my $href=&Apache::lonxml::get_param('href',$parstack,$safeeval, |
undef,1); |
undef,1); |
$currentstring=&Apache::lonenc::encrypt_ref($token,{'href'=>$href}); |
$currentstring=&Apache::lonenc::encrypt_ref($token,{'href'=>$href}); |
} elsif ($target eq 'tex') { |
|
my $a=&Apache::lonxml::get_param('href',$parstack,$safeeval,undef,1); |
|
my $b=&Apache::lonxml::get_param('name',$parstack,$safeeval,undef,1); |
|
if ($a=~/\S/) { |
|
$a=~s/([^\\])%/$1\\\%/g; |
|
$currentstring .= '\ref{URI: '.$a.'}'; |
|
} elsif ($b=~/\S/) { |
|
$currentstring .= '\ref{Anchor: '.$b.'}'; |
|
} else { |
|
$currentstring.=''; |
|
} |
|
} |
} |
return $currentstring; |
return $currentstring; |
} |
} |
Line 1611 sub end_a {
|
Line 1568 sub end_a {
|
if ($target eq 'web' || $target eq 'webgrade') { |
if ($target eq 'web' || $target eq 'webgrade') { |
$currentstring .= $token->[2]; |
$currentstring .= $token->[2]; |
} |
} |
|
if ($target eq 'tex') { |
|
my $href = |
|
&Apache::lonxml::get_param('href',$parstack,$safeeval,undef,1); |
|
my $name = |
|
&Apache::lonxml::get_param('name',$parstack,$safeeval,undef,1); |
|
if ($href =~ /\S/) { |
|
$href =~ s/([^\\])%/$1\\\%/g; |
|
$currentstring .= ' ({\tt URI:'.&Apache::lonxml::latex_special_symbols($href).'})'; |
|
} elsif ($name =~ /\S/) { |
|
$currentstring .= ' ({\tt Anchor:'.&Apache::lonxml::latex_special_symbols($name).'})'; |
|
} else { |
|
$currentstring.=''; |
|
} |
|
} |
return $currentstring; |
return $currentstring; |
} |
} |
|
|
Line 1948 sub start_table {
|
Line 1919 sub start_table {
|
if ($target eq 'web' || $target eq 'webgrade') { |
if ($target eq 'web' || $target eq 'webgrade') { |
$currentstring .= $token->[4]; |
$currentstring .= $token->[4]; |
} elsif ($target eq 'tex') { |
} elsif ($target eq 'tex') { |
my $aa = {}; |
push(@Apache::londefdef::table, {}); |
push @Apache::londefdef::table, $aa; |
|
$Apache::londefdef::table[-1]{'row_number'} = -1; |
$Apache::londefdef::table[-1]{'row_number'} = -1; |
#maximum table's width (default coincides with text line length) |
#maximum table's width (default coincides with text line length) |
if ($#Apache::londefdef::table==0) { |
if ($#Apache::londefdef::table==0) { |
Line 2023 sub start_table {
|
Line 1993 sub start_table {
|
$Apache::londefdef::table[-1]{'minlen'}=[]; |
$Apache::londefdef::table[-1]{'minlen'}=[]; |
$Apache::londefdef::table[-1]{'content'}=[]; |
$Apache::londefdef::table[-1]{'content'}=[]; |
$Apache::londefdef::table[-1]{'align'}=[]; |
$Apache::londefdef::table[-1]{'align'}=[]; |
$currentstring.='\keephidden{NEW TABLE ENTRY}'; |
$currentstring.=' \keephidden{NEW TABLE ENTRY}'; |
|
|
|
|
} |
} |
Line 2231 sub end_table {
|
Line 2201 sub end_table {
|
# single rowspan, columspan and combined row/colspans will |
# single rowspan, columspan and combined row/colspans will |
# work correctly. LaTeX is delicate here. |
# work correctly. LaTeX is delicate here. |
# RF. |
# RF. |
|
|
# Start a rowspan if necessary: |
# Start a rowspan if necessary: |
|
|
|
my $primary_col_width = $fwidth[$jn]; # Width of primary column. |
my $rowspan = $Apache::londefdef::table[-1]{'rowspan'}[$in][$jn]; |
my $rowspan = $Apache::londefdef::table[-1]{'rowspan'}[$in][$jn]; |
my $colspan = $Apache::londefdef::table[-1]{'colspan'}[$in][$jn]; |
my $colspan = $Apache::londefdef::table[-1]{'colspan'}[$in][$jn]; |
# |
# |
# Do the appropriate magic if this has a colspan |
# Do the appropriate magic if this has a colspan |
# |
# |
|
|
|
my $spanwidth = 0; |
if ($colspan > 1) { |
if ($colspan > 1) { |
|
for (my $spancol = $jn; $spancol < $jn + $colspan; $spancol++) { |
|
$spanwidth += $fwidth[$spancol]; |
|
} |
$output .= '\multicolumn{'. |
$output .= '\multicolumn{'. |
$colspan |
$colspan |
.'}{|l|}{'; |
."}"; |
|
if ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'c') { |
|
$output .= '{|c|}{'; |
|
} elsif ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'r') { |
|
$output .= '{|r|}{'; |
|
} |
|
else { |
|
$output .= "{|p{$spanwidth mm}|}{"; |
|
} |
|
|
|
} else { |
|
$spanwidth = $primary_col_width; # If no span width will be just colwidth |
} |
} |
|
|
|
# Rowspan... if colspan is 1, and there's an alignment we'll need |
|
# to kick in a multicolumn in order to get the alignment spec. |
|
# this must precede the multirow or LaTex gets quite upset. |
|
# Naturally if colspan > 1 we've already done that above ^ |
|
# |
|
my $multirow_aligned = 0; |
if ($rowspan > 1) { |
if ($rowspan > 1) { |
|
if ($colspan == 1) { |
|
if ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'c') { |
|
$output .= '\multicolumn{1}{|c|}{'; |
|
$multirow_aligned = 1; |
|
} elsif ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'r') { |
|
$output .= '\multicolumn{1}{|r|}{'; |
|
$multirow_aligned = 1; |
|
} |
|
} |
$have_rowspan++; |
$have_rowspan++; |
$output .= '\multirow{'.$rowspan.'}[0]{'.$fwidth[$jn].'mm}{'; |
if ($multirow_aligned) { |
|
$output .= '\multirow{'.$rowspan.'}[0]{*}{'; |
|
} else { |
|
$output .= '\multirow{'.$rowspan."}[0]{$spanwidth mm}{"; |
|
} |
|
|
|
$Apache::londefdef::table[-1]{'content'}[$in][$jn] =~ |
|
s{^\s*\\par\s*}{}; |
|
$Apache::londefdef::table[-1]{'content'}[$in][$jn] =~ |
|
s{\s*\\vskip\s*0pt\s*$}{}; |
|
|
|
# |
|
# If we did not throw in a multicolumn to align, then add |
|
# an extra { |
|
# so we close correctly without having to keep additional state |
|
# around |
|
# |
|
if (!$multirow_aligned) { |
|
$output .= '{'; |
|
} |
} |
} |
if (($rowspan eq '^') || ($rowspan eq '_')) { |
if (($rowspan eq '^') || ($rowspan eq '_')) { |
$have_rowspan++; |
$have_rowspan++; |
} |
} |
#-------------------------------------------------------------- |
#-------------------------------------------------------------- |
|
|
|
|
if ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'c') { |
# For right and center alignment of single cells. |
$output.=¢er_correction().'\begin{center}'; |
# we are going to use a multicolumn with a span of 1 to specify alignment. |
} elsif ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'r') { |
# |
$output.=' \hfill \llap{' |
if ($colspan == 1 && $rowspan == 1) { |
|
if ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'c') { |
|
$output .= '\multicolumn{1}{|c|}{'; |
|
} elsif ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'r') { |
|
$output .= '\multicolumn{1}{|r|}{'; |
|
} |
} |
} |
|
|
$output.=$Apache::londefdef::table[-1]{'content'}[$in][$jn]; |
$output.=$Apache::londefdef::table[-1]{'content'}[$in][$jn]; |
if ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'c') { |
|
$output.='\end{center}'; |
if (($colspan == 1 && $rowspan == 1) && |
} elsif ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'r') { |
(($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'c') || |
$output.='} '; |
($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'r'))) { |
|
$output .= '}'; |
} |
} |
|
|
# Close off any open multirow: |
# Close off any open multirow: |
|
|
if ($rowspan > 1) { |
if ($rowspan > 1) { |
$output .= '}'; |
$output .= '}}'; |
} |
} |
# Close off the colspan... |
# Close off the colspan... |
# |
# |
Line 2832 sub start_img {
|
Line 2861 sub start_img {
|
#if original gif/jpg/png file exist do following: |
#if original gif/jpg/png file exist do following: |
my $origsrc=$src; |
my $origsrc=$src; |
my ($path,$file) = &get_eps_image($src); |
my ($path,$file) = &get_eps_image($src); |
|
# &Apache::lonnet::logthis("Image source: $src result: $path $file"); |
$src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src); |
$src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src); |
&Apache::lonxml::debug("path = $path file = $file src = $src"); |
&Apache::lonxml::debug("path = $path file = $file src = $src"); |
if (-e $src) { |
if (-e $src) { |
&Apache::lonxml::debug("$src exists"); |
&Apache::lonxml::debug("$src exists"); |
my ($height_param,$width_param)= |
my ($height_param,$width_param)= |
&image_size($origsrc,0.3,$parstack,$safeeval); |
&image_size($origsrc,0.3,$parstack,$safeeval); |
my $destpath = $path; |
|
$destpath =~ s/ /\_/g; # Spaces in path cause LaTex to vomit. |
|
my $destfile = $file; |
|
$destfile =~ s/ /\_/g; |
|
my $size; |
my $size; |
if ($width_param) { $size.='width='.$width_param.' mm,'; } |
if ($width_param) { $size.='width='.$width_param.' mm,'; } |
if ($height_param) { $size.='height='.$height_param.' mm]'; } |
if ($height_param) { $size.='height='.$height_param.' mm]'; } |
|
# Default size if not able to extract that (e.g. eps image). |
|
|
|
# &Apache::lonnet::logthis("Size = $size"); |
|
|
$size='['.$size; |
$size='['.$size; |
$size=~s/,$/]/; |
$size=~s/,$/]/; |
$currentstring .= '\graphicspath{{'.$destpath.'}}' |
$currentstring .= '\graphicspath{{'.$path.'}}' |
.'\includegraphics'.$size.'{'.$destfile.'} '; |
.'\includegraphics'.$size.'{'.$file.'} '; |
|
my $closure; |
# If there's an alignment specification we need to honor it here. |
($currentstring, $closure) = &align_latex_image($align, |
# For the horizontal alignments, we will also honor the |
$latex_rendering, |
# value of the latex specfication. The default is parbox, |
$currentstring, |
# and that's used for illegal values too. |
$width_param, |
# |
$height_param); |
# Even though we set a default alignment value, the user |
$currentstring .= $closure; |
# could have given us an illegal value. In that case we |
|
# just use the default alignment of bottom.. |
|
if ($align eq "top") { |
|
$currentstring = '\raisebox{-'.$height_param.'mm}{'.$currentstring.'}'; |
|
} elsif (($align eq "center") || ($align eq "middle")) { # Being kind |
|
my $offset = $height_param/2; |
|
$currentstring = '\raisebox{-'.$offset.'mm}{'.$currentstring.'}'; |
|
} elsif ($align eq "left") { |
|
if ($latex_rendering eq "parpic") { |
|
$currentstring = '\parpic[l]{'.$currentstring.'}'; |
|
} else { # wrapfig render |
|
$currentstring = '\begin{wrapfigure}{l}{'.$width_param.'mm}' |
|
.'\scalebox{1.0}{'.$currentstring.'}\end{wrapfigure}'; |
|
} |
|
} elsif ($align eq "right") { |
|
if ($latex_rendering eq "parpic") { |
|
$currentstring = '\parpic[r]{'.$currentstring.'}'; |
|
} else { # wrapfig rendering |
|
$currentstring = '\begin{wrapfigure}{r}{'.$width_param.'mm}' |
|
.'\scalebox{1.0}{'.$currentstring.'}\end{wrapfigure}'; |
|
|
|
} |
|
} else { # Bottom is also default. |
|
# $currentstring = '\raisebox{'.$height_param.'mm}{'.$currentstring.'}'; |
|
} |
|
} else { |
} else { |
&Apache::lonxml::debug("$src does not exist"); |
&Apache::lonxml::debug("$src does not exist"); |
#original image file doesn't exist so check the alt attribute |
#original image file doesn't exist so check the alt attribute |
Line 2908 sub start_img {
|
Line 2914 sub start_img {
|
$currentstring .=&Apache::edit::select_arg('Alignment:','align', |
$currentstring .=&Apache::edit::select_arg('Alignment:','align', |
['','bottom','middle','top','left','right'],$token,5); |
['','bottom','middle','top','left','right'],$token,5); |
$currentstring .=&Apache::edit::select_arg('TeXwrap:', 'TeXwrap', |
$currentstring .=&Apache::edit::select_arg('TeXwrap:', 'TeXwrap', |
['', 'parbox', 'parpic'], $token, 2); |
['', 'none','parbox', 'parpic', 'wrapfigure'], $token, 2); |
$currentstring .=&Apache::edit::select_arg('Encyrpt URL:','encrypturl', |
$currentstring .=&Apache::edit::select_arg('Encrypt URL:','encrypturl', |
['no','yes'], $token, 2); |
['no','yes'], $token, 2); |
$currentstring .=&Apache::edit::end_row().&Apache::edit::start_spanning_row(); |
$currentstring .=&Apache::edit::end_row().&Apache::edit::start_spanning_row(); |
my $src= &Apache::lonxml::get_param('src',$parstack,$safeeval); |
my $src= &Apache::lonxml::get_param('src',$parstack,$safeeval); |
Line 3131 sub start_frameset {
|
Line 3137 sub start_frameset {
|
my ($target,$token) = @_; |
my ($target,$token) = @_; |
my $currentstring = ''; # Close any pending para. |
my $currentstring = ''; # Close any pending para. |
if ($target eq 'web' || $target eq 'webgrade') { |
if ($target eq 'web' || $target eq 'webgrade') { |
if (!$Apache::lonxml::registered && |
$currentstring = |
$env{'request.state'} eq 'published') { |
&Apache::loncommon::start_page($Apache::londefdef::title, |
$currentstring.='<head>'. |
$Apache::londefdef::head, |
&Apache::lonmenu::registerurl(undef,$target).'</head>'; |
{'add_entries' => $token->[2], |
} |
'no_title' => 1, |
my $onLoad=''; |
'force_register' => 1, |
foreach my $key (keys(%{$token->[2]})) { |
'frameset' => 1,}); |
if ($key =~ /^onload$/i) { |
|
$onLoad.=$token->[2]->{$key}.';'; |
|
delete($token->[2]->{$key}); |
|
} |
|
} |
|
$token->[2]->{'onload'}=&Apache::lonmenu::loadevents().';'.$onLoad; |
|
my $onUnload=''; |
|
foreach my $key (keys(%{$token->[2]})) { |
|
if ($key =~ /^onunload$/i) { |
|
$onUnload.=$token->[2]->{$key}.';'; |
|
delete($token->[2]->{$key}); |
|
} |
|
} |
|
$token->[2]->{'onunload'}=&Apache::lonmenu::unloadevents(). |
|
';'.$onUnload; |
|
|
|
$currentstring .= '<'.$token->[1]; |
|
foreach (keys %{$token->[2]}) { |
|
$currentstring.=' '.$_.'="'.$token->[2]->{$_}.'"'; |
|
} |
|
$currentstring.='>'; |
|
} |
} |
return $currentstring; |
return $currentstring; |
} |
} |
Line 3420 sub start_blockquote {
|
Line 3406 sub start_blockquote {
|
if ($target eq 'web' || $target eq 'webgrade') { |
if ($target eq 'web' || $target eq 'webgrade') { |
$currentstring .= $token->[4]; |
$currentstring .= $token->[4]; |
} |
} |
|
if ($target eq 'tex') { |
|
$currentstring .= '\begin{quote}'; |
|
} |
return $currentstring; |
return $currentstring; |
} |
} |
|
|
Line 3429 sub end_blockquote {
|
Line 3418 sub end_blockquote {
|
if ($target eq 'web' || $target eq 'webgrade') { |
if ($target eq 'web' || $target eq 'webgrade') { |
$currentstring = $token->[2]; |
$currentstring = $token->[2]; |
} |
} |
|
if ($target eq 'tex') { |
|
$currentstring = '\end{quote}'; |
|
} |
return $currentstring; |
return $currentstring; |
} |
} |
|
|
Line 4229 sub get_eps_image {
|
Line 4221 sub get_eps_image {
|
&Apache::lonnet::repcopy($orig_src); # Failure is not completely fatal. |
&Apache::lonnet::repcopy($orig_src); # Failure is not completely fatal. |
} |
} |
&Apache::lonxml::debug("get_eps_image: Original image: $orig_src"); |
&Apache::lonxml::debug("get_eps_image: Original image: $orig_src"); |
my ($spath, $sname, $sext) = fileparse($src, qr/\.(gif|png|jpg|jpeg)/i); |
my ($spath, $sname, $sext) = &fileparse($src, qr/\.(gif|png|jpg|jpeg)/i); |
$src=~s/\.(gif|png|jpg|jpeg)$/\.eps/i; |
$src=~s/\.(gif|png|jpg|jpeg)$/\.eps/i; |
$src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src); |
$src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src); |
&Apache::lonxml::debug("Filelocation gives: $src"); |
&Apache::lonxml::debug("Filelocation gives: $src"); |
Line 4254 sub get_eps_image {
|
Line 4246 sub get_eps_image {
|
my $newsrc=$orig_src; |
my $newsrc=$orig_src; |
$newsrc =~ s|(.*)/res/|/home/httpd/html/res/|; |
$newsrc =~ s|(.*)/res/|/home/httpd/html/res/|; |
&Apache::lonxml::debug("queueing $newsrc for dynamic eps production."); |
&Apache::lonxml::debug("queueing $newsrc for dynamic eps production."); |
print FILE "$newsrc\n"; |
print FILE ("$newsrc\n"); |
close FILE; |
close(FILE); |
$src=~s|/home/httpd/html/res|/home/httpd/prtspool|; |
$src=~s|/home/httpd/html/res|/home/httpd/prtspool|; |
$src=~s|/home/([^/]*)/public_html/|/home/httpd/prtspool/$1/|; |
$src=~s|/home/([^/]*)/public_html/|/home/httpd/prtspool/$1/|; |
if ($sext ne "") { # Put the ext. back in to uniquify. |
if ($sext ne "") { # Put the ext. back in to uniquify. |
$src =~ s/\.eps$/$sext.eps/; |
$src =~ s/\.eps$/$sext.eps/; |
} |
} |
|
|
} |
} |
|
|
} |
} |
|
} else { |
|
# If the postscript file has spaces in its name, |
|
# LaTeX will gratuitiously vomit. Therefore |
|
# queue such files for copy with " " replaced by "_". |
|
# printout.pm will know them by their .ps or .eps extensions. |
|
my $newsrc = $orig_src; |
|
$newsrc =~ s|(.*)/res/|/home/httpd/html/res/|; |
|
open(FILE,">>/home/httpd/prtspool/$env{'user.name'}_$env{'user.domain'}_printout.dat"); |
|
print FILE "$src\n"; |
|
close FILE; |
|
$src=~s|/home/httpd/html/res|/home/httpd/prtspool|; |
|
$src=~s|/home/([^/]*)/public_html/|/home/httpd/prtspool/$1/|; |
} |
} |
my ($path,$file)=($src=~m|(.*)/([^/]*)$|); |
my ($path,$file)=($src=~m|(.*)/([^/]*)$|); |
|
$path =~ s/ /\_/g; |
|
$file =~ s/ /\_/g; |
&Apache::lonxml::debug("get_eps_image returning: $path / $file<BR />"); |
&Apache::lonxml::debug("get_eps_image returning: $path / $file<BR />"); |
return ($path.'/',$file); |
return ($path.'/',$file); |
} |
} |
Line 4276 sub eps_generation {
|
Line 4284 sub eps_generation {
|
print $temp_file "$src\n"; |
print $temp_file "$src\n"; |
my $newsrc = $src; |
my $newsrc = $src; |
$newsrc =~ s/(\.gif|\.jpg|\.jpeg)$/\.eps/i; |
$newsrc =~ s/(\.gif|\.jpg|\.jpeg)$/\.eps/i; |
$newsrc=~s/\/home\/httpd\/html\/res//; |
$newsrc=~s{/home/httpd/html/res}{}; |
$newsrc=~s/\/home\/([^\/]*)\/public_html\//\/$1\//; |
$newsrc=~s{/home/($LONCAPA::username_re)/public_html/}{/$1/}; |
$newsrc=~s/\/\.\//\//; |
$newsrc=~s{/\./}{/}; |
$newsrc=~s/\/([^\/]+)\.(ps|eps)/\//; |
$newsrc=~s{/([^/]+)\.(ps|eps)}{/}; |
if ($newsrc=~/\/home\/httpd\/lonUsers\//) { |
if ($newsrc=~m{/home/httpd/lonUsers/}) { |
$newsrc=~s/\/home\/httpd\/lonUsers//; |
$newsrc=~s{/home/httpd/lonUsers}{}; |
$newsrc=~s/\/([^\/]+)\/(\w)\/(\w)\/(\w)\//\/$1\//; |
$newsrc=~s{/($LONCAPA::domain_re)/./././}{/$1/}; |
} |
} |
if ($newsrc=~/\/userfiles\//) { |
if ($newsrc=~m{/userfiles/}) { |
return ' \graphicspath{{'.$newsrc.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} '; |
return ' \graphicspath{{'.$newsrc.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} '; |
} else { |
} else { |
return ' \graphicspath{{/home/httpd/prtspool'.$newsrc.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} '; |
return ' \graphicspath{{/home/httpd/prtspool'.$newsrc.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} '; |
Line 4348 sub LATEX_length {
|
Line 4356 sub LATEX_length {
|
return $value; |
return $value; |
} |
} |
|
|
|
# Wrap image 'stuff' inside of the LaTeX required to implement |
|
# alignment: |
|
# align_tex_image(align, latex_rendering, image) |
|
# Where: |
|
# align - The HTML alignment specification. |
|
# latex_rendering - rendering hint for latex. |
|
# image - The LaTeX needed to insert the image itsef. |
|
# width,height - dimensions of the image. |
|
# Returns: |
|
# The 1/2 wrapped image and the stuff required to close the |
|
# wrappage. This allows e.g. randomlabel to insert more stuff |
|
# into the closure. |
|
# |
|
sub align_latex_image { |
|
my ($align, $latex_rendering, $image, $width, $height) = @_; |
|
my $currentstring; # The 1/2 wrapped image. |
|
my $closure; # The closure of the wrappage. |
|
# If there's an alignment specification we need to honor it here. |
|
# For the horizontal alignments, we will also honor the |
|
# value of the latex specfication. The default is parbox, |
|
# and that's used for illegal values too. |
|
# |
|
# Even though we set a default alignment value, the user |
|
# could have given us an illegal value. In that case we |
|
# just use the default alignment of bottom.. |
|
$currentstring = "\n% figurewrapping \n"; |
|
if ($align eq "top") { |
|
$currentstring .= '\raisebox{-'.$height.'mm}{'.$image; |
|
$closure = '}'; |
|
} elsif (($align eq "center") || ($align eq "middle")) { # Being kind |
|
my $offset = $height/2; |
|
$currentstring .= '\raisebox{-'.$offset.'mm}{'.$image; |
|
$closure = '}'; |
|
} elsif ($align eq "left") { |
|
if ($latex_rendering eq "parpic") { |
|
$currentstring .= '\parpic[l]{'.$image; |
|
$closure = '}'; |
|
} elsif ($latex_rendering eq "parbox") { |
|
$currentstring .= '\begin{minipage}[l]{'.$width.'mm}' |
|
.$image; |
|
$closure = '\end{minipage}'; |
|
} elsif ($latex_rendering eq "wrapfigure" |
|
|| $latex_rendering ne 'none') { # wrapfig render |
|
$currentstring .= |
|
'\begin{wrapfigure}{l}{'.$width.'mm}' |
|
.'\scalebox{1.0}{'.$image; |
|
$closure = '}\end{wrapfigure}'; |
|
} |
|
} elsif ($align eq "right") { |
|
if ($latex_rendering eq "parpic") { |
|
$currentstring .= '\parpic[r]{'.$image; |
|
$closure = '}'; |
|
} elsif ($latex_rendering eq "parbox") { |
|
$currentstring .= '\begin{minipage}[r]{'.$width.'mm}' |
|
.$image; |
|
$closure = '\end{minipage}'; |
|
} elsif ($latex_rendering eq "wrapfigure" |
|
|| $latex_rendering ne 'none') { # wrapfig render |
|
$currentstring .= |
|
'\begin{wrapfigure}{r}{'.$width.'mm}' |
|
.'\scalebox{1.0}{'.$image; |
|
$closure = '}\end{wrapfigure}'; |
|
} |
|
} else { # Bottom is also default. |
|
# $currentstring = '\raisebox{'.$height.'mm}{'.$image.'}'; |
|
$currentstring .= "{$image"; |
|
$closure = '}'; |
|
} |
|
$currentstring .= "\n% end wrappage\n"; |
|
$closure = "\n% Begin closure\n".$closure."\n% End closure\n"; |
|
return ($currentstring, $closure); |
|
} |
|
|
# is_inside_of $tagstack $tag |
# is_inside_of $tagstack $tag |
# This sub returns true if the current state of Xml processing |
# This sub returns true if the current state of Xml processing |