jsmath plugin

jsmath plugin by Stephen Gould
Plugin for displaying LaTeX equations using jsMath

Last updated on 2010-01-20. Provides Syntax.
Compatible with DokuWiki 2009-02-14.

Similar to asciimath, asciimathml, format, latex, math, math2.

Tagged with formula, latex, math.

Download

For convenience, the plugin is available in two different archive formats.

Download plugin-jsmath.tar plugin-jsmath.zip

Advantages

  • Use LaTeX syntax without the need to have LaTeX installed (both client and server).
  • The rendering is done automatically by a JavaScript library that just has to be uploaded to the server.
  • The client does not need to install anything since there is a quite nice picture font available.
  • If the client installs the LaTeX fonts, the client's browser can display math formulas in the high-quality fonts also used by LaTeX.
  • If you enable the optional $x^i$ syntax, you can write inline math as if you were in LaTeX.
  • You can alternatively also use the \[x^i\] syntax to enter block math formulas.

Installation

Step 1: jsMath Library

jsMath is a JavaScript library that renders LaTeX in your browser and is required by the jsmath plugin for DokuWiki. Follow the installation instructions. In short:

  1. Download jsMath and extract the zip-file to a directory on your webspace.
  2. Optionally download the jsMath Image Fonts and extract the zip-file to the same directory.
  3. Optionally install the TeX fonts for jsMath on your local machine.

Step 2: jsmath Plugin

  1. Install the jsmath plugin for DokuWiki using the plugin manager as usual.
  2. Go to the DokuWiki Configuration Settings page (available in the admin menu) and set the full URL to your jsMath installation. This is the directory to which you installed the JavaScript library in Step 1.
  3. Optionally disable the dollar syntax (e.g. if you use dollars as currency symbols).

NOTE: When trying to display latex formulas for the first time, make sure to clear the browser cache. In Firefox, just press 'Ctrl-Shift-R'. Otherwise you'll get frustrated thinking the install didn't go through. Also try adding somewhere in your latex test page this:

~~NOCACHE~~

Usage

Once jsmath and jsMath are correctly installed, you can embed LaTeX code into your document.

Block Formulas

This will display an equation in block format, on its own line:

<jsmath>\lim_{n\to\infty}\sum_{i=1}^{n} \frac{1}{i}=\infty</jsmath>

Alternatively, the square bracket syntax is completely equivalent:

\[\lim_{n\to\infty}\sum_{i=1}^{n} \frac{1}{i}=\infty\]

Inline Formulas

The following example will cause jmath to display the formula inline:

<jsm>\lim_{n\to\infty}\sum_{i=1}^{n} \frac{1}{i}</jsm>

Alternatively, the dollar syntax is completely equivalent:

$\lim_{n\to\infty}\sum_{i=1}^{n} \frac{1}{i}$

Development

If you want to contribute to this plugin, go to the project page of this plugin and contact Holger.

Discussion

Please report your issues to the issue tracker.

Unresolved Issues

Conflict with asciisvg plugin

Hi,

When asciisvg is installed, jsmath does not work anymore.

Any workaround? Thanks.

Answer: Please report details to the issue tracker. – Holger.

New line issue

Issue 1

Hello, I recently switched to jsmath plugin (first I had an hack for that). I've noticed that in array environment the new line command (double backslash) is interpreted by DokuWiki and not by jsmath plugin, causing a new line in the source code rather than in the array environment.

Is there anybody else with the same issue?

Thank you, Emanuele

ANSWER: Hi Emanuele, I saw the same thing; if you escape your backslashes, it should work, a la: \\\\

Update: I forgot, also other DokuWiki commands are overwritten before the code is passed to jsmath plugin. In example, with this code

  \sigma(c)

I get a copyright symbol in the formula.

I opened a bug ticket in the project page.

Resolved Issues

Error in code (line 8 of install_js.php)

I'm not entirely sure where to report this but I thought here might be easiest. I couldn't get jsMath to work for quite awhile and kept getting an index not defined error. The problem comes in line 8 of install_js.php which reads

  $jsMathURL = $conf['jsmath'];

when it should really read

  $jsMathURL = $conf['jsMath_url'];

This solved the problem. -Marc

Answer: Thanks for reporting that bug, it's fixed now. –Holger.

jsMath does not work :( in my installation

Hi all,
jsMath sample page works fine, but not in my DokuWiki installation.

test page: http://research.andrefranz.de/doku.php?id=test
jsMath URL: http://research.andrefranz.de/jsMath/

2009/11/24 10:05

Answer: There is a new version of the plugin available, which fixes the problem.

jsmath has no effect in my DokuWiki installation

Hi all, I installed the jsMath library on my web server, and I can see that it works (I can execute the test cases in jsMath's test/ directory). I've installed the jsmath DokuWiki plugin, and I have configured the URL to the jsMath installation in the JsMath section of the configuration settings.

The result… nothing. Math formulas such as

<jsmath>\lim_{n\to\infty}\sum_{i=1}^{n} \frac{1}{i}=\infty</jsmath>

are inlined, and not displayed properly. There is no error message in the Apache log. It's as if the jsmath plugin had not been installed.

Does anybody have an idea how to fix this? Thanks in advance!

Answer: It should work now. – Holger.

Hi. I have the same problem. I have installed XAMPP in my server.

if I write:

<jsmath>\lim_{n\to\infty}\sum_{i=1}^{n} \frac{1}{i}=\infty</jsmath>

The result is:

\lim_{n\to\infty}\sum_{i=1}^{n} \frac{1}{i}=\infty

2009/12/01 12:01

Answer: I ran into the same issue. You have to install the jsMath Image Fonts as noted on the jsMath download page :!:

Hi guys. I also tried to install the latest version jsMath3.6 and jsMath Image Fonts 1.3, I put the fonts to the directory and the whole stuff seems to work, but I am unable to make it work like the posted. I also get the same result like indicated above, and after the HTML page in DokuWiki is generated I even don't see that the jsMath JavaScript was included or called. In Internet Explorer I get the following error:

Details zum Fehler auf der Webseite

Benutzer-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.0.3705; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)
Zeitstempel: Wed, 2 Dec 2009 10:56:00 UTC


Meldung: Syntaxfehler
Zeile: 1
Zeichen: 1
Code: 0
URI: http://server/dokuwiki/lib/plugins/jsmath/install_js.php

Does anybody have an idea how could I solve this problem?

Unable to get this working

Hello, I installed the jsMath library on my local DokuWiki installation. I followed this up with the jsmath plugin installation. I updated the URL in the configuration settings also. However, when I try something simple as well - it is not being rendered by jsmath. Locations to which I have installed are as follows :

Directory where jsMath is installed : /Users/vikasm/Sites/dokuwiki/lib/jsMath
URL specified on the configuration page : file:///Users/vikasm/Sites/dokuwiki/lib/jsMath
jsMath library version : 3.6b
jsmath plugin version : 2009-03-31

Error message seen in the Apache logs is as follows :

[Sun Jun 14 08:13:37 2009] [error] [client ::1] PHP Notice: Undefined index: jsmath in /Users/vikasm/Sites/dokuwiki/lib/plugins/jsmath/install_js.php on line 8, referer: http://localhost/~vikasm/dokuwiki/doku.php?id=start&do=show

Could you let me know what I am doing wrong ?

Regards, Vikas

ANSWER You're not doing anything wrong, the error lies on line 8 of your /Users/vikasm/Sites/dokuwiki/lib/plugins/jsmath/install_js.php, where a conf/default.php is referenced; you might either want to comment out lines 7-8 of that file, as so:

/* require('conf/default.php'); $jsMathURL = $conf['jsmath']; */

or replace conf/default.php with ../../../conf/default.php, if you have that file. I solved my problem by entering the path to jsMath in DokuWiki control panel and then commenting out those lines.

Regards, Emanuele Cipolla

Answer2: I replaced 'require' by 'include'. There should not be an error anymore. – Holger.

path to jsMath?

Hello, I cannot find the place in DokuWiki Configuration Settings page to set the full URL to the jsMath installation. Only the dollar sign option shows up.

thanks for the good job!

ANSWER Please make sure that you have the most recent version installed (at least version 2009-03-06). – Holger

A solution to the «jsMath installed but plugin not working» issue

On January 17th 2010, DokuWiki 2009-12-25b “Lemming” :
I installed jsMath (V 3.6c) and jsMath-fonts (Version 1.3), jsMath/test is working. I install and configure the jsmath DokuWiki plugin and… jsmath does not work in the DokuWiki page :-( I just see \lim_{n\to\infty}\sum_{i=1}^{n} \frac{1}{i}=\infty

jsMath/test loads plugins/noImageFonts.js before jsMath.js. I did the same in DokuWiki jsmath plugin file install_js.php and it worked. Don't know if I did something evil though…

Here is the version I use

install_js.php
<?php
// This file reads the configuration of the jsmath plugin
// and then installs the jsMath Library on the JavaScript level.
// It is invoked from script.js
 
// First read default value
include('conf/default.php');
$jsMathURL = $conf['jsMath_url'];
// Then overwrite with actual value (if present in local.php)
include('../../../conf/local.php');
$jsMathURL = $conf['plugin']['jsmath']['jsMath_url'];
?>
 
document.write('<script type="text/javascript">jsMath = {Controls: {cookie: {scale: 120}}}</script>');
document.write('<script type="text/javascript" src="<?php echo($jsMathURL); ?>/plugins/noImageFonts.js"></script>');
document.write('<script type="text/javascript" src="<?php echo($jsMathURL); ?>/jsMath.js"></script>');
 
function installJsMath()
{
    jsMath.Process(document);
}
 
addInitEvent(installJsMath);

– Thanks, this is included in the new version 2010-01-20. I wonder why it worked for me, though. Holger.

Old Discussions

jsMath returns warnings

On DokuWiki 2008-05-05. jsMath returns warnings. It seems it has some conflicts with DokuWiki. See following:

Warning: array_merge() [function.array-merge]: Argument #2 is not an array in C:\DokuWikiStick\dokuwiki\lib\plugins\syntax.php on line 134

Warning: array_merge() [function.array-merge]: Argument #1 is not an array in C:\DokuWikiStick\dokuwiki\lib\plugins\syntax.php on line 134

Warning: array_merge() [function.array-merge]: Argument #1 is not an array in C:\DokuWikiStick\dokuwiki\lib\plugins\syntax.php on line 134
Re: jsMath returns warnings

I think this was an error in getAllowedTypes(), now fixed.

Works fine now

It works now. Thank you.

Error

Then trying to clear cache, DokuWiki return this error message:

“It looks like jsMath failed to set up properly (error code -7). I will try to keep going, but it could get ugly.”

What could be an error?

SPAN vs DIV

This really works very nicely for equations and formulae, but when I enter a pmatrix (for instance) it isn't displayed properly since it is between span tags, not div tags. I see from the render function that there is a div-tag possibility (if $match is not true), but I can't figure out how to make that happen. Can someone please tell me how to get my matrices to display correctly?

  • meanwhile 1), I have tried some more to figure it out for myself, and learned some about how syntax plugins should work. I have discovered that existing documentation may not be wrong, but it doesn't give enough good clues on how to build syntax descriptors that do more than one thing, …depending
  • Splitting the syntax.php in two parts seems to be the way to go to get the jsmath text enclosed in either div or span tags, depending…
  • Depending on what, though?
    1. A different wiki_tag : <jsm> for inline, and <jsmb> for block, for example.
    2. presence of forced linefeeds (or equationarray constructs) in the enveloped string. I've tried to add detection of
      between the <jsm> and </jsm> boundaries but my regexp to do so isn't yet correct.
    3. a simplified version of #2: <jsm>\n to open and \n<jsm> to close. This works for me, and makes some intuitive sense: LaTeX math expressions that are in-line (no cr/lf) between tags are inline , and those where the <jsm> and </jsm> tags appear on line preceding and following the expression are block in div tags in HTML.
1) this is written by me, the same me, a few days later–I'd sign in but there doesn't seem to be any way to register–call me duckedape and write to me at laposte dot net if you wish
 
plugin/jsmath.txt · Last modified: 2010/01/25 19:14 by 74.93.99.97
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Imprint Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki
WikiForumIRCBugsGitXRefTranslate