Skip to content
Snippets Groups Projects
Commit fda28532 authored by Chris Sangwin's avatar Chris Sangwin
Browse files

Modify the mathjax filter behaviour to force some maths in the question text. ...

Modify the mathjax filter behaviour to force some maths in the question text.  Tidy up the healthcheck.
parent 7edbc374
No related branches found
No related tags found
No related merge requests found
...@@ -77,11 +77,7 @@ echo html_writer::tag('dt', stack_string('texinlinestyle')); ...@@ -77,11 +77,7 @@ echo html_writer::tag('dt', stack_string('texinlinestyle'));
echo html_writer::tag('dd', format_text(stack_string('healthchecksampleinlinetex'))); echo html_writer::tag('dd', format_text(stack_string('healthchecksampleinlinetex')));
if ($config->mathsdisplay === 'mathjax') { if ($config->mathsdisplay === 'mathjax') {
$settingsurl = new moodle_url('/admin/settings.php', array('section' => 'additionalhtml')); echo html_writer::tag('p', stack_string('healthchecklatexmathjax'));
echo html_writer::tag('p', stack_string('healthchecklatexmathjax',
$settingsurl->out()));
echo html_writer::tag('textarea', s(stack_maths_output_mathjax::get_mathjax_code()),
array('readonly' => 'readonly', 'wrap' => 'virtual', 'rows' => '12', 'cols' => '100'));
} else { } else {
$settingsurl = new moodle_url('/admin/filters.php'); $settingsurl = new moodle_url('/admin/filters.php');
echo html_writer::tag('p', stack_string('healthcheckfilters', echo html_writer::tag('p', stack_string('healthcheckfilters',
......
...@@ -457,7 +457,7 @@ $string['healthcheckconnectintro'] = 'We are trying to evaluate the following CA ...@@ -457,7 +457,7 @@ $string['healthcheckconnectintro'] = 'We are trying to evaluate the following CA
$string['healthcheckfilters'] = 'Please ensure that the {$a->filter} is enabled on the <a href="{$a->url}">Manage filters</a> page.'; $string['healthcheckfilters'] = 'Please ensure that the {$a->filter} is enabled on the <a href="{$a->url}">Manage filters</a> page.';
$string['healthchecklatex'] = 'Check LaTeX is being converted correctly'; $string['healthchecklatex'] = 'Check LaTeX is being converted correctly';
$string['healthchecklatexintro'] = 'STACK generates LaTeX on the fly, and enables teachers to write LaTeX in questions. It assumes that LaTeX will be converted by a moodle filter. Below are samples of displayed and inline expressions in LaTeX which should be appear correctly in your browser. Problems here indicate incorrect moodle filter settings, not faults with STACK itself. STACK only uses the single and double dollar notation itself, but some question authors may be relying on the other forms.'; $string['healthchecklatexintro'] = 'STACK generates LaTeX on the fly, and enables teachers to write LaTeX in questions. It assumes that LaTeX will be converted by a moodle filter. Below are samples of displayed and inline expressions in LaTeX which should be appear correctly in your browser. Problems here indicate incorrect moodle filter settings, not faults with STACK itself. STACK only uses the single and double dollar notation itself, but some question authors may be relying on the other forms.';
$string['healthchecklatexmathjax'] = 'One way to get equation rendering to work is to copy the following code into the <b>Within HEAD</b> setting on <a href="{$a}">Additional HTML</a>.'; $string['healthchecklatexmathjax'] = 'STACK relies on the Moodle MathJax filter. An alternative is to add javascript code to Moodle\'s additional HTML. See the STACK installation docs for more details of this option.';
$string['healthcheckmathsdisplaymethod'] = 'Maths display method being used: {$a}.'; $string['healthcheckmathsdisplaymethod'] = 'Maths display method being used: {$a}.';
$string['healthcheckmaximabat'] = 'The maxima.bat file is missing'; $string['healthcheckmaximabat'] = 'The maxima.bat file is missing';
$string['healthcheckmaximabatinfo'] = 'This script tried to automatically copy the maxima.bat script from inside "C:\Program files\Maxima-1.xx.y\bin" into "{$a}\stack". However, this seems not to have worked. Please copy this file manually.'; $string['healthcheckmaximabatinfo'] = 'This script tried to automatically copy the maxima.bat script from inside "C:\Program files\Maxima-1.xx.y\bin" into "{$a}\stack". However, this seems not to have worked. Please copy this file manually.';
......
...@@ -78,7 +78,7 @@ class qtype_stack_renderer extends qtype_renderer { ...@@ -78,7 +78,7 @@ class qtype_stack_renderer extends qtype_renderer {
// Now format the questiontext. This should be done after the subsitutions of inputs and PRTs. // Now format the questiontext. This should be done after the subsitutions of inputs and PRTs.
$questiontext = $question->format_text( $questiontext = $question->format_text(
stack_maths::process_display_castext($questiontext, $this), stack_maths::process_display_castext($questiontext, $this, true),
$question->questiontextformat, $question->questiontextformat,
$qa, 'question', 'questiontext', $question->id); $qa, 'question', 'questiontext', $question->id);
......
...@@ -48,11 +48,12 @@ class stack_maths { ...@@ -48,11 +48,12 @@ class stack_maths {
* then passed to Moodle's {@link format_text()} function. * then passed to Moodle's {@link format_text()} function.
* @param string $text the content to process. * @param string $text the content to process.
* @param qtype_stack_renderer $renderer (options) the STACK renderer, if you have one. * @param qtype_stack_renderer $renderer (options) the STACK renderer, if you have one.
* @param bool $forcesomemaths force the text to contain some mathematics.
* @return string the content ready to pass to format_text. * @return string the content ready to pass to format_text.
*/ */
public static function process_display_castext($text, qtype_stack_renderer $renderer = null) { public static function process_display_castext($text, qtype_stack_renderer $renderer = null, $forcesomemaths = false) {
return self::get_output()->process_display_castext($text, return self::get_output()->process_display_castext($text,
stack_utils::get_config()->replacedollars, $renderer); stack_utils::get_config()->replacedollars, $renderer, $forcesomemaths);
} }
/** /**
......
...@@ -53,8 +53,8 @@ abstract class stack_maths_output_filter_base extends stack_maths_output { ...@@ -53,8 +53,8 @@ abstract class stack_maths_output_filter_base extends stack_maths_output {
return $html; return $html;
} }
public function process_display_castext($text, $replacedollars, qtype_stack_renderer $renderer = null) { public function process_display_castext($text, $replacedollars, qtype_stack_renderer $renderer = null, $forcesomemaths = false) {
$text = parent::process_display_castext($text, $replacedollars, $renderer); $text = parent::process_display_castext($text, $replacedollars, $renderer, $forcesomemaths);
$text = $this->find_equations_and_replace_delimiters($text); $text = $this->find_equations_and_replace_delimiters($text);
return $text; return $text;
} }
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Stack. If not, see <http://www.gnu.org/licenses/>. // along with Stack. If not, see <http://www.gnu.org/licenses/>.
require_once($CFG->dirroot .'/filter/mathjaxloader/filter.php');
/** /**
* STACK maths output methods for using MathJax. * STACK maths output methods for using MathJax.
...@@ -23,24 +24,12 @@ ...@@ -23,24 +24,12 @@
*/ */
class stack_maths_output_mathjax extends stack_maths_output { class stack_maths_output_mathjax extends stack_maths_output {
/** public function process_display_castext($text, $replacedollars, qtype_stack_renderer $renderer = null, $forcesomemaths = false) {
* @return string code that should be pasted into Admin -> Appearance -> // When rendering with MathJax the questiontext must always contain some maths.
* Additional HTML -> Head code to make MathJax work the way STACK expects. // This is to ensure the javascript is active so that any ajax processing is picked up.
*/ if ($forcesomemaths && strpos($text, '\(') === false && strpos($text, '\[') === false) {
public static function get_mathjax_code() { $text .= '\(\)';
return <<<END }
<script type="text/x-mathjax-config"> return parent::process_display_castext($text, $replacedollars, $renderer);
MathJax.Hub.Config({
MMLorHTML: { prefer: "HTML" },
tex2jax: {
displayMath: [['\\\\[', '\\\\]']],
inlineMath: [['\\\\(', '\\\\)']],
processEscapes: true
},
TeX: { extensions: ['enclose.js'] }
});
</script>
<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script>
END;
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment