0

我找到了一个简单的 WordPress插件 ,它可以通过乳胶支持启用降价。

它运行良好,只是它不支持某些乳胶代码,例如

\begin{align*} 
    a+b=c\\
    a+a=2a
\end{align*} . 

任何人都可以帮助改进插件吗?所以它可以逃避乳胶代码

\begin{...}  
   ...
\end{...} 

我在这个插件中找到了以下代码来逃避一些乳胶代码:

  function doDisplayMath($text) {
  # Wrap text between \[ and \] in display math tags.

  $text = preg_replace_callback('{
  ^\\\\         # line starts with a single backslash (double escaping)
  \[            # followed by a square bracket
  (.+)          # then the actual LaTeX code
  \\\\          # followed by another backslash
  \]            # and closing bracket
  \s*$          # and maybe some whitespace before the end of the line
  }mx',
  array(&$this, '_doDisplayMath_callback'), $text);

return $text;
}

function _doDisplayMath_callback($matches) {
$texblock = $matches[1];
# $texblock = htmlspecialchars(trim($texblock), ENT_NOQUOTES);
$texblock = trim($texblock);
if (MARKDOWN_MATH_TYPE == "mathjax") {
  $texblock = "<span class=\"MathJax_Preview\">[$texblock]</span><script type=\"math/tex; mode=display\">$texblock</script>";
} else {
      $texblock = "<div class=\"math\">$texblock</div>";
  }
    return "\n\n".$this->hashBlock($texblock)."\n\n";
}

function makeCodeSpan($code) {
#
# Create a code span markup for $code. Called from handleSpanToken.
#
    $code = htmlspecialchars(trim($code), ENT_NOQUOTES);
    return $this->hashPart("<code>$code</code>");
}

所以我添加了一个新的相似函数:

function doBeginEnd($text) {
  # Wrap text between \begin and \end{...} in display math tags.

  $text = preg_replace_callback('{
  ^\\\\         # line starts with a single backslash (double escaping)
  \"begin\"     # followed by  "begin"
  (.+)          # then the actual LaTeX code
  \\\\          # followed by another backslash
  \"end\"       # and "end"
  \{            # and {
  (.+)          # and a string
  \}            # and }
  \s*$          # and maybe some whitespace before the end of the line
  }mx',
  array(&$this, '_doDisplayMath_callback'), $text);

return $text;
}

function _doBeginEnd_callback($matches) {
$texblock = $matches[1];
# $texblock = htmlspecialchars(trim($texblock), ENT_NOQUOTES);
$texblock = trim($texblock);
if (MARKDOWN_MATH_TYPE == "mathjax") {
  $texblock = "<span class=\"MathJax_Preview\">[$texblock]</span><script 
              type=\"math/tex; mode=display\">$texblock</script>";
    } else {
              $texblock = "<div class=\"math\">$texblock</div>";
           }
    return "\n\n".$this->hashBlock($texblock)."\n\n";
}

它不起作用,有什么帮助我吗?谢谢。

4

0 回答 0