diff --git a/filter/mathjaxloader/filter.php b/filter/mathjaxloader/filter.php index 0906e18fb49..9fab93b9e79 100644 --- a/filter/mathjaxloader/filter.php +++ b/filter/mathjaxloader/filter.php @@ -140,7 +140,13 @@ class filter_mathjaxloader extends moodle_text_filter { if ($hasextra) { // If custom dilimeters are used, wrap whole text to prevent autolinking. $text = '' . $text . ''; - } else { + } else if (preg_match('/\\\\[[(]/', $text) || preg_match('/\$\$/', $text)) { + // Only parse the text if there are mathjax symbols in it. The recognized + // math environments are \[ \] and $$ $$ for display mathematics and \( \) + // for inline mathematics. + // Note: 2 separate regexes seems to perform better here than using a single + // regex with groupings. + // Wrap display and inline math environments in nolink spans. // Do not wrap nested environments, i.e., if inline math is nested // inside display math, only the outer display math is wrapped in