Manual:Enable TeX/problems

From MediaWiki.org
Jump to: navigation, search

Many users reported problems with installation of texvc for Extension:Math.

There are 2 groups of such problems:

  • it doesn't work even from the command line
  • it does work from the command line, but not from PHP
    • So how does one fix this if it works on the command line and not in PHP (errors like: Failed to parse (unknown error):"

Command line[edit | edit source]

You need to install with PS support (ImageMagick is not nice to compile by hand, get binaries if you can) or Ghostscript, Latex, dvips (part of Latex).

If you do, check permissions.

Comment file unlinking out in render.ml to see what's going on better.

strace or equivalent utility may be useful for tracing command executions.

You need GNU make to compile texvc. On some non-Linux Unices it's under name gmake instead of make.

PHP[edit | edit source]

Check that it works from the command line. If not, see the previous section.

The environment under Apache/PHP is different that the shell. Typical problems:

  • user may be different; check permissions.
  • PATH variable may be different; use absolute paths in render.ml if you can't fix it.
  • you may be in a jail/chroot.

Error : Failed to parse (Missing texvc executable)[edit | edit source]

Failed to parse (Missing texvc executable); please see math/README to configure.)

That error is returned in response to this test:

 if( function_exists( 'is_executable' ) && !is_executable( $wgTexvc ) ) {
   return $this->_error( 'math_notexvc' );
 }

So, if you're getting the error there are a few possibilities:

  • $wgTexvc is set to the wrong path
  • the file doesn't exist
  • the file isn't executable by the web server according to permissions
  • some weird PHP restriction is preventing you from accessing the file
  • If running on Windows, you may need to install Cygwin and ensure that SH is on the PATH.

You should check into all of these possibilities.

If you are running selinux, it may be denying permission to httpd to execute the file. See the selinux section below.

Another possibility is that you wrote that wiki page before compiling texvc, and haven't rerendered any math since. Remember that page renderings are aggressively cached; run your tests in a preview and try varying texts.

Someone managed to fix it by "by uninstalling the Suse native apache, mysql, php, and mediawiki, and replacing them with xampp and mediawiki tarball.". He has no idea why it worked. Another dirty fix if you are absolutely sure things should be working and this is causing the problem, is commenting the return line and replacing it by a dummy as in

   # return $this->_error( 'math_notexvc' );
   $cmd = "foo";

which bypasses the check and goes ahead running the command.

If you are running AppArmor (Suse 10 does this by default) add texvc to the AppArmor Profile, this can most easily be done via yast2. Be sure to enable execute rights ("x") in the editor, otherwise AppArmor will block the execution of texvc. If AppArmor is blocking an application usually it is logged in /var/log/apparmor.

Error : Failed to parse (PNG conversion failed; check for correct installation of latex, dvips, gs, and convert)[edit | edit source]

This is the most severe error. It indicates, that the directories with the programs mentioned are not reachable for the texvc program. If you see these commands at command line with commands

which latex
which dvips
which gs
which convert

then, perhaps, nothing can be done: this software is not compatible with your server.

If you are running selinux, it may be preventing the parse. See the Selinux section below.

I got the same errormessage and which latex, which dvips, etc all showed that the necessary binaries where in the path. After running "fmtutil-sys --all" once on the commandline of the server (as root) it worked. So maybe you wan't to try this also.

A cause of this is that texvc cannot see a latex.fmt file. This lives in various places, possibly under ~/.texsomethingorother/web2c. Copy it into your images/tmp directory. Lord knows what's going on here but it seems to do the business.

LaTeX Error: File `cancel.sty' not found[edit | edit source]

If you see PNG conversion errors in your wiki, check the log files in images/tmp for any LaTeX errors, such as the one above. In this case, LaTeX is failing because it cannot find the file 'cancel.sty', which is missing from some texlive installations. This can be solved by installing a package named texlive-(latex-)extra, or (in Gentoo) by adding 'extra' to your USE flags when compiling texlive. Be warned that this does drag in a lot of additional packages.

(cancel.sty is provided in package texlive-cancel in openSUSE and Fedora)

Ubuntu 13.04 
apt-get install texlive-latex-extra

Error: Failed to parse (Cannot write to or create math temp directory)[edit | edit source]

This is an error I got for an installation on:

Red Hat Enterprise Linux Client release 5.6 (Tikanga)

and the MediaWiki installation was done under root permission.

The web server is trying to write latex related stuff into the images/tmp directory. The directory images/tmp is defined to be owned by the root user and root group.

The solution: change the group of the directory to the group of the web server (in my case group=apache, user=apache):

chgrp apache images/tmp

and then add the write permission for the group on this directory

chmod g+w images/tmp

I'm not sure if it is necessary, but I have restarted httpd and reloaded the wiki page.

Error: math_output_error[edit | edit source]

This problem is related with the previous (Failed to parse). For mediawiki ver. 1.20, the solution was to set the correct permissions so that the web server can create directories below the images directory. One solution is to create the directory images/math and set the permissions:

chown www-data images/math

chgrp www-data images/math

(Replace www-data with what your web server uses if needed)

safe_mode[edit | edit source]

If you use PHP safe_mode, you will have to patch includes/Math.php and use a wrapper script for texvc.

For more details, see: http://xylofaan.ulyssis.org/patch/mediawiki/math_safe_mode/

Using safe_mode the owner of the script should be the same as the owner of the files [1]. Change the permissions to apache:apache with

chown -R apache:apache <PATH_TO_MEDIAWIKI_DIRECTORY>

Works with complicate equations but fails with simple ones[edit | edit source]

My system works with a complicate equation (with fractions, integrals,...) but it fails on

<math>\frac{dy}{dx}</math>

But it works when I put \,\! in the end of the line (forcing to render in .PNG)

<math>\frac{dy}{dx}\,\!</math>

render.ml[edit | edit source]

render.ml is the only file that contains commands executed by texvc. If you need to change command names or their paths, edit that file. It should be straightforward.

Which latex, dvips, convert ...[edit | edit source]

A universal fix is to change render.ml to use the env shell command in each of the let cmd_ ... = statements. To verify and see which commands are returned by the env command just try, for example, at the command prompt $ which latex.

let cmd_dvips tmpprefix = "env dvips ...
let cmd_latex tmpprefix = "env latex ...
let cmd_convert tmpprefix finalpath = "env convert ...

Then run make in the math directory again. You may need to restart Apache.

Permissions problem[edit | edit source]

latex doesn't have an option to specify an output directory, so it just places the output files (.log, .aux, .dvi) into the current directory. The render.ml file line

    if Util.run_in_other_directory tmppath (cmd_latex tmpprefix0) != 0

handles this by calling the function run_in_other_directory defined in util.ml. Function run_in_other_directory attempts to save the current directory, change directory to the proper output (temp) directory, call latex, then change back to the previous current directory. To get the current directory, a function called Sys.getcwd is used, but if there are not sufficient permissions to read the directory (all parent directories back to the root must be readable by the user running texvc), then texvc just quits. There will be a .tex file in the temp directory, but no .dvi or other files. One way to fix this is to replace the above line of render.ml with these two lines:

   Sys.chdir tmppath;
   if Sys.command (cmd_latex tmpprefix) != 0

(Recompile texvc.) This will change the current directory, then run latex. Changing back to the original directory doesn't appear to be necessary.

Installing tetex[edit | edit source]

Rather than using a global directory, e.g. /opt/local/bin/, for installation or symlinking, your latex installation is more likely able to find its configuration files if you install everything in the teTeX directory and referencing the binaries directly.

For example, configure teTeX to install into /home/wiki/local/teTeX/ with ./configure --prefix=/home/wiki/local/teTeX/. Then, rather than symlinking them, reference them directly from render.ml, i.e.

let cmd_dvips tmpprefix = "/home/wiki/local/teTeX/bin/x86-unknown-linux-gnu/dvips ...
let cmd_latex tmpprefix = "/home/wiki/local/teTeX/bin/x86-unknown-linux-gnu/latex ...

In this way, the latex and dvips executables know their own directory and will search the immediate parents for the relevent teTeX configuration files. Without them, and without the relevant environment variables, these executables may be unable to find their configuration, and you will get a relatively generic error.

dvipng[edit | edit source]

GhostScript, ImageMagick and dvips can be replaced by dvipng. It may be easier to configure on some systems, and would be much faster. In addition it can do transparent background (full-alpha or all-or-nothing transparency as wished). It can also report the baseline position if desired.

There is a patch for render.ml to do that, seemailarchive:wikitech-l/2004-April/009596.html The patch will make an image with a full-alpha transparent background (with dvipng >= 1.6). Remember that there are problems with IE and full-alpha transparency. To use all-or-nothing transparency with dvipng >= 1.6, use '-bg transparent' (all lowercase).


MySQL error 1267: Illegal mix of collocations[edit | edit source]

After restoring or transferring a MySQL database:

An error message is displayed:

A database query syntax error has occurred. This may indicate a bug in the software. The last attempted database query was: (SQL query hidden) from within function "MathRenderer::_recall". MySQL returned error "1267: Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '=' (localhost)".

Possible solution: in LocalSettings.php, change the value of $wgDBmysql5 to false;

If this doesn't work for you, use phpMyAdmin to pull up the *wiki_math table in the wikidb, click the Structure tab, and change the collation on each column that is "latin1_swedish_ci" to "utf8_general_ci". That fixed it here. Then just do the usual things: install ocaml and latex, cd <wikidir>/math, and make to build texvc.

It seems that when upgrading older wikis up through various MySQL versions, somehow "latin1_swedish_ci" ends up getting stuffed on collation order fields at the database, table, and column levels. This is not what the built-in LaTeX "<math>" extension wants to see. This is not fixed-up by MediaWiki's upgrade.php script.

Selinux[edit | edit source]

On Linux systems with selinux support, such as recent versions of Fedora Core, restrictions enacted by selinux can result in puzzling manifestations. On selinux-enabled systems, it is a good idea to check for records in the selinux log files. On Fedora Core, these are found at /var/log/audit/audit.log. For testing purposes, under Fedora selinux can be disabled interactively with the command:

 sudo /usr/sbin/setenforce 0  

and re-enabled with the command:

 sudo /usr/sbin/setenforce 1  

On some systems, for example Fedora Core 7, you can obtain interesting information if you have access to the setroubleshoot browser, a tool which can be accessed from the desktop menus "System" and "Administration". Each time selinux prevents an action from being performed, for example a file access involved in the texvc machinery, it records information that can be viewed in this browser. The browser also describes how to enable the prevented access, typically by performing chcon commands on the specified file. After a sequence of such commands it may be possible to get texvc working properly without disabling selinux.

On one system where texvc was failing to work properly, the shell script was able to create files in the file system normally, but unable to write any contents to these files, where each write request generated an selinux audit log entry of the following form:

type=AVC msg=audit(1165430855.036:398755): avc:  denied  { write } for  pid=30145 
comm="httpd" name=php-eaccelerator dev=dm-0 ino=16034837 scontext=root:system_r:httpd_t 
tcontext=system_u:object_r:var_t tclass=dir

MediaWiki detected this error as an empty status response from the texvc shell comamnd, as the contents of the write() call to return the status result was denied by selinux. Note that when testing texvc on the command line, the status string written by texvc to stdout does not normally contain a terminating newline, so one some shells the string will not be displayed. To verify that the status string is returning normally, one can run texvc as follows:

 ./math/texvc arguments > out 
 ls -l out   # view file size 
 vi out      # view status contents 

Another option is to run texvc under strace to see that it is functioning normally.

If you are getting the error message "Error : Failed to parse (Missing texvc executable)" or the same error for texvcheck, it may be because these files don't have the necessary selinux context settings. You can check this by running:

ls -Z texvc

This will display a context like "unconfined_u:object_r:httpd_sys_content_t". That context is not sufficient to allow execution. Change the context by running:

chcon -t httpd_exec_t texvc

See also: SELinux and m:Texvc

An alternative to trying to get texvc to work is to rewrite the Math.php render code to use PHP instead: Texvc PHP Alternative

PaX[edit | edit source]

PaX is a security feature built into Gentoo Hardened systems designed to add extra memory protection to the kernel. Normally this is a good thing, but it plays havoc with texvc (apparently because texvc relies upon rewriting its own ELF in memory). The solution is to use the paxctl utility to disable MPROTECT on texvc and associated executables:

 sudo paxctl -m math/texvc math/texvc_test math/texvc_tex

This should resolve the dreaded "error while loading shared libraries: cannot make segment writable for relocation: Permission denied" problem.

Apache Chroot[edit | edit source]

Help needed on getting texvc to work with a chrooted apache.

overleftrightarrow[edit | edit source]

The token "\overleftrightarrow" is not handled correctly by Texvc. The parser assumes that the function is part of the normal TeX distribution, whereas it is actually a part of ams-math. Therefore, if you do not have any other ams-math functions within the math tags, then it will not be rendered.

Example of overleftrightarrow on its own (known to fail)
\overleftrightarrow{A B}
Example of \overleftrightarrow with other ams-math functions (known to work correctly)
\overleftrightarrow{A B} \mathit{i}    or    \overleftrightarrow{A B} \mathit{\ }.