![]() ![]() | ![]() |
rt of bug 3103 is fixed. </p> is corrected.
1: # The LearningOnline Network with CAPA 2: # Tags Default Definition Module 3: # 4: # $Id: londefdef.pm,v 1.226 2004/07/12 17:19:13 sakharuk Exp $ 5: # 6: # 7: # Copyright Michigan State University Board of Trustees 8: # 9: # This file is part of the LearningOnline Network with CAPA (LON-CAPA). 10: # 11: # LON-CAPA is free software; you can redistribute it and/or modify 12: # it under the terms of the GNU General Public License as published by 13: # the Free Software Foundation; either version 2 of the License, or 14: # (at your option) any later version. 15: # 16: # LON-CAPA is distributed in the hope that it will be useful, 17: # but WITHOUT ANY WARRANTY; without even the implied warranty of 18: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19: # GNU General Public License for more details. 20: # 21: # You should have received a copy of the GNU General Public License 22: # along with LON-CAPA; if not, write to the Free Software 23: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 24: # 25: # /home/httpd/html/adm/gpl.txt 26: # 27: # http://www.lon-capa.org/ 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: # 39: # 40: # last modified 06/26/00 by Alexander Sakharuk 41: # 11/6,11/30,02/01/01,5/4 Gerd Kortemeyer 42: # 01/18 Alex Sakharuk 43: 44: package Apache::londefdef; 45: 46: use Apache::lonnet(); 47: use strict; 48: use Apache::lonxml; 49: use Apache::File(); 50: use Image::Magick; 51: use Apache::lonmenu(); 52: use Apache::lonmeta(); 53: use Apache::Constants qw(:common); 54: 55: 56: BEGIN { 57: 58: &Apache::lonxml::register('Apache::londefdef',('a','abbr','acronym','accessrule','address','allow','applet','area','b','base','basefont','bgo','bgsound','big','blink','blockquote','blankspace','body','br','button','caption','center','cite','code','col','colgroup','dd','del','dfn','dir','div','dl','dt','em','embed','externallink','fieldset','font','form','frame','frameset','h1','h2','h3','h4','h5','h6','head','hr','html','i','iframe','img','input','ins','insert','isindex','kbd','keygen','label','layer','legend','li','link','m','map','marquee','menu','meta','multicol','nobr','noembed','noframes','nolayer','noscript','object','ol','optgroup','option','output','p','param','pre','q','s','samp','select','server','small','spacer','span','strike','strong','sub','sup','table','tbody','td','textarea','tfoot','th','thead','title','tr','tt','tthoption','u','ul','var','wbr','hideweboutput')); 59: 60: } 61: 62: sub initialize_londefdef { 63: $Apache::londefdef::TD_redirection=0; 64: @Apache::londefdef::table = (); 65: $Apache::londefdef::select=0; 66: @Apache::londefdef::description=(); 67: $Apache::londefdef::DD_redirection=0; 68: $Apache::londefdef::DT_redirection=0; 69: } 70: 71: #======================= TAG SUBROUTINES ===================== 72: #-- <output> 73: sub start_output { 74: my ($target) = @_; 75: if ($target eq 'meta') { $Apache::lonxml::metamode--; } 76: return ''; 77: } 78: sub end_output { 79: my ($target) = @_; 80: if ($target eq 'meta') { $Apache::lonxml::metamode++; } 81: return ''; 82: } 83: #-- <m> tag 84: sub start_m { 85: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_; 86: my $currentstring = ''; 87: my $inside = &Apache::lonxml::get_all_text_unbalanced("/m",$parser); 88: if ($target eq 'web' || $target eq 'analyze') { 89: $inside ='\\documentstyle{article}'.$inside; 90: &Apache::lonxml::debug("M is starting with:$inside:"); 91: my $eval=&Apache::lonxml::get_param('eval',$parstack,$safeeval); 92: if ($eval eq 'on') { 93: $inside=&Apache::run::evaluate($inside,$safeeval,$$parstack[-1]); 94: #&Apache::lonxml::debug("M is evaulated to:$inside:"); 95: } 96: $currentstring = &Apache::lontexconvert::converted(\$inside); 97: if ($Apache::lontexconvert::errorstring) { 98: &Apache::lonxml::warning("tth error: ". 99: $Apache::lontexconvert::errorstring); 100: $Apache::lontexconvert::errorstring=''; 101: } 102: #&Apache::lonxml::debug("M is ends with:$currentstring:"); 103: $Apache::lonxml::post_evaluate=0; 104: } elsif ($target eq 'tex') { 105: $currentstring = $inside; 106: my $eval=&Apache::lonxml::get_param('eval',$parstack,$safeeval); 107: if ($eval eq 'on') { 108: $currentstring=&Apache::run::evaluate($currentstring,$safeeval,$$parstack[-1]); 109: } 110: if ($currentstring=~/^(\s*\\\\\s*)*$/) {$currentstring = ' \vskip 0 mm ';} 111: $Apache::lonxml::post_evaluate=0; 112: } 113: return $currentstring; 114: } 115: 116: sub end_m { 117: my ($target,$token) = @_; 118: my $currentstring = ''; 119: if ($target eq 'tex') { 120: $currentstring = ""; 121: } 122: return $currentstring; 123: } 124: 125: sub start_tthoption { 126: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; 127: my $result; 128: if ($target eq 'web') { 129: my $inside = &Apache::lonxml::get_all_text("/tthoption",$parser); 130: $inside=~s/^\s*//; 131: if ($ENV{'browser.mathml'}) { 132: &tth::ttmoptions($inside); 133: } else { 134: &tth::tthoptions($inside); 135: } 136: } 137: return $result; 138: } 139: 140: sub end_tthoption { 141: my ($target,$token) = @_; 142: my $result; 143: return $result; 144: } 145: 146: #-- <html> tag (end tag optional) 147: sub start_html { 148: my ($target,$token) = @_; 149: my $currentstring = ''; 150: my $options=$ENV{'course.'.$ENV{'request.course.id'}.'.tthoptions'}; 151: &Apache::lontexconvert::init_tth(); 152: if ($target eq 'web' || $target eq 'edit') { 153: $currentstring = &Apache::lonxml::xmlbegin(). 154: &Apache::lonxml::fontsettings(); 155: } elsif ($target eq 'tex') { 156: @Apache::londefdef::table = (); 157: $currentstring .= '\documentclass[letterpaper]{article}'; 158: if ($ENV{'form.latex_type'}=~'batchmode') {$currentstring .='\batchmode';} 159: $currentstring .= '\newcommand{\keephidden}[1]{}'. 160: '\renewcommand{\deg}{$^{\circ}$}'. 161: '\usepackage{longtable}'. 162: '\usepackage{textcomp}'. 163: '\usepackage{makeidx}'. 164: '\usepackage[dvips]{graphicx}'. 165: '\usepackage{epsfig}'. 166: '\usepackage{calc}'. 167: '\usepackage{amsmath}'. 168: '\usepackage{amssymb}'. 169: '\usepackage{amsfonts}'. 170: '\usepackage{amsthm}'. 171: '\usepackage{amscd}'. 172: '\newenvironment{choicelist}{\begin{list}{}{\setlength{\rightmargin}{0in}\setlength{\leftmargin}{0.13in}\setlength{\topsep}{0.05in}\setlength{\itemsep}{0.022in}\setlength{\parsep}{0in}\setlength{\belowdisplayskip}{0.04in}\setlength{\abovedisplayskip}{0.05in}\setlength{\abovedisplayshortskip}{-0.04in}\setlength{\belowdisplayshortskip}{0.04in}}}{\end{list}}'. 173: '\renewenvironment{theindex}{\begin{list}{}{{\vskip 1mm \noindent \large\textbf{Index}} \newline \setlength{\rightmargin}{0in}\setlength{\leftmargin}{0.13in}\setlength{\topsep}{0.01in}\setlength{\itemsep}{0.1in}\setlength{\parsep}{-0.02in}\setlength{\belowdisplayskip}{0.01in}\setlength{\abovedisplayskip}{0.01in}\setlength{\abovedisplayshortskip}{-0.04in}\setlength{\belowdisplayshortskip}{0.01in}}}{\end{list}}'; 174: } 175: return $currentstring; 176: } 177: 178: sub end_html { 179: my ($target,$token) = @_; 180: my $currentstring = ''; 181: if ($target eq 'web') { 182: $currentstring = &Apache::lonxml::xmlend(); 183: } 184: return $currentstring; 185: } 186: 187: #-- <head> tag (end tag optional) 188: sub start_head { 189: my ($target,$token) = @_; 190: my $currentstring = ''; 191: if ($target eq 'web') { 192: $currentstring = $token->[4]; 193: } 194: return $currentstring; 195: } 196: 197: sub end_head { 198: my ($target,$token) = @_; 199: my $currentstring = ''; 200: if ($target eq 'web' && $ENV{'request.state'} eq 'published') { 201: $currentstring = &Apache::lonmenu::registerurl(undef,$target). 202: $token->[2]; 203: } 204: return $currentstring; 205: } 206: 207: #-- <map> tag (end tag required) 208: sub start_map { 209: my ($target,$token) = @_; 210: my $currentstring = ''; 211: if ($target eq 'web') { 212: $currentstring = $token->[4]; 213: } 214: return $currentstring; 215: } 216: 217: sub end_map { 218: my ($target,$token) = @_; 219: my $currentstring = ''; 220: if ($target eq 'web') { 221: $currentstring = $token->[2]; 222: } 223: return $currentstring; 224: } 225: 226: #-- <select> tag (end tag required) 227: sub start_select { 228: my ($target,$token) = @_; 229: my $currentstring = ''; 230: if ($target eq 'web') { 231: $currentstring = $token->[4]; 232: } elsif ($target eq 'tex') { 233: $Apache::londefdef::select=0; 234: } 235: return $currentstring; 236: } 237: 238: sub end_select { 239: my ($target,$token) = @_; 240: my $currentstring = ''; 241: if ($target eq 'web') { 242: $currentstring = $token->[2]; 243: } 244: return $currentstring; 245: } 246: 247: #-- <option> tag (end tag optional) 248: sub start_option { 249: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; 250: my $currentstring = ''; 251: if ($target eq 'web') { 252: $currentstring = $token->[4]; 253: } elsif ($target eq 'tex') { 254: $Apache::londefdef::select++; 255: if ($Apache::londefdef::select == 1) { 256: $currentstring='\noindent\fbox{'.&Apache::lonxml::get_param('value',$parstack,$safeeval).'}\keephidden{'; 257: } else { 258: $currentstring='\keephidden{'; 259: } 260: } 261: return $currentstring; 262: } 263: 264: sub end_option { 265: my ($target,$token) = @_; 266: my $currentstring = ''; 267: if ($target eq 'web') { 268: $currentstring = $token->[2]; 269: } elsif ($target eq 'tex') { 270: $currentstring='}'; 271: } 272: return $currentstring; 273: } 274: 275: #-- <input> tag (end tag forbidden) 276: sub start_input { 277: my ($target,$token) = @_; 278: my $currentstring = ''; 279: if ($target eq 'web') { 280: $currentstring = $token->[4]; 281: } 282: return $currentstring; 283: } 284: 285: sub end_input { 286: my ($target,$token) = @_; 287: my $currentstring = ''; 288: if ($target eq 'web') { 289: $currentstring = $token->[2]; 290: } 291: return $currentstring; 292: } 293: 294: #-- <textarea> tag (end tag required) 295: sub start_textarea { 296: my ($target,$token) = @_; 297: my $currentstring = ''; 298: if ($target eq 'web') { 299: $currentstring = $token->[4]; 300: } 301: return $currentstring; 302: } 303: 304: sub end_textarea { 305: my ($target,$token) = @_; 306: my $currentstring = ''; 307: if ($target eq 'web') { 308: $currentstring = $token->[2]; 309: } 310: return $currentstring; 311: } 312: 313: #-- <form> tag (end tag required) 314: sub start_form { 315: my ($target,$token) = @_; 316: my $currentstring = ''; 317: if ($target eq 'web') { 318: $currentstring = $token->[4]; 319: } 320: return $currentstring; 321: } 322: 323: sub end_form { 324: my ($target,$token) = @_; 325: my $currentstring = ''; 326: if ($target eq 'web') { 327: $currentstring = $token->[2]; 328: } 329: return $currentstring; 330: } 331: 332: #-- <title> tag (end tag required) 333: sub start_title { 334: my ($target,$token) = @_; 335: my $currentstring = ''; 336: if ($target eq 'web') { 337: $currentstring = $token->[4]; 338: } elsif ($target eq 'tex') { 339: $currentstring .= '\keephidden{Title of the document: ' 340: } 341: if ($target eq 'meta') { 342: $currentstring='<title>'; 343: &start_output($target); 344: } 345: return $currentstring; 346: } 347: 348: sub end_title { 349: my ($target,$token) = @_; 350: my $currentstring = ''; 351: if ($target eq 'web') { 352: $currentstring = $token->[2]; 353: } elsif ($target eq 'tex') { 354: $currentstring .= '}'; 355: } 356: if ($target eq 'meta') { 357: &end_output($target); 358: $currentstring='</title>'; 359: } 360: return $currentstring; 361: } 362: 363: #-- <meta> tag (end tag forbidden) 364: sub start_meta { 365: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; 366: my $currentstring = ''; 367: if ($target eq 'web') { 368: my $args=''; 369: if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; } 370: if ($args eq '') { 371: &Apache::lonxml::get_all_text("/meta",$parser); 372: } else { 373: $currentstring = $token->[4]; 374: } 375: } elsif ($target eq 'meta') { 376: unless (&Apache::lonxml::get_param 377: ('http-equiv',$parstack,$safeeval,undef,1)) { 378: my $name=$token->[2]->{'name'}; 379: $name=~tr/A-Z/a-z/; 380: $name=~s/\s/\_/gs; 381: $name=~s/\W//gs; 382: if ($name) { 383: $currentstring='<'.$name; 384: my $display=&Apache::lonxml::get_param 385: ('display',$parstack,$safeeval,undef,1); 386: if ($display) { 387: $display=~s/\"/\'/g; 388: $currentstring.=' display="'.$display.'"'; 389: } 390: $currentstring.='>'. 391: &Apache::lonxml::get_param 392: ('content',$parstack,$safeeval,undef,1). 393: '</'.$name.'>'; 394: } 395: my $display=&Apache::lonxml::get_param 396: ('display',$parstack,$safeeval,undef,1); 397: if ($display) { 398: $display=&HTML::Entities::encode($display,'<>&"'); 399: $currentstring.='<'.$name.'.display>'.$display. 400: '</'.$name.'.display>'; 401: } 402: } 403: } elsif ($target eq 'tex') { 404: my $content=&Apache::lonxml::get_param('content',$parstack,$safeeval); 405: my $name=&Apache::lonxml::get_param('name',$parstack,$safeeval); 406: if ((not defined $content) && (not defined $name)) { 407: &Apache::lonxml::startredirection(); 408: } 409: } 410: return $currentstring; 411: } 412: 413: sub end_meta { 414: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; 415: my $currentstring = ''; 416: if ($target eq 'web') { 417: my $args=''; 418: if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; } 419: if ($args ne '') { 420: $currentstring = $token->[4]; 421: } 422: } elsif ($target eq 'tex') { 423: my $content=&Apache::lonxml::get_param('content',$parstack,$safeeval); 424: my $name=&Apache::lonxml::get_param('name',$parstack,$safeeval); 425: if ((not defined $content) && (not defined $name)) { 426: &Apache::lonxml::endredirection(); 427: } 428: } 429: return $currentstring; 430: } 431: 432: # accessrule 433: sub start_accessrule { 434: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; 435: my $currentstring = ''; 436: my $eff=&Apache::lonxml::get_param 437: ('effect',$parstack,$safeeval,undef,1); 438: my $realm=&Apache::lonxml::get_param 439: ('realm',$parstack,$safeeval,undef,1); 440: my $role=&Apache::lonxml::get_param 441: ('role',$parstack,$safeeval,undef,1); 442: $realm=~s/\s+//g; 443: $realm=~s/\//\_/g; 444: $realm=~s/^\_//; 445: $realm=~s/\W/\;/g; 446: $role=~s/\s+//g; 447: $role=~s/\//\_/g; 448: $role=~s/\W/\;/g; 449: if ($target eq 'web') { 450: my $args=''; 451: if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; } 452: if ($args eq '') { 453: &Apache::lonxml::get_all_text("/accessrule",$parser); 454: } else { 455: $currentstring = $token->[4]; 456: } 457: } 458: if ($target eq 'meta') { 459: $currentstring='<rule>'.$eff.':'.$realm.':'.$role.'</rule>'; 460: } 461: return $currentstring; 462: } 463: 464: sub end_accessrule { 465: my ($target,$token,$tagstack,$parstack,$parser) = @_; 466: my $currentstring = ''; 467: if ($target eq 'web') { 468: my $args=''; 469: if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; } 470: if ($args ne '') { 471: $currentstring = $token->[4]; 472: } 473: } 474: return $currentstring; 475: } 476: 477: #-- <body> tag (end tag required) 478: sub start_body { 479: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; 480: my $currentstring = ''; 481: if ($target eq 'web') { 482: if ($Apache::lonhomework::parsing_a_problem) { 483: &Apache::lonxml::warning("<body> tag found inside of <problem> tag this can cause problems."); 484: return ''; 485: } 486: if (!$Apache::lonxml::registered && 487: $ENV{'request.state'} eq 'published') { 488: $currentstring.='<head>'. 489: &Apache::lonmenu::registerurl(undef,$target).'</head>'; 490: } 491: # Accessibility 492: if ($ENV{'browser.imagesuppress'} eq 'on') { 493: delete($token->[2]->{'background'}); 494: } 495: if ($ENV{'browser.fontenhance'} eq 'on') { 496: my $style=''; 497: foreach my $key (keys(%{$token->[2]})) { 498: if ($key =~ /^style$/i) { 499: $style.=$token->[2]->{$key}.';'; 500: delete($token->[2]->{$key}); 501: } 502: } 503: $token->[2]->{'style'}=$style.'; font-size: x-large;'; 504: } 505: if ($ENV{'browser.blackwhite'} eq 'on') { 506: delete($token->[2]->{'font'}); 507: delete($token->[2]->{'link'}); 508: delete($token->[2]->{'alink'}); 509: delete($token->[2]->{'vlink'}); 510: delete($token->[2]->{'bgcolor'}); 511: delete($token->[2]->{'background'}); 512: } 513: # Overload loads 514: my $onLoad=''; 515: foreach my $key (keys(%{$token->[2]})) { 516: if ($key =~ /^onload$/i) { 517: $onLoad.=$token->[2]->{$key}.';'; 518: delete($token->[2]->{$key}); 519: } 520: } 521: $token->[2]->{'onload'}=&Apache::lonmenu::loadevents().';'.$onLoad; 522: my $onUnload=''; 523: foreach my $key (keys(%{$token->[2]})) { 524: if ($key =~ /^onunload$/i) { 525: $onUnload.=$token->[2]->{$key}.';'; 526: delete($token->[2]->{$key}); 527: } 528: } 529: $token->[2]->{'onunload'}=&Apache::lonmenu::unloadevents(). 530: ';'.$onUnload; 531: 532: $currentstring .= '<'.$token->[1]; 533: foreach (keys %{$token->[2]}) { 534: $currentstring.=' '.$_.'="'.$token->[2]->{$_}.'"'; 535: } 536: $currentstring.='>'; 537: if ($ENV{'request.state'} ne 'published') { 538: $currentstring.=(<<EDITBUTTON); 539: <form method="post"> 540: <input type="submit" name="editmode" accesskey="e" value="Edit" /> 541: </form> 542: EDITBUTTON 543: } else { 544: $currentstring.=&Apache::lonmenu::menubuttons(undef,$target,1); 545: } 546: $currentstring.=&Apache::lonxml::message_location(); 547: } elsif ($target eq 'tex') { 548: $currentstring = '\begin{document}'; 549: } 550: return $currentstring; 551: } 552: 553: sub end_body { 554: my ($target,$token) = @_; 555: my $currentstring = ''; 556: if ($target eq 'web') { 557: $currentstring = $token->[2]; 558: } elsif ($target eq 'tex') { 559: $currentstring = '\strut\newline\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}\newline\noindent \end{document}'; 560: } 561: return $currentstring; 562: } 563: 564: #-- <center> tag (end tag required) 565: sub start_center { 566: my ($target,$token) = @_; 567: my $currentstring = ''; 568: if ($target eq 'web') { 569: $currentstring = $token->[4]; 570: } elsif ($target eq 'tex') { 571: $currentstring = '\begin{center}'; 572: } 573: return $currentstring; 574: } 575: 576: sub end_center { 577: my ($target,$token) = @_; 578: my $currentstring = ''; 579: if ($target eq 'web') { 580: $currentstring = $token->[2]; 581: } elsif ($target eq 'tex') { 582: $currentstring = '\end{center}'; 583: } 584: return $currentstring; 585: } 586: 587: #-- <b> tag (end tag required) 588: sub start_b { 589: my ($target,$token) = @_; 590: my $currentstring = ''; 591: if ($target eq 'web') { 592: $currentstring = $token->[4]; 593: } elsif ($target eq 'tex') { 594: $currentstring = '\textbf{'; 595: } 596: return $currentstring; 597: } 598: 599: sub end_b { 600: my ($target,$token) = @_; 601: my $currentstring = ''; 602: if ($target eq 'web') { 603: $currentstring = $token->[2]; 604: } elsif ($target eq 'tex') { 605: $currentstring = '}'; 606: } 607: return $currentstring; 608: } 609: 610: #-- <strong> tag (end tag required) 611: sub start_strong { 612: my ($target,$token) = @_; 613: my $currentstring = ''; 614: if ($target eq 'web') { 615: $currentstring = $token->[4]; 616: } elsif ($target eq 'tex') { 617: $currentstring = '\textbf{'; 618: } 619: return $currentstring; 620: } 621: 622: sub end_strong { 623: my ($target,$token) = @_; 624: my $currentstring = ''; 625: if ($target eq 'web') { 626: $currentstring = $token->[2]; 627: } elsif ($target eq 'tex') { 628: $currentstring = '}'; 629: } 630: return $currentstring; 631: } 632: 633: #-- <h1> tag (end tag required) 634: sub start_h1 { 635: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; 636: my $currentstring = ''; 637: if ($target eq 'web') { 638: $currentstring .= $token->[4]; 639: } elsif ($target eq 'tex') { 640: my $pre; 641: my $align=lc(&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1)); 642: if ($align eq 'center') { 643: $pre='\begin{center}'; 644: } elsif ($align eq 'left') { 645: $pre='\rlap{'; 646: } elsif ($align eq 'right') { 647: $pre=' \hfill \llap{'; 648: } 649: my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0); 650: if (not defined $TeXsize) {$TeXsize="large";} 651: $currentstring .= $pre.'{\\'.$TeXsize.' \textbf{'; 652: } elsif ($target eq 'meta') { 653: $currentstring='<subject>'; 654: &start_output($target); 655: } 656: return $currentstring; 657: } 658: 659: sub end_h1 { 660: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; 661: my $currentstring = ''; 662: if ($target eq 'web') { 663: $currentstring .= $token->[2]; 664: } elsif ($target eq 'tex') { 665: my $post='\vskip 0 mm '; 666: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1); 667: if ($align eq 'center') { 668: $post='\end{center}'; 669: } elsif ($align eq 'left') { 670: $post='} \hfill'.'\vskip 0 mm '; 671: } elsif ($align eq 'right') { 672: $post='}'.'\vskip 0 mm '; 673: } 674: $currentstring .= '}}'.$post; 675: } elsif ($target eq 'meta') { 676: &end_output($target); 677: $currentstring='</subject>'; 678: } 679: return $currentstring; 680: } 681: 682: #-- <h2> tag 683: sub start_h2 { 684: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; 685: my $currentstring = ''; 686: if ($target eq 'web') { 687: $currentstring .= $token->[4]; 688: } elsif ($target eq 'tex') { 689: my $pre; 690: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1); 691: if ($align eq 'center') { 692: $pre='\begin{center}'; 693: } elsif ($align eq 'left') { 694: $pre='\rlap{'; 695: } elsif ($align eq 'right') { 696: $pre=' \hfill \llap{'; 697: } 698: my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0); 699: if (not defined $TeXsize) {$TeXsize="large";} 700: $currentstring .= $pre.'{\\'.$TeXsize.' \textbf{'; 701: } 702: return $currentstring; 703: } 704: 705: sub end_h2 { 706: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; 707: my $currentstring = ''; 708: if ($target eq 'web') { 709: $currentstring .= $token->[2]; 710: } elsif ($target eq 'tex') { 711: my $post='\vskip 0 mm '; 712: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1); 713: if ($align eq 'center') { 714: $post='\end{center}'; 715: } elsif ($align eq 'left') { 716: $post='} \hfill'.'\vskip 0 mm '; 717: } elsif ($align eq 'right') { 718: $post='}'.'\vskip 0 mm '; 719: } 720: $currentstring .= '}}'.$post; 721: } 722: return $currentstring; 723: } 724: 725: #-- <h3> tag 726: sub start_h3 { 727: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; 728: my $currentstring = ''; 729: if ($target eq 'web') { 730: $currentstring .= $token->[4]; 731: } elsif ($target eq 'tex') { 732: my $pre; 733: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1); 734: if ($align eq 'center') { 735: $pre='\begin{center}'; 736: } elsif ($align eq 'left') { 737: $pre='\rlap{'; 738: } elsif ($align eq 'right') { 739: $pre=' \hfill \llap{'; 740: } 741: my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0); 742: if (not defined $TeXsize) {$TeXsize="large";} 743: $currentstring .= $pre.'{\\'.$TeXsize.' \textbf{'; 744: } 745: return $currentstring; 746: } 747: 748: sub end_h3 { 749: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; 750: my $currentstring = ''; 751: if ($target eq 'web') { 752: $currentstring .= $token->[2]; 753: } elsif ($target eq 'tex') { 754: my $post='\vskip 0 mm '; 755: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1); 756: if ($align eq 'center') { 757: $post='\end{center}'; 758: } elsif ($align eq 'left') { 759: $post='} \hfill'.'\vskip 0 mm '; 760: } elsif ($align eq 'right') { 761: $post='}'.'\vskip 0 mm '; 762: } 763: $currentstring .= '}}'.$post; 764: } 765: return $currentstring; 766: } 767: 768: #-- <h4> tag 769: sub start_h4 { 770: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; 771: my $currentstring = ''; 772: if ($target eq 'web') { 773: $currentstring .= $token->[4]; 774: } elsif ($target eq 'tex') { 775: my $pre; 776: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1); 777: if ($align eq 'center') { 778: $pre='\begin{center}'; 779: } elsif ($align eq 'left') { 780: $pre='\rlap{'; 781: } elsif ($align eq 'right') { 782: $pre=' \hfill \llap{'; 783: } 784: my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0); 785: if (not defined $TeXsize) {$TeXsize="large";} 786: $currentstring .= $pre.'{\\'.$TeXsize.' \textbf{'; 787: } 788: return $currentstring; 789: } 790: 791: sub end_h4 { 792: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; 793: my $currentstring = ''; 794: if ($target eq 'web') { 795: $currentstring .= $token->[2]; 796: } elsif ($target eq 'tex') { 797: my $post='\vskip 0 mm '; 798: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1); 799: if ($align eq 'center') { 800: $post='\end{center}'; 801: } elsif ($align eq 'left') { 802: $post='} \hfill'.'\vskip 0 mm '; 803: } elsif ($align eq 'right') { 804: $post='}'.'\vskip 0 mm '; 805: } 806: $currentstring .= '}}'.$post; 807: } 808: return $currentstring; 809: } 810: 811: #-- <h5> tag 812: sub start_h5 { 813: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; 814: my $currentstring = ''; 815: if ($target eq 'web') { 816: $currentstring .= $token->[4]; 817: } elsif ($target eq 'tex') { 818: my $pre; 819: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1); 820: if ($align eq 'center') { 821: $pre='\begin{center}'; 822: } elsif ($align eq 'left') { 823: $pre='\rlap{'; 824: } elsif ($align eq 'right') { 825: $pre=' \hfill \llap{'; 826: } 827: my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0); 828: if (not defined $TeXsize) {$TeXsize="large";} 829: $currentstring .= $pre.'{\\'.$TeXsize.' \textbf{'; 830: } 831: return $currentstring; 832: } 833: 834: sub end_h5 { 835: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; 836: my $currentstring = ''; 837: if ($target eq 'web') { 838: $currentstring .= $token->[2]; 839: } elsif ($target eq 'tex') { 840: my $post='\vskip 0 mm '; 841: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1); 842: if ($align eq 'center') { 843: $post='\end{center}'; 844: } elsif ($align eq 'left') { 845: $post='} \hfill'.'\vskip 0 mm '; 846: } elsif ($align eq 'right') { 847: $post='}'.'\vskip 0 mm '; 848: } 849: $currentstring .= '}}'.$post; 850: } 851: return $currentstring; 852: } 853: 854: #-- <h6> tag 855: sub start_h6 { 856: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; 857: my $currentstring = ''; 858: if ($target eq 'web') { 859: $currentstring .= $token->[4]; 860: } elsif ($target eq 'tex') { 861: my $pre; 862: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1); 863: if ($align eq 'center') { 864: $pre='\begin{center}'; 865: } elsif ($align eq 'left') { 866: $pre='\rlap{'; 867: } elsif ($align eq 'right') { 868: $pre=' \hfill \llap{'; 869: } 870: my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0); 871: if (not defined $TeXsize) {$TeXsize="large";} 872: $currentstring .= $pre.'{\\'.$TeXsize.' \textbf{'; 873: } 874: return $currentstring; 875: } 876: 877: sub end_h6 { 878: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; 879: my $currentstring = ''; 880: if ($target eq 'web') { 881: $currentstring .= $token->[2]; 882: } elsif ($target eq 'tex') { 883: my $post='\vskip 0 mm '; 884: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1); 885: if ($align eq 'center') { 886: $post='\end{center}'; 887: } elsif ($align eq 'left') { 888: $post='} \hfill'.'\vskip 0 mm '; 889: } elsif ($align eq 'right') { 890: $post='}'.'\vskip 0 mm '; 891: } 892: $currentstring .= '}}'.$post; 893: } 894: return $currentstring; 895: } 896: 897: #--- <cite> tag (end tag required) 898: sub start_cite { 899: my ($target,$token) = @_; 900: my $currentstring = ''; 901: if ($target eq 'web') { 902: $currentstring .= $token->[4]; 903: } elsif ($target eq 'tex') { 904: $currentstring .= '\textit{'; 905: } 906: return $currentstring; 907: } 908: 909: sub end_cite { 910: my ($target,$token) = @_; 911: my $currentstring = ''; 912: if ($target eq 'web') { 913: $currentstring .= $token->[2]; 914: } elsif ($target eq 'tex') { 915: $currentstring .= '}'; 916: } 917: return $currentstring; 918: } 919: 920: #-- <i> tag (end tag required) 921: sub start_i { 922: my ($target,$token) = @_; 923: my $currentstring = ''; 924: if ($target eq 'web') { 925: $currentstring .= $token->[4]; 926: } elsif ($target eq 'tex') { 927: $currentstring .= '\textit{'; 928: } 929: return $currentstring; 930: } 931: 932: sub end_i { 933: my ($target,$token) = @_; 934: my $currentstring = ''; 935: if ($target eq 'web') { 936: $currentstring .= $token->[2]; 937: } elsif ($target eq 'tex') { 938: $currentstring .= '}'; 939: } 940: return $currentstring; 941: } 942: 943: #-- <address> tag (end tag required) 944: sub start_address { 945: my ($target,$token) = @_; 946: my $currentstring = ''; 947: if ($target eq 'web') { 948: $currentstring .= $token->[4]; 949: } elsif ($target eq 'tex') { 950: $currentstring .= '\textit{'; 951: } 952: return $currentstring; 953: } 954: 955: sub end_address { 956: my ($target,$token) = @_; 957: my $currentstring = ''; 958: if ($target eq 'web') { 959: $currentstring .= $token->[2]; 960: } elsif ($target eq 'tex') { 961: $currentstring .= '}'; 962: } 963: return $currentstring; 964: } 965: 966: #-- <dfn> tag (end tag required) 967: sub start_dfn { 968: my ($target,$token) = @_; 969: my $currentstring = ''; 970: if ($target eq 'web') { 971: $currentstring .= $token->[4]; 972: } elsif ($target eq 'tex') { 973: $currentstring .= '\textit{'; 974: } 975: return $currentstring; 976: } 977: 978: sub end_dfn { 979: my ($target,$token) = @_; 980: my $currentstring = ''; 981: if ($target eq 'web') { 982: $currentstring .= $token->[2]; 983: } elsif ($target eq 'tex') { 984: $currentstring .= '}'; 985: } 986: return $currentstring; 987: } 988: 989: #-- <tt> tag (end tag required) 990: sub start_tt { 991: my ($target,$token) = @_; 992: my $currentstring = ''; 993: if ($target eq 'web') { 994: $currentstring .= $token->[4]; 995: } elsif ($target eq 'tex') { 996: $currentstring .= '\texttt{'; 997: } 998: return $currentstring; 999: } 1000: 1001: sub end_tt { 1002: my ($target,$token) = @_; 1003: my $currentstring = ''; 1004: if ($target eq 'web') { 1005: $currentstring .= $token->[2]; 1006: } elsif ($target eq 'tex') { 1007: $currentstring .= '}'; 1008: } 1009: return $currentstring; 1010: } 1011: 1012: #-- <kbd> tag (end tag required) 1013: sub start_kbd { 1014: my ($target,$token) = @_; 1015: my $currentstring = ''; 1016: if ($target eq 'web') { 1017: $currentstring .= $token->[4]; 1018: } elsif ($target eq 'tex') { 1019: $currentstring .= '\texttt{'; 1020: } 1021: return $currentstring; 1022: } 1023: 1024: sub end_kbd { 1025: my ($target,$token) = @_; 1026: my $currentstring = ''; 1027: if ($target eq 'web') { 1028: $currentstring .= $token->[2]; 1029: } elsif ($target eq 'tex') { 1030: $currentstring .= '}'; 1031: } 1032: return $currentstring; 1033: } 1034: 1035: #-- <code> tag (end tag required) 1036: sub start_code { 1037: my ($target,$token) = @_; 1038: my $currentstring = ''; 1039: if ($target eq 'web') { 1040: $currentstring .= $token->[4]; 1041: } elsif ($target eq 'tex') { 1042: $currentstring .= '\texttt{'; 1043: } 1044: return $currentstring; 1045: } 1046: 1047: sub end_code { 1048: my ($target,$token) = @_; 1049: my $currentstring = ''; 1050: if ($target eq 'web') { 1051: $currentstring .= $token->[2]; 1052: } elsif ($target eq 'tex') { 1053: $currentstring .= '}'; 1054: } 1055: return $currentstring; 1056: } 1057: 1058: #-- <em> tag (end tag required) 1059: sub start_em { 1060: my ($target,$token) = @_; 1061: my $currentstring = ''; 1062: if ($target eq 'web') { 1063: $currentstring .= $token->[4]; 1064: } elsif ($target eq 'tex') { 1065: $currentstring .= '\emph{'; 1066: } 1067: return $currentstring; 1068: } 1069: 1070: sub end_em { 1071: my ($target,$token) = @_; 1072: my $currentstring = ''; 1073: if ($target eq 'web') { 1074: $currentstring .= $token->[2]; 1075: } elsif ($target eq 'tex') { 1076: $currentstring .= '}'; 1077: } 1078: return $currentstring; 1079: } 1080: 1081: #-- <q> tag (end tag required) 1082: sub start_q { 1083: my ($target,$token) = @_; 1084: my $currentstring = ''; 1085: if ($target eq 'web') { 1086: $currentstring .= $token->[4]; 1087: } elsif ($target eq 'tex') { 1088: $currentstring .= '\emph{'; 1089: } 1090: return $currentstring; 1091: } 1092: 1093: sub end_q { 1094: my ($target,$token) = @_; 1095: my $currentstring = ''; 1096: if ($target eq 'web') { 1097: $currentstring .= $token->[2]; 1098: } elsif ($target eq 'tex') { 1099: $currentstring .= '}'; 1100: } 1101: return $currentstring; 1102: } 1103: 1104: #-- <p> tag (end tag optional) 1105: #optional attribute - align="center|left|right" 1106: sub start_p { 1107: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; 1108: my $currentstring = ''; 1109: if ($target eq 'web') { 1110: $currentstring .= $token->[4]; 1111: } elsif ($target eq 'tex') { 1112: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1); 1113: if ($align eq 'center') { 1114: $currentstring='\begin{center}\par'; 1115: } elsif ($align eq 'right') { 1116: $currentstring='\makebox['.$ENV{'form.textwidth'}.']{\hfill\llap{'; 1117: } elsif ($align eq 'left') { 1118: $currentstring='\noindent\makebox['.$ENV{'form.textwidth'}.']{\rlap{'; 1119: } else { 1120: $currentstring='\par '; 1121: } 1122: my $signal=1;#<p> does not work inside <b>...</b> 1123: foreach my $tag (@$tagstack) {if (lc($tag) eq 'b') {$signal=0;} 1124: if (!$signal) {$currentstring = '';} 1125: } 1126: } 1127: return $currentstring; 1128: } 1129: 1130: sub end_p { 1131: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; 1132: my $currentstring = ''; 1133: if ($target eq 'web') { 1134: $currentstring .= $token->[2]; 1135: } elsif ($target eq 'tex') { 1136: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1); 1137: if ($align eq 'center') { 1138: $currentstring .= '\end{center}'; 1139: } elsif ($align eq 'right') { 1140: $currentstring .= '}}'; 1141: } elsif ($align eq 'left') { 1142: $currentstring .= '}\hfill}'; 1143: } 1144: } 1145: return $currentstring; 1146: } 1147: 1148: #-- <br> tag (end tag forbidden) 1149: sub start_br { 1150: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; 1151: my $currentstring = ''; 1152: if ($target eq 'web') { 1153: $currentstring .= $token->[4]; 1154: } elsif ($target eq 'tex') { 1155: if (($$tagstack[-2] eq 'b') || ($$tagstack[-2] eq 'strong') || 1156: ($$tagstack[-2] eq 'ol') || ($$tagstack[-2] eq 'ul')) { 1157: $currentstring .= ' \vskip 0 mm '; 1158: } elsif ($$tagstack[-2] ne 'sub' && $$tagstack[-2] ne 'sup') { 1159: $currentstring .= '\strut \\\\ \strut '; 1160: } 1161: } 1162: return $currentstring; 1163: } 1164: 1165: sub end_br { 1166: my ($target,$token) = @_; 1167: my $currentstring = ''; 1168: if ($target eq 'web') { 1169: $currentstring .= $token->[2]; 1170: } 1171: return $currentstring; 1172: } 1173: 1174: #-- <big> tag (end tag required) 1175: sub start_big { 1176: my ($target,$token) = @_; 1177: my $currentstring = ''; 1178: if ($target eq 'web') { 1179: $currentstring .= $token->[4]; 1180: } elsif ($target eq 'tex') { 1181: $currentstring .= '{\large '; 1182: } 1183: return $currentstring; 1184: } 1185: 1186: sub end_big { 1187: my ($target,$token) = @_; 1188: my $currentstring = ''; 1189: if ($target eq 'web') { 1190: $currentstring .= $token->[2]; 1191: } elsif ($target eq 'tex') { 1192: $currentstring .= '}'; 1193: } 1194: return $currentstring; 1195: } 1196: 1197: #-- <small> tag (end tag required) 1198: sub start_small { 1199: my ($target,$token) = @_; 1200: my $currentstring = ''; 1201: if ($target eq 'web') { 1202: $currentstring .= $token->[4]; 1203: } elsif ($target eq 'tex') { 1204: $currentstring .= '{\footnotesize '; 1205: } 1206: return $currentstring; 1207: } 1208: 1209: sub end_small { 1210: my ($target,$token) = @_; 1211: my $currentstring = ''; 1212: if ($target eq 'web') { 1213: $currentstring .= $token->[2]; 1214: } elsif ($target eq 'tex') { 1215: $currentstring .= '}'; 1216: } 1217: return $currentstring; 1218: } 1219: 1220: #-- <basefont> tag (end tag forbidden) 1221: sub start_basefont { 1222: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; 1223: my $currentstring = ''; 1224: if ($target eq 'web') { 1225: $currentstring = $token->[4]; 1226: } elsif ($target eq 'tex') { 1227: my $basesize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval); 1228: if (defined $basesize) { 1229: $currentstring = '{\\'.$basesize.' '; 1230: } 1231: } 1232: return $currentstring; 1233: } 1234: 1235: sub end_basefont { 1236: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; 1237: my $currentstring = ''; 1238: if ($target eq 'web') { 1239: $currentstring = $token->[4]; 1240: } elsif ($target eq 'tex') { 1241: my $basesize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval); 1242: if (defined $basesize) { 1243: $currentstring = '}'; 1244: } 1245: } 1246: return $currentstring; 1247: } 1248: 1249: #-- <font> tag (end tag required) 1250: sub start_font { 1251: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; 1252: my $currentstring = ''; 1253: if ($target eq 'web') { 1254: my $face=&Apache::lonxml::get_param('face',$parstack,$safeeval); 1255: if ($face!~/symbol/i) { 1256: if (($ENV{'browser.fontenhance'} eq 'on') || 1257: ($ENV{'browser.blackwhite'} eq 'on')) { return ''; } 1258: } 1259: $currentstring = $token->[4]; 1260: } elsif ($target eq 'tex') { 1261: my $fontsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval); 1262: if (defined $fontsize) { 1263: $currentstring = '{\\'.$fontsize.' '; 1264: } 1265: } 1266: return $currentstring; 1267: } 1268: 1269: sub end_font { 1270: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; 1271: my $currentstring = ''; 1272: if ($target eq 'web') { 1273: $currentstring = $token->[2]; 1274: } elsif ($target eq 'tex') { 1275: my $fontsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval); 1276: if (defined $fontsize) { 1277: $currentstring = '}'; 1278: } 1279: } 1280: return $currentstring; 1281: } 1282: 1283: #-- <strike> tag (end tag required) 1284: sub start_strike { 1285: my ($target,$token) = @_; 1286: my $currentstring = ''; 1287: if ($target eq 'web') { 1288: $currentstring .= $token->[4]; 1289: } elsif ($target eq 'tex') { 1290: &Apache::lonxml::startredirection(); 1291: } 1292: return $currentstring; 1293: } 1294: 1295: sub end_strike { 1296: my ($target,$token) = @_; 1297: my $currentstring = ''; 1298: if ($target eq 'web') { 1299: $currentstring .= $token->[2]; 1300: } elsif ($target eq 'tex') { 1301: $currentstring=&Apache::lonxml::endredirection(); 1302: $currentstring=~s/(\S)(\s+)(\S)/$1\}$2\\underline\{$3/g; 1303: $currentstring=~s/^\s*(\S)/\\underline\{$1/; 1304: $currentstring=~s/(\S)\s*$/$1\}/; 1305: } 1306: return $currentstring; 1307: } 1308: 1309: #-- <s> tag (end tag required) 1310: sub start_s { 1311: my ($target,$token) = @_; 1312: my $currentstring = ''; 1313: if ($target eq 'web') { 1314: $currentstring .= $token->[4]; 1315: } elsif ($target eq 'tex') { 1316: &Apache::lonxml::startredirection(); 1317: } 1318: return $currentstring; 1319: } 1320: 1321: sub end_s { 1322: my ($target,$token) = @_; 1323: my $currentstring = ''; 1324: if ($target eq 'web') { 1325: $currentstring .= $token->[2]; 1326: } elsif ($target eq 'tex') { 1327: $currentstring=&Apache::lonxml::endredirection(); 1328: $currentstring=~s/(\S)(\s+)(\S)/$1\}$2\\underline\{$3/g; 1329: $currentstring=~s/^\s*(\S)/\\underline\{$1/; 1330: $currentstring=~s/(\S)\s*$/$1\}/; 1331: } 1332: return $currentstring; 1333: } 1334: 1335: #-- <sub> tag (end tag required) 1336: sub start_sub { 1337: my ($target,$token) = @_; 1338: my $currentstring = ''; 1339: if ($target eq 'web') { 1340: $currentstring .= $token->[4]; 1341: } elsif ($target eq 'tex') { 1342: $currentstring .= '\ensuremath{_{'; 1343: } 1344: return $currentstring; 1345: } 1346: 1347: sub end_sub { 1348: my ($target,$token) = @_; 1349: my $currentstring = ''; 1350: if ($target eq 'web') { 1351: $currentstring .= $token->[2]; 1352: } elsif ($target eq 'tex') { 1353: $currentstring .= '}}'; 1354: } 1355: return $currentstring; 1356: } 1357: 1358: #-- <sup> tag (end tag required) 1359: sub start_sup { 1360: my ($target,$token) = @_; 1361: my $currentstring = ''; 1362: if ($target eq 'web') { 1363: $currentstring .= $token->[4]; 1364: } elsif ($target eq 'tex') { 1365: $currentstring .= '\ensuremath{^{'; 1366: } 1367: return $currentstring; 1368: } 1369: 1370: sub end_sup { 1371: my ($target,$token) = @_; 1372: my $currentstring = ''; 1373: if ($target eq 'web') { 1374: $currentstring .= $token->[2]; 1375: } elsif ($target eq 'tex') { 1376: $currentstring .= '}}'; 1377: } 1378: return $currentstring; 1379: } 1380: 1381: #-- <hr> tag (end tag forbidden) 1382: sub start_hr { 1383: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; 1384: my $currentstring = ''; 1385: if ($target eq 'web') { 1386: $currentstring .= $token->[4]; 1387: } elsif ($target eq 'tex') { 1388: my $LaTeXwidth = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0); 1389: if (defined $LaTeXwidth) { 1390: if ($LaTeXwidth=~/^%/) { 1391: substr($LaTeXwidth,0,1)=''; 1392: $LaTeXwidth=($LaTeXwidth/100).'\textwidth'; 1393: } 1394: } else { 1395: $LaTeXwidth ='0.9\textwidth'; 1396: } 1397: my ($pre,$post); 1398: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1); 1399: if (($align eq 'center') || (not defined $align)) { 1400: $pre=''; $post=''; 1401: } elsif ($align eq 'left') { 1402: $pre='\rlap{'; $post='} \hfill'; 1403: } elsif ($align eq 'right') { 1404: $pre=' \hfill \llap{'; $post='}'; 1405: } 1406: $currentstring .= ' \vskip 0 mm \noindent\makebox['.$LaTeXwidth.']{'.$pre.'\makebox['. 1407: $LaTeXwidth.'][b]{\hrulefill}'.$post.'}\vskip 0 mm '; 1408: } 1409: return $currentstring; 1410: } 1411: 1412: sub end_hr { 1413: my ($target,$token) = @_; 1414: my $currentstring = ''; 1415: if ($target eq 'web') { 1416: $currentstring .= $token->[2]; 1417: } 1418: return $currentstring; 1419: } 1420: 1421: #-- <div> tag (end tag required) 1422: sub start_div { 1423: my ($target,$token) = @_; 1424: my $currentstring = ''; 1425: if ($target eq 'web') { 1426: $currentstring .= $token->[4]; 1427: } 1428: return $currentstring; 1429: } 1430: 1431: sub end_div { 1432: my ($target,$token) = @_; 1433: my $currentstring = ''; 1434: if ($target eq 'web') { 1435: $currentstring .= $token->[2]; 1436: } 1437: return $currentstring; 1438: } 1439: 1440: #-- <a> tag (end tag required) 1441: sub start_a { 1442: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; 1443: my $currentstring = ''; 1444: if ($target eq 'web') { 1445: $currentstring .= $token->[4]; 1446: } elsif ($target eq 'tex') { 1447: my $a=&Apache::lonxml::get_param('href',$parstack,$safeeval,undef,1); 1448: my $b=&Apache::lonxml::get_param('name',$parstack,$safeeval,undef,1); 1449: if ($a=~/\S/) { 1450: $a=~s/([^\\])%/$1\\\%/g; 1451: $currentstring .= '\ref{URI: '.$a.'}'; 1452: } elsif ($b=~/\S/) { 1453: $currentstring .= '\ref{Anchor: '.$b.'}'; 1454: } else { 1455: $currentstring.=''; 1456: } 1457: } 1458: return $currentstring; 1459: } 1460: 1461: sub end_a { 1462: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; 1463: my $currentstring = ''; 1464: if ($target eq 'web') { 1465: $currentstring .= $token->[2]; 1466: } 1467: return $currentstring; 1468: } 1469: 1470: #-- <li> tag (end tag optional) 1471: sub start_li { 1472: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; 1473: my $currentstring = ''; 1474: if ($target eq 'web') { 1475: $currentstring = $token->[4]; 1476: } elsif ($target eq 'tex') { 1477: my $type=&Apache::lonxml::get_param('type',$parstack,$safeeval,undef,1); 1478: if ($type=~/circle/) { 1479: $currentstring .= ' \item[o] '; 1480: } elsif ($type=~/square/) { 1481: $currentstring .= ' \item[$\Box$] '; 1482: } elsif ($type ne '') { 1483: $currentstring .= ' \item['.$type.'] '; 1484: } else { 1485: $currentstring .= ' \item '; 1486: } 1487: } 1488: return $currentstring; 1489: } 1490: 1491: sub end_li { 1492: my ($target,$token) = @_; 1493: my $currentstring = ''; 1494: if ($target eq 'web') { 1495: $currentstring = $token->[2]; 1496: } 1497: return $currentstring; 1498: } 1499: 1500: #-- <u> tag (end tag required) 1501: sub start_u { 1502: my ($target,$token) = @_; 1503: my $currentstring = ''; 1504: if ($target eq 'web') { 1505: $currentstring .= $token->[4]; 1506: } elsif ($target eq 'tex') { 1507: &Apache::lonxml::startredirection(); 1508: } 1509: return $currentstring; 1510: } 1511: 1512: sub end_u { 1513: my ($target,$token) = @_; 1514: my $currentstring = ''; 1515: if ($target eq 'web') { 1516: $currentstring .= $token->[2]; 1517: } elsif ($target eq 'tex') { 1518: $currentstring=&Apache::lonxml::endredirection(); 1519: $currentstring=~s/(\S)(\s+)(\S)/$1\}$2\\underline\{$3/g; 1520: $currentstring=~s/^\s*(\S)/\\underline\{$1/; 1521: $currentstring=~s/(\S)\s*$/$1\}/; 1522: } 1523: return $currentstring; 1524: } 1525: 1526: #-- <ul> tag (end tag required) 1527: sub start_ul { 1528: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; 1529: my $currentstring = ''; 1530: if ($target eq 'web') { 1531: $currentstring = $token->[4]; 1532: } elsif ($target eq 'tex') { 1533: my $TeXtype=&Apache::lonxml::get_param('type',$parstack,$safeeval,undef,0); 1534: if ($TeXtype eq 'disc') { 1535: $currentstring .= '\renewcommand{\labelitemi}{$\bullet$}'. 1536: '\renewcommand{\labelitemii}{$\bullet$}'. 1537: '\renewcommand{\labelitemiii}{$\bullet$}'. 1538: '\renewcommand{\labelitemiv}{$\bullet$}'; 1539: } elsif ($TeXtype eq 'circle') { 1540: $currentstring .= '\renewcommand{\labelitemi}{$\circ$}'. 1541: '\renewcommand{\labelitemii}{$\circ$}'. 1542: '\renewcommand{\labelitemiii}{$\circ$}'. 1543: '\renewcommand{\labelitemiv}{$\circ$}'; 1544: } elsif ($TeXtype eq 'square') { 1545: $currentstring .= '\renewcommand{\labelitemi}{$\diamond$}'. 1546: '\renewcommand{\labelitemii}{$\diamond$}'. 1547: '\renewcommand{\labelitemiii}{$\diamond$}'. 1548: '\renewcommand{\labelitemiv}{$\diamond$}'; 1549: } 1550: $currentstring .= '\strut \begin{itemize}'; 1551: } 1552: return $currentstring; 1553: } 1554: 1555: sub end_ul { 1556: my ($target,$token) = @_; 1557: my $currentstring = ''; 1558: if ($target eq 'web') { 1559: $currentstring = $token->[2]; 1560: } elsif ($target eq 'tex') { 1561: $currentstring = '\end{itemize} \renewcommand{\labelitemi}{$\bullet$}'. 1562: '\renewcommand{\labelitemii}{$\bullet$}'. 1563: '\renewcommand{\labelitemiii}{$\bullet$}'. 1564: '\renewcommand{\labelitemiv}{$\bullet$}\strut '; 1565: } 1566: return $currentstring; 1567: } 1568: 1569: #-- <menu> tag (end tag required) 1570: sub start_menu { 1571: my ($target,$token) = @_; 1572: my $currentstring = ''; 1573: if ($target eq 'web') { 1574: $currentstring = $token->[4]; 1575: } elsif ($target eq 'tex') { 1576: $currentstring = " \\begin{itemize} "; 1577: } 1578: return $currentstring; 1579: } 1580: 1581: sub end_menu { 1582: my ($target,$token) = @_; 1583: my $currentstring = ''; 1584: if ($target eq 'web') { 1585: $currentstring = $token->[2]; 1586: } elsif ($target eq 'tex') { 1587: $currentstring = " \\end{itemize}"; 1588: } 1589: return $currentstring; 1590: } 1591: 1592: #-- <dir> tag (end tag required) 1593: sub start_dir { 1594: my ($target,$token) = @_; 1595: my $currentstring = ''; 1596: if ($target eq 'web') { 1597: $currentstring = $token->[4]; 1598: } elsif ($target eq 'tex') { 1599: $currentstring = " \\begin{itemize} "; 1600: } 1601: return $currentstring; 1602: } 1603: 1604: sub end_dir { 1605: my ($target,$token) = @_; 1606: my $currentstring = ''; 1607: if ($target eq 'web') { 1608: $currentstring = $token->[2]; 1609: } elsif ($target eq 'tex') { 1610: $currentstring = " \\end{itemize}"; 1611: } 1612: return $currentstring; 1613: } 1614: 1615: #-- <ol> tag (end tag required) 1616: sub start_ol { 1617: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; 1618: my $currentstring = ''; 1619: if ($target eq 'web') { 1620: $currentstring = $token->[4]; 1621: } elsif ($target eq 'tex') { 1622: my $type=&Apache::lonxml::get_param('type',$parstack,$safeeval,undef,0); 1623: if ($type eq '1') { 1624: $currentstring .= '\renewcommand{\labelenumi}{\arabic{enumi}.}'. 1625: '\renewcommand{\labelenumii}{\arabic{enumii}.}'. 1626: '\renewcommand{\labelenumiii}{\arabic{enumiii}.}'. 1627: '\renewcommand{\labelenumiv}{\arabic{enumiv}.}'; 1628: } elsif ($type eq 'A') { 1629: $currentstring .= '\renewcommand{\labelenumi}{\Alph{enumi}.}'. 1630: '\renewcommand{\labelenumii}{\Alph{enumii}.}'. 1631: '\renewcommand{\labelenumiii}{\Alph{enumiii}.}'. 1632: '\renewcommand{\labelenumiv}{\Alph{enumiv}.}'; 1633: } elsif ($type eq 'a') { 1634: $currentstring .= '\renewcommand{\labelenumi}{\alph{enumi}.}'. 1635: '\renewcommand{\labelenumii}{\alph{enumii}.}'. 1636: '\renewcommand{\labelenumiii}{\alph{enumiii}.}'. 1637: '\renewcommand{\labelenumiv}{\alph{enumiv}.}'; 1638: } elsif ($type eq 'i') { 1639: $currentstring .= '\renewcommand{\labelenumi}{\roman{enumi}.}'. 1640: '\renewcommand{\labelenumii}{\roman{enumii}.}'. 1641: '\renewcommand{\labelenumiii}{\roman{enumiii}.}'. 1642: '\renewcommand{\labelenumiv}{\roman{enumiv}.}'; 1643: } elsif ($type eq 'I') { 1644: $currentstring .= '\renewcommand{\labelenumi}{\Roman{enumi}.}'. 1645: '\renewcommand{\labelenumii}{\Roman{enumii}.}'. 1646: '\renewcommand{\labelenumiii}{\Roman{enumiii}.}'. 1647: '\renewcommand{\labelenumiv}{\Roman{enumiv}.}'; 1648: } 1649: $currentstring .= '\strut \begin{enumerate}'; 1650: } 1651: return $currentstring; 1652: } 1653: 1654: sub end_ol { 1655: my ($target,$token) = @_; 1656: my $currentstring = ''; 1657: if ($target eq 'web') { 1658: $currentstring = $token->[2]; 1659: } elsif ($target eq 'tex') { 1660: $currentstring = '\end{enumerate}\renewcommand{\labelenumi}{\arabic{enumi}.}'. 1661: '\renewcommand{\labelenumii}{\arabic{enumii}.}'. 1662: '\renewcommand{\labelenumiii}{\arabic{enumiii}.}'. 1663: '\renewcommand{\labelenumiv}{\arabic{enumiv}.}\strut '; 1664: } 1665: return $currentstring; 1666: } 1667: 1668: #-- <dl> tag (end tag required) 1669: sub start_dl { 1670: my ($target,$token) = @_; 1671: my $currentstring = ''; 1672: if ($target eq 'web') { 1673: $currentstring = $token->[4]; 1674: } elsif ($target eq 'tex') { 1675: $currentstring = '\begin{description}'; 1676: @Apache::londefdef::description=(); 1677: $Apache::londefdef::DD_redirection=0; 1678: $Apache::londefdef::DT_redirection=0; 1679: } 1680: return $currentstring; 1681: } 1682: 1683: sub end_dl { 1684: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; 1685: my $currentstring = ''; 1686: if ($target eq 'web') { 1687: $currentstring = $token->[2]; 1688: } elsif ($target eq 'tex') { 1689: if ($Apache::londefdef::DT_redirection) { 1690: my $data=&item_cleanup; 1691: push @Apache::londefdef::description,'\item['.$data.']'; 1692: $Apache::londefdef::DT_redirection=0; 1693: } elsif ($Apache::londefdef::DD_redirection) { 1694: $Apache::londefdef::description[-1].=&Apache::lonxml::endredirection(); 1695: } 1696: foreach my $element (@Apache::londefdef::description) { 1697: $currentstring.=' '.$element.' '; 1698: } 1699: @Apache::londefdef::description=(); 1700: $currentstring.='\end{description}'; 1701: } 1702: return $currentstring; 1703: } 1704: 1705: #-- <dt> tag (end tag optional) 1706: sub start_dt { 1707: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; 1708: my $currentstring=''; 1709: if ($target eq 'web') { 1710: $currentstring = $token->[4]; 1711: } elsif ($target eq 'tex') { 1712: if ($Apache::londefdef::DT_redirection) { 1713: my $data=&item_cleanup; 1714: push @Apache::londefdef::description,'\item['.$data.']'; 1715: $Apache::londefdef::DT_redirection=0; 1716: } elsif ($Apache::londefdef::DD_redirection) { 1717: $Apache::londefdef::description[-1].=&Apache::lonxml::endredirection(); 1718: $Apache::londefdef::DD_redirection=0; 1719: } 1720: &Apache::lonxml::startredirection(); 1721: $Apache::londefdef::DT_redirection=1; 1722: } 1723: return $currentstring; 1724: } 1725: 1726: sub end_dt { 1727: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; 1728: my $currentstring = ''; 1729: if ($target eq 'web') { 1730: $currentstring = $token->[2]; 1731: } elsif ($target eq 'tex') { 1732: my $data=&item_cleanup; 1733: push @Apache::londefdef::description,'\item['.$data.']'; 1734: $Apache::londefdef::DT_redirection=0; 1735: } 1736: return $currentstring; 1737: } 1738: 1739: sub item_cleanup { 1740: my $item=&Apache::lonxml::endredirection(); 1741: $item=~s/\\begin{center}//g; 1742: $item=~s/\\end{center}//g; 1743: return $item; 1744: } 1745: 1746: #-- <dd> tag (end tag optional) 1747: sub start_dd { 1748: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; 1749: my $currentstring = ''; 1750: if ($target eq 'web') { 1751: $currentstring = $token->[4]; 1752: } elsif ($target eq 'tex') { 1753: if ($Apache::londefdef::DT_redirection) { 1754: my $data=&item_cleanup; 1755: push @Apache::londefdef::description,'\item['.$data.']'; 1756: $Apache::londefdef::DT_redirection=0; 1757: } 1758: $Apache::londefdef::DD_redirection=1; 1759: &Apache::lonxml::startredirection(); 1760: } 1761: return $currentstring; 1762: } 1763: 1764: sub end_dd { 1765: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; 1766: my $currentstring = ''; 1767: if ($target eq 'web') { 1768: $currentstring = $token->[2]; 1769: } elsif ($target eq 'tex') { 1770: $Apache::londefdef::description[-1].=&Apache::lonxml::endredirection(); 1771: $Apache::londefdef::DD_redirection=0; 1772: } 1773: return $currentstring; 1774: } 1775: 1776: #-- <table> tag (end tag required) 1777: #list of supported attributes: border,width,TeXwidth 1778: sub start_table { 1779: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; 1780: my ($textwidth,$currentstring)=('',''); 1781: if ($target eq 'web') { 1782: $currentstring = $token->[4]; 1783: } elsif ($target eq 'tex') { 1784: my $aa = {}; 1785: push @Apache::londefdef::table, $aa; 1786: $Apache::londefdef::table[-1]{'row_number'} = -1; 1787: #maximum table's width (default coincides with text line length) 1788: if ($#Apache::londefdef::table==0) { 1789: $textwidth=&recalc($ENV{'form.textwidth'}); #result is always in mm 1790: $textwidth=~/(\d+\.?\d*)/; 1791: $textwidth=0.95*$1; #accounts "internal" LaTeX space for table frame 1792: } else { 1793: if ($Apache::londefdef::table[-2]{'TeXlen'}[$Apache::londefdef::table[-2]{'row_number'}][$Apache::londefdef::table[-2]{'counter_columns'}]=~/\d/) { 1794: #the maximum width of nested table is determined by LATeX width of parent cell 1795: $textwidth=$Apache::londefdef::table[-2]{'TeXlen'}[$Apache::londefdef::table[-2]{'row_number'}][$Apache::londefdef::table[-2]{'counter_columns'}]; 1796: } else { 1797: #try to use all space not used before (minus 5% for LaTeX table internal) - rather silly 1798: my $textwidth=$Apache::londefdef::table[-2]{'width'}; 1799: for (my $i=0;$i<$Apache::londefdef::table[-2]{'counter_columns'};$i++) { 1800: $textwidth=$textwidth-$Apache::londefdef::table[-2]{'TeXlen'}[0][$i]; 1801: } 1802: } 1803: } 1804: my $TeXwidth = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0); 1805: if (not defined $TeXwidth) { 1806: my $htmlwidth = &Apache::lonxml::get_param('width',$parstack,$safeeval,undef,1); 1807: if ($htmlwidth=~/%/) { 1808: $Apache::londefdef::table[-1]{'percent'}=1; 1809: $htmlwidth=~/(\d+)/; 1810: $Apache::londefdef::table[-1]{'width'}=$1*$textwidth/100;; 1811: } else { 1812: $Apache::londefdef::table[-1]{'width'}=$textwidth; 1813: } 1814: } elsif ($TeXwidth=~/%/) { 1815: $Apache::londefdef::table[-1]{'percent'}=1; 1816: $TeXwidth=~/(\d+)/; 1817: $Apache::londefdef::table[-1]{'width'}=$1*$textwidth/100; 1818: } else { 1819: $Apache::londefdef::table[-1]{'forcetablewidth'}=1; 1820: $Apache::londefdef::table[-1]{'width'}=$TeXwidth; 1821: } 1822: #table's border 1823: my $border = &Apache::lonxml::get_param('border',$parstack,$safeeval); 1824: my $permission=&Apache::lonxml::get_param('TeXDropEmptyColumns',$parstack,$safeeval,undef,0); 1825: unless (defined $border) { $border = 0; } 1826: if ($border) { 1827: $Apache::londefdef::table[-1]{'hinc'} = '\hline '; 1828: $Apache::londefdef::table[-1]{'vinc'} = '&'; 1829: $Apache::londefdef::table[-1]{'vvinc'} = '|'; 1830: } else { 1831: $Apache::londefdef::table[-1]{'hinc'} = ''; 1832: $Apache::londefdef::table[-1]{'vinc'} = '&'; 1833: $Apache::londefdef::table[-1]{'vvinc'} = ''; 1834: } 1835: if ($#Apache::londefdef::table==0) { 1836: $Apache::londefdef::table[-1]{'output'}='\strut\newline\strut\setlength{\tabcolsep}{1 mm}'; 1837: } 1838: $Apache::londefdef::table[-1]{'output'}.=' \noindent \begin{tabular} '; 1839: $Apache::londefdef::table[-1]{'TeXlen'}=[]; 1840: $Apache::londefdef::table[-1]{'objectlen'}=[]; 1841: $Apache::londefdef::table[-1]{'maxlen'}=[]; 1842: $Apache::londefdef::table[-1]{'minlen'}=[]; 1843: $Apache::londefdef::table[-1]{'content'}=[]; 1844: $Apache::londefdef::table[-1]{'align'}=[]; 1845: $currentstring='\keephidden{NEW TABLE ENTRY}'; 1846: } 1847: return $currentstring; 1848: } 1849: 1850: sub end_table { 1851: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; 1852: my $currentstring = ''; 1853: if ($target eq 'web') { 1854: $currentstring = $token->[2]; 1855: } elsif ($target eq 'tex') { 1856: my $inmemory = ''; 1857: my $output = ''; 1858: my $WARNING=''; 1859: #width of columns from TeXwidth attributes 1860: for (my $in=0;$in<=$Apache::londefdef::table[-1]{'row_number'};$in++) { 1861: for (my $jn=0;$jn<=$Apache::londefdef::table[-1]{'counter_columns'};$jn++) { 1862: if ($Apache::londefdef::table[-1]{'TeXlen'}[0][$jn]<$Apache::londefdef::table[-1]{'TeXlen'}[$in][$jn]) { 1863: $Apache::londefdef::table[-1]{'TeXlen'}[0][$jn]=$Apache::londefdef::table[-1]{'TeXlen'}[$in][$jn]; 1864: } 1865: } 1866: } 1867: #free space and number of empty columns 1868: my ($available_space,$empty_columns)=($Apache::londefdef::table[-1]{'width'},0); 1869: ## &Apache::lonnet::logthis("Available space $Apache::londefdef::table[-1]{'width'}"); 1870: for (my $jn=0;$jn<=$Apache::londefdef::table[-1]{'counter_columns'};$jn++) { 1871: if ($Apache::londefdef::table[-1]{'TeXlen'}[0][$jn]==0) { 1872: $empty_columns++; 1873: } else { 1874: $available_space=$available_space-$Apache::londefdef::table[-1]{'TeXlen'}[0][$jn]; 1875: } 1876: } 1877: #boundaries for contents columns 1878: my @min_len=();#columns can not be narrower 1879: my @max_len=();#maximum length of column 1880: for (my $jn=0;$jn<=$Apache::londefdef::table[-1]{'counter_columns'};$jn++) { 1881: my ($localmin,$localmax)=(0,0); 1882: for (my $in=0;$in<=$Apache::londefdef::table[-1]{'row_number'};$in++) { 1883: if ($localmin<$Apache::londefdef::table[-1]{'minlen'}[$in][$jn]) { 1884: $localmin=$Apache::londefdef::table[-1]{'minlen'}[$in][$jn]; 1885: } 1886: if ($localmax<$Apache::londefdef::table[-1]{'maxlen'}[$in][$jn]) { 1887: $localmax=$Apache::londefdef::table[-1]{'maxlen'}[$in][$jn]; 1888: } 1889: } 1890: push @min_len, $localmin; 1891: push @max_len, $localmax; 1892: } 1893: for (my $jn=0;$jn<=$Apache::londefdef::table[-1]{'counter_columns'};$jn++) { 1894: my $localmin=0,; 1895: for (my $in=0;$in<=$Apache::londefdef::table[-1]{'row_number'};$in++) { 1896: if ($localmin<$Apache::londefdef::table[-1]{'objectlen'}[$in][$jn]) { 1897: $localmin=$Apache::londefdef::table[-1]{'objectlen'}[$in][$jn]; 1898: } 1899: } 1900: if ($max_len[$jn]<$localmin) {$max_len[$jn]=$localmin;}#object size is bigger 1901: if ($min_len[$jn]<$localmin) {$min_len[$jn]=$localmin;}#object size is bigger 1902: if ($Apache::londefdef::table[-1]{'TeXlen'}[0][$jn]!=0) { 1903: $min_len[$jn]=0; 1904: $max_len[$jn]=0; 1905: } 1906: } 1907: #final adjustment of column width 1908: my @fwidth=@{$Apache::londefdef::table[-1]{'TeXlen'}[0]};#final width array 1909: my @adjust=(); 1910: #step 1. adjustment by maximum value 1911: my $space_neeeded=0; 1912: for (my $jn=0;$jn<=$#max_len;$jn++) { 1913: $space_neeeded=$space_neeeded+$max_len[$jn]; 1914: } 1915: if ($space_neeeded<=$available_space) { 1916: for (my $jn=0;$jn<=$#max_len;$jn++) { 1917: if ($fwidth[$jn]==0) { 1918: $fwidth[$jn]=$max_len[$jn]; 1919: } 1920: } 1921: } else { 1922: #step 2. adjustment by minimum value (estimation) 1923: $space_neeeded=0; 1924: for (my $jn=0;$jn<=$#min_len;$jn++) { 1925: $space_neeeded+=$min_len[$jn]; 1926: } 1927: if ($space_neeeded>$available_space) { 1928: $WARNING=' \textbf{NOT ENOUGH SPACE FOR TABLE} '; 1929: for (my $jn=0;$jn<=$#max_len;$jn++) { 1930: if ($fwidth[$jn]==0) { 1931: $fwidth[$jn]=$min_len[$jn]; 1932: } 1933: } 1934: } else { 1935: #step 3. adjustment over minimal + corrections 1936: my $enlarge_coef=$available_space/$space_neeeded; 1937: my $acsessive=0; 1938: for (my $jn=0;$jn<=$#min_len;$jn++) { 1939: $adjust[$jn]=$min_len[$jn]*$enlarge_coef; 1940: if ($adjust[$jn]>$max_len[$jn]) { 1941: $fwidth[$jn]=$max_len[$jn]; 1942: $acsessive=$acsessive+$adjust[$jn]-$max_len[$jn]; 1943: $adjust[$jn]=0; 1944: } 1945: } 1946: if ($acsessive>0) { 1947: #we have an excess of space and can redistribute it 1948: my $notempty_columns=0; 1949: for (my $jn=0;$jn<=$#min_len;$jn++) { 1950: if ($adjust[$jn]!=0) { 1951: $notempty_columns++; 1952: } 1953: } 1954: my $per_column=$acsessive/$notempty_columns; 1955: for (my $jn=0;$jn<=$#min_len;$jn++) { 1956: if ($adjust[$jn]!=0) { 1957: $adjust[$jn]+=$per_column; 1958: $fwidth[$jn]=$adjust[$jn]; 1959: } 1960: } 1961: } else { 1962: for (my $jn=0;$jn<=$#min_len;$jn++) { 1963: $fwidth[$jn]=$adjust[$jn]; 1964: } 1965: } 1966: } 1967: } 1968: #use all available width if it is defined in % or as TeXwidth 1969: if (($Apache::londefdef::table[-1]{'percent'}==1) || ($Apache::londefdef::table[-1]{'forcetablewidth'}==1)) { 1970: my $current=0; 1971: for (my $i=0;$i<=$#fwidth;$i++) { 1972: $current+=$fwidth[$i]; 1973: } 1974: my $coef=$Apache::londefdef::table[-1]{'width'}/$current; 1975: for (my $i=0;$i<=$#fwidth;$i++) { 1976: $fwidth[$i]*=$coef; 1977: } 1978: } 1979: #removing of empty columns if allowed 1980: my $permission=&Apache::lonxml::get_param('TeXDropEmptyColumns',$parstack,$safeeval,undef,0); 1981: if ($permission eq 'yes') { 1982: my @cleaned_table=(); 1983: my @cleaned_header=(); 1984: my $colind=0; 1985: for (my $jn=0;$jn<=$Apache::londefdef::table[-1]{'counter_columns'};$jn++) { 1986: if ($fwidth[$jn]!=0) { 1987: #we need to copy column 1988: for (my $in=0;$in<=$Apache::londefdef::table[-1]{'row_number'};$in++) { 1989: $cleaned_table[$in][$colind]=$Apache::londefdef::table[-1]{'content'}[$in][$jn]; 1990: $cleaned_header[$colind]=$fwidth[$jn]; 1991: } 1992: $colind++; 1993: } 1994: } 1995: $Apache::londefdef::table[-1]{'content'}=\@cleaned_table; 1996: @fwidth=@cleaned_header; 1997: } 1998: #construct header of the table 1999: my $header_of_table = '{'.$Apache::londefdef::table[-1]{'vvinc'}; 2000: for (my $in=0;$in<=$#fwidth;$in++) { 2001: $header_of_table.='p{'.$fwidth[$in].' mm}'.$Apache::londefdef::table[-1]{'vvinc'}; 2002: } 2003: $header_of_table .= '}'; 2004: #fill the table 2005: for (my $in=0;$in<=$Apache::londefdef::table[-1]{'row_number'};$in++) { 2006: for (my $jn=0;$jn<=$#fwidth;$jn++) { 2007: if ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'c') { 2008: $output.='\begin{center}'; 2009: } elsif ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'r') { 2010: $output.=' \hfill \llap{' 2011: } 2012: $output.=$Apache::londefdef::table[-1]{'content'}[$in][$jn]; 2013: if ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'c') { 2014: $output.='\end{center}'; 2015: } elsif ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'r') { 2016: $output.='} '; 2017: } 2018: if ($jn!=$#fwidth) {$output.=' '.$Apache::londefdef::table[-1]{'vinc'};} 2019: } 2020: $output.=' \\\\ '.$Apache::londefdef::table[-1]{'hinc'}.' '; 2021: } 2022: $Apache::londefdef::table[-1]{'output'} .= $header_of_table.$Apache::londefdef::table[-1]{'hinc'}.$output.'\end{tabular}\strut\newline\strut '; 2023: if ($#Apache::londefdef::table > 0) { 2024: my $inmemory = $Apache::londefdef::table[-1]{'output'}; 2025: pop @Apache::londefdef::table; 2026: push @{$Apache::londefdef::table[-1]{'include'}}, $inmemory; 2027: } else { 2028: $currentstring .= $Apache::londefdef::table[-1]{'output'}; 2029: pop @Apache::londefdef::table; 2030: undef @Apache::londefdef::table; 2031: } 2032: } 2033: return $currentstring; 2034: } 2035: 2036: #-- <tr> tag (end tag optional) 2037: sub start_tr { 2038: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; 2039: my $currentstring = ''; 2040: if ($target eq 'web') { 2041: $currentstring = $token->[4]; 2042: } elsif ($target eq 'tex') { 2043: $Apache::londefdef::table[-1]{'row_number'}++; 2044: my $alignchar=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1); 2045: if ($alignchar ne '') { 2046: push @ {$Apache::londefdef::table[-1]{'rows'} },substr($alignchar,0,1); 2047: } else { 2048: push @ {$Apache::londefdef::table[-1]{'rows'} }, 'l'; 2049: } 2050: push ( @{ $Apache::londefdef::table[-1]{'rowdata'} }, $Apache::londefdef::table[-1]{'hinc'}); 2051: $Apache::londefdef::table[-1]{'counter_columns'} = -1; 2052: push @ {$Apache::londefdef::table[-1]{'TeXlen'}}, []; 2053: push @ {$Apache::londefdef::table[-1]{'objectlen'}}, []; 2054: push @ {$Apache::londefdef::table[-1]{'minlen'}}, []; 2055: push @ {$Apache::londefdef::table[-1]{'maxlen'}}, []; 2056: push @ {$Apache::londefdef::table[-1]{'content'}}, []; 2057: } 2058: return $currentstring; 2059: } 2060: 2061: sub end_tr { 2062: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; 2063: my $currentstring = ''; 2064: if ($target eq 'web') { 2065: $currentstring = $token->[2]; 2066: } elsif ($target eq 'tex') { 2067: if ($Apache::londefdef::TD_redirection) { 2068: &end_td_tex($parstack,$parser,$safeeval); 2069: } 2070: } 2071: return $currentstring; 2072: } 2073: 2074: #-- <td> tag (end tag optional) 2075: sub start_td { 2076: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; 2077: my $currentstring = ''; 2078: if ($target eq 'web') { 2079: $currentstring = $token->[4]; 2080: } elsif ($target eq 'tex') { 2081: $Apache::londefdef::TD_redirection = 1; 2082: &tag_check('tr','td',$tagstack,$parstack,$parser,$safeeval); 2083: } 2084: return $currentstring; 2085: } 2086: 2087: sub tag_check { 2088: my ($good_tag,$bad_tag,$tagstack,$parstack,$parser,$safeeval) = @_; 2089: my @ar=@$parstack; 2090: for (my $i=$#ar-1;$i>=0;$i--) { 2091: if (lc($$tagstack[$i]) eq $good_tag) { 2092: &start_td_tex($parstack,$parser,$safeeval); 2093: last; 2094: } elsif (lc($$tagstack[$i]) eq $bad_tag) { 2095: splice @ar, $i+1; 2096: &end_td_tex(\@ar,$parser,$safeeval); 2097: &start_td_tex($parstack,$parser,$safeeval); 2098: last; 2099: } 2100: } 2101: return ''; 2102: } 2103: 2104: sub start_td_tex { 2105: my ($parstack,$parser,$safeeval) = @_; 2106: my $alignchar = substr(&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1),0,1); 2107: if ($alignchar eq '') { 2108: $alignchar = $Apache::londefdef::table[-1]{'rows'}[-1]; 2109: } 2110: push @{ $Apache::londefdef::table[-1]{'align'}[$Apache::londefdef::table[-1]{'row_number'}] }, $alignchar; 2111: $Apache::londefdef::table[-1]{'counter_columns'}++; 2112: my $TeXwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0); 2113: if (defined $TeXwidth) { 2114: my $current_length=&recalc($TeXwidth); 2115: $current_length=~/(\d+\.?\d*)/; 2116: push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$1; 2117: } 2118: &Apache::lonxml::startredirection(); 2119: return ''; 2120: } 2121: 2122: sub end_td_tex { 2123: my ($parstack,$parser,$safeeval) = @_; 2124: my $current_row = $Apache::londefdef::table[-1]{'row_number'}; 2125: my $data=&Apache::lonxml::endredirection(); 2126: my $TeXwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0); 2127: if (defined $TeXwidth) { 2128: push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0'; 2129: push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0'; 2130: push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0'; 2131: } else { 2132: if (($data=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) or ($data=~m/\[(\d+\.?\d*)\s*mm\]/)) { 2133: my $garbage_data=$data; 2134: my $fwidth=0; 2135: while ($garbage_data=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) { 2136: my $current_length=&recalc($1); 2137: $current_length=~/(\d+\.?\d*)/; 2138: if ($fwidth<$1) {$fwidth=$1;} 2139: $garbage_data=~s/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)//; 2140: } 2141: while ($garbage_data=~m/\[(\d+\.?\d*)\s*mm\]/) { 2142: my $current_length=$1; 2143: if ($fwidth<$current_length) {$fwidth=$current_length;} 2144: $garbage_data=~s/\[(\d+\.?\d*)\s*mm\]//; 2145: } 2146: push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0'; 2147: push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$fwidth; 2148: push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0'; 2149: push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0'; 2150: } else { 2151: $data=~s/^\s+(\S.*)/$1/; 2152: $data=~s/(.*\S)\s+$/$1/; 2153: $data=~s/(\s)+/$1/; 2154: my ($current_length,$min_length)=(0,0); 2155: if ($data=~/\\vskip/) { 2156: my $newdata=$data; 2157: $newdata=~s/\\vskip \d*\.?\d*\s*mm/THISISJUSTTEMPORARYSEPARATOR/g; 2158: my @newdata=split(/THISISJUSTTEMPORARYSEPARATOR/,$newdata); 2159: foreach my $elementdata (@newdata) { 2160: my $lengthnewdata=2.5*&LATEX_length($elementdata); 2161: if ($lengthnewdata>$current_length) {$current_length=$lengthnewdata;} 2162: my @words=split(/ /,$elementdata); 2163: foreach my $word (@words) { 2164: my $lengthword=2.5*&LATEX_length($word); 2165: if ($min_length<$lengthword) {$min_length=$lengthword;} 2166: } 2167: } 2168: } else { 2169: $current_length=2.5*&LATEX_length($data); 2170: my @words=split(/ /,$data); 2171: foreach my $word (@words) { 2172: my $lengthword=2.5*&LATEX_length($word); 2173: if ($min_length<$lengthword) {$min_length=$lengthword;} 2174: } 2175: } 2176: push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0'; 2177: push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0'; 2178: push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$current_length; 2179: push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$min_length; 2180: } 2181: } 2182: for (my $in=0; $in<=$#{$Apache::londefdef::table[-1]{'include'}};$in++) { 2183: $data=~s/\\keephidden\{NEW TABLE ENTRY\}/$Apache::londefdef::table[-1]{'include'}[$in]/; 2184: } 2185: push @ {$Apache::londefdef::table[-1]{'content'}[-1] },$data; 2186: return''; 2187: } 2188: 2189: sub end_td { 2190: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; 2191: my $currentstring = ''; 2192: if ($target eq 'web') { 2193: $currentstring = $token->[2]; 2194: } elsif ($target eq 'tex') { 2195: $Apache::londefdef::TD_redirection =0; 2196: &end_td_tex($parstack,$parser,$safeeval); 2197: } 2198: return $currentstring; 2199: } 2200: 2201: #-- <th> tag (end tag optional) 2202: sub start_th { 2203: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; 2204: my $currentstring = ''; 2205: if ($target eq 'web') { 2206: $currentstring = $token->[4]; 2207: } elsif ($target eq 'tex') { 2208: my $what_to_push = substr(&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1),0,1); 2209: if ($what_to_push eq '') { 2210: $what_to_push = substr($Apache::londefdef::table[-1]{'rows'}[0],0,1);; 2211: } 2212: push @{ $Apache::londefdef::table[-1]{'columns'} }, $what_to_push; 2213: $Apache::londefdef::table[-1]{'counter_columns'}++; 2214: &Apache::lonxml::startredirection(); 2215: } 2216: return $currentstring; 2217: } 2218: 2219: sub end_th { 2220: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; 2221: my $currentstring = ''; 2222: if ($target eq 'web') { 2223: $currentstring = $token->[2]; 2224: } elsif ($target eq 'tex') { 2225: my $current_row = $Apache::londefdef::table[-1]{'row_number'}; 2226: my $data=&Apache::lonxml::endredirection(); 2227: my $TeXwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0); 2228: if (defined $TeXwidth) { 2229: my $current_length=&recalc($TeXwidth); 2230: $current_length=~/(\d+)/; 2231: $Apache::londefdef::table[-1]{'TeXlength'} .= $1.','; 2232: $Apache::londefdef::table[-1]{'length'} .= '0,'; 2233: } else { 2234: if ($data=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) { 2235: my $current_length=&recalc($1); 2236: $current_length=~/(\d+)/; 2237: $Apache::londefdef::table[-1]{'TeXlength'} .= $1.','; 2238: $Apache::londefdef::table[-1]{'length'} .= '0,'; 2239: } else { 2240: $data=~/^\s*(\S.*)/; 2241: $data=$1; 2242: $data=~/(.*\S)\s*$/; 2243: $data=$1; 2244: my $current_length=2*length($data); 2245: $Apache::londefdef::table[-1]{'length'} .= $current_length.','; 2246: $Apache::londefdef::table[-1]{'TeXlength'} .= '0,'; 2247: } 2248: } 2249: for (my $in=0; $in<=$#{$Apache::londefdef::table[-1]{'include'}};$in++) { 2250: $data=~s/\\keephidden\{NEW TABLE ENTRY\}/$Apache::londefdef::table[-1]{'include'}[$in]/; 2251: } 2252: $data='\textbf{'.$data.'}'; 2253: @{ $Apache::londefdef::table[-1]{'rowdata'} }[$current_row] .= '\parbox{TOBECHANGEDONNUMBER}{'.$data.'} '.$Apache::londefdef::table[-1]{'vinc'}; 2254: } 2255: return $currentstring; 2256: } 2257: #-- <img> tag (end tag forbidden) 2258: sub start_img { 2259: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; 2260: my $src = &Apache::lonxml::get_param('src',$parstack,$safeeval, 2261: undef,1); 2262: if (not $src and ($target eq 'web' or $target eq 'tex')) { 2263: my $inside = &Apache::lonxml::get_all_text("/img",$parser); 2264: return ''; 2265: } 2266: $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=$src; 2267: my $currentstring = ''; 2268: my $scaling = .3; 2269: if ($target eq 'web') { 2270: if ($ENV{'browser.imagesuppress'} ne 'on') { 2271: $currentstring.= $token->[4]; 2272: } else { 2273: my $alttag= &Apache::lonxml::get_param 2274: ('alt',$parstack,$safeeval,undef,1); 2275: unless ($alttag) { 2276: $alttag=&Apache::lonmeta::alttag 2277: ($Apache::lonxml::pwd[-1],$src); 2278: } 2279: $currentstring.='[IMAGE: '.$alttag.']'; 2280: } 2281: } elsif ($target eq 'tex') { 2282: $src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src); 2283: #if uploaded restore the path 2284: if ($src=~/^\/uploaded\/([^\/]+)\/([^\/]+)\/simplepage\/([^\/]+)$/) { 2285: $src=&Apache::loncommon::propath($1,$2).'/userfiles/simplepage/'.$3; 2286: } elsif ($src=~/^\/uploaded\/([^\/]+)\/([^\/]+)\/aboutme\/([^\/]+)$/) { 2287: $src=&Apache::loncommon::propath($1,$2).'/userfiles/aboutme/'.$3; 2288: } 2289: #if original gif/jpg/png file exist do following: 2290: if (-e $src) { 2291: #what is the image size? 2292: my $width_param=&image_size($src,$scaling,$parstack,$safeeval); 2293: my ($file,$path)=&file_path($src); 2294: my $newsrc = $src; 2295: $newsrc =~ s/\.(gif|jpg|png)$/.eps/i; 2296: $file=~s/\.(gif|jpg|png)$/.eps/i; 2297: #where can we find the picture? 2298: if (-e $newsrc) { 2299: #eps counterpart for image exist 2300: if ($path) { 2301: $currentstring .= '\vskip 1 mm \noindent\graphicspath{{'.$path.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} '; 2302: } 2303: } else { 2304: #there is no eps counterpart for image - check for ps one 2305: $newsrc =~ s/\.eps$/\.ps/; 2306: if (-e $newsrc) { 2307: #ps counterpart for image exist 2308: $file =~ s/\.eps$/\.ps/; 2309: if ($path) { 2310: $currentstring .= '\vskip 1 mm \noindent\graphicspath{{'.$path.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} '; 2311: } 2312: } else { 2313: #care about eps dynamical generation 2314: $currentstring.='\vskip 1 mm '.&eps_generation($src,$file,$width_param); 2315: } 2316: } 2317: } else { 2318: #original image file doesn't exist so check the alt attribute 2319: my $alt = 2320: &Apache::lonxml::get_param('alt',$parstack,$safeeval,undef,1); 2321: unless ($alt) { 2322: $alt=&Apache::lonmeta::alttag($Apache::lonxml::pwd[-1],$src); 2323: } 2324: 2325: if ($alt) { 2326: $currentstring .= ' '.$alt.' '; 2327: } else { 2328: #<allow> tag will care about replication 2329: } 2330: } 2331: } elsif ($target eq 'edit') { 2332: $currentstring .=&Apache::edit::tag_start($target,$token); 2333: $currentstring .=&Apache::edit::text_arg('Image Url:','src',$token,70). 2334: &Apache::edit::browse('src',undef,'alt').' '. 2335: &Apache::edit::search('src',undef,'alt').'<br />'; 2336: $currentstring .=&Apache::edit::text_arg('Description:','alt',$token,70).'<br />'; 2337: $currentstring .=&Apache::edit::text_arg('width (pixel):','width',$token,5); 2338: $currentstring .=&Apache::edit::text_arg('height (pixel):','height',$token,5).'<br />'; 2339: $currentstring .=&Apache::edit::text_arg('TeXwidth (mm):','TeXwidth',$token,5); 2340: $currentstring .=&Apache::edit::text_arg('TeXheight (mm):','TeXheight',$token,5); 2341: $currentstring .=&Apache::edit::end_row().&Apache::edit::start_spanning_row(); 2342: my $src=&Apache::lonxml::get_param('src',$parstack,$safeeval); 2343: my $alt=&Apache::lonxml::get_param('alt',$parstack,$safeeval); 2344: my $width=&Apache::lonxml::get_param('width',$parstack,$safeeval); 2345: my $height=&Apache::lonxml::get_param('height',$parstack,$safeeval); 2346: $currentstring .= '<img src="'.$src.'" alt="'.$alt.'" '; 2347: if ($width) { $currentstring.=' width="'.$width.'" '; } 2348: if ($height) { $currentstring.=' height="'.$height.'" '; } 2349: $currentstring .= ' />'; 2350: } elsif ($target eq 'modified') { 2351: my ($osrc,$owidth,$oheight)= 2352: ($token->[2]{'src'},$token->[2]{'width'},$token->[2]{'height'}); 2353: my $ctag=&Apache::edit::get_new_args($token,$parstack, 2354: $safeeval,'src','alt', 2355: 'TeXwidth','TeXheight', 2356: 'width','height'); 2357: my ($nsrc,$nwidth,$nheight)= 2358: ($token->[2]{'src'},$token->[2]{'width'},$token->[2]{'height'}); 2359: my $loc=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$nsrc); 2360: &image_replication($loc); 2361: my ($iwidth,$iheight); 2362: if (-e $loc) { 2363: my $image = Image::Magick->new; 2364: $image->Read($loc); 2365: ($iwidth, $iheight) = ($image->Get('width'), 2366: $image->Get('height')); 2367: } 2368: if ($osrc ne $nsrc || (!$nwidth && !$nheight)) { 2369: # changed image or no size specified, 2370: # if they didn't explicitly change the 2371: # width or height use the ones from the image 2372: if ($iwidth && $iheight) { 2373: if ($owidth == $nwidth || (!$nwidth && !$nheight)) { 2374: $token->[2]{'width'} = $iwidth;$ctag=1; 2375: } 2376: if ($oheight == $nheight || (!$nwidth && !$nheight)) { 2377: $token->[2]{'height'}=$iheight;$ctag=1; 2378: } 2379: } 2380: } 2381: my ($cwidth,$cheight)=($token->[2]{'width'},$token->[2]{'height'}); 2382: # if we don't have a width or height 2383: if ($iwidth && $cwidth && !$cheight) { 2384: $token->[2]{'height'}=int(($cwidth/$iwidth)*$iheight);$ctag=1; 2385: } 2386: if ($iheight && $cheight && !$cwidth) { 2387: $token->[2]{'width'}=int(($cheight/$iheight)*$iwidth);$ctag=1; 2388: } 2389: if ($ctag) {$currentstring=&Apache::edit::rebuild_tag($token);} 2390: } 2391: return $currentstring; 2392: } 2393: 2394: sub end_img { 2395: my ($target,$token) = @_; 2396: my $currentstring = ''; 2397: if ($target eq 'web') { 2398: $currentstring = $token->[2]; 2399: } elsif ($target eq 'tex') { 2400: $currentstring = ''; 2401: } 2402: return $currentstring; 2403: } 2404: 2405: #-- <applet> tag (end tag required) 2406: sub start_applet { 2407: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; 2408: 2409: my $code=&Apache::lonxml::get_param('code',$parstack,$safeeval,undef,1); 2410: $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=$code; 2411: 2412: my $archive=&Apache::lonxml::get_param('archive',$parstack,$safeeval, 2413: undef,1); 2414: $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=$archive; 2415: 2416: my $currentstring = ''; 2417: if ($target eq 'web') { 2418: if ($ENV{'browser.appletsuppress'} ne 'on') { 2419: $currentstring = $token->[4]; 2420: } else { 2421: my $alttag= &Apache::lonxml::get_param('alt',$parstack, 2422: $safeeval,undef,1); 2423: unless ($alttag) { 2424: $alttag=&Apache::lonmeta::alttag($Apache::lonxml::pwd[-1], 2425: $code); 2426: } 2427: $currentstring='[APPLET: '.$alttag.']'; 2428: } 2429: } elsif ($target eq 'tex') { 2430: my $alttag= &Apache::lonxml::get_param('alt',$parstack, 2431: $safeeval,undef,1); 2432: unless ($alttag) { 2433: my $code=&Apache::lonxml::get_param('code',$parstack,$safeeval, 2434: undef,1); 2435: $alttag=&Apache::lonmeta::alttag($Apache::lonxml::pwd[-1], 2436: $code); 2437: } 2438: $currentstring.='\begin{center} \fbox{Java Applet: '.$alttag. 2439: '.}\end{center}'; 2440: } 2441: return $currentstring; 2442: } 2443: 2444: sub end_applet { 2445: my ($target,$token) = @_; 2446: my $currentstring = ''; 2447: if ($target eq 'web') { 2448: $currentstring = $token->[2]; 2449: } elsif ($target eq 'tex') { 2450: } 2451: return $currentstring; 2452: } 2453: 2454: #-- <embed> tag (end tag optional/required) 2455: sub start_embed { 2456: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; 2457: my $src=&Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1); 2458: $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=$src; 2459: my $currentstring = ''; 2460: if ($target eq 'web') { 2461: if ($ENV{'browser.embedsuppress'} ne 'on') { 2462: $currentstring = $token->[4]; 2463: } else { 2464: my $alttag=&Apache::lonxml::get_param 2465: ('alt',$parstack,$safeeval,undef,1); 2466: unless ($alttag) { 2467: $alttag=&Apache::lonmeta::alttag($Apache::lonxml::pwd[-1],$src); 2468: } 2469: $currentstring='[EMBED: '.$alttag.']'; 2470: } 2471: } elsif ($target eq 'tex') { 2472: } 2473: return $currentstring; 2474: } 2475: 2476: sub end_embed { 2477: my ($target,$token) = @_; 2478: my $currentstring = ''; 2479: if ($target eq 'web') { 2480: $currentstring = $token->[2]; 2481: } elsif ($target eq 'tex') { 2482: } 2483: return $currentstring; 2484: } 2485: 2486: #-- <param> tag (end tag forbidden) 2487: sub start_param { 2488: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; 2489: if (&Apache::lonxml::get_param 2490: ('name',$parstack,$safeeval,undef,1)=~/^cabbase$/i) { 2491: $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]= 2492: &Apache::lonxml::get_param('value',$parstack,$safeeval,undef,1); 2493: } 2494: $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]= 2495: &Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1); 2496: my $currentstring = ''; 2497: if ($target eq 'web') { 2498: $currentstring = $token->[4]; 2499: } elsif ($target eq 'tex') { 2500: } 2501: return $currentstring; 2502: } 2503: 2504: sub end_param { 2505: my ($target,$token) = @_; 2506: my $currentstring = ''; 2507: if ($target eq 'web') { 2508: $currentstring = $token->[2]; 2509: } elsif ($target eq 'tex') { 2510: } 2511: return $currentstring; 2512: } 2513: 2514: #-- <allow> tag 2515: sub start_allow { 2516: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; 2517: my $src = &Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1); 2518: $src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src); 2519: $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]= 2520: &Apache::lonnet::clutter($src); 2521: &image_replication($src); 2522: my $result; 2523: if ($target eq 'edit') { 2524: $result .=&Apache::edit::tag_start($target,$token); 2525: $result .=&Apache::edit::text_arg('File Spec:','src',$token,70); 2526: $result .=&Apache::edit::end_row();#.&Apache::edit::start_spanning_row(); 2527: } elsif ($target eq 'modified') { 2528: my $constructtag=&Apache::edit::get_new_args($token,$parstack, 2529: $safeeval,'src'); 2530: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); } 2531: } 2532: return $result; 2533: } 2534: 2535: sub end_allow { 2536: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; 2537: if ( $target eq 'edit') { return (&Apache::edit::end_table()); } 2538: return ''; 2539: } 2540: 2541: #-- Frames (end tag required) 2542: #-- <frameset> 2543: sub start_frameset { 2544: my ($target,$token) = @_; 2545: my $currentstring = ''; 2546: if ($target eq 'web') { 2547: if (!$Apache::lonxml::registered && 2548: $ENV{'request.state'} eq 'published') { 2549: $currentstring.='<head>'. 2550: &Apache::lonmenu::registerurl(undef,$target).'</head>'; 2551: } 2552: my $onLoad=''; 2553: foreach my $key (keys(%{$token->[2]})) { 2554: if ($key =~ /^onload$/i) { 2555: $onLoad.=$token->[2]->{$key}.';'; 2556: delete($token->[2]->{$key}); 2557: } 2558: } 2559: $token->[2]->{'onload'}=&Apache::lonmenu::loadevents().';'.$onLoad; 2560: my $onUnload=''; 2561: foreach my $key (keys(%{$token->[2]})) { 2562: if ($key =~ /^onunload$/i) { 2563: $onUnload.=$token->[2]->{$key}.';'; 2564: delete($token->[2]->{$key}); 2565: } 2566: } 2567: $token->[2]->{'onunload'}=&Apache::lonmenu::unloadevents(). 2568: ';'.$onUnload; 2569: 2570: $currentstring .= '<'.$token->[1]; 2571: foreach (keys %{$token->[2]}) { 2572: $currentstring.=' '.$_.'="'.$token->[2]->{$_}.'"'; 2573: } 2574: $currentstring.='>'; 2575: } 2576: return $currentstring; 2577: } 2578: 2579: sub end_frameset { 2580: my ($target,$token) = @_; 2581: my $currentstring = ''; 2582: if ($target eq 'web') { 2583: $currentstring = $token->[2]; 2584: } 2585: return $currentstring; 2586: } 2587: 2588: #-- <xmp> (end tag required) 2589: sub start_xmp { 2590: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; 2591: my $currentstring = ''; 2592: if ($target eq 'web') { 2593: $currentstring .= $token->[4]; 2594: } elsif ($target eq 'tex') { 2595: $currentstring .= '\begin{verbatim}'; 2596: } 2597: return $currentstring; 2598: } 2599: 2600: sub end_xmp { 2601: my ($target,$token) = @_; 2602: my $currentstring = ''; 2603: if ($target eq 'web') { 2604: $currentstring .= $token->[2]; 2605: } elsif ($target eq 'tex') { 2606: $currentstring .= '\end{verbatim}'; 2607: } 2608: return $currentstring; 2609: } 2610: 2611: #-- <pre> (end tag required) 2612: sub start_pre { 2613: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; 2614: my $currentstring = ''; 2615: if ($target eq 'web') { 2616: $currentstring .= $token->[4]; 2617: } elsif ($target eq 'tex') { 2618: $currentstring .= '\begin{verbatim}'; 2619: } 2620: return $currentstring; 2621: } 2622: 2623: sub end_pre { 2624: my ($target,$token) = @_; 2625: my $currentstring = ''; 2626: if ($target eq 'web') { 2627: $currentstring .= $token->[2]; 2628: } elsif ($target eq 'tex') { 2629: $currentstring .= '\end{verbatim}'; 2630: } 2631: return $currentstring; 2632: } 2633: 2634: #-- <insert> 2635: sub start_insert { 2636: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; 2637: my $currentstring = ''; 2638: if ($target eq 'web') { 2639: my $display = &Apache::lonxml::get_param('display',$parstack,$safeeval,undef,1); 2640: $currentstring .= '<b>'.$display.'</b>';; 2641: } 2642: return $currentstring; 2643: } 2644: 2645: sub end_insert { 2646: my ($target,$token) = @_; 2647: my $currentstring = ''; 2648: if ($target eq 'web') { 2649: $currentstring .= ''; 2650: } 2651: return $currentstring; 2652: } 2653: 2654: #-- <externallink> 2655: sub start_externallink { 2656: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; 2657: my $currentstring = ''; 2658: if ($target eq 'web') { 2659: my $display = &Apache::lonxml::get_param('display',$parstack,$safeeval,undef,1); 2660: $currentstring .= '<b>'.$display.'</b>';; 2661: } 2662: return $currentstring; 2663: } 2664: 2665: sub end_externallink { 2666: my ($target,$token) = @_; 2667: my $currentstring = ''; 2668: if ($target eq 'web') { 2669: $currentstring .= ''; 2670: } 2671: return $currentstring; 2672: } 2673: 2674: #-- <blankspace heigth=""> 2675: sub start_blankspace { 2676: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; 2677: my $currentstring = ''; 2678: if ($target eq 'tex') { 2679: my $howmuch = &Apache::lonxml::get_param('heigth',$parstack,$safeeval,undef,1); 2680: $currentstring .= '\vskip '.$howmuch.' '; 2681: } 2682: return $currentstring; 2683: } 2684: 2685: sub end_blankspace { 2686: my ($target,$token) = @_; 2687: my $currentstring = ''; 2688: if ($target eq 'tex') { 2689: $currentstring .= ''; 2690: } 2691: return $currentstring; 2692: } 2693: 2694: #-- <abbr> tag (end tag required) 2695: sub start_abbr { 2696: my ($target,$token) = @_; 2697: my $currentstring = ''; 2698: if ($target eq 'web') { 2699: $currentstring = $token->[4]; 2700: } 2701: return $currentstring; 2702: } 2703: 2704: sub end_abbr { 2705: my ($target,$token) = @_; 2706: my $currentstring = ''; 2707: if ($target eq 'web') { 2708: $currentstring = $token->[2]; 2709: } 2710: return $currentstring; 2711: } 2712: 2713: #-- <acronym> tag (end tag required) 2714: sub start_acronym { 2715: my ($target,$token) = @_; 2716: my $currentstring = ''; 2717: if ($target eq 'web') { 2718: $currentstring = $token->[4]; 2719: } 2720: return $currentstring; 2721: } 2722: 2723: sub end_acronym { 2724: my ($target,$token) = @_; 2725: my $currentstring = ''; 2726: if ($target eq 'web') { 2727: $currentstring = $token->[2]; 2728: } 2729: return $currentstring; 2730: } 2731: 2732: #-- <area> tag (end tag forbidden) 2733: sub start_area { 2734: my ($target,$token) = @_; 2735: my $currentstring = ''; 2736: if ($target eq 'web') { 2737: $currentstring = $token->[4]; 2738: } 2739: return $currentstring; 2740: } 2741: 2742: sub end_area { 2743: my ($target,$token) = @_; 2744: my $currentstring = ''; 2745: if ($target eq 'web') { 2746: $currentstring = $token->[2]; 2747: } 2748: return $currentstring; 2749: } 2750: 2751: #-- <base> tag (end tag forbidden) 2752: sub start_base { 2753: my ($target,$token) = @_; 2754: my $currentstring = ''; 2755: if ($target eq 'web') { 2756: $currentstring = $token->[4]; 2757: } 2758: return $currentstring; 2759: } 2760: 2761: sub end_base { 2762: my ($target,$token) = @_; 2763: my $currentstring = ''; 2764: if ($target eq 'web') { 2765: $currentstring = $token->[2]; 2766: } 2767: return $currentstring; 2768: } 2769: 2770: #-- <bdo> tag (end tag required) 2771: sub start_bdo { 2772: my ($target,$token) = @_; 2773: my $currentstring = ''; 2774: if ($target eq 'web') { 2775: $currentstring = $token->[4]; 2776: } 2777: return $currentstring; 2778: } 2779: 2780: sub end_bdo { 2781: my ($target,$token) = @_; 2782: my $currentstring = ''; 2783: if ($target eq 'web') { 2784: $currentstring = $token->[2]; 2785: } 2786: return $currentstring; 2787: } 2788: 2789: #-- <bgsound> tag (end tag optional) 2790: sub start_bgsound { 2791: my ($target,$token) = @_; 2792: my $currentstring = ''; 2793: if ($target eq 'web') { 2794: $currentstring = $token->[4]; 2795: } 2796: return $currentstring; 2797: } 2798: 2799: sub end_bgsound { 2800: my ($target,$token) = @_; 2801: my $currentstring = ''; 2802: if ($target eq 'web') { 2803: $currentstring = $token->[2]; 2804: } 2805: return $currentstring; 2806: } 2807: 2808: #-- <blink> tag (end tag required) 2809: sub start_blink { 2810: my ($target,$token) = @_; 2811: my $currentstring = ''; 2812: if ($target eq 'web') { 2813: $currentstring = $token->[4]; 2814: } 2815: return $currentstring; 2816: } 2817: 2818: sub end_blink { 2819: my ($target,$token) = @_; 2820: my $currentstring = ''; 2821: if ($target eq 'web') { 2822: $currentstring = $token->[2]; 2823: } 2824: return $currentstring; 2825: } 2826: 2827: #-- <blockquote> tag (end tag required) 2828: sub start_blockquote { 2829: my ($target,$token) = @_; 2830: my $currentstring = ''; 2831: if ($target eq 'web') { 2832: $currentstring = $token->[4]; 2833: } 2834: return $currentstring; 2835: } 2836: 2837: sub end_blockquote { 2838: my ($target,$token) = @_; 2839: my $currentstring = ''; 2840: if ($target eq 'web') { 2841: $currentstring = $token->[2]; 2842: } 2843: return $currentstring; 2844: } 2845: 2846: #-- <button> tag (end tag required) 2847: sub start_button { 2848: my ($target,$token) = @_; 2849: my $currentstring = ''; 2850: if ($target eq 'web') { 2851: $currentstring = $token->[4]; 2852: } 2853: return $currentstring; 2854: } 2855: 2856: sub end_button { 2857: my ($target,$token) = @_; 2858: my $currentstring = ''; 2859: if ($target eq 'web') { 2860: $currentstring = $token->[2]; 2861: } 2862: return $currentstring; 2863: } 2864: 2865: #-- <caption> tag (end tag required) 2866: sub start_caption { 2867: my ($target,$token) = @_; 2868: my $currentstring = ''; 2869: if ($target eq 'web') { 2870: $currentstring = $token->[4]; 2871: } 2872: return $currentstring; 2873: } 2874: 2875: sub end_caption { 2876: my ($target,$token) = @_; 2877: my $currentstring = ''; 2878: if ($target eq 'web') { 2879: $currentstring = $token->[2]; 2880: } 2881: return $currentstring; 2882: } 2883: 2884: #-- <col> tag (end tag forbdden) 2885: sub start_col { 2886: my ($target,$token) = @_; 2887: my $currentstring = ''; 2888: if ($target eq 'web') { 2889: $currentstring = $token->[4]; 2890: } 2891: return $currentstring; 2892: } 2893: 2894: sub end_col { 2895: my ($target,$token) = @_; 2896: my $currentstring = ''; 2897: if ($target eq 'web') { 2898: $currentstring = $token->[2]; 2899: } 2900: return $currentstring; 2901: } 2902: 2903: #-- <colgroup> tag (end tag optional) 2904: sub start_colgroup { 2905: my ($target,$token) = @_; 2906: my $currentstring = ''; 2907: if ($target eq 'web') { 2908: $currentstring = $token->[4]; 2909: } 2910: return $currentstring; 2911: } 2912: 2913: sub end_colgroup { 2914: my ($target,$token) = @_; 2915: my $currentstring = ''; 2916: if ($target eq 'web') { 2917: $currentstring = $token->[2]; 2918: } 2919: return $currentstring; 2920: } 2921: 2922: #-- <del> tag (end tag required) 2923: sub start_del { 2924: my ($target,$token) = @_; 2925: my $currentstring = ''; 2926: if ($target eq 'web') { 2927: $currentstring = $token->[4]; 2928: } 2929: return $currentstring; 2930: } 2931: 2932: sub end_del { 2933: my ($target,$token) = @_; 2934: my $currentstring = ''; 2935: if ($target eq 'web') { 2936: $currentstring = $token->[2]; 2937: } 2938: return $currentstring; 2939: } 2940: 2941: #-- <fieldset> tag (end tag required) 2942: sub start_fieldset { 2943: my ($target,$token) = @_; 2944: my $currentstring = ''; 2945: if ($target eq 'web') { 2946: $currentstring = $token->[4]; 2947: } 2948: return $currentstring; 2949: } 2950: 2951: sub end_fieldset { 2952: my ($target,$token) = @_; 2953: my $currentstring = ''; 2954: if ($target eq 'web') { 2955: $currentstring = $token->[2]; 2956: } 2957: return $currentstring; 2958: } 2959: 2960: #-- <frame> tag (end tag forbidden) 2961: sub start_frame { 2962: my ($target,$token) = @_; 2963: my $currentstring = ''; 2964: if ($target eq 'web') { 2965: $currentstring = $token->[4]; 2966: } 2967: return $currentstring; 2968: } 2969: 2970: sub end_frame { 2971: my ($target,$token) = @_; 2972: my $currentstring = ''; 2973: if ($target eq 'web') { 2974: $currentstring = $token->[2]; 2975: } 2976: return $currentstring; 2977: } 2978: 2979: #-- <iframe> tag (end tag required) 2980: sub start_iframe { 2981: my ($target,$token) = @_; 2982: my $currentstring = ''; 2983: if ($target eq 'web') { 2984: $currentstring = $token->[4]; 2985: } 2986: return $currentstring; 2987: } 2988: 2989: sub end_iframe { 2990: my ($target,$token) = @_; 2991: my $currentstring = ''; 2992: if ($target eq 'web') { 2993: $currentstring = $token->[2]; 2994: } 2995: return $currentstring; 2996: } 2997: 2998: #-- <ins> tag (end tag required) 2999: sub start_ins { 3000: my ($target,$token) = @_; 3001: my $currentstring = ''; 3002: if ($target eq 'web') { 3003: $currentstring = $token->[4]; 3004: } 3005: return $currentstring; 3006: } 3007: 3008: sub end_ins { 3009: my ($target,$token) = @_; 3010: my $currentstring = ''; 3011: if ($target eq 'web') { 3012: $currentstring = $token->[2]; 3013: } 3014: return $currentstring; 3015: } 3016: 3017: #-- <isindex> tag (end tag forbidden) 3018: sub start_isindex { 3019: my ($target,$token) = @_; 3020: my $currentstring = ''; 3021: if ($target eq 'web') { 3022: $currentstring = $token->[4]; 3023: } 3024: return $currentstring; 3025: } 3026: 3027: sub end_isindex { 3028: my ($target,$token) = @_; 3029: my $currentstring = ''; 3030: if ($target eq 'web') { 3031: $currentstring = $token->[2]; 3032: } 3033: return $currentstring; 3034: } 3035: 3036: #-- <keygen> tag (end tag forbidden) 3037: sub start_keygen { 3038: my ($target,$token) = @_; 3039: my $currentstring = ''; 3040: if ($target eq 'web') { 3041: $currentstring = $token->[4]; 3042: } 3043: return $currentstring; 3044: } 3045: 3046: sub end_keygen { 3047: my ($target,$token) = @_; 3048: my $currentstring = ''; 3049: if ($target eq 'web') { 3050: $currentstring = $token->[2]; 3051: } 3052: return $currentstring; 3053: } 3054: 3055: #-- <label> tag 3056: sub start_label { 3057: my ($target,$token) = @_; 3058: my $currentstring = ''; 3059: if ($target eq 'web') { 3060: $currentstring = $token->[4]; 3061: } 3062: return $currentstring; 3063: } 3064: 3065: sub end_label { 3066: my ($target,$token) = @_; 3067: my $currentstring = ''; 3068: if ($target eq 'web') { 3069: $currentstring = $token->[2]; 3070: } 3071: return $currentstring; 3072: } 3073: 3074: #-- <layer> tag (end tag required) 3075: sub start_layer { 3076: my ($target,$token) = @_; 3077: my $currentstring = ''; 3078: if ($target eq 'web') { 3079: $currentstring = $token->[4]; 3080: } 3081: return $currentstring; 3082: } 3083: 3084: sub end_layer { 3085: my ($target,$token) = @_; 3086: my $currentstring = ''; 3087: if ($target eq 'web') { 3088: $currentstring = $token->[2]; 3089: } 3090: return $currentstring; 3091: } 3092: 3093: #-- <legend> tag (end tag required) 3094: sub start_legend { 3095: my ($target,$token) = @_; 3096: my $currentstring = ''; 3097: if ($target eq 'web') { 3098: $currentstring = $token->[4]; 3099: } 3100: return $currentstring; 3101: } 3102: 3103: sub end_legend { 3104: my ($target,$token) = @_; 3105: my $currentstring = ''; 3106: if ($target eq 'web') { 3107: $currentstring = $token->[2]; 3108: } 3109: return $currentstring; 3110: } 3111: 3112: #-- <link> tag (end tag forbidden) 3113: sub start_link { 3114: my ($target,$token) = @_; 3115: my $currentstring = ''; 3116: if ($target eq 'web') { 3117: $currentstring = $token->[4]; 3118: } 3119: return $currentstring; 3120: } 3121: 3122: sub end_link { 3123: my ($target,$token) = @_; 3124: my $currentstring = ''; 3125: if ($target eq 'web') { 3126: $currentstring = $token->[2]; 3127: } 3128: return $currentstring; 3129: } 3130: 3131: #-- <marquee> tag (end tag optional) 3132: sub start_marquee { 3133: my ($target,$token) = @_; 3134: my $currentstring = ''; 3135: if ($target eq 'web') { 3136: $currentstring = $token->[4]; 3137: } 3138: return $currentstring; 3139: } 3140: 3141: sub end_marquee { 3142: my ($target,$token) = @_; 3143: my $currentstring = ''; 3144: if ($target eq 'web') { 3145: $currentstring = $token->[2]; 3146: } 3147: return $currentstring; 3148: } 3149: 3150: #-- <multicol> tag (end tag required) 3151: sub start_multicol { 3152: my ($target,$token) = @_; 3153: my $currentstring = ''; 3154: if ($target eq 'web') { 3155: $currentstring = $token->[4]; 3156: } 3157: return $currentstring; 3158: } 3159: 3160: sub end_multicol { 3161: my ($target,$token) = @_; 3162: my $currentstring = ''; 3163: if ($target eq 'web') { 3164: $currentstring = $token->[2]; 3165: } 3166: return $currentstring; 3167: } 3168: 3169: #-- <nobr> tag (end tag required) 3170: sub start_nobr { 3171: my ($target,$token) = @_; 3172: my $currentstring = ''; 3173: if ($target eq 'web') { 3174: $currentstring = $token->[4]; 3175: } elsif ($target eq 'tex') { 3176: $currentstring='\mbox{'; 3177: } 3178: return $currentstring; 3179: } 3180: 3181: sub end_nobr { 3182: my ($target,$token) = @_; 3183: my $currentstring = ''; 3184: if ($target eq 'web') { 3185: $currentstring = $token->[2]; 3186: } elsif ($target eq 'tex') { 3187: $currentstring='}'; 3188: } 3189: return $currentstring; 3190: } 3191: 3192: #-- <noembed> tag (end tag required) 3193: sub start_noembed { 3194: my ($target,$token) = @_; 3195: my $currentstring = ''; 3196: if ($target eq 'web') { 3197: $currentstring = $token->[4]; 3198: } 3199: return $currentstring; 3200: } 3201: 3202: sub end_noembed { 3203: my ($target,$token) = @_; 3204: my $currentstring = ''; 3205: if ($target eq 'web') { 3206: $currentstring = $token->[2]; 3207: } 3208: return $currentstring; 3209: } 3210: 3211: #-- <noframes> tag (end tag required) 3212: sub start_noframes { 3213: my ($target,$token) = @_; 3214: my $currentstring = ''; 3215: if ($target eq 'web') { 3216: $currentstring = $token->[4]; 3217: } 3218: return $currentstring; 3219: } 3220: 3221: sub end_noframes { 3222: my ($target,$token) = @_; 3223: my $currentstring = ''; 3224: if ($target eq 'web') { 3225: $currentstring = $token->[2]; 3226: } 3227: return $currentstring; 3228: } 3229: 3230: #-- <nolayer> tag (end tag required) 3231: sub start_nolayer { 3232: my ($target,$token) = @_; 3233: my $currentstring = ''; 3234: if ($target eq 'web') { 3235: $currentstring = $token->[4]; 3236: } 3237: return $currentstring; 3238: } 3239: 3240: sub end_nolayer { 3241: my ($target,$token) = @_; 3242: my $currentstring = ''; 3243: if ($target eq 'web') { 3244: $currentstring = $token->[2]; 3245: } 3246: return $currentstring; 3247: } 3248: 3249: #-- <noscript> tag (end tag required) 3250: sub start_noscript { 3251: my ($target,$token) = @_; 3252: my $currentstring = ''; 3253: if ($target eq 'web') { 3254: $currentstring = $token->[4]; 3255: } 3256: return $currentstring; 3257: } 3258: 3259: sub end_noscript { 3260: my ($target,$token) = @_; 3261: my $currentstring = ''; 3262: if ($target eq 'web') { 3263: $currentstring = $token->[2]; 3264: } 3265: return $currentstring; 3266: } 3267: 3268: #-- <object> tag (end tag required) 3269: sub start_object { 3270: my ($target,$token) = @_; 3271: my $currentstring = ''; 3272: if ($target eq 'web') { 3273: $currentstring = $token->[4]; 3274: } 3275: return $currentstring; 3276: } 3277: 3278: sub end_object { 3279: my ($target,$token) = @_; 3280: my $currentstring = ''; 3281: if ($target eq 'web') { 3282: $currentstring = $token->[2]; 3283: } 3284: return $currentstring; 3285: } 3286: 3287: #-- <optgroup> tag (end tag required) 3288: sub start_optgroup { 3289: my ($target,$token) = @_; 3290: my $currentstring = ''; 3291: if ($target eq 'web') { 3292: $currentstring = $token->[4]; 3293: } 3294: return $currentstring; 3295: } 3296: 3297: sub end_optgroup { 3298: my ($target,$token) = @_; 3299: my $currentstring = ''; 3300: if ($target eq 'web') { 3301: $currentstring = $token->[2]; 3302: } 3303: return $currentstring; 3304: } 3305: 3306: #-- <samp> tag (end tag required) 3307: sub start_samp { 3308: my ($target,$token) = @_; 3309: my $currentstring = ''; 3310: if ($target eq 'web') { 3311: $currentstring = $token->[4]; 3312: } elsif ($target eq 'tex') { 3313: $currentstring='\texttt{'; 3314: } 3315: return $currentstring; 3316: } 3317: 3318: sub end_samp { 3319: my ($target,$token) = @_; 3320: my $currentstring = ''; 3321: if ($target eq 'web') { 3322: $currentstring = $token->[2]; 3323: } elsif ($target eq 'tex') { 3324: $currentstring='}'; 3325: } 3326: return $currentstring; 3327: } 3328: 3329: #-- <server> tag 3330: sub start_server { 3331: my ($target,$token) = @_; 3332: my $currentstring = ''; 3333: if ($target eq 'web') { 3334: $currentstring = $token->[4]; 3335: } 3336: return $currentstring; 3337: } 3338: 3339: sub end_server { 3340: my ($target,$token) = @_; 3341: my $currentstring = ''; 3342: if ($target eq 'web') { 3343: $currentstring = $token->[2]; 3344: } 3345: return $currentstring; 3346: } 3347: 3348: #-- <spacer> tag (end tag forbidden) 3349: sub start_spacer { 3350: my ($target,$token) = @_; 3351: my $currentstring = ''; 3352: if ($target eq 'web') { 3353: $currentstring = $token->[4]; 3354: } 3355: return $currentstring; 3356: } 3357: 3358: sub end_spacer { 3359: my ($target,$token) = @_; 3360: my $currentstring = ''; 3361: if ($target eq 'web') { 3362: $currentstring = $token->[2]; 3363: } 3364: return $currentstring; 3365: } 3366: 3367: #-- <span> tag (end tag required) 3368: sub start_span { 3369: my ($target,$token) = @_; 3370: my $currentstring = ''; 3371: if ($target eq 'web') { 3372: $currentstring = $token->[4]; 3373: } 3374: return $currentstring; 3375: } 3376: 3377: sub end_span { 3378: my ($target,$token) = @_; 3379: my $currentstring = ''; 3380: if ($target eq 'web') { 3381: $currentstring = $token->[2]; 3382: } 3383: return $currentstring; 3384: } 3385: 3386: #-- <tbody> tag (end tag optional) 3387: sub start_tbody { 3388: my ($target,$token) = @_; 3389: my $currentstring = ''; 3390: if ($target eq 'web') { 3391: $currentstring = $token->[4]; 3392: } 3393: return $currentstring; 3394: } 3395: 3396: sub end_tbody { 3397: my ($target,$token) = @_; 3398: my $currentstring = ''; 3399: if ($target eq 'web') { 3400: $currentstring = $token->[2]; 3401: } 3402: return $currentstring; 3403: } 3404: 3405: #-- <tfoot> tag (end tag optional) 3406: sub start_tfoot { 3407: my ($target,$token) = @_; 3408: my $currentstring = ''; 3409: if ($target eq 'web') { 3410: $currentstring = $token->[4]; 3411: } 3412: return $currentstring; 3413: } 3414: 3415: sub end_tfoot { 3416: my ($target,$token) = @_; 3417: my $currentstring = ''; 3418: if ($target eq 'web') { 3419: $currentstring = $token->[2]; 3420: } 3421: return $currentstring; 3422: } 3423: 3424: #-- <thead> tag (end tag optional) 3425: sub start_thead { 3426: my ($target,$token) = @_; 3427: my $currentstring = ''; 3428: if ($target eq 'web') { 3429: $currentstring = $token->[4]; 3430: } 3431: return $currentstring; 3432: } 3433: 3434: sub end_thead { 3435: my ($target,$token) = @_; 3436: my $currentstring = ''; 3437: if ($target eq 'web') { 3438: $currentstring = $token->[2]; 3439: } 3440: return $currentstring; 3441: } 3442: 3443: #-- <var> tag 3444: sub start_var { 3445: my ($target,$token) = @_; 3446: my $currentstring = ''; 3447: if ($target eq 'web') { 3448: $currentstring = $token->[4]; 3449: } elsif ($target eq 'tex') { 3450: $currentstring = '\textit{'; 3451: } 3452: return $currentstring; 3453: } 3454: 3455: sub end_var { 3456: my ($target,$token) = @_; 3457: my $currentstring = ''; 3458: if ($target eq 'web') { 3459: $currentstring = $token->[2]; 3460: } elsif ($target eq 'tex') { 3461: $currentstring = '}'; 3462: } 3463: return $currentstring; 3464: } 3465: 3466: #-- <wbr> tag (end tag forbidden) 3467: sub start_wbr { 3468: my ($target,$token) = @_; 3469: my $currentstring = ''; 3470: if ($target eq 'web') { 3471: $currentstring = $token->[4]; 3472: } 3473: return $currentstring; 3474: } 3475: 3476: sub end_wbr { 3477: my ($target,$token) = @_; 3478: my $currentstring = ''; 3479: if ($target eq 'web') { 3480: $currentstring = $token->[2]; 3481: } 3482: return $currentstring; 3483: } 3484: 3485: #-- <hideweboutput> tag 3486: sub start_hideweboutput { 3487: my ($target,$token) = @_; 3488: if ($target eq 'web') { 3489: &Apache::lonxml::startredirection(); 3490: } 3491: return ''; 3492: } 3493: 3494: sub end_hideweboutput { 3495: my ($target,$token) = @_; 3496: my $currentstring = ''; 3497: if ($target eq 'web') { 3498: $currentstring = &Apache::lonxml::endredirection(); 3499: } 3500: return ''; 3501: } 3502: 3503: 3504: sub image_replication { 3505: my $src = shift; 3506: if (not -e $src) { &Apache::lonnet::repcopy($src); } 3507: #replicates eps or ps 3508: my $epssrc = my $pssrc = $src; 3509: $epssrc =~ s/\.(gif|jpg|jpeg|png)$/.eps/i; 3510: $pssrc =~ s/\.(gif|jpg|jpeg|png)$/.ps/i; 3511: if (not -e $epssrc && not -e $pssrc) { 3512: my $result=&Apache::lonnet::repcopy($epssrc); 3513: if ($result ne OK) { &Apache::lonnet::repcopy($pssrc); } 3514: } 3515: return ''; 3516: } 3517: 3518: sub image_size { 3519: my ($src,$scaling,$parstack,$safeeval)=@_; 3520: #size of image from gif/jpg/jpeg/png 3521: my $image = Image::Magick->new; 3522: my $current_figure = $image->Read($src); 3523: my $width_param = $image->Get('width') * $scaling;; 3524: my $height_param = $image->Get('height') * $scaling;; 3525: undef $image; 3526: #do we have any specified LaTeX size of the picture? 3527: my $TeXwidth = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval); 3528: my $TeXheight = &Apache::lonxml::get_param('TeXheight',$parstack,$safeeval); 3529: #do we have any specified web size of the picture? 3530: my $width = &Apache::lonxml::get_param('width',$parstack,$safeeval, 3531: undef,1); 3532: if ($TeXwidth ne '') { 3533: if ($TeXwidth=~/(\d+)\s*\%/) { 3534: $width_param = $1*$ENV{'form.textwidth'}/100; 3535: } else { 3536: $width_param = $TeXwidth; 3537: } 3538: } elsif ($TeXheight ne '') { 3539: $width_param = $TeXheight/$height_param*$width_param; 3540: } elsif ($width ne '') { 3541: $width_param = $width*$scaling; 3542: } 3543: if ($width_param > $ENV{'form.textwidth'}) {$width_param =0.95*$ENV{'form.textwidth'}} 3544: return $width_param; 3545: } 3546: 3547: sub eps_generation { 3548: my ($src,$file,$width_param) = @_; 3549: my $filename = "/home/httpd/prtspool/$ENV{'user.name'}_$ENV{'user.domain'}_printout.dat"; 3550: my $temp_file = Apache::File->new('>>'.$filename); 3551: print $temp_file "$src\n"; 3552: my $newsrc = $src; 3553: $newsrc =~ s/(\.gif|\.jpg|\.jpeg)$/\.eps/i; 3554: $newsrc=~s/\/home\/httpd\/html\/res//; 3555: $newsrc=~s/\/home\/([^\/]*)\/public_html\//\/$1\//; 3556: $newsrc=~s/\/\.\//\//; 3557: $newsrc=~s/\/([^\/]+)\.(ps|eps)/\//; 3558: if ($newsrc=~/\/home\/httpd\/lonUsers\//) { 3559: $newsrc=~s/\/home\/httpd\/lonUsers//; 3560: $newsrc=~s/\/([^\/]+)\/(\w)\/(\w)\/(\w)\//\/$1\//; 3561: } 3562: return ' \graphicspath{{/home/httpd/prtspool'.$newsrc.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} '; 3563: } 3564: 3565: sub file_path { 3566: my $src=shift; 3567: my ($file,$path); 3568: if ($src =~ m!(.*)/([^/]*)$!) { 3569: $file = $2; 3570: $path = $1.'/'; 3571: } 3572: return $file,$path; 3573: } 3574: 3575: sub recalc { 3576: my $argument = shift; 3577: if (not $argument=~/(mm|cm|in|pc|pt)/) {return $argument.' mm';} 3578: $argument=~/\s*(\d+\.?\d*)\s*(mm|cm|in|pc|pt)/; 3579: my $value=$1; 3580: my $units=$2; 3581: if ($units eq 'cm') { 3582: $value*=10; 3583: } elsif ($units eq 'in') { 3584: $value*=25.4; 3585: } elsif ($units eq 'pc') { 3586: $value*=(25.4*12/72.27); 3587: } elsif ($units eq 'pt') { 3588: $value*=(25.4/72.27); 3589: } 3590: return $value.' mm'; 3591: } 3592: 3593: sub LATEX_length { 3594: my $garbage=shift; 3595: $garbage=~s/^\s+$//; 3596: $garbage=~s/^\s+(\S.*)/$1/;#space before 3597: $garbage=~s/(.*\S)\s+$/$1/;#space after 3598: $garbage=~s/(\s)+/$1/;#only one space 3599: $garbage=~s/(\\begin{([^\}]+)}|\\end{([^\}]+)})//g;#remove LaTeX \begin{...} and \end{...} 3600: $garbage=~s/(\$\_\{|\$\_|\$\^{|\$\^|\}\$)//g;#remove $_{,$_,$^{,$^,}$ 3601: $garbage=~s/([^\\])\$/$1/g;#$ 3602: $garbage=~s/(\\ensuremath\{\_\{|\\ensuremath\{\_|\\ensuremath\{\^{|\\ensuremath\{\^|\})//g;#remove \ensuremath{...} 3603: $garbage=~s/(\\alpha|\\beta|\\gamma|\\delta|\\epsilon|\\verepsilon|\\zeta|\\eta|\\theta|\\vartheta|\\iota|\\kappa|\\lambda|\\mu|\\nu|\\xi|\\pi|\\varpi|\\rho|\\varrho|\\sigma|\\varsigma|\\tau|\\upsilon|\\phi|\\varphi|\\chi|\\psi|\\omega|\\Gamma|\\Delta|\\Theta|\\Lambda|\\Xi|\\Pi|\\Sigma|\\Upsilon|\\Phi|\\Psi|\\Omega)/1/g; 3604: $garbage=~s/(\\pm|\\mp|\\times|\\div|\\cdot|\\ast|\\star|\\dagger|\\ddagger|\\amalg|\\cap|\\cup|\\uplus|\\sqcap|\\sqcup|\\vee|\\wedge|\\oplus|\\ominus|\\otimes|\\circ|\\bullet|\\diamond|\\lhd|\\rhd|\\unlhd|\\unrhd|\\oslash|\\odot|\\bigcirc|\\Box|\\Diamond|\\bigtriangleup|\\bigtriangledown|\\triangleleft|\\triangleright|\\setminus|\\wr)/1/g; 3605: $garbage=~s/(\\le|\\ll|\\leq|\\ge|\\geq|\\gg|\\neq|\\doreq|\\sim|\\simeq|\\subset|\\subseteq|\\sqsubset|\\sqsubseteq|\\in|\\vdash|\\models|\\supset|\\supseteq|\\sqsupset|\\sqsupseteq|\\ni|\\dash|\\perp|\\approx|\\cong|\\equiv|\\propto|\\prec|\\preceq|\\parallel|\\asymp|\\smile|\\frown|\\bowtie|\\succ|\\succeq|\\mid)/1/g; 3606: $garbage=~s/(\\not<|\\\\not\\le|\\not\\prec|\\not\\preceq|\\not\\subset|\\not\\subseteq|\\not\\sqsubseteq|\\not\\in|\\not>|\\not\\ge|\\not\\succ|\\notsucceq|\\not\\supset|\\notsupseteq|\\not\\sqsupseteq|\\notin|\\not=|\\not\\equiv|\\not\\sim|\\not\\simeq|\\not\\approx|\\not\\cong|\\not\\asymp)/1/g; 3607: $garbage=~s/(\\leftarrow|\\gets|\\Leftarrow|\\rightarrow|\\to|\\Rightarrow|\\leftrightarrow|\\Leftrightarrow|\\mapsto|\\hookleftarrow|\\leftharpoonup|\\leftkarpoondown|\\rightleftharpoons|\\longleftarrow|\\Longleftarrow|\\longrightarrow|\\Longrightarrow|\\longleftrightarrow|\\Longleftrightarrow|\\longmapsto|\\hookrightarrow|\\rightharpoonup|\\rightharpoondown|\\uparrow|\\Uparrow|\\downarrow|\\Downarrow|\\updownarrow|\\Updownarrow|\\nearrow|\\searrow|\\swarrow|\\nwarrow)/11/g; 3608: $garbage=~s/(\\aleph|\\hbar|\\imath|\\jmath|\\ell|\\wp|\\Re|\\Im|\\mho|\\prime|\\emptyset|\\nabla|\\surd|\\partial|\\top|\\bot|\\vdash|\\dashv|\\forall|\\exists|\\neg|\\flat|\\natural|\\sharp|\\\||\\angle|\\backslash|\\Box|\\Diamond|\\triangle|\\clubsuit|\\diamondsuit|\\heartsuit|\\spadesuit|\\Join|\\infty)/11/g; 3609: $garbage=~s/(\\hat{([^}]+)}|\\check{([^}]+)}|\\dot{([^}]+)}|\\breve{([^}]+)}|\\acute{([^}]+)}|\\ddot{([^}]+)}|\\grave{([^}]+)}|\\tilde{([^}]+)}|\\mathring{([^}]+)}|\\bar{([^}]+)}|\\vec{([^}]+)})/$1/g; 3610: #remove some other LaTeX command 3611: $garbage=~s|\\(\w+)\\|\\|g; 3612: $garbage=~s|\\(\w+)(\s*)|$2|g; 3613: $garbage=~s|\+|11|g; 3614: my $value=length($garbage); 3615: return $value; 3616: } 3617: 3618: 3619: 3620: 3621: 1; 3622: __END__