From f5ceb06a326f40b10a8dea76a372c8d873b613eb Mon Sep 17 00:00:00 2001 From: sam_marshall Date: Tue, 6 Nov 2007 15:49:03 +0000 Subject: [PATCH] MDL-12039 Added ability to configure alt text when using TeX filter --- filter/tex/filter.php | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/filter/tex/filter.php b/filter/tex/filter.php index e8b0709e0b..08857337ef 100644 --- a/filter/tex/filter.php +++ b/filter/tex/filter.php @@ -38,9 +38,11 @@ $CFG->texfilterdir = "filter/tex"; - -function string_file_picture_tex($imagefile, $tex= "", $height="", $width="", $align="middle") { - // Given the path to a picture file in a course, or a URL, +function string_file_picture_tex($imagefile, $tex= "", $height="", $width="", $align="middle", $alt='') { + if($alt==='') { + $alt=s($tex); + } +// Given the path to a picture file in a course, or a URL, // this function includes the picture in the page. global $CFG; @@ -53,6 +55,11 @@ function string_file_picture_tex($imagefile, $tex= "", $height="", $width="", $a $tex = str_replace('>','>',$tex); $tex = str_replace('"','"',$tex); $tex = str_replace("\'",''',$tex); + // Note that we retain the title tag as TeX format rather than using + // the alt text, even if supplied. The alt text is intended for blind + // users (to provide a text equivalent to the equation) while the title + // is there as a convenience for sighted users who want to see the TeX + // code. $title = "title=\"$tex\""; } if ($height) { @@ -72,7 +79,7 @@ function string_file_picture_tex($imagefile, $tex= "", $height="", $width="", $a $output .= urlencode($tex) . "', 'popup', 'menubar=0,location=0,scrollbars,"; $output .= "resizable,width=300,height=240', 0);\">"; } - $output .= "\"".s($origtex)."\"slasharguments) { // Use this method if possible for better caching $output .= "$CFG->wwwroot/$CFG->texfilterdir/pix.php/$imagefile"; } else { @@ -119,12 +126,14 @@ function tex_filter ($courseid, $text) { } // TeX expression + // or TeX expression // or $$ TeX expression $$ // or \[ TeX expression \] // original tag of MathType and TeXaide (dlnsk) // or [tex] TeX expression [/tex] // somtime it's more comfortable than (dlnsk) - preg_match_all('/(.+?)<\/tex>|\$\$(.+?)\$\$|\\\\\[(.+?)\\\\\]|\\[tex\\](.+?)\\[\/tex\\]/is', $text, $matches); + preg_match_all('/(.+?)<\/tex>|\$\$(.+?)\$\$|\\\\\[(.+?)\\\\\]|\\[tex\\](.+?)\\[\/tex\\]/is', $text, $matches); for ($i=0; $i','',$texexp); $texexp = str_replace('','',$texexp); $texexp = str_replace('','',$texexp); @@ -148,7 +157,7 @@ function tex_filter ($courseid, $text) { insert_record("cache_filters",$texcache, false); } $filename = $md5 . ".gif"; - $text = str_replace( $matches[0][$i], string_file_picture_tex($filename, $texexp, '', '', $align), $text); + $text = str_replace( $matches[0][$i], string_file_picture_tex($filename, $texexp, '', '', $align, $alt), $text); } return $text; } -- 2.39.5