Extension talk:Math

Previous discussions were archived for 2011–2014 and 2015–2016 on 2016-10-20.

Raw <Math> tag in visual editor edit and math formula editor

2

I followed every step but raw <Math> tag shows in visual editor edit and math formula editor.

It's fine in view mode.

I tried to build Mathoid Server myself, but it seems to have failed.

It is a bit slow when used with the following content, but it is working.

Please let me know if there is a fast wgMathMathMLUrl in Asia.

// Set MathML as default rendering option

$wgDefaultUserOptions['math'] = 'mathml';$wgMathFullRestbaseURL = 'https://en.wikipedia.org/api/rest_';

$wgMathMathMLUrl = 'https://mathoid-beta.wmflabs.org/'; Reply to "Raw <Math> tag in visual editor edit and math formula editor" Math extension stopped working 1 Hello, I had following settings and all worked fine: wfLoadExtension( 'Math' ); // Set MathML as default rendering option$wgDefaultUserOptions['math'] = 'mathml';
$wgMathFullRestbaseURL = 'https://en.wikipedia.org/api/rest_';$wgMathMathMLUrl = 'https://mathoid-beta.wmflabs.org/';


But today I have noticed that extension does not work anymore showing mistake: Math extension cannot connect to Restbase

What had happened and how can I fix it?

Reply to "Math extension stopped working"

Math extension error

1

Hello! I am new to mediawiki and have inherited an environment that is currently running a mediawiki server. I was asked to get the Math extension installed for my users, and I believe I have done so correctly. However, my user is seeing an error displayed on the page, showing the following:

Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("$3") from server "$2":): {\displaystyle \nabla \cdot E = \rho/\epsilon_0 }

I have seen similar articles referring to this error, but they seem to be showing a RESTbase issue. I can provide additional information if needed, I thank you all for your time

Math error

2

Hi

I have the following configuration in LocalSettings.php:

$wgMathValidModes[] = 'mathml';$wgDefaultUserOptions['math'] = 'mathml';

$wgMathFullRestbaseURL = 'https://en.wikipedia.org/api/rest_v1/'; However, formula do not render correctly. For example, this code: $<20$ displays: Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "/mathoid/local/v1/":): {\displaystyle <20} What is causing the error and how to resolve it? Thanks! not rendering correctly for me either with the default settings. Test Rendering the input "x^2+\text{a sample Text}" succeeded. Test Comparing to the reference rendering succeeded. Test Rendering of a+b in plain MathML mode succeeded. Test Checking the presence of '+' in the MathML output succeeded. Test Comparing the generated SVG with the reference failed. Test Checking if MathML input is supported succeeded. Test Rendering Presentation MathML sample failed. Test Checking if the link to SVG image is correct failed. Backend tests for rendering mode MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools) completed. doestn seem to be anyone maintaining this project atm though. Reply to "Math error" Is there a way that I can change or add things into the tex-header? 1 For example, define new commands that are available for the entire wiki? Reply to "Is there a way that I can change or add things into the tex-header?" Math extension cannot connect to Restbase. 23 解析失敗 (MathML 使用 SVG 或 PNG 備用 (建議用於現代瀏覽器與輔助工具)：從伺服器 "http://api.formulasearchengine.com/v1/" 收到無效的回應 ("Math extension cannot connect to Restbase.")。) http://api.formulasearchengine.com/v1/ is error so many times. This extension seems dead. I was having the same problem, but by changing a line in LocalSettings.php to$wgMathFullRestbaseURL= 'https://en.wikipedia.org/api/rest_';

and running "php update.php", the problem went away. So I think the above statement "This extension seems dead" is not the definitive word.

Pointing $wgMathFullRestbaseURL to wikipedia doesn't seem to work since MediaWiki 1.30 It works for me with MediaWiki 1.30 and LAMP on Ubuntu 18.04 machine I later discovered it doesn't work when you have RestBase installed and configured for Visual Editor. Otherwise it should work. Has anyone had this problem again recently because it's suddenly occurred on my wiki? I tried the alternate Restbase Urls but nothing has worked. We also observed following Math/LaTex rendering to PNG issue while upgraded from MediaWiki 1.30.0 to MediaWiki 1.31.1. But, it's not the issue in earlier version (1.30.0) (Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle \sigma_1^\prime} and Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): Looks like a problem with wikipedia servers... We were not using Mathoid Server as a service in earlier MediaWiki v1.30.0. hence the Math/LaTex rendering to PNG was just working fine with LaTex/DVI libs. but, when we upgraded to this MediaWiki v 1.31.1, the above issue is occurred in the same server environment. Hence, could you let know how we can bypass the Mathoid Server dependency in this LTS version(MediaWiki 1.31.1) and still we can make Math render working as it's working in MediaWiki 1.30.0 ? If you do not install mathoid (and RESTBase), you may use wikipedia's RESTBase, which is what it's using now by default. However, you must ensure PHP is able to connect to wikipedia, which is probably blocked by one of your firewalls or SELinux and that's the error message you're getting There is security restrictions to connect from our corporate network to the internet. so I unable to test wiki's Restbase Hence, I have install for the 'methoid' webservice in our local RHEL7 server. I have opted for the dev-config available in the Mathoid package. Now the daemon is running with following pid. But, I see the listening server IP indicates 0.0.0.0:10044 {"name":"mathoid","hostname":"domainname.com","pid":23788,"level":30,"levelPath":"info","msg":"Worker 23788 listening on 0.0.0.0:10044","time":"2019-06-06T11:21:19.871Z","v":0} Could you let know how can we get the appropriate IP that need to configure with below parameters for Math in LocalSettings.php ? I have already checked with 'domainname:port' is still not working for following configuration in LocalSettings.php wfLoadExtension( 'Math' );$wgDefaultUserOptions['math'] = 'mathml';

$wgMathMathMLUrl = 'https://domainname.com:10044/'; I think you also need RESTBase, or at least this is how I have configured (what would be the purpose of RESTBase, after all?). Then$wgMathMathMLUrl points to RESTBase, and you enable the math endpoint in RESTBase to point to mathoid daemon.

Actually RESTBase server implementation along with Mathoid server is required only when you are running such a Huge WIKI.

But for small enterprise wiki with limited memory to render math formulae, we need to install/setup/configure the Mathoid server for WIKI locally in the RHEL7 server followed with below steps.

** First Install Mathoid server pre-requisites packages dependency in RHEL7 server.

# yum update -y [required when need to update latest packages available in the server]

# yum install -y epel-release

# yum install -y gcc-c++ nodejs npm mocha librsvg2-devel pkgconfig git

# yum groupinstall -y 'Development Tools'

** Second, Install Mathoid server in the desired server location.

# cd /var/data/wiki/

# git clone https://github.com/wikimedia/mathoid/

# cd mathoid

# chmod 775 server.js cli.js

** Third, Run the Mathoid server and test

# npm install

# npm test

** Fourth, Add below lines under LocalSettings.php to map mathoid server with mediawiki

$wgMathoidCli = ['/var/data/wiki/mathoid/cli.js', '-c', '/var/data/wiki/mathoid/config.yaml']; # Below lines required to add in LocalSettings.php to Opt Mathoid server test-config as dependency [Note. Ensure you already got installed below Math extension compatible with the MediaWiki version] wfLoadExtension( 'Math' );$wgMathValidModes[] = 'mathml';

$wgDefaultUserOptions['math'] = 'mathml';$wgMathMathMLUrl = 'http://12.23.34.45:10044/';

** Fifth, Change below line is the api interface for MediaWiki in Mathoid server config.yaml

Restart HTTPD server : # systemctl restart httpd

You are all DONE !

The math formula should render to desired formats in .png !

Any ideas? Same problem here.

Can anyone provide a simple php_curl request that Math could make to wiki's Restbase, in order to test whether this is a problem of the code or a problem of the web host?

Thank you!

This post was hidden by Anu8791 (history)

I tried connecting to both the Wikimedia and Wikipedia Restbases with the same problem (MediaWiki 1.32). The issue in my case was with how the MediaWiki core handles HTTP responses. I haven't seen anyone else mention it, so here's my other comment on the issue with two hacks.

I used one of Johanngan's hacks above and it works!

See that thread I will post some more details

This suddenly started happening on my MediaWiki1.28 install. Johanngan's second hack worked perfectly. Many thanks!

Reply to "Math extension cannot connect to Restbase."

getID3() v1.9.18 vs. v1.9

1

Attempting to install 'Math-REL1_33-183fd5c.tar.gz' on our server:

• MediaWiki 1.33.0
• PHP 7.2.19-0ubuntu0.18.04.1 (apache2handler)
• MySQL 5.7.26-0ubuntu0.18.04.1

The tar file is extracted to '../extensions/Math'.

Running 'update.php' produces the following error.

cd ./wiki/maintenance
sudo php update.php

# Error.
james-heinrich/getid3: 1.9.18 installed, ^1.9 required.
Error: your composer.lock file is not up to date. Run "composer update --no-dev" to install newer dependencies


Is this an error? The 'getid3 v1.9.18' library was installed for the TimedMediaHandler extension. The following is from 'Special:Version' under "Installed Libraries":

james-heinrich/getid3	1.9.18	GPL-1.0-or-later, LGPL-3.0-only and MPL-2.0	PHP script that extracts useful information from popular multimedia file formats


Is there a work around for this? Or, does 'getID3()' need to be rolled back to v1.9?

Thanks for any help.

Reply to "getID3() v1.9.18 vs. v1.9"

https://wikimedia.org/api/rest_v1/ returning code 0 and not 200

13

Using mediawiki 1.31 and Math extension REL_31

Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":)

If i change it to allow code 0:

diff --git a/MathRestbaseInterface.php b/MathRestbaseInterface.php
index 2dc5d45..5355177 100644
--- a/MathRestbaseInterface.php
+++ b/MathRestbaseInterface.php
@@ -364,7 +364,7 @@ class MathRestbaseInterface {
*/
public function evaluateRestbaseCheckResponse( $response ) {$json = json_decode( $response['body'] ); - if ($response['code'] === 200 ) {
+               if ( $response['code'] === 200 ||$response['code'] === 0) {
$headers =$response['headers'];
$this->hash =$headers['x-resource-location'];
$this->success =$json->success;



I get

Failed to parse (Conversion error. Server ("https://wikimedia.org/api/rest_") reported: "Cannot get mml. Server problem.")

Is the RESTBase server down?

Is the RESTBase server down?

No, but maybe the Mathoid service is?

My Math extension have been failing with the same error since a few days.

I've had this problem too. After some debugging, it appears that PHP's curl was refusing the SSL certificate of https://wikimedia.org/api/rest_ . I downloaded a cacert.pem file and pointed edited the php.ini to point to under under variable curl.cainfo and openssl.cafile. This fixed my problem.

[curl]

curl.cainfo = "C:\PHP7\cacert.pem"

[openssl]

openssl.cafile="C:\PHP7\cacert.pem"

Since today I have the same issue. Where did you download the cacert.pem file?

We have the same issue as OP. Adding certificates to php.ini did not help.

Our problems started after a system update. The issue is probably caused by changes in other packages.

I had the same issues as OP on MediaWiki 1.32. The HTTP responses were coming back just fine (rendered math and everything); the problem was coming from the MultiHttpClient in the core. It parses the HTTP response code from the header with a regex match that's hard coded to look for HTTP/1.x, when in fact my server was receiving an HTTP/2 response. The code 0 was a default that was never overwritten thanks to the failed match.

I found two workarounds that resolved the issue for me.

1. Change all the checks in MathRestbaseInterface.php to accept a code 0 response.
2. Go against Do_not_hack_MediaWiki_core and modify the regex in MultiHttpClient to properly match the HTTP/2 response code.
• I'm pretty sure I only modified one line of code. Here's what I did:
1. Locate the file MultiHttpClient.php. It should be on the path: <Your MediaWiki root directory>/includes/libs/MultiHttpClient.php.
2. Search for the line of code that uses preg_match(), in the getCurlHandle method. For me it was on line 390 (MW 1.33), line 392 (MW 1.32).
3. Change the argument from "/^(HTTP\/1\.[01]) (\d{3}) (.*)/" to "/^(HTTP\/[12](?:\.[01])?) (\d{3}) (.*)/"
• Just to be clear, here's the diff:
diff MultiHttpClient_orig.php MultiHttpClient.php

392c392
< 				if ( preg_match( "/^(HTTP\/1\.[01]) (\d{3}) (.*)/", $header,$matches ) ) {
---
> 				if ( preg_match( "/^(HTTP\/[12](?:\.[01])?) (\d{3}) (.*)/", $header,$matches ) ) {

I ended up going with the second option. It seems like an overhaul of the MultiHttpClient is in the works with T202352, so maybe this issue will resolve itself in future releases.

Could you describe in a bit more detail what you did to MultiHttpClient? I might go by your second solution as well.

Edited my above comment with more details on what I did.

I used the Johangan's hack:

1. Change all the checks in MathRestbaseInterface.php to accept a code 0 response."

and it worked.

When I have created a patch file to use in our docker container, I'll post it as a gist here...

I did what Johangan recommended as well. Here's my rough patch, which "works".

--- MathRestbaseInterface.php	2019-08-09 19:10:54.000000000 -0500
+++ MathRestbaseInterface.php	2019-08-09 19:23:45.000000000 -0500
@@ -8,6 +8,8 @@

use MediaWiki\Logger\LoggerFactory;

+const WikiMediaServersReturnInvalidErrorCodes = true;
+
class MathRestbaseInterface {
private $hash = false; private$tex;
@@ -382,7 +384,7 @@
*/
public function evaluateRestbaseCheckResponse( $response ) {$json = json_decode( $response['body'] ); - if ($response['code'] === 200 ) {
+		if ( $response['code'] === 200 || WikiMediaServersReturnInvalidErrorCodes ) {$headers = $response['headers'];$this->hash = $headers['x-resource-location'];$this->success = $json->success; @@ -439,7 +441,7 @@ * @throws MWException */ private function evaluateContentResponse($type, array $response, array$request ) {
-		if ( $response['code'] === 200 ) { + if ($response['code'] === 200 || WikiMediaServersReturnInvalidErrorCodes ) {
if ( array_key_exists( 'x-mathoid-style', $response['headers'] ) ) {$this->mathoidStyle = $response['headers']['x-mathoid-style']; } @@ -474,3 +476,4 @@ throw new MWException( "Cannot get$type. $detail" ); } } +  Reply to "https://wikimedia.org/api/rest_v1/ returning code 0 and not 200" Forcing MathML output 5 I'm pretty sure that as an editor one can't make it do that for other people. That would break the reader experience for the 99% of readers whose device won't render MathML. It's the same way that we don't let editors force the output to have an autoplaying video, even if they really want to; it'd be an anti-user feature. I feel that Jdforrester_(WMF) missed my point, or I ignore something important myself. The question is not about overriding intended behaviour by planting hacks to wiki code – were it, I’d ask another way, such as “which code can force the extension to switch to MathML?”. The question is about control of the extension by its end user. What do you mean by "end user"? System administrator? Page editor? Reader? Who ultimately consumes a wiki page? Reader, of course. Sysadmins definitely don’t fall under the “end” user class unless we discuss tools intended for system administration. Reply to "Forcing MathML output" How to use chinese letters within a formula? 10 <math display="block"><mtext>&#x9E21;</mtext>[/itex] $<mtext>{&#x9E21;} &#x9E21; "Chinese letters"</mtext>$ These attempts failed with: Failed to parse (syntax error): {\displaystyle <mtext>&#x9E21;</mtext>} Failed to parse (syntax error): <mtext>{&#x9E21;} &#x9E21; "Chinese letters"</mtext> Is there any other way to add chinese letters within a formula? You can write ${\displaystyle {\text{鸡}}}$ , however depending your device the appearance might be broken or not as good as normal text. Thanks for the suggestion, I am looking for an elegant solution, but yours won't work either: $鸡$ Failed to parse (lexing error): 鸡 You have to write it inside \text or \mbox like $\text{鸡}$: ${\displaystyle \sum _{{\mbox{鸡}}={\frac {\text{维基百科}}{\text{维基百科}}}}^{\mbox{鸡}}{\text{维基百科}}}$ . If you want to help making it look better, you could test the inline svg proposal here phab:T195861 and share your experience or push for alternative rendering solutions. Thanks again! It works in MathML render mode, but fails in PNG images render mode... (just toggle in Preferences -> Math) with the error: Failed to parse (PNG conversion failed; check for correct installation of latex and dvipng (or dvips + gs + convert)): \text{鸡} All packages are installed, the diagnostics passed (Manual:$wgUseTeX#Diagnostics) and other formulas correctly shown.

This kind of Unicode rendering issue was reported before in bug 798 some Latin letters are still not supported, including those that include multiple diacritics (as well as letters from other languages i.e. chinese).

For ex. this is working:

$\text{àáâãäåæçčďèéěêëìíîïňñòóôõöřšťøùúůûüýÿžß}$

and this not working:

$\text{²°µ´}$

One workaround is to switch the rendering mode from PNG to MathML:

<math forcemathmode="mathml">\text{²³°´µ}[/itex]

Is this a known problem?

There are a lot of rendering issues with the current setup, but you must be referring to texvc, which is not used in mediawiki anymore and I have not seen anybody offering to maintain it.

If you are using mediawiki on your own wiki, you can just use Mathjax and the problems are gone, Mathml unfortunately only works with firefox.

I am not familiar with the MathJax extension. You can use the SimpleMathJax extension or no extension at all. The SimpleMathJax extension is only a few lines of javascript. You could add something like https://de.wikipedia.org/wiki/Benutzer:Debenben/MathJax.js to the page MediaWiki:Common.js in your wiki if you want  and other LaTeX delimiters like math.stackexchange or scholarpedia use, otherwise just customize it according to the MathJax documentation http://docs.mathjax.org/en/latest/

After I saved your script to my Common.js it had no effect, no rendering occured. With the SimpleMathJax extension enabled and the HTML text from https://codepen.io/pkra/pen/pgOyaw (1) everything looks fine, except the first two formulas:

$$f(u_1) = f(u_0) + hf'(u_0)+{h^2\over 2!}f(u_0) + \cdots + {h^{n+1}\over (n+1)!}f^{(n+1)}(u_0) + o(h^{n+1}).$$

$$f(u) = f'(u) = f(u) = \cdots = f^{(n)}(u) = 0;\quad f^{(n+1)}(u) \ne 0.$$

(1) Note. I had to add $wgSmjInlineMath = [ ["$","$"] ]; to LocalSettings.php, as well as to remove from the HTML text the whitespaces before any$\$.

Reply to "How to use chinese letters within a formula?"