<?php
// This file reads the configuration of the jsmath plugin
// and then installs the jsMath Library on the JavaScript level.
// It is invoked from script.js

// First read default value
include('conf/default.php');
$backend = $conf['backend'];
$backend_url = $conf['backend_url'];

// if available load a preload config file
$preload = '../../../inc/preload.php';
if (@file_exists($preload)) include($preload);
if(!defined('DOKU_CONF')) define('DOKU_CONF','../../../conf/');

// Then overwrite with actual value (if present in local.php)
include(DOKU_CONF.'local.php');
if(isset($conf['plugin']['jsmath']['backend']))
{
  $backend = $conf['plugin']['jsmath']['backend'];
}
if(isset($conf['plugin']['jsmath']['backend_url']))
{
  $backend_url = $conf['plugin']['jsmath']['backend_url'];
}

// Now, depending on the backend, write the necessary javascript code.
//
// backend == jsMath ?
if ($backend != 'MathJax')
{
?>
document.write('<script type="text/javascript">jsMath = {Controls: {cookie: {scale: 120}}}</script>');
document.write('<script type="text/javascript" src="<?php echo($backend_url); ?>/plugins/noImageFonts.js"></script>');
document.write('<script type="text/javascript" src="<?php echo($backend_url); ?>/jsMath.js"></script>');

function installJsMath()
{
    jsMath.Process(document);
}

addInitEvent(installJsMath);

<?php
}
else // backend == MathJax
{
?>
document.write('<script type="text/javascript" src="<?php echo($backend_url); ?>/MathJax.js">MathJax.Hub.Config({extensions: ["jsMath2jax.js"], jax: ["input/TeX", "output/HTML-CSS"] });</script>');
<?php
}
?>
