Commit 5a7b0f81 authored by Geoff Rowland's avatar Geoff Rowland Committed by Aaron Wells

Add MathJax and mhchem support to Mahara (bug #1464858)

This provides support for rendering LaTeX into math
& chemistry equations.

Change-Id: I34a30296f46ba7eeb635e6924172ddc6e65175c3
Signed-off-by: Aaron Wells's avatarAaron Wells <aaronw@catalyst.net.nz>
parent e62fc897
......@@ -712,6 +712,14 @@ $siteoptionform = array(
'help' => true,
'disabled' => in_array('wysiwyg', $OVERRIDDEN),
),
'mathjax' => array(
'type' => 'switchbox',
'title' => get_string('mathjax', 'admin'),
'description' => get_string('mathjaxdescription', 'admin'),
'defaultvalue' => get_config('mathjax'),
'help' => true,
'disabled' => in_array('mathjax', $OVERRIDDEN),
),
'sitefilesaccess' => array(
'type' => 'switchbox',
'title' => get_string('sitefilesaccess', 'admin'),
......@@ -784,7 +792,7 @@ function siteoptions_submit(Pieform $form, $values) {
'sitename','lang','theme', 'dropdownmenu',
'defaultaccountlifetime', 'defaultregistrationexpirylifetime', 'defaultaccountinactiveexpire', 'defaultaccountinactivewarn',
'defaultaccountlifetimeupdate', 'allowpublicviews', 'allowpublicprofiles', 'allowanonymouspages', 'generatesitemap',
'registration_sendweeklyupdates', 'institutionexpirynotification', 'institutionautosuspend', 'requireregistrationconfirm',
'registration_sendweeklyupdates', 'mathjax', 'institutionexpirynotification', 'institutionautosuspend', 'requireregistrationconfirm',
'showselfsearchsideblock', 'nousernames', 'searchplugin', 'showtagssideblock',
'tagssideblockmaxtags', 'country', 'viewmicroheaders', 'userscanchooseviewthemes',
'remoteavatars', 'userscanhiderealnames', 'antispam', 'spamhaus', 'surbl', 'anonymouscomments',
......
......@@ -1042,6 +1042,9 @@
if (!config['handheld_device'] && tinyMCE && tinyMCE.activeEditor && tinyMCE.activeEditor.id) {
tinyMCE.execCommand('mceRemoveEditor', false, tinyMCE.activeEditor.id);
}
if (config.mathjax && MathJax !== undefined) {
MathJax.Hub.Queue(["Typeset", MathJax.Hub]);
}
workspace.find('.mediaplayer-container').each(function() {
$(this).css({'height': ''});
$('mediaplayer:first', this).show();
......
......@@ -458,6 +458,9 @@ $string['watchlistdelaydescription'] = 'The delay in minutes between sending ema
$string['watchlistdelaytitle'] = 'Watchlist notification delay';
$string['defaultmultipleblogs'] = 'Multiple journals';
$string['defaultmultipleblogsdescription1'] = 'Allow users to have multiple journals by default. Users can override this in their account settings page.';
$string['mathjax'] = 'Enable MathJax';
$string['mathjaxdescription'] = 'MathJax renders LaTeX markup into properly formatted math and science equations, on portfolio pages.';
$string['mathjaxconfig'] = 'MathJax configuration';
// Site content
$string['about'] = 'About';
......
<!-- @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later -->
<!-- @copyright For copyright information on Mahara, please see the README file distributed with this software. -->
<h3>MathJax</h3>
MathJax is a JavaScript display engine for TeX, LaTeX, AsciiMath and MathMl notation which allows mathematics and science equations to be displayed in Mahara pages.
<p>MathJax allows the display of equations throughout your Mahara installation.</p>
<h4>MathJax URL</h4>
<p>The default configuration uses the latest stable version on the MathJax Content Distribution Network (CDN). http and https protocols may be used, as appopriate.</p>
<p>Alternatively, $cfg->mathjaxpath may use a local server installation of MathJax. See <a href="http://docs.mathjax.org/en/latest/installation.html">http://docs.mathjax.org/en/latest/installation.html</a></p>
<p>The default includes a commonly used configuration allowing input of MathML, AsciiMath, TeX or LaTeX and processing to MathML or HTML-CSS</p>
<h4>MathJax additional configuration</h4>
<p>Additional MathJax configuration can be added to $cfg->mathjaxconfig. The default MathJax configuration should be appropriate for most users, but MathJax is highly configurable and any of the standard MathJax configuration options can be added here.</p>
<p>By default, includes the mhchem extension which adds the \ce macro for chemical formulae. See <a href="http://docs.mathjax.org/en/latest/tex.html#tex-and-latex-extensions">http://docs.mathjax.org/en/latest/tex.html#tex-and-latex-extensions</a>.</p>
......@@ -633,3 +633,21 @@ $cfg->showloginsideblock = true;
* experience.
*/
$cfg->ajaxifyblocks = true;
/**
* @global string $cfg->mathjaxpath Determines the path to CDN or server-local installation of MathJax.js.
* If MathJax is enabled, use to configure path to MathJax.
*/
$cfg->mathjaxpath = '//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML&delayStartupUntil=configured';
/**
* @global string $cfg->mathjaxconfig Determines MathJax configuration options.
* The default MathJax configuration should be appropriate for most users, but MathJax is highly configurable
* and any of the standard MathJax configuration options can be added here.
*/
$cfg->mathjaxconfig = '
MathJax.Hub.Config({
TeX:{extensions: ["mhchem.js"]}
});
MathJax.Hub.Configured();
';
......@@ -202,6 +202,11 @@ function smarty($javascript = array(), $headers = array(), $pagestrings = array(
$javascript_array[] = $jsroot . 'jquery/deprecated_jquery.js';
$headers[] = '<script type="application/javascript">$j=jQuery;</script>';
// If necessary, load MathJax configuration
if (get_config('mathjax')) {
$headers[] = '<script type="application/javascript">'.get_config('mathjaxconfig').'</script>';
}
// TinyMCE must be included first for some reason we're not sure about
//
// Note: we do not display tinyMCE for mobile devices
......@@ -399,6 +404,11 @@ EOF;
}
$javascript_array[] = $jsroot . 'keyboardNavigation.js';
//If necessary, load MathJax path
if (get_config('mathjax')) {
$javascript_array[] = get_config('mathjaxpath');
}
$strings = array();
foreach ($pagestrings as $k => $v) {
if (is_array($v)) {
......
......@@ -21,6 +21,9 @@ jQuery(function($) {
if ($(this).is(':empty')){
$(this).closest('.panel').addClass('hidden');
}
if (config.mathjax && MathJax !== undefined) {
MathJax.Hub.Queue(["Typeset", MathJax.Hub, blocks.get(i)]);
}
});
}
......
......@@ -17,7 +17,8 @@
'userid': {$USER->get('id')},
'mobile': {if $MOBILE}1{else}0{/if},
'handheld_device': {if $HANDHELD_DEVICE}1{else}0{/if},
'cc_enabled': {$CC_ENABLED|intval}
'cc_enabled': {$CC_ENABLED|intval},
'mathjax': {ifconfig key=mathjax}1{else}0{/ifconfig}
{literal}}{/literal};
</script>
{$STRINGJS|safe}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment