Author: ralf.lederle
Description:
Rendering of any mathematical formula with latex does not work.
An error message is displayed: Failed to parse (unknown error): f'(x)=\sqrt[3]{x}
The system is: Windows 2003 Server, IIS 6.0, PHP 5.2.5, PostgreSQL 8.2.6
When I enable debug logging, the log file shows:
TeX: sh -c "G:/Inetpub/mediawiki-1.12.0/texvc.exe \"G:\Inetpub\mediawiki-1.12.0/images/tmp\" \"G:\Inetpub\mediawiki-1.12.0/images/tmp\" \"f'(x)=\sqrt[3]{x}\" \"UTF-8\""
TeX output:
The problem is, that the command is executed by the cygwin Unix shell, but the quoting is for the Windows cmd shell. Also the backslashes in the path names don't work.
In Math.php the escapeshellarg command is used to escape the arguments, but under Windows it doesn't use single quotes but double quotes. I changed the code so that it uses single quotes and replaces the backslashes in the paths with slashes:
original code
$cmd = $wgTexvc . ' ' .
escapeshellarg( $wgTmpDirectory ).' '. escapeshellarg( $wgTmpDirectory ).' '. escapeshellarg( $this->tex ).' '. escapeshellarg( $wgInputEncoding );
if ( wfIsWindows() ) {
- Invoke it within cygwin sh, because texvc expects sh features in its default shell
$cmd = 'sh -c ' . wfEscapeShellArg( $cmd );
}
new code
if ( !wfIsWindows() ) {
$cmd = $wgTexvc . ' ' .
escapeshellarg( $wgTmpDirectory ).' '. escapeshellarg( $wgTmpDirectory ).' '. escapeshellarg( $this->tex ).' '. escapeshellarg( $wgInputEncoding );
} else {
- change backslashes to slashes
$wgTexvc = str_replace( "\\", "/", $wgTexvc );
$wgTmpDirectory = str_replace( "\\", "/", $wgTmpDirectory );
- quote with single quotes like
escapeshellarg under Unix
$cmd = $wgTexvc . " '" .
str_replace( "'", "'\\''", $wgTmpDirectory )."' '". str_replace( "'", "'\\''", $wgTmpDirectory )."' '". str_replace( "'", "'\\''", $this->tex )."' '". str_replace( "'", "'\\''", $wgInputEncoding )."'";
- Invoke it within cygwin sh, because texvc expects sh features in its default shell
$cmd = 'sh -c ' . wfEscapeShellArg( $cmd );
}
Now the rendering of the formula works and the log file shows:
TeX: sh -c "G:/Inetpub/mediawiki-1.12.0/texvc.exe 'G:/Inetpub/mediawiki-1.12.0/images/tmp' 'G:/Inetpub/mediawiki-1.12.0/images/tmp' 'f'\''(x)=\sqrt[3]{x}' 'UTF-8'"
TeX output:
+a8cc6d0afcc385914fbb3ac48a7ec868
Version: unspecified
Severity: major
OS: Windows Server 2003
Platform: PC