Aleksei Tepljakov
Forum Replies Created
-
Good point. Basically, I think we can finally consider this issue resolved ๐
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-equationas 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.Added support for โdollarsignedโ inline math as well.
But now there’s also the issue with\begin{env} ... \end{env}. Will have to figure out a regex for handling that as well, hopefully for a generalenvand not forequation,align, etc. separately.Ok, here’s a solution. It only works for math enclosed in
\( math \)(inline) and\[ math \](displayed). Dollar signs are too much of a hassle to implement properly.function fixWpTypoMathCompat($content) { 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); } } 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); } return $content; }Added this as action with default priority to my plugin and then set up an option in wp-typography to ignore
lire-equationclass. Seems to be working. Will test further.Tried using the filter hooks, no go. Let me know how you applied this in your setup.
What’s more important, I realied just now that I apparently only targeted inline math $like=this$, but displayed equations also suffer from automatic insertion of like $$myequation=1$$ or \[this=0\].
This thing becomes more complicated by the minute.Cool, thanks. I’ll give it a go as soon as I can.
Hi @pputzer, can we return to this discussion? Regrettably I didn’t have time to do anything with my website, and it’s not yet public, but that again there’s a chance the problem described above could be fixed before the official release.
Above you mentioned some new filter hooks. Is that a thing already or…?
@pputzer: I’m using a custom plugin, more info here http://atdesign.ee/lire/
Direct link to download: http://atdesign.ee/lire/download/lire-wp-0.1.zip
It is heavily outdated, but still works.I have no idea ๐ I will publish my website next week. Most likely, I won’t be using math in the beginning while testing out cross-posting etc., so maybe it can indeed wait.
Alright. Then I will proceed with adding the wrapper via my plugin. In this case, the execution order of plugins becomes important. Once that’s done and dusted I’ll share the code with you.
@pputzer: I haven’t done exhaustive tests as I don’t have time. My new WordPress website has been in development for almost 4 years and I have no other option but to test features as I go along. Sometimes I discover bugs like this that must be fixed.
With that in mind — do you have a solution? I didn’t get around to implementing a wrapper inserter in my math plugin yet and I’m wondering whether that would be optimal in this case.
- This reply was modified 6 years, 11 months ago by Aleksei Tepljakov.
Right now I have the PHP version at hand:
(?<!\\)\$((?:\\[^\n\r\x{2028}\x{2029}]|[^$])*)(?<!\\)\$Didn’t extensively test it.
Yes.
Anyway, I’ve tried the JS filtering solution, and in principle it could work, but it seems to overcomplicate matters. Rather, I would do this at PHP level.
One idea that I had was to use RegEx instead of actually creating a parser. In fact, I was able to cook up a JS RegEx that captured all $…$ groups skipping over \$ (\$ is used where I actually want the dollar sign to appear).
At PHP level, if this RegEx is used, it is straightforward to wrap all of these $…$ groups in a <span> with some class. But this must run before ­ is inserted. So, I would appreciate it if you made this as an option in the plugin.
Let me know what you think.
MathML is not an option, I’m afraid.
I am actually using a custom solution for LaTeX. Before MathJax parses the page, I can run a separate JS which would filter the ­ guys out. Probably will use this solution for now.
Plugin added. If you already have it installed, a new version notification will probably pop up in your dashboard.
The clean way is to remove the old version prior to ‘updating’ otherwise the plugin will be somewhat messed up and you will have to uninstall it twice to get rid of it.
The plugin is available here:
http://ww.wp.xz.cn/extend/plugins/ie6-support-for-2010-theme/