Skip to content

Instantly share code, notes, and snippets.

@adeel
Created March 31, 2014 20:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adeel/9901313 to your computer and use it in GitHub Desktop.
Save adeel/9901313 to your computer and use it in GitHub Desktop.
A MediaWiki extension which adds support for itex2mml.
<?php
# itex2mml.php
# A MediaWiki extension which adds support for itex2mml.
if (!defined('MEDIAWIKI')) die();
$wgExtensionCredits['other'][] = array(
'name' => 'itex2mml',
'description' => 'Adds support for math via itex2mml.',
'version' => '0.1'
);
$wgHooks['ParserAfterTidy'][] = 'itex2mml_hook';
function itex2mml_hook(&$parser, &$text) {
$text = itex2mml($text);
return true;
}
function itex2mml($src) {
$file = get_random_filename();
file_put_contents($file, $src);
exec("itex2MML < \"" . $file . "\"", $output);
$result = join("\n", $output);
return $result;
}
function get_random_filename() {
while (true) {
$filename = uniqid("itex2mml", true);
$filepath = sys_get_temp_dir() . "/" . $filename;
if (!file_exists($filepath))
return $filepath;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment