That’s right. I do it like this:
if (defined("LIRE_USE_WITH_WP_TYPOGRAPHY") && LIRE_USE_WITH_WP_TYPOGRAPHY === true) {
add_action('the_content', array(&$wpLire, 'fixWpTypoMathCompat'), 1);
}
And I’ve also come up with updated code that also takes into account \begin{env}...\end{env}
. I guess for completeness I should also do $$...$$
, but that can probably wait. For reference, this is what I have now:
define("LIRE_USE_WITH_WP_TYPOGRAPHY", true);
define("LIRE_FIX_DOLLAR_INLINE_MATH_WP_TYPOGRAPHY", true);
define("LIRE_FIX_ENVS_WP_TYPOGRAPHY", true);
function fixWpTypoMathCompat($content) {
// Display equations \[ ... \]
preg_match_all('/\\\\\[(?!\\\\\]).*?\\\\\]/s', $content, $result, PREG_PATTERN_ORDER);
for ($i = 0; $i < count($result[0]); $i++) {
for ($i = 0; $i < count($result[0]); $i++) {
$now_eq = $result[0][$i];
$content = str_replace($now_eq, "<div class=\"lire-equation\">" . $result[0][$i] . "</div>", $content);
}
}
// Environments such as \begin{equation} ... \end{equation}
if (defined("LIRE_FIX_ENVS_WP_TYPOGRAPHY") && LIRE_FIX_ENVS_WP_TYPOGRAPHY === true) {
preg_match_all('/\\\\begin{([A-Za-z]+\*?)}.+?\\\\end{\g{1}}/s', $content, $result, PREG_PATTERN_ORDER);
for ($i = 0; $i < count($result[0]); $i++) {
$now_eq = $result[0][$i];
$content = str_replace($now_eq, "<div class=\"lire-equation\">" . $result[0][$i] . "</div>", $content);
}
}
// Inline equations \( ... \)
preg_match_all('/\\\\\((?!\\\\\)).*?\\\\\)/s', $content, $result, PREG_PATTERN_ORDER);
for ($i = 0; $i < count($result[0]); $i++) {
$now_eq = $result[0][$i];
$content = str_replace($now_eq, "<span class=\"lire-equation\">" . $result[0][$i] . "</span>", $content);
}
// Inline equations $ ... $
if (defined("LIRE_FIX_DOLLAR_INLINE_MATH_WP_TYPOGRAPHY") && LIRE_FIX_DOLLAR_INLINE_MATH_WP_TYPOGRAPHY === true) {
preg_match_all('/(?<!\\\\)\$((?:\\\\[^\n\r\x{2028}\x{2029}]|[^$])*)(?<!\\\\)\$/u', $content, $result, PREG_PATTERN_ORDER);
for ($i = 0; $i < count($result[0]); $i++) {
$now_eq = $result[0][$i];
$content = str_replace($now_eq, "<span class=\"lire-equation\">" . $result[0][$i] . "</span>", $content);
}
}
return $content;
}
What would be really cool is if you could add lire-equation
as a default ignored class when you update the plugin. Or, maybe suggest some other class name that would be more generic, I’m open to suggestions as I can easily change the class name in my plugin.