# LinuxTex

## Description

I've just adapted Cookbook-V1.LinuxTex to PmWiki v2. This is my strongified version.

## Features

- Allows references to equations
- Supports
`pmatrix`

and other environments - coming: possibility to change font size and color (ThomasP August 21, 2006, at 04:12 AM); update: color can be changed using dvipng parameters, size by introducing a parameter in the latex preamble

## See also

- Latexrender class as part of PublishPDF from wikipublisher does a similar thing (but additionally offering export to print media), see below

## Files

- linuxtexnk.phpΔ
- linuxtexrvdb.phpΔ - Additions by Rein (see below)
- linuxtexsb.phpΔ - Additions mentioned by Nils and added by Stefan (Most up to date. Use this one)

## Install

- Place the latest linuxtex file in your cookbook dir and add the
`include_once("...")`

to your config.php as usual. - Customize the paths to your latex, dvipng or _dvips and convert_ executables (see the code). (You will have to have a latex distribution installed on your server - some hints for this can be found here.)
- Last not least make sure that
`pub/cache`

exists in your wiki dir and is writable by the web server.

## Usage

From Cookbook-V1:

The script assumes that you have a /pub/img/latex/ directory the webserver user has write permissions to.

- {$ latex formula $} , for inline equations, like \( a+b \) in latex
- {% label, latex formula %} , for \begin{math} like equations, EQ(label) can be used anywhere on the page as an anchor to the equation

Put useful settings for these tags in your local.css or another appropriate place:

- span.mathRef for the anchor to the equation
- img.formulaMath for equations with label, put a dotted line arround them or something
- img.inlineMath, gues what, for inline equations
- span.eqCount, for the little number behind labeled equations

## Troubleshooting

Arised problems together with their solutions can be found here.

## Development

Once-issues that are resolved by now and have found their way into the code, and discussion about future features etc. can be found here.

## Comments

Please, when adding a comment, give the date and your name and place a horizontal separator for better readibility. Place open issues here on the page, solutions rather at this page. ThomasP August 21, 2006, at 04:46 AM

In the code it says

*EQ(label) can be used anywhere on the page as an anchor to the equation*

but this is seemingly not the case. The reference has to come after the equation for it to work.

- Matthijs Sypkens Smit

## Still to incorporate into the code:

### Allowing environments

_{A bug report: can not display matrix formulas.}

Although I has used linuxtexsb, all scripts of linuxtex may have the matrix problem. It contains two problem, 1) to translate from \begin{pmatrix} to \begin{nothing{}pmatrix} and 2) to translate from & to & ;. I resolved first problem to eliminate line 135 from linuxtexsb.php ~~ but I do not know how to resolve second problem... ~~
Second problem has resolved using "str_replace" function like Nils's method.

line 135 of linuxtexsb.php

// $tex = preg_replace('/{([^ ]+})/','{\nothing{}$1',$tex); # Obfuscate potential filenames

` $tex = str_replace('&','&',$tex); `

- Yasuto

*Environments*: As currently written, the pattern replacement that obscures filenames also prevents the use of environments in math mode, such as matrix environments and the AMS multi-equation building blocks `gathered`

, `aligned`

, and `alignedat`

. Including a negative lookbehind assertion in line 135 of linuxtexsb.php allows the use of environments:

$tex = preg_replace('/(?<!\bbegin|\bend){([^ ]+})/','{\nothing{}$1',$tex); # Obfuscate potential filenames

--nbk

### Chdir issue when having safe_mode on

I had a problem with PHP safe_mode. All of the commands are in safe_mode_exec_dir, however it still doesn't like the call exec("cd $ImgCacheDir && $latexPath work.tex"), I assume because the call to "cd" requires a shell, which is in /bin, not /usr/bin. As a workaround, I modified my local version to do $olddir=getcwd(); chdir($ImgCacheDir); exec("$latexPath work.tex"); chdir($olddir); (and the same for the other exec() calls). But this is really ugly, is there a better way?

--Ian

## See also

- Cookbook /
- AMmathjax Add markup to embed math using ASCII MATH by MathJax. (Stable)
- ASCIIMath Display MathML rendered ascii formula into PmWiki 2.x pages (Stable)
- Formula Lightweight rendering of mathematical formulas in wiki pages (Beta)
- JsMath Add markup to display and embed mathematical formulas in wiki pages using TeX. (Obsolete - use MathJax)
- LaTeXMathJax MathJax support for PmWiki (stable)
- LaTeXMathML Translating LaTeX math notation dynamically to Presentation MathML (Stable)
- LuaExecute Lets Lua scripts dynamically generate parts of your wiki page (Beta)
- MathJax Add markup to embed math using TeX syntax. (Stable)
- Mathtex Add markup to display and embed several lines of mathematical formulas in wiki pages (testing)
- MimeTeX Add markup to display and embed mathematical formulas in wiki pages (Stable)
- SageCell This allows you to embed an interactive SageCell into your webpage. Sage is an open source alternative to MathLab, Mathematica, and Maple. (Stable)
- SimpleJsMath Notes on modifying the jsMath for a skin (not a complete recipe)
- TrueLatex Enables interpretation and rendering of real LaTeX markups in PmWiki. Support for XeLaTex included in v1.8. (Working perfectly. Very simple to use, customizable and comes with lots of options.)

### Wikipublisher

Those who need to produce print versions of equation pages may like to investigate the PublishPDF library, which includes the Latexrender class library to support equation markup. For a working example, see http://www.wikipublisher.org/wiki/index.php?n=Wikipublisher.LatexEquations and click the pdf icon. It adds the following markups to pmwiki:

{$ latex equation code $} for unnumbered equations {$label, latex equation code $} for numbered equations EQ(label) to refer to a numbered equation

In print, the EQ markup finds references anywhere on the page. On the web, it only finds references above and the one immediately after the EQ. An advantage of using the latexrender library is that its authors appear to have put some effort into catching latex commands which pose a security risk.