Page MenuHomePhabricator

math markup in section heading
Open, Stalled, Needs TriagePublicBUG REPORT

Description

*When a formula using <math>...</math> is used in a section heading, the heading looks fine, as does the edit summary, but the entry in the table of contents may look seriously weird.

*Example: this edit: https://en.wikipedia.org/w/index.php?title=Wikipedia:Reference_desk/Mathematics&diff=1053566474&oldid=1053505892
*The wikitext of the section heading is: == <math>|3^x - 2^y| = 1</math> ==
*In the edit summary this is rendered as: ‎|3^x - 2^y| = 1
**But the table of contents shows: '"UNIQ--postMath-00000043-QINU"'

What happens?:

What should have happened instead?:

Software version (if not a Wikimedia wiki), browser information, screenshots, other information, etc:

Event Timeline

There are a very large number of changes, so older changes are hidden. Show Older Changes

Thanks to Wikipedia user Stwalkerster for pointing me here. I encountered this bug today, on Absolute magnitude. I applied a work-around, typing the section title manually (see this diff). This was possible because the name included no special characters in this instance, but I would prefer to have a solution that also works with more difficult cases (compare this example on my Wikipedia sandbox).

I get the feeling that is a new problem that did not exist before or a regression. Since the math extension did not change for quite a while this is something that depends on a core change. Maybe we can see which changes have been performed when the problem was discovered first. I have no idea.

As I wrote in T295430 (my duplicate):

This seems to be a new issue, and likely related to the changes from T287767 / T295187.

I also proposed how it could be fixed when a similar issue appeared elsewhere in the past:

Looks like this is implemented in the TOC code in Parser.php: https://github.com/wikimedia/mediawiki/blob/da99ed653f0443fca55908000af7c96f69ac59a5/includes/parser/Parser.php#L4279. The code comment there even calls out <math>, but presumably this no longer works because Math is not using normal strip markers.

I don't really understand why the math parser hook code is the way it is. Assuming that it can't be changed, you could probably add a hook near that code in Parser.php, and implement it in Math to replace the fake strip markers with the source, similar to what is done for 'mw:editsection'.

Unfortunately, I don't really understand how this code should do the rendering.

Normally math generates the marker with that code.

https://github.com/wikimedia/mediawiki-extensions-Math/blob/8fb24c9731a1718690a1a9e03ee3207f0544d76c/src/HookHandlers/ParserHooksHandler.php#L80-L85

After everything is done (onParserAfterTidy) all these markers are replaced with the actual rendering.

https://github.com/wikimedia/mediawiki-extensions-Math/blob/8fb24c9731a1718690a1a9e03ee3207f0544d76c/src/HookHandlers/ParserHooksHandler.php#L158-L172

The reason for don't that is that we need to render all math tags in parallel to avoid timeouts for pages with many formulae.

Maybe can you explain your solution again in more detail? I am afraid I have the feeling I was unable to understand it. What exactly could be done to resolve the problem?

Change 768850 had a related patch set uploaded (by Func; author: Func):

[mediawiki/core@master] parser: Parse ToC along with page contents

https://gerrit.wikimedia.org/r/768850

T295091 is interesting. Whatever parsing needs to be done to fix that needs to be done *before* we extract the headings to make the table of contents, since the half-parsed content otherwise ends up in the JSON section data as well. In the next release I hope to remove getTOCHTML entirely and generate the TOC in :getText from the section contents in all code paths, so it is pretty important that the right data end up there. It may be that whatever tricks <math> is currently doing need to be adjusted (or math content stripped from headings).

Change 768850 abandoned by Func:

[mediawiki/core@master] parser: Parse ToC along with page contents

Reason:

https://gerrit.wikimedia.org/r/768850

(I don't think this is related to MediaWiki-Comment-store, per its description: The Comment store in MediaWiki is responsible for storing edit summaries, log action comments and other such short strings (referred to as "comments"). If this wasn't a mistake, feel free to tag it again, but please explain why.)

T295091

There is a big problem whith the tables of my mathematical works :

LaTeX symbols aren't any more displayed correctly.

This problem exists since several month and it's time that is to be resolved.

My works are on Wikiversité/Faculté de mathématiques.

Hi @GF612BRJMDLO5XLHC, welcome to Wikimedia Phabricator! If there is an issue somewhere, then please provide direct links to that issue. Thanks a lot! :)

T295091

Correction :

There is a big problem whith the tables of contents of my mathematical works :

LaTeX symbols aren't any more displayed correctly.

This problem exists since several months and it's time it to be resolved.

My works are on Wikiversité/Faculté de mathématiques.

Physikerwelt moved this task from Inbox to Next-up on the Math board.EditedMay 14 2022, 1:46 PM
Physikerwelt added a subscriber: Stegmujo.

To summarize. Math in section headings does not work but is not clear why. Do people think it can be resolved from within the Math extension?

I made a test on https://portal.mardi4nfdi.de/w/index.php?title=User:Schubotz&oldid=103511 and it looks good

Screenshot 2022-05-14 at 15-50-02 User Schubotz - MaRDI portal.png (286×502 px, 34 KB)
(Fig 1, LaTeXML mode)

Screenshot 2022-05-14 at 15-51-30 User Schubotz - MaRDI portal.png (310×369 px, 34 KB)
(Fig 2, MathML mode, the page contains special macros that are not supported by Mathoid so the red errors are to be expected.)

Screenshot 2022-05-14 at 15-53-44 User Schubotz - MaRDI portal.png (291×361 px, 33 KB)
(Fig 3, PNG mode, see above)

From that I get the impression that it is not a problem with the Math extension alone.

I made the same screenshot again in MathML mode

Screenshot 2022-07-03 at 17-33-30 User Schubotz - MaRDI portal.png (1×1 px, 199 KB)

and now I also see the error. So we might have a regression. Can this be a regression of https://gerrit.wikimedia.org/r/c/mediawiki/extensions/Math/+/710115 ?

@Stegmujo did we update our portal page?

Math Extension is deployed from wmf/1.39.0-wmf.16 to wikibase container in the portal, which was built yesterday and restarted in portainer some hours ago.
MathSearch runs on a local modified setup which is deployed via override script.

Someone complained about it on the Hebrew Wikipedia recently. Is anyone looking at it, by any chance?

I would, however, if you could help with the code review?

I can try, although it would be much better if someone who actually knows the Parser would also take a look. I am really, really not a Parser expert.

I expect that reverting https://github.com/wikimedia/mediawiki-extensions-Math/commit/a245040c203cd46f7886fbfc551ef4041f95099d will solve the problem. I can test later at home, but I need a second person for code review (of the revert).

Change 821245 had a related patch set uploaded (by Physikerwelt; author: Physikerwelt):

[mediawiki/extensions/Math@master] Revert "Remove special handling of math in sections"

https://gerrit.wikimedia.org/r/821245

Change 821245 abandoned by Physikerwelt:

[mediawiki/extensions/Math@master] Revert "Remove special handling of math in sections"

Reason:

This does not solve the problem

https://gerrit.wikimedia.org/r/821245

I expect that reverting https://github.com/wikimedia/mediawiki-extensions-Math/commit/a245040c203cd46f7886fbfc551ef4041f95099d will solve the problem. I can test later at home, but I need a second person for code review (of the revert).

Unfortunately, this did not help. So we need to search somewhere else.

@Amire80 Did you make any progress in identifying the reason for the problem? Meanwhile, we are working on a fast PHP-based math rendering that makes strip-markers altogether superfluous for math rendering.

Any progress? I stumbled over yet another instance of this problem today (Talk:Mathematical_coincidence#Explaining_%7F'%22%60UNIQ--postMath-00000106-QINU%60%22'%7F), so the problem obviously still exists.

Physikerwelt changed the task status from Open to Stalled.Oct 21 2023, 9:44 PM

Meanwhile,

Screenshot 2023-10-21 at 23.42.09.png (1×1 px, 305 KB)
it looks good with the new native MathML rendering mode

As another sample page, our WikiJournal article on statistics (on Wikiversity) has a bunch of symbols generated using <math> which are broken on Table of Contents https://en.wikiversity.org/wiki/WikiJournal_Preprints/Design_effect