Giter Site home page Giter Site logo

jmnote / simplemathjax Goto Github PK

View Code? Open in Web Editor NEW
31.0 4.0 22.0 22.58 MB

MediaWiki Extension SimpleMathJax

Home Page: https://www.mediawiki.org/wiki/Extension:SimpleMathJax

License: MIT License

PHP 34.53% JavaScript 65.47%
mediawiki-extension mathjax

simplemathjax's Introduction

The SimpleMathJax extension enables MathJax, a Javascript library, for typesetting TeX formula in MediaWiki inside math environments.

https://www.mediawiki.org/wiki/Extension:SimpleMathJax

Installation

  • git clone in extensions directory
  • Using CDN is recommended. Because it's much faster than using local resources in most cases. ("the benefits of using a CDN")
$ git clone https://github.com/jmnote/SimpleMathJax.git
  • (Optional) If you want to use not CDN but local mathjax scripts, you can use git clone recursive.
$ git clone --recursive https://github.com/jmnote/SimpleMathJax.git
  • LocalSettings.php
wfLoadExtension( 'SimpleMathJax' );

Optional Settings

Setting name Description default value custom value example
$wgSmjUseCdn use CDN or local scripts true false
$wgSmjUseChem enable chem tag true false
$wgSmjEnableMenu MathJax.options.enableMenu true false
$wgSmjDisplayMath MathJax.tex.displayMath [] [['$$','$$'],['\[','\]']]
$wgSmjExtraInlineMath MathJax.tex.inlineMath [] [['\(', '\)']]
$wgSmjScale MathJax.chtml.scale 1 1.5
$wgSmjDisplayAlign MathJax.chtml.displayAlign center left
$wgSmjWrapDisplaystyle wrap with displaystyle true false

If you want to change font size, set $wgSmjScale.

wfLoadExtension( 'SimpleMathJax' );
$wgSmjScale = 1.5;

If you want to use local module, set $wgSmjUseCdn.

wfLoadExtension( 'SimpleMathJax' );
$wgSmjUseCdn = false;

If you want to enable some extra inlineMath symbol pairs, set $wgSmjExtraInlineMath.

wfLoadExtension( 'SimpleMathJax' );
$wgSmjExtraInlineMath = [["$","$"],["\\(","\\)"]];

If you want to disable MathJax context menu, set $wgSmjEnableMenu.

wfLoadExtension( 'SimpleMathJax' );
$wgSmjEnableMenu = false;

Hooks

The hook SimpleMathJaxAttributes is available to add attributes to the span around the math. This hook provides you with the opportunity to ensure that your own code does not interfere with MathJax's rendering of math.

For instance, if Lingo's JS functions are called before MathJax is invoked, then it is possible that Lingo will change the text so that MathJax could no longer render the math.

Lingo understands that it should not touch anything inside an element with the class noglossary so the following code can be used to keep Lingo from ruining math:

$wfHook['SimpleMathJaxAttributes']
	= function ( array &attributes, string $tex ) {
		$attributes['class'] = 'noglossary';
	}

simplemathjax's People

Contributors

adnn avatar badshah400 avatar cubercsl avatar guyru avatar hexmode avatar jamesmontalvo3 avatar jmnote avatar liberaldev avatar nikerabbit avatar poiega avatar rickselby avatar v-gar avatar vedmaka avatar yardenac avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

simplemathjax's Issues

dollar sign is not available

  1. 한국인이신 것 같아 한국어로 먼저 질문해봅니다.
    원래 MathJax로 $ x^2 + y^2 = z^2 $와 같은 수식을 쓸 수 있는 것으로 아는데,
    테스트해본 결과 그게 되지 않아서 태그로 감싸고 있습니다.
    이것이 약간 불편하다고 생각해서, 이 이슈를 해결해주실 수 있는지 궁금합니다.
  2. If you are NOT Korean, ignore the first paragraph; I just think that you use my mother tongue.
    I thought that MathJax supports dollar sign expression like $ x^2 + y^2 = z^2 $,
    but it did not work and I'm wrapping all expressions with tag.
    I think it is a little uncomfortable, so I ask you that you can solve this issue.

Problem with numeration of formulas

Thanks a lot for your extension! It works great, but there is a problem with numeration of formulas.
I use Mediawiki 1.31.1. I tried to set a number of the formula and wrote this code:

\begin{equation} t^n-1\ge{n\cdot(t-1)}. \end{equation}

But number was absent. I have found the cause. The extension uses tags "math" for inlineMath. But there are no tags for displayMath. So I added additional tags (dmath) for displayed equations.

I added new variable (SmjDisplayMath) to extension.json:

"config": {
"SmjSize": 100,
"SmjUseCDN": true,
"SmjUseChem": true,
"SmjInlineMath": [],
"SmjDisplayMath": []
},

Then I changed SimpleMathJax_body.php. I wrote some code for new parameter SmjDisplayMath.

public static function setup( Parser $parser ) {
global $wgOut, $wgSmjUseCDN, $wgSmjSize, $wgSmjUseChem, $wgSmjInlineMath, $wgSmjDisplayMath;

  $wgOut->addModules( $wgSmjUseCDN ? 'ext.SmjCDN' : 'ext.SmjLocal' );
  $wgOut->addJsConfigVars( 'wgSmjSize', $wgSmjSize );
  $wgOut->addJsConfigVars( 'wgSmjUseChem', $wgSmjUseChem );
  $wgSmjInlineMath[] = ["[math]","[/math]"];
  $wgSmjDisplayMath[] = ["[dmath]","[/dmath]"];
  $wgOut->addJsConfigVars( 'wgSmjInlineMath', $wgSmjInlineMath );
  $wgOut->addJsConfigVars( 'wgSmjDisplayMath', $wgSmjDisplayMath );
  $parser->setHook( 'math', __CLASS__ . '::renderMath' );
  $parser->setHook( 'dmath', __CLASS__ . '::renderDMath' );
  if( $wgSmjUseChem ) $parser->setHook( 'chem', __CLASS__ . '::renderChem' );

}
public static function renderDMath($tex, array $args, Parser $parser, PPFrame $frame ) {
$tex = str_replace('>', ';', $tex);
$tex = str_replace('<', '\lt ', $tex);
$tex = str_replace('>', '\gt ', $tex);
return self::renderDTex($tex, $parser);
}
private static function renderDTex($tex, $parser) {
return ["[dmath]${tex}[/dmath]", 'markerType'=>'nowiki'];
}

And in the file ext.SmjCDN.js I changed several lines:

tex2jax: { displayMath: mw.config.get('wgSmjDisplayMath'),
inlineMath: mw.config.get('wgSmjInlineMath') }
MathJax.Hub.Queue(function() {
$(".MathJax").parent().css('opacity',1);
$(".MathJax_Display").parent().css('opacity',1);
});
MathJax.Hub.Config({ TeX: { equationNumbers: {autoNumber: "AMS"} } });

This code worked correctly. But I am not a programmer, so my code is not optimal. I think my code is terrible from a programmer's point of view :) May be you can add new tag to the code of your extension? I think that new tag is useful for displaying math.

Use of ParserOutput::addModules with non-array argument was deprecated in MediaWiki 1.38

We recently upgrade from Mediawiki 1.37 to 1.38. SimpleMathJax is causing an issue in ParserOutput extension:

Deprecated: Use of ParserOutput::addModules with non-array argument was deprecated in MediaWiki 1.38.
[Called from SimpleMathJaxHooks::renderTex in /var/www/html/w/extensions/SimpleMathJax/SimpleMathJaxHooks.php
at line 34] in /var/www/html/w/includes/debug/MWDebug.php on line 377

This seems to fix it:

# git diff
diff --git a/SimpleMathJaxHooks.php b/SimpleMathJaxHooks.php
index 71cc9488..e794a508
--- a/SimpleMathJaxHooks.php
+++ b/SimpleMathJaxHooks.php
@@ -31,8 +31,8 @@ class SimpleMathJaxHooks {
        }

        private static function renderTex($tex, $parser) {
-               $parser->getOutput()->addModules( 'ext.SimpleMathJax' );
-               $parser->getOutput()->addModules( 'ext.SimpleMathJax.mobile' ); // For MobileFrontend
+               $parser->getOutput()->addModules( [ 'ext.SimpleMathJax' ] );
+               $parser->getOutput()->addModules( [ 'ext.SimpleMathJax.mobile' ] ); // For MobileFrontend
                $attributes = [ "style" => "opacity:.5" ];
                Hooks::run( "SimpleMathJaxAttributes", [ &$attributes, $tex ] );
                $element = Html::Element( "span", $attributes, "[math]{$tex}[/math]" );

Here's the issue on our wiki:

parser-output-mw-138

How to typeset in display instead of inline style

I've got SimpleMathJax running on an internal wiki, and typesetting an equation via

:<math>
  \frac{\partial^2}{\partial t^2} \nabla \cdot \mathbf{E} = 4 \pi \frac{\partial}{\partial t} \nabla \cdot \mathbf{J}
</math>

sets the equation on the page in inline mode inline mode (you can tell by the relatively small derivative symbols). Is there a convenient way to set it in LaTeX's display style instead?

Extension incompatible with Firefox Native MathML add-on

I am trying to load a set of formulas on https://www.rieselprime.de/ziki/Math_rendering, which uses this package. It loads fine with the base browser configuration (Kubuntu 19.10, Firefox 78), but when loaded using Firefox's Native MathML add-on, it only displays TeX within [math] tags. For example, the first row in the large table reads [math]\dot{a}, \ddot{a}, \acute{a}, \grave{a}[/math]. The Math MediaWiki extension does not have this problem.

Support of Mathjax 2

Thanks for your extension, it worked fine (I used SimpleMathjax 0.7.4), but some errors have appeared in MW 1.36:

Deprecated: Registering handler for ParserFirstCallInit before MediaWiki bootstrap complete was deprecated in MediaWiki 1.35 [Called from SimpleMathJax::onRegistration in ...\extensions\SimpleMathJax\SimpleMathJax_body.php at line 6] in ...\includes\debug\MWDebug.php on line 376

I tried to install new version 0.8.2, but there is a problem: new version of SimpleMathjax works only with mathjax 3. Mathjax 3 doesn't support some commands (for example the line break(\) is not work).

Is it possible to integrate support of Mathjax 2 in SimpleMathjax 0.8.2? Or may be make some changes in SimpleMathjax 0.7.4 for compatability with MW 1.36?

P.S. I found one issue with local version of Mathjax. I tried to set $wgSmjUseCDN = false; in the LocalSettings.php, but MathJax still loaded from CDN. I changed string №128 in ext.SimpleMathJax.js and MathJax became loading from local copy.

I changed script.src = mw.config.get('wgSmjUseCdn') toscript.src = mw.config.get('wgSmjUseCDN').

Resolved

This was resolved as this:

     $tex = str_replace('\lang', '\langle ', $tex);
     $tex = str_replace('\rang', '\rangle ', $tex);

inside renderMath() of SimpleMathJax_body.php. This ticket can be closed

Does not seem to load with MinervaNeue on 1.36.1

I am using 0.8.2 on MW 1.36.1 with MobileFrontend 2.3.0 (f78273c) and MinervaNeue (20711d8) from May 28th 2021. On pages rendered with MinervaNeue the JS is not included at all and the expressions are not rendered.

Prior to this I used 0.7.4 with 1.35.2 which worked fine.

compatibility with wikipedia

Hello,

I've move to the new version of SimpleMathJax (from Oct 18, 2020). It works. As for the previous version, there are some compatibility issues for parsing words-like \N, \R \Mu etc. which are very common in wikipedia. Here is an example https://handwiki.org/wiki/Closure%20operator (red capital N is not parsed)

One solution is to add the following lines:

           $tex = str_replace('\Mu', '\mu', $tex);
            $tex = str_replace('\Q ', '\mathbb{Q} ', $tex);
            $tex = str_replace('\Z ', '\mathbb{Z} ', $tex);
            $tex = str_replace('\0 ', '\mathbb{0} ', $tex);
            $tex = str_replace('\A ', '\mathbb{A} ', $tex);
            $tex = str_replace('\R ', '\mathbb{R} ', $tex);
            $tex = str_replace('\C ', '\mathbb{C} ', $tex);
            $tex = str_replace('\S ', '\mathbb{S} ', $tex);
            $tex = str_replace('\R ', '\mathbb{R} ', $tex);
            $tex = str_replace('\Beta', '\mathbf{B}', $tex);

to renderMath() function, but it is not very elegant since it requires space after the tag (without it, it will corrupt other latex keys). Unfortunately, spaces after \A \C are not common in Wikipedia. It would be useful to add some method to parse such symbols.

Undefined control sequence

I am getting the following error message "Undefined control sequence" for the following:

\geqslant
\leqslant
\because
\varpropto
\therefore
\implies
\impliedby

I am not sure if this is something I am doing wrong?
I am currently using SimpleMathJax v. 0.73 on MediaWiki 1.31
I have successfully used these terms in the past with the 2015 versions on MediaWiki 1.28

Problem with SimpleMathJax rendering on Firefox

Hello!

I've just installed SimpleMathJax and tested it by inserting: <math>E=mc^2</math>

On Chrome (OSX) it renders correctly.

However, on firefox (OSX) it displays the formula three times: pic

The second two renditions seem to be one font size smaller than the first.

Is there any way to fix this?

π

Missing features/ compartibility problem

Hi,
SimpleMathJax is a great tool. We use it for the math encyclopedia called HandWiki, replacing the server-side math parsing with the client-side "SimpleMathJax". We see some pages where SimpleMathJax failed to parse equations. For example, this page imported from Wikipedia:

https://handwiki.org/wiki/Kalman_filter

has a few yellow boxes "Missing argument for \mathbf". Is it possible to fix this?
There are more problematic pages with equations like this that indicate that SimpleMathJax is 100% replacement for what is used by Wikipedia. But we are not sure how automatically catch such pages with SimpleMathJax parsing problems.

un-rendered [math] block remains visible after editing page with VisualEditor

When using VisualEditor to render the page, the math block's rendering is changed to
image

This is fine, since VE provides the user with a dialog to edit the math if they click on the box.

After saving the page, whether the math is changed or not, the un-rendered grey box of TeX-formatted math remains.

SimpleMathJax should use whatever methods it can (I imagine there is a VE hook somewhere) to re-render the math after a page save.

SimpleMathJax does not render in Firefox at times

This is kind of unusual and it may be related to another component in our stack. My apologies in advance if that is the case.

The Crypto++ wiki uses SimpleMathJax for math markup on occasion. As an example, here is our Elliptic Curve Digital Signature Algorithm page:

wiki-1

Now here is the weird thing... IF I click the Page tab or the Read tab, then the math symbols go missing. IF I click the Reload button then the math symbols appear again. Below, the tabs are highlighted in blue, the missing symbols are highlighted in red, and the reload is highlighted in green.

wiki-2

When the math symbols fail to render it looks like the HTML is present:

wiki-3

Our stack includes a CentOS 7 Virtual Machine from GoDaddy. The MediaWiki information can be found at Special:Version, and it includes MW 1.30, PHP 7.1 and MySQL 5.5. I keep everything fully patched (the best I can).

The browser is configured to send Do Not Track with requests, and it does not accept third party cookies. This may happen on other platforms like Linux and other browsers like Chrome. I don't use browsers like IE or Chrome so I can't say for sure.

I'm not sure where to begin to troubleshoot the issue. If there is a mailing list to discuss issues, then please point it out. I don't like polluting issue trackers with opening discussions of problems.

Any help in learning the cause of the problem would be appreciated.


I think we ruled out the EFF's HTTPS Everywhere at Issue 14654, mathjax.org may need ruleset updated.

new keyword

Suggest to add

T: "{\mathbb{T}}",

in resources/ext.SimpleMathJax.js to make it consistent with Wikipedia (it was checked on HandwIki)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.