Skip to content

Commit

Permalink
Merge pull request #2 from LarsGit223/master
Browse files Browse the repository at this point in the history
Added Linux support, added ODT support.
  • Loading branch information
MichaelGr committed May 1, 2015
2 parents f8368d0 + 4100fed commit 6656be1
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 11 deletions.
35 changes: 32 additions & 3 deletions mimetexrender.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,25 @@
* @package mimetexrender
*
*/
if(!defined('MIMETEXEXE')) define('MIMETEXEXE','"'.realpath(dirname(__FILE__).'/mimetex.exe').'"');

/**
* ChangeLog:
*
* [04/30/2015]: by LarsDW223
* Added support for Linux systems:
* The location of 'mimetex' under Linux is queried by executing 'which mimetex'.
* The Linux version of 'mimetex' is not included in this plugin, if it is not installed
* it needs to be installed manually first e.g. using 'sudo apt-get install mimetex'.
*/

if(!defined('MIMETEXEXE')) define('MIMETEXEXE','"'.realpath(dirname(__FILE__).'/mimetex.exe').'"');

class mimetexRender {

// ====================================================================================
// Variable Definitions
// ====================================================================================
var $_tmp_dir = "c:/temp";

// i was too lazy to write mutator functions for every single program used
// just access it outside the class or change it here if nescessary
// var $_mimetex_path = ;
Expand Down Expand Up @@ -61,6 +71,24 @@ class mimetexRender {
* cache directory
*/
function render($cachefilename, $formula) {
// Guess operating system
$usr_bin_dir = opendir('/usr/bin');
if ( $usr_bin_dir === false ) {
// Directory '/usr/bin' does not exist (or is not accessible).
// Assume Windows installation.
$_tmp_dir = "c:/temp";
$executeable = MIMETEXEXE;
} else {
// Directory '/usr/bin' exists. Assume Linux installation.
closedir ($usr_bin_dir);
$_tmp_dir = DOKU_PLUGIN.'temp';
$executeable = exec('which mimetex');
}

if ( empty ($executeable) === true ) {
$this->_error = "could not locate 'mimetex' command";
return false;
}

$formula = preg_replace("/>/i", ">", $formula);
$formula = preg_replace("/&lt;/i", "<", $formula);
Expand Down Expand Up @@ -91,7 +119,8 @@ function render($cachefilename, $formula) {

// convert tex file to gif using mimetex.exe
$img = $tmp.".gif";
$command = MIMETEXEXE." -f ".$tex." -e ".$img;

$command = $executeable." -f ".$tex." -e ".$img;

$status_code = exec($command);

Expand Down
27 changes: 19 additions & 8 deletions syntax.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@
* @author Michael Gritsaenko <michael.gritsaenko@gmail.com>
* @date 2011-02-01
*/

if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');

/**
* ChangeLog:
*
* [04/30/2015]: by LarsDW223
* Added ODT support.
*/

// must be run within Dokuwiki
if(!defined('DOKU_INC')) die();
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'syntax.php');

Expand Down Expand Up @@ -76,14 +84,10 @@ function handle($match, $state, $pos) {
*/
function render($mode, &$renderer, $formula) {
global $conf;
if($mode == 'xhtml' && strlen($formula[0]) > 1) {
if( ($mode == 'xhtml' || $mode == 'odt') && strlen($formula[0]) > 1) {
if ( !is_dir($conf['mediadir'] . '/latex') ) {
mkdir($conf['mediadir'] . '/latex', 0777-$conf['dmask']);
}
if ( is_readable($filename) ) {
$renderer->doc .= '<img src="'.$url.'" class="media" title="Graph" alt="Graph" />';
return true;
}

$hash = md5(serialize($formula));
$cachefilename = $conf['mediadir'] . '/latex/'.$hash.'.gif';
Expand All @@ -100,7 +104,14 @@ function render($mode, &$renderer, $formula) {
}
}

$renderer->doc .= '<img src="'.$cacheurl.'" class="media" title="mimeTeX" alt="mimeTeX" />';
switch ($mode) {
case 'odt':
$renderer->_odtAddImage ($cachefilename);
break;
default:
$renderer->doc .= '<img src="'.$cacheurl.'" class="media" title="mimeTeX" alt="mimeTeX" />';
break;
}
return true;
}
return false;
Expand Down

0 comments on commit 6656be1

Please sign in to comment.