Page MenuHomePhabricator

Render math values properly
Closed, ResolvedPublic

Description

Right now it looks like this in the stamtent boxes:

<math>a^2 + b^2 = c^2</math>

Event Timeline

The description is quite brief, can you provide an example?

The math formatters are in the Math extension, that possibly complicates things here.

@Physikerwelt: We're talking about the wikitext formatter for math here, that seems to be returning plain <math> tags. In order to use that via Lua, we need to preprocess those… that's kind of ugly (and also, slow).

That's to be expected. The wikitext math tag contains tex. Otherwise it would not be wikitext. It has to be differentiated between the html math tags (which contain mathml markup) and the wikitext math tags. That's not the same at all.
If lua does not process wikitext correctly, I think that's nothing that should be solved manually, otherwise other tags will cause similar problems.

Does anyone of you know what we need to do to fix this?

Does anyone of you know what we need to do to fix this?

The <math> tag needs to be preprocessed if outputted by Lua. The math formatter can hardly do that: Preprocessing depends on the concrete Parser instance.

Also we run into problems here because we probably don't want to pollute our wikitext output with that.

In theory we could special case this either on the PHP side or in Lua and run the wikitext through Parser::preprocess or [[https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#frame:preprocess|frame:preprocess]] respectively. For that we probably want to have another callback on the data type definition that allows us to determine whether the outputted wikitext needs preprocessing or not (that's also quite ugly?).

As discussed with @hoo one option would be to use {{#tag:math|content|atrib=value}} rather than <math artrib=value>content</math> in the wikitext formatter. @hoo can you test if that renders ok with lua?

As discussed with @hoo one option would be to use {{#tag:math|content|atrib=value}} rather than <math artrib=value>content</math> in the wikitext formatter. @hoo can you test if that renders ok with lua?

Tested… and it doesn't… it needs preprocessing just like using the tag does :/

@hoo anyhow, it was worth a try. Thus we need to debate about some kind of preprocessing.

I'm not really sure how to reproduce this problem. Is there more documentation on the parser function {{#property| ...}} as opposed to here https://www.mediawiki.org/wiki/Extension:Wikibase_Client#Data_transclusion? When I use the property parser function I see the raw texvc source code.

I did not make a lot of progress here. However, at least I found a way to render math using a custom module https://en.wikipedia.org/wiki/Module:ShowMath

Physikerwelt claimed this task.

This is now part of the module, wd. Also custom parsing functions exist for special types of Math markup in [[ portal.mardi4nfdi.de/wiki/module:wd | non-wmf-hosted ]] wikis:

function Config:getValue(snak, raw, link, short, anyLang, unitOnly, noSpecial, type)
...

		if datatype == 'string' then

...
			elseif subtype == 'math' and not raw then
				local attribute = nil

				if (type == parameters.property or (type == parameters.qualifier and self.propertyID == aliasesP.hasPart)) and snak.property == aliasesP.definingFormula then
					attribute = {qid = self.entityID}
				end--

				return mw.getCurrentFrame():extensionTag("math", datavalue, attribute)
			elseif subtype == 'contentmath' and not raw then
				return mw.getCurrentFrame():extensionTag{
					name="math",
					content= datavalue, 
					args={forcemathmode="latexml"}
					}
			elseif subtype == 'mathml' and not raw then
				return mw.getCurrentFrame():extensionTag{
					name="math",
					content= datavalue, 
					args={type="pmml", class="wikibase-mathml", forcemathmode="mathml"}
					}