2015-02-23 75 views
0

我正在将latex转换为mathml的过程中,php.Texmath是通过它可以完成转换过程的命令行工具。Php不支持数学字符

乳胶文件:

\mathbf{f} = (f_{1}, 
f_{2})^{\prime} 

test.php的:

shell_exec('echo "password" | sudo -S /root/.cabal/bin/texmath latexfile > outputfile'); 

如果我运行这个PHP文件thorugh命令行,它产生所需的输出文件,该文件是以下 命令行脚本:php test.php

<math display="block" xmlns="http://www.w3.org/1998/Math/MathML"> 
    <mrow> 
    <mstyle mathvariant="bold"> 
     <mi></mi> 
    </mstyle> 
    <mo>=</mo> 
    <mo stretchy="false" form="prefix">(</mo> 
    <msub> 
     <mi>f</mi> 
     <mn>1</mn> 
    </msub> 
    <mo>,</mo> 
    <msub> 
     <mi>f</mi> 
     <mn>2</mn> 
    </msub> 
    <msup> 
     <mo stretchy="false" form="postfix">)</mo> 
     <mo>′</mo> 
    </msup> 
    </mrow> 
</math> 

当我运行这个php f通过浏览器得到输出文件,如

<math display="block" xmlns="http://www.w3.org/1998/Math/MathML"> 
    <mrow> 
    <mstyle mathvariant="bold"> 
     <mi> 

它忽略所有的数学类型字符。为什么它只通过命令行而不是通过浏览器提供所需的输出。当我在编辑器中打开这两个文件时,它显示'UTF-8'。这是字符编码问题吗?如何解决这个问题。

回答

0

只是我之前了shell_exec

$locale = 'en_US.utf-8'; 
setlocale(LC_ALL, $locale); 
putenv('LC_ALL='.$locale); 
shell_exec('echo "password" | sudo -S /root/.cabal/bin/texmath latexfile > outputfile'); 

然后生成具有特殊字符的文件改变郎像下面。从SO

1

一定要加入这一行之前的任何输出发送到浏览器:

header('Content-Type: application/mathml+xml; charset=utf-8'); 

这样一来,你告诉你的浏览器页面将是一个MATHML使用UTF-8编码文件。如果您使用的是Web服务器,请务必将所需的MIME类型添加到支持的格式列表中。

另一方面,你可以添加一个utf-8头文件本身。根据维基百科,这应该是你的文件的标题:

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE math PUBLIC "-//W3C//DTD MathML 2.0//EN" 
     "http://www.w3.org/Math/DTD/mathml2/mathml2.dtd"> 
+0

我最好的猜测会是字符集确实 – hanshenrik 2015-02-23 21:06:50

+0

我试过'header('Content-Type:application/xml; charset = utf-8') ;'它没有任何改变。然后尝试'header('Content-Type:application/mathml + xml; charset = utf-8');'下载php文件 – Learning 2015-02-24 06:14:01

+0

附加说明:如果我在本地主机服务器上运行php文件,它会给出想要的结果。如果在Web服务器中编码问题,那么本地主机如何输出具有特殊字符的文件。我不明白。我挣扎了两天 – Learning 2015-02-24 06:23:21