Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F8566
work2
Public
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Authored By
•
bzimport
Nov 22 2014, 12:03 AM
2014-11-22 00:03:32 (UTC+0)
Size
8 KB
Referenced Files
None
Subscribers
None
work2
View Options
Index: Math.hooks.php
===================================================================
--- Math.hooks.php (revision 105196)
+++ Math.hooks.php (working copy)
@@ -127,6 +127,9 @@
} else {
throw new MWException( "Math extension does not currently support $type database." );
}
+
+ $sql = dirname( __FILE__ ) . '/db/patch-math_baseline.sql';
+ $updater->addExtensionField( 'math', 'math_baseline', $sql );
return true;
}
Index: db/patch-math_baseline.sql
===================================================================
--- db/patch-math_baseline.sql (revision 0)
+++ db/patch-math_baseline.sql (revision 0)
@@ -0,0 +1 @@
+ALTER TABLE /*_*/math ADD math_baseline int;
Property changes on: db/patch-math_baseline.sql
___________________________________________________________________
Added: svn:eol-style
+ native
Index: db/math.sql
===================================================================
--- db/math.sql (revision 105196)
+++ db/math.sql (working copy)
@@ -17,7 +17,9 @@
math_html text,
-- MathML output from texvc, if any
- math_mathml text
+ math_mathml text,
+
+ math_baseline int
) /*$wgDBTableOptions*/;
CREATE UNIQUE INDEX /*i*/math_inputhash ON /*_*/math (math_inputhash);
Index: math/render.ml
===================================================================
--- math/render.ml (revision 105196)
+++ math/render.ml (working copy)
@@ -1,16 +1,7 @@
(* vim: set sw=8 ts=8 et: *)
-let cmd_dvips tmpprefix = "dvips -q -R -E " ^ tmpprefix ^ ".dvi -f >" ^ tmpprefix ^ ".ps"
let cmd_latex tmpprefix = "latex " ^ tmpprefix ^ ".tex >/dev/null"
-(* Putting -transparent white in converts arguments will sort-of give you transperancy *)
-let cmd_convert tmpprefix finalpath = "convert -quality 100 -density 120 " ^ tmpprefix ^ ".ps " ^ finalpath ^ " >/dev/null 2>/dev/null"
-
-(* Putting -bg Transparent in dvipng's arguments will give full-alpha transparency *)
-(* Note that IE have problems with such PNGs and need an additional javascript snippet *)
-(* Putting -bg transparent in dvipng's arguments will give binary transparency *)
-let cmd_dvipng tmpprefix finalpath backcolor = "dvipng -bg \'" ^ backcolor ^ "\' -gamma 1.5 -D 120 -T tight --strict " ^ tmpprefix ^ ".dvi -o " ^ finalpath ^ " >/dev/null 2>/dev/null"
-
exception ExternalCommandFailure of string
let render tmppath finalpath outtex md5 backcolor =
@@ -19,12 +10,10 @@
let unlink_all () =
begin
(* Commenting this block out will aid in debugging *)
- Sys.remove (tmpprefix ^ ".dvi");
+(*
Sys.remove (tmpprefix ^ ".aux");
Sys.remove (tmpprefix ^ ".log");
- Sys.remove (tmpprefix ^ ".tex");
- if Sys.file_exists (tmpprefix ^ ".ps")
- then Sys.remove (tmpprefix ^ ".ps");
+ Sys.remove (tmpprefix ^ ".tex");*)
end in
let f = (Util.open_out_unless_exists (tmpprefix ^ ".tex")) in
@@ -39,20 +28,9 @@
if Util.run_in_other_directory tmppath (cmd_latex tmpprefix0) != 0
then (
unlink_all (); raise (ExternalCommandFailure "latex")
- ) else if (Sys.command (cmd_dvipng tmpprefix (finalpath^"/"^md5^".png") backcolor) != 0)
- then (
- if (Sys.command (cmd_dvips tmpprefix) != 0)
- then (
- unlink_all ();
- raise (ExternalCommandFailure "dvips")
- ) else if (Sys.command (cmd_convert tmpprefix (finalpath^"/"^md5^".png")) != 0)
- then (
- unlink_all ();
- raise (ExternalCommandFailure "convert")
- ) else (
- unlink_all ()
- )
) else (
+ (* Keep the DVI file so it can be final-converted via the PHP-side code *)
+ Sys.rename (tmpprefix ^ ".dvi") (finalpath^"/"^md5^".dvi");
unlink_all ()
)
end
Index: math/texutil.ml
===================================================================
--- math/texutil.ml (revision 105196)
+++ math/texutil.ml (working copy)
@@ -77,7 +77,7 @@
(if !modules_color then "\\usepackage[dvips,usenames]{color}\n" else "") ^
(if !modules_teubner then "\\usepackage[greek]{babel}\n\\usepackage{teubner}\n" else "") ^
(if !modules_euro then "\\usepackage{eurosym}\n" else "") ^
- "\\usepackage{cancel}\n\\pagestyle{empty}\n\\begin{document}\n$$\n"
+ "\\usepackage{cancel}\n\\usepackage[active,textmath]{preview}\n\\pagestyle{empty}\n\\begin{document}\n$$\n"
(* TeX fragment appended after the content *)
let get_footer () = "\n$$\n\\end{document}\n"
Index: Math.body.php
===================================================================
--- Math.body.php (revision 105196)
+++ Math.body.php (working copy)
@@ -37,6 +37,7 @@
var $html = '';
var $mathml = '';
var $conservativeness = 0;
+ var $baseline = 0;
function __construct( $tex, $params = array() ) {
$this->tex = $tex;
@@ -166,6 +167,22 @@
return $this->_error( 'math_unknown_error' );
}
+ $dvi = "$wgTmpDirectory/{$this->hash}.dvi";
+ $png = "$wgTmpDirectory/{$this->hash}.png";
+
+ if( file_exists( $png ) && filesize( $png ) > 0 ) {
+ // Legacy version of texvc has pre-rendered the PNG for us.
+ // We won't know baseline information.
+ $this->baseline = 0;
+ } else if (file_exists( $dvi ) ) {
+ // Render to PNG and get baseline offset data for positioning.
+ $this->baseline = $this->renderPng( $dvi, $png );
+ unlink( $dvi );
+ } else {
+ // Neither png nor dvi exists. Failure! Failure!
+ return $this->_error( 'math_dvi_error' );
+ }
+
if( !file_exists( "$wgTmpDirectory/{$this->hash}.png" ) ) {
return $this->_error( 'math_image_error' );
}
@@ -206,6 +223,7 @@
'math_html_conservativeness' => $this->conservativeness,
'math_html' => $this->html,
'math_mathml' => $this->mathml,
+ 'math_baseline' => $this->baseline,
),
__METHOD__
);
@@ -239,7 +257,7 @@
'math',
array(
'math_outputhash', 'math_html_conservativeness', 'math_html',
- 'math_mathml'
+ 'math_mathml', 'math_baseline'
),
array(
'math_inputhash' => $dbr->encodeBlob( pack( "H32", $this->md5 ) ) # Binary packed, not hex
@@ -255,6 +273,7 @@
$this->conservativeness = $rpage->math_html_conservativeness;
$this->html = $rpage->math_html;
$this->mathml = $rpage->math_mathml;
+ $this->baseline = intval( $rpage->math_baseline );
$filename = $this->_getHashPath() . "/{$this->hash}.png";
@@ -344,7 +363,8 @@
'img',
array(
'class' => 'tex',
- 'alt' => $this->tex
+ 'alt' => $this->tex,
+ 'style' => 'vertical-align: ' . (-1 * $this->baseline) . 'px',
),
array(
'src' => $url
@@ -379,4 +399,41 @@
}
return $math->render();
}
+
+ /**
+ * Since MediaWiki 1.19-era, texvc products .dvi files directly rather than .png.
+ * This allows the PHP side of things to run the dvi->PNG converter and get more
+ * information, such as the baseline.
+ *
+ * @param $dviPath string
+ * @param $pngPath string
+ * @return int baseline offset
+ */
+ function renderPng( $dviPath, $pngPath ) {
+ global $wgTexvcBackgroundColor, $wgMathDirectory;
+ $command = implode( " ", array(
+ 'dvipng',
+ '-bg',
+ $wgTexvcBackgroundColor,
+ '-gamma',
+ 1.5,
+ '-D',
+ 120,
+ '-T',
+ 'tight',
+ '--strict',
+ $dviPath,
+ "-o",
+ $pngPath,
+ "--depth",
+ "--height",
+ ) );
+ $output = wfShellExec($command);
+ if (preg_match( '/^\[\d+ depth=(-?\d+) height=(-?\d+)\]/m', $output, $matches ) ) {
+ $depth = intval( $matches[1] );
+ $height = intval( $matches[2] );
+ return $depth;
+ }
+ return 0;
+ }
}
Index: Math.i18n.php
===================================================================
--- Math.i18n.php (revision 105196)
+++ Math.i18n.php (working copy)
@@ -27,7 +27,8 @@
'math_unknown_function' => 'unknown function',
'math_lexing_error' => 'lexing error',
'math_syntax_error' => 'syntax error',
- 'math_image_error' => 'PNG conversion failed; check for correct installation of latex and dvipng (or dvips + gs + convert)',
+ 'math_dvi_error' => 'LaTeX to DVI conversion failed; check for correct installation of latex',
+ 'math_image_error' => 'PNG conversion failed; check for correct installation of dvipng',
'math_bad_tmpdir' => 'Cannot write to or create math temp directory',
'math_bad_output' => 'Cannot write to or create math output directory',
'math_notexvc' => 'Missing texvc executable; please see math/README to configure.',
File Metadata
Details
Attached
Mime Type
text/x-diff
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
8085
Default Alt Text
work2 (8 KB)
Attached To
Mode
T34694: Use baseline shift when positioning inline math PNGs or SVGs
Attached
Detach File
Event Timeline
Log In to Comment