Table of Contents

LaTeX Plugin

Compatible with DokuWiki

  • 2024-02-06 "Kaos" no
  • 2023-04-04 "Jack Jackrum" unknown
  • 2022-07-31 "Igor" unknown
  • 2020-07-29 "Hogfather" no

plugin Renders inline LaTeX code

Last updated on
2011-04-29
Provides
Syntax, Admin
Repository
Source
By Alexander Krause, Michael Boyle, Mark Lundeberg

This plugin uses LaTeX+ImageMagick to render mathematical formulae embedded within a DokuWiki page. This gives a professional look to equations, and the syntax allows almost copy-paste conversion between DokuWiki and LaTeX manuscripts. For example, you may simply type $ a + b = c $ into your wiki code and it will automatically be shown as $ a + b = c $.1)

Installation

Search and install the plugin using the Extension Manager. Refer to Plugins on how to install plugins manually.

:!: External requirements: This plugin requires the following software to be installed on the server hosting your wiki. If you do not have root access, contact your administrator.2)

:!: This plugin will not work in PHP safe mode. - unless your server administrator has specifically allowed access to the software this plugin needs.

:!: This plugin does not work with PHP 7 and disables DokuWiki (blank screen) with an entry in error.log: PHP Fatal error: Class syntax_plugin_latex_common contains 1 abstract method and mu st therefore be declared abstract or implement the remaining methods (dokuwiki\\Extension\\SyntaxPlugin::handle)

This can be fixed by adding the lines at the end of latexinc.php

function handle($match, $state, $pos, Doku_Handler $handler){
    return array();
}

See: https://github.com/fsiwi-hka/dokuwiki-plugin-latex/pull/1/commits/02507d33bccded74e60143355aad7ca683011739

Systems

Variously out-dated but quite in-depth installation instructions can be found on E-razor's wiki. You might also consult the similar instructions for math in MediaWiki (but note that DokuWiki's plugin does not need texvc, OCaml, etc.). Here is a summary

Examples

wiki code result
$ a + b = c $
<latex>\begin{algorithm}[H] \KwData{this text} \KwResult{how to write algorithm with \LaTeX2e } initialization\; \While{not at end of this document}{ read current\; \eIf{understand}{ go to next section\; current section becomes this one\; }{ go back to the beginning of current section\; } } \caption{How to write algorithms} \end{algorithm}</latex> it's not working properly!
\begin{eqnarray*} & & \frac{3}{4 \pi} \sqrt{4 \cdot x^2 12}\\ & & \lim_{n \to \infty} \sum_{k=1}^n \frac{1}{k^2} = \frac{\pi^2}{6}\\ & & {\it f}(x) = \frac{1}{\sqrt{x} x^2}\\ & & e^{i \pi} + 1 = 0\; \end{eqnarray*}
from ursoswald.ch

<latex>\setlength{\unitlength}{1mm} \begin{picture}(93,46) \put( 0,14){\vector(1,0){60}} \put(61,13){$x$} \put(20,4){\vector(0,1){37}} \put(19,43){$y$} \put(50,34){\circle*{2}} \put(52,35){$P$} \multiput(20,34)(4,0){8}{\line(1,0){2}} \put(14.5,33.5){$y_P$} \multiput(50,14)(0,4){5}{\line(0,1){2}} \put(48,11){$x_P$} \put( 2,8){\vector(3,1){56}} \put(59,26.5){$x'$} \multiput(50,34)(1.9,-5.7){2} {\line(1,-3){1.2}} \put(52,22){$x_P'$} \multiput(50,34)(-5.8,-1.933){6} {\line(-3,-1){3.6}} \put(12,21){$y_P'$} \put(22,8){\vector(-1,3){10.5}} \put(10,41){$y'$} \end{picture}</latex>

Syntax

The following syntax is recognized by the LaTeX plugin at the moment. For the most part, the recognized syntax is inserted as-is into a small LaTeX template (which can be changed in the Configuration Manager), then compiled:

Caveats

Configuration/Settings

From the Configuration Manager, you can modify the following settings:

To use your favorite LaTex packages, you need to add them using \\usepackage{…} to the default.php file located in the …\dokuwiki\lib\plugins\latex\conf folder. You can put the “use package” statements any where in the block of existing “use package” statements. After adding \\usepackage{tikz} and \\usepackage{algorithm2e}, drawings and algorithms produced using TikZ and algorithm2e, respectively, all work nicely. Some other packages should work as well.

Admin plugin

There is an admin plugin included for ease in managing the LaTeX image cache, which can easily grow to thousands of equations in size. This can be accessed through the administration actions panel.

The admin plugin also allows you to troubleshoot problems in the rendering process.

Troubleshooting

Specific issues

Development

This plugin was originally written by Alexander 'E-razor' Krause based on class.latexrender.php by Benjamin Zeiss then extended by Michael Boyle, and is now maintained on github by Mark Lundeberg.

Discussion

Local with MacTeX: LaTeX compilation failed

On OS X 10.8, I have a local and up to date DokuWiki installation, which works fine. Further, I have installed the latex plugin and a standard MacTeX (up to date) installation. LaTeX works fine when I compile the tex code provided the plugin.

Using the latex plugin in DokuWiki instead produces “LaTeX render failed” with the hint “LaTeX compilation failed”.

Could you please give me a hand for making the plugin work? Christian

Me too!! I have the same problem

As a quick and dirty fix, try putting the absolute paths (the ones that show up when you type, e.g., which latex) into the file dokuwiki/lib/plugins/latex/conf/default.php, e.g.,

Misc

Control over the Images

If the embedded images are not perfectly aligned, you can gain more control by adding 'media_latex' to the class in syntax.php lines 91 and 96. After that create an style.css with 'img.media_latex{ … }'.

I'm not sure if that applies for the current plugin (there's no syntax.php), and anyway there are already two CSS styles declared in plugins/latex/all.css : The first style img.latex_displayed is for equations on their own line such as $$ G(x) = 2 $$, which have a slight indent. The second style img.latex_inline sets vertical alignment to middle for in-line latex such as $a + b = c$. -Mark

Color settings

After installation, the default color is dark red.

How to set the default color to black:

Go to: Administration > Configuration Settings > Plugin Settings > Latex Plugin Settings > plugin-latex-preamble.

Delete the following two lines:

\definecolor{MyColour}{rgb}{0.50,0.00,0.00}
{\color{MyColour}

Click “Save”, and you're done.

Dollar Signs

Maybe a stupid question but how can I display the Dollars symbol ($) on the page ? The plugin replace all my $ by the message “Latex render failed” It's not very easy to use %%$%% !
Yes, that's an unfortunate side effect of the plugin. If you don't mind losing the $ a+b $ syntax entirely, you can delete plugins/latex/syntax/dollar.php. Another way you could consider is to add a space to dollar.php line 14, changing the trigger pattern from
$this->Lexer->addEntryPattern('\$(?=.*\$)',$mode,'plugin_latex_dollar');

to

$this->Lexer->addEntryPattern('\$ (?=.*\$)',$mode,'plugin_latex_dollar');

That way, the plugin would only activate on text like ”the sum $ a+b $“ where the $ is followed by a space, and would not activate on text like ”projected total cost of $2000“. -Mark

Well, why don't you try <nowiki>? -Di

=== mask $*Dollar*$ as in /* comment */ plugin

Instead of a space add an * to the EntryPattern and the ExitPattern in dollar.php.
1. This is a very rare combination and
2. it will work for all those languages which have a currency symbol after the ammount. E.g. in many european countries we are used to write 2.000,00$
3. It will not break all existing pages.
So change dolar.php to:
$this->Lexer->addEntryPattern('\$\*(?=.*\$)',$mode,'plugin_latex_dollar');  

and also add an * to the ExitPattern:

function postConnect() { $this->Lexer->addExitPattern('\*\$','plugin_latex_dollar'); }

The syntax will change to $* a + b = c *$ which is close to the comment-plugin Syntax (/* a comment */. And $2000, 2.000,00$ and a $ alone will work as before.
-TT, 2013-02-28

ReadOnly-Access

If i give the group @ALL an “Read”-Permission to read the page, they can access and read the normal Text…but the Latex-Image are not there! What to do?
Solved! Need to give “Read”-Permission to “wiki:latex:*”

Toolbar buttons disappear

The DokuWiki toolbar buttons were not visible anymore after installation of the Latex plug-in (Using a fresh install with QuickPHP / Firefox12 / DokuWiki Angua / default template / default settings). As a solution, I disabled and then enabled the Latex plug-in (This does not “prove” that this plug-in is the actual cause). Can anybody confirm this?

Latex syntax in tables

Generally, latex does not work in a table. For example,

|  \begin{equation*} e=mc^2 \end{equation*}  |

results in:

\begin{equation*} e = mc2 \end{equation*}
Strange, it works here!
-TT, 2013-02.28

Not rendering Latex Code

Plugin does not render any latex code in dokuwiki pages, displays only the text as if not recognizing the syntax. No images in corresponding image folder. With admin tool everything is working fine. Found no error messages or anything. Any hints?

See Latex Render Failure #9 on the GitHub page of the plugin : permission problem with ImageMagick policies. “They can be set in /etc/ImageMagick-6/policy.xml. In particular you should change the line <policy domain=“coder” rights=“none” pattern=“PS” /> to <policy domain=“coder” rights=“read” pattern=“PS” />”

Converting to PDF

There are a few plugins to convert the pages to pdf, for example:

https://www.dokuwiki.org/plugin:dw2pdf

Unfortunately I am not able to see the latex formulas in the pdf document. Anyone have any idea how to fix this or know of a dokuwiki to pdf convert that acutally works with this latex plugin?

dw2pdf does not seem to work with (some) transparent png images. Either try setting the imagetype in the laxtex config to jpg or if you want the png add -alpha remove to the convert options
-PT, 2015-02-22
An idea how to fix this (at least in Firefox, Linux of course):
add ?do=export_html to the address line of your Firefox and press Enter. Then use ctrl+p to start the print dialog. Choose print to file + pdf and voilla, there it is a pdf export with all latex parts.
-TT, 2013-02-28

Blacklist

It is mentioned above that some words are blacklisted and that the blacklist is kept “just in case”. The presence of blacklisted words causes the error “Fail: triggered security filter; contains blacklisted LaTeX tags”. Where can one find the blacklist? — krichter 2014-08-13 14:43

From class.latexrender.php

var $_latex_tags_blacklist = array(
	   "include","def","command","loop","repeat","open","toks","output","input",
	   "catcode","name","^^",
	   "\\every","\\errhelp","\\errorstopmode","\\scrollmode","\\nonstopmode","\\batchmode",
	   "\\read","\\write","csname","\\newhelp","\\uppercase", "\\lowercase","\\relax","\\aftergroup",
	   "\\afterassignment","\\expandafter","\\noexpand","\\special"
	    );

This would be my guess. — Chris_P

Blacklist

Maintained (patched) version of this plugin can be found at latex-was.

1)
vertical alignment is a bit better in practice.
2)
or consider installing the simpler MimeTeX plugin which requires no external software