LaTeX on a shared host

It is possible to run LaTeX under a shared host. It might not be beautiful, but it works. If you wish to do this, be aware that this is not an official hack.

Mediawiki versions after 1.18

Find a LaTeX engine

• Download Extension:Math and place the files in extensions/Math
• Add the following line to your LocalSetting.php:
require_once("$IP/extensions/Math/Math.php");  If you have CGI support on your host do the code changes described below, then set the server running the mathtex or mimetex cgi script by setting in LocalSettings.php: $wgTrustedMathMimetexUrl = 'http://localhost/cgi-bin/mimetex.cgi?';


If you don't have CGI support on your host do the code changes described below, then set the server running the mathtex or mimetex cgi script by setting in LocalSettings.php:

$wgTrustedMathMimetexUrl = 'http://www.forkosh.com/mathtex.cgi';  or $wgTrustedMathMimetexUrl =  'http://www.forkosh.com/mimetex.cgi';


MediaWiki 1.20

On MediaWiki 1.20 and shared hosting:

• Add the following line to the function renderMath in the file extensions\Math\MathRenderer.php:[note 1]
...


The function then looks as follows:

...


Not sure what those "..." are supposed to mean. Regardless, it looks like there's recently been a complete overhaul of the code. It still doesn't respect the $wgTrustedMathMimetexUrl parameter in LocalSettings.php though, which makes it kinda useless. I just checked out the "origin/REL1_20" branch so that I could implement the changes listed below in the MediaWiki 1.19 section. I have this working with MediaWiki 1.21.2, though really, I don't know how long this downgrade trick will work. $ cd extensions
$git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/Math.git$ cd Math
$git checkout origin/REL1_20  At that point you can implement the familiar change in the MediaWiki 1.19 section below. Aspensmonster (talk) 05:41, 15 September 2013 (UTC) MediaWiki 1.19 • Add the following line to the function renderMath in the file extensions\Math\Math.body.php: return '<img class="tex" src="http://www.forkosh.com/mathtex.cgi?' . rawurlencode($tex) . '" alt="LaTeX: ' . htmlspecialchars($tex) . '">';  The function then looks as follows: public static function renderMath($tex, $params = array(), ParserOptions$parserOptions = null ) {
if( trim( $tex ) == "" ) { return ""; } return '<img class="tex" src="http://www.forkosh.com/mathtex.cgi?' . rawurlencode($tex) . '" alt="LaTeX: ' . htmlspecialchars($tex) . '">';$math = new MathRenderer( $tex,$params );
if ( $parserOptions ) {$math->setOutputMode( $parserOptions->getMath() ); } return$math->render();
}

This has been successfully tested on 1.19.2 - Stefahn (talk) 23:24, 4 December 2012 (UTC)
This has been successfully tested on 1.20.2 - --Tosfos (talk) 23:54, 13 December 2012 (UTC)
1.19 works on MediaWiki 1.20.3, with either of the external servers. - --Rob Kam (talk) 10:40, 8 April 2013 (UTC)

MediaWiki 1.18

In MediaWiki 1.18 there is no more script incl/Math (see below). Install Mediawiki:Math Extension separately. Math.php is present in extensions/math/math.body.php. Replace the function renderMath here (see below) and it works.

Older than 1.18 MediaWiki

Open Math.php in $WikiPath/includes/Math.php (or Math.body.php) and find this function (at the bottom): public static function renderMath($tex, $params=array() ) { global$wgUser;
$math = new MathRenderer($tex, $params );$math->setOutputMode( $wgUser->getOption('math')); return$math->render();
}


Add this line after the first line:

return '<img class="tex" src="http://www.example.com/cgi-bin/mimetex.cgi?' . rawurlencode($tex) . '" alt="LaTeX: ' . htmlspecialchars($tex) . '">';


Result:

public static function renderMath( $tex,$params=array() ) {
return '<img class="tex" src="http://www.example.com/cgi-bin/mimetex.cgi?' . rawurlencode($tex) . '" alt="LaTeX: ' . htmlspecialchars($tex) . '">';
global $wgUser;$math = new MathRenderer( $tex,$params );
$math->setOutputMode($wgUser->getOption('math'));
return $math->render(); }  Where http://www.example.com/cgi-bin/mimetex.cgi? is the URL of your mimeTeX installation or the public one. Then enable TeX in LocalSettings.php Remember this is not official, and may not work with some versions. I've tried version 1.5.5. Also working on version 1.5.6 --80.62.185.50 00:03, 7 February 2006 (UTC) Work fine on Mediawiki 1.6.3 --82.50.10.47 12:23, 17 April 2006 (UTC) Commented out all existing lines of renderMath.$math and \$wgUser are obviously not used in the patched version. This change has not been tested. See page history for old version. --Archimerged 02:58, 27 May 2006 (UTC)
Tried on MediaWiki 1.12 and it does not work. Do you have a patch?
Works on my 1.12. I used the external mimetex server, cose I have problems with my cgi-bin.
Working on version 1.13.1 with external mathtex server.
Working on version 1.14 with external mathtex server.
Working on version 1.15.1 with external mathtex server.
Working on version 1.16.0, :) thanks alot for this great help
Working on version 1.17.0, using mathtex server and this fix