diff --git a/filter/mathjaxloader/filter.php b/filter/mathjaxloader/filter.php
index 3726c95dd45..88f22bfef26 100644
--- a/filter/mathjaxloader/filter.php
+++ b/filter/mathjaxloader/filter.php
@@ -163,7 +163,19 @@ class filter_mathjaxloader extends moodle_text_filter {
}
if ($hasinline || $hasdisplay || $hasextra) {
$PAGE->requires->yui_module('moodle-filter_mathjaxloader-loader', 'M.filter_mathjaxloader.typeset');
- return '' . $text . '';
+ if ($hasextra) {
+ $text = '' + $text + '';
+ } else {
+ if ($hasinline) {
+ $text = preg_replace('/\\\\\\([\S\s]*?\\\\\\)/u',
+ '\0', $text);
+ }
+ if ($hasdisplay) {
+ $text = preg_replace('/\$\$[\S\s]*?\$\$|\\\\\\[[\S\s]*?\\\\\\]/u',
+ '\0', $text);
+ }
+ }
+ return '' . $text . '';
}
return $text;
}