フィルターのクリア

How can I use MathJax to render the LaTeX math in the published output in MATLAB 7.10 (R2010a)?

14 ビュー (過去 30 日間)
I want to use MathJax to render the LaTeX math in the published output in MATLAB 7.10 (R2010a).

採用された回答

MathWorks Support Team
MathWorks Support Team 2015 年 8 月 28 日

Refer to the following instructions for a workaround:

1) Start MATLAB and run the following commands:

   u = userpath;
   workingDir = u(1:find(u==pathsep,1,'first')-1);
   customXsl = fullfile(workingDir,'mxdom2mathjax.xsl');
   disp(customXsl)
   copyfile(which('private/mxdom2simplehtml.xsl'),customXsl)
   fileattrib(customXsl,'+w')
   disp(customXsl)
   edit(customXsl)

2) In the MATLAB Editor, add code to the XSL file to include MathJax in your generated HTML file:

Find this line:

   <head>

And insert these lines after it:

   <script type="text/javascript"
     src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
   </script>

3) In the MATLAB Editor, alter code in the XSL file to include use of MathJax to render the equations.

Find these lines:

 <xsl:template match="img[@class='equation']">
   <img>
     <xsl:attribute name="src"><xsl:value-of select="@src"/></xsl:attribute>
     <xsl:attribute name="alt"><xsl:value-of select="@alt"/></xsl:attribute>
   </img>
 </xsl:template>

And replace them with these:

 

 <xsl:template match="img[@class='equation']">
   <span class="MathJax_Preview">
       <img>
           <xsl:attribute name="src"><xsl:value-of select="@src"/></xsl:attribute>
           <xsl:attribute name="alt"><xsl:value-of select="@alt"/></xsl:attribute>
       </img>
   </span>
   <script type="math/tex">
     <xsl:call-template name="removeDollars">
       <xsl:with-param name="string" select="@alt"/>
     </xsl:call-template>
   </script>
 </xsl:template>
 <xsl:template name="removeDollars">
   <xsl:param name="string"/>
     <xsl:choose>
       <xsl:when test="concat(substring($string,1,2),substring($string,string-length($string)-1,2))='$$$$'">
         <xsl:value-of select="substring($string,3,string-length($string)-4)"/>
       </xsl:when>
       <xsl:when test="concat(substring($string,1,1),substring($string,string-length($string),1))='$$'">
         <xsl:value-of select="substring($string,2,string-length($string)-2)"/>
       </xsl:when>
       <xsl:otherwise>
         T<xsl:value-of select="$string"/>
       </xsl:otherwise>
     </xsl:choose>
 </xsl:template>

4) Save your changes.

5) Now publish your MATLAB program to HTML using this modified stylesheet.

For releases prior to MATLAB 8.0 (R2012b), use the following code:

   opts = [];
   opts.stylesheet = customXsl;
   opts.outputDir = tempname;
   htmlFile = publish('YOURFILE',opts);
   web(htmlFile,'-browser')

Make sure to replace "YOURFILE" with the name of the MATLAB program you wish to publish.

For releases starting with MATLAB 8.0 (R2012b), under the 'Publish' button in the Publish tab, select 'Edit Publishing Options'. In the 'Output Settings' section, enter the name of the new XSL file in the blank labeled, 'XSL file'. Then, click 'Publish'.

  2 件のコメント
Mikhail
Mikhail 2014 年 7 月 9 日

The required changes are not very diligently formatted. The first change should read:

<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>

The second change should read:

<xsl:template match="img[@class='equation']">
  <span class="MathJax_Preview">
    <img>
      <xsl:attribute name="src"><xsl:value-of select="@src"/>
      </xsl:attribute>
      <xsl:attribute name="alt"><xsl:value-of select="@alt"/>
      </xsl:attribute>
    </img>
  </span>
  <script type="math/tex">
    <xsl:call-template name="removeDollars">
      <xsl:with-param name="string" select="@alt"/>
    </xsl:call-template>
  </script>
</xsl:template>
<xsl:template name="removeDollars">
  <xsl:param name="string"/>
  <xsl:choose>
    <xsl:when test="concat(substring($string,1,2),substring($string,string-length($string)-1,2))='$$$$'">
      <xsl:value-of select="substring($string,3,string-length($string)-4)"/>
    </xsl:when>
    <xsl:when test="concat(substring($string,1,1),substring($string,string-length($string),1))='$$'">
      <xsl:value-of select="substring($string,2,string-length($string)-2)"/>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$string"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

I hope i got it right.

Royi Avital
Royi Avital 2017 年 8 月 11 日
I wish you added support fot LaTeX using $$<LaTeX Code>$$ and $<LaTeX Code>$ inside the new Live Editor.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeText Files についてさらに検索

タグ

タグが未入力です。

製品


リリース

R2010a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by