Extension:LaTeXSVG

From MediaWiki.org
Jump to: navigation, search
Information icon.svg

The LaTeXSVG rendering class for MediaWiki will only work for MediaWiki installations up to version 1.17. As of MediaWiki 1.18, the math rendering capability has been outsourced. Changes are necessary in order to get LaTeXSVG to work in MediaWiki versions ≥ 1.18.

It could take a couple of minutes to get LaTeXSVG even to work in newer versions — or a couple of hours; I don't know. In lack of time I decided to mark LaTeXSVG as obsolete from now on, even not least because a modern, cross-browser compatible, performant, feature-rich and easy-to-integrate mathematics/LaTeX JavaScript display engine exists with MathJax, which can be easily integrated into MediaWiki.

MediaWiki extensions manual - list
Crystal Clear action run.png
LaTeXSVG

Release status: beta

LaTeXSVG.svg
Implementation Media
Description LaTeX to SVG and PNG rendering class
Author(s) B.Eng. René Schwarz
Last version 1.0 (2011/02/11)
MediaWiki 1.16-1.17
PHP 5+
License Creative Commons BY-SA 3.0 Germany
Download http://downloads.rene-schwarz.com/dc/file/18
Example here

Check usage (experimental)

Contents

[edit] Purpose

This file is a replacement for the original Math.php of MediaWiki, which enables MediaWiki to render LaTeX expressions to SVG and PNG images, which are embedded into the page (SVG as first option, PNG as a fallback for browsers aren't supporting SVG yet). LaTeXSVG is intended for the use on Windows operating systems, but should even work on Linux and possibly other OS (I haven't tried it).


[edit] Usage

Just type your math as usual, e.g. <math>x + y = 1</math>.


[edit] Download instructions

The LaTeXSVG class for MediaWiki is available for download here.


[edit] Installation procedure

[edit] Requirements

LaTeXSVG uses some tools to render LaTeX formulas and to convert them into SVG and PNG images. At the moment this mass of tools is needed, because SVG support is experimental or yet not implemented by the most tools. Anyway, to get LaTeXSVG work you will need the following software installed on your server:


[edit] Installation

  1. Download LaTeXSVG from here (the file is named Math.php).
  2. Rename the original Math.php in your MediaWiki installation (e.g. c:\path\to\mediawiki\includes\Math.php) to Math.php.orig.
  3. Move the downloaded Math.php to this directory.
  4. Download pdfcrop.pl to the temporary directory for math rendering (e.g. c:\path\to\mediawiki\images\temp).
  5. Configure LaTeXSVG.


[edit] Configuration

Open Math.php in a text editor (e.g. Notepad++) and look for these lines:


class LaTeXSVG
{
    # *******************************************************************************
    #                                   CONFIG
    # *******************************************************************************
    
    /// relative URL to math directory (public on the webserver; w/o trailing slash)
    private $_http_path =       'http://www.yourwiki.com/images/math';
    /// file system path to the $IP/images/math dir (without trailing slash)
    private $_mathdir =         'C:/path/to/your/wiki/images/math';
    /// file system path to a temp dir (without trailing slash)
    private $_tmpdir =          'C:/path/to/your/wiki/images/tmp';
    /// file system path to pdflatex.exe (MikTeX)
    private $_path_pdflatex =   'C:/path/to/MiKTeX28/miktex/bin/pdflatex.exe';
    /// file system path to perl.exe
    private $_path_perl =       'C:/path/to/Perl64/bin/perl.exe';
    /// file system path to gswin32c.exe (Ghostscript)
    private $_path_gs =         'C:/path/to/gs/gs8.70/bin/gswin32c.exe';
 
    /// max length of LaTeX formula (number of chars)
    private $_max_length =      4000;
 
    /// max width of generated PNG/SVG (pixel)
    private $_max_width =       900;
 
    /// max height of generated PNG/SVG (pixel)
    private $_max_height =      300;
 
    /// not allowed LaTeX tags in formula
    private $_latex_tags_blacklist = array(
        "include","def","command","loop","repeat","open","toks","output","input",
        "catcode","^^",
        "\\every","\\errhelp","\\errorstopmode","\\scrollmode","\\nonstopmode","\\batchmode",
        "\\read","\\write","csname","\\newhelp","\\uppercase", "\\lowercase","\\relax","\\aftergroup",
        "\\afterassignment","\\expandafter","\\noexpand","\\special"
        );
 
    /// LaTeX header
    private $_latex_header =    "\\documentclass[10pt,a4paper]{scrreprt}\\n\\usepackage{amssymb,amsmath}
                                 \\usepackage[latin1]{inputenc}";
 
 
 
    # *******************************************************************************


Change the upper lines to match your file system. Parameters in the bottom lines are optional and can be used to customize LaTeXSVG. You can find the explanation for the particular parameters inline.

If everything is fine with the installation, you can now render a LaTeX expression in your MediaWiki installation (e.g. <math>x+y=1</math>) without any errors.


[edit] Difference of SVG and PNG formula rendering

Some time ago I tried to print a page with LaTeX formulas of Wikipedia. The result was really ugly, because all LaTeX expressions in the MediaWiki software will be rendered to PNG images by default. Due to the nature of rasterized images, all scalings generate artifacts („Jaggies“). So a solution would be a vector image of the formulas.

Vector images in HTML is a hot topic today, because rasterized image file types (e.g. png, gif, jpg) are the most common in the web caused by the lack of browser support of vector images. SVG (Scalable Vector Graphics) are a really good thing, which is currently being implemented in all major browsers.

So I had the wish to render math within the MediaWiki software to an SVG image instead of an PNG image. Because all SVG implementations in the major browsers are experimental, a fallback solution is neccessary.

I have written a replacement for the original Math.php of MediaWiki, which works on Windows servers (I think it should even work on Linux systems, but at the moment I have no time to verify that), called the LaTeXSVG class. This class enables MediaWiki to render LaTeX formulas both to an PNG and an SVG image. This class automatically generates HTML code for the embedding of the SVG image with the fallback solution of an PNG image within a page.

You can compare an original rendered formula and the result of this MediaWiki modification on my website (here it is not allowed to embed objects in raw HTML for security purposes).


[edit] Bugs & Feedback

Feedback and bug reports are ever welcome at this page.


[edit] License

I distribute LaTeXSVG under the terms of the Creative Commons - Attribution-Share Alike 3.0 Germany License.

Personal tools
Namespaces

Variants
Actions
Navigation
Support
Download
Development
Communication
Print/export
Toolbox