如何将 tex4ht 与新的 Maple Latex 样式文件一起使用?

如何将 tex4ht 与新的 Maple Latex 样式文件一起使用?

Maple 现在有一个新的 Latex 转换软件。

这会将 Maple 表达式(和整个文档)转换为 Latex。

Maple 带有自己的样式文件,现在需要这些文件,因为生成的 Latex 使用此样式文件中定义的宏和命令。据我所知,目前没有办法避免这种情况。

编译为 pdf 时使用样式文件没有问题lualatex。一切正常。

问题是我无法在模式下使其与 tex4ht 一起工作mathjax。生成的 Latex 中使用的某些命令和宏无法被识别mathjax

我尝试将这些添加到我的 .cfg 文件中,但不起作用。我不知道我是否做错了什么,或者是否还有其他事情要做才能使其与 一起工作mathjax。所以现在我所有的 HTML 编译都显示这些命令为未知,这使得数学不可读。以下是指向实际页面昨晚建造。

这是使用小型 Latex 的 MWE,由 Maple 生成,我将其复制到我的 Latex 文档中

\documentclass[11pt]{article}
\usepackage{amsmath} 
\usepackage{maplestd2e}%this style file comes with Maple

\begin{document}
\[%example code copied from Maple conversion to Latex
u(x,y ,t) = \Mapleoverset{\infty}{\Mapleunderset{\mathit{m} =1}{\sum }}
\Mapleoverset{\infty}{\Mapleunderset{n =1}{\sum}}
\sin(n \pi  x) \sin(\mathit{m} \pi  y)
\]
\end{document}

maplestd2e.sty在网上搜索这个名字就可以找到。但我也在这里放了一份maplestd2e.sty如果有人想尝试上述内容。

这样做lualatex foo5.tex没有问题,并且给出了正确的输出

在此处输入图片描述

但当使用

make4ht -ulm default -a debug foo5.tex "mathjax,htm"

它给

在此处输入图片描述

发生这种情况时,通常意味着我需要在 .cfg 中定义此命令来教授mathjax此命令。但我尝试这样做,但没有奏效。这就是我尝试的。查看 Maple 的样式文件以查看命令的作用。这些位于上述链接文件的末尾附近

\newcommand{\Mapleoverset}[2]%
  {\mathop{\kern\z@#2}\limits^{#1}}
\newcommand{\Mapleunderset}[2]%
  {\mathop{\kern\z@#2}\limits_{#1}}

因此我编辑了 .cfg 文件,并在MathJaxConfig以下宏部分中添加了

Mapleoverset: ["\\mathop{\#2}\\limits^{\#1}",2],
Mapleunderset: ["\\mathop{\#2}\\limits_{\#1}",2]

然后使用进行编译

 make4ht -ulm default -a debug -c ./nma_mathjax.cfg foo5.tex "mathjax,htm"

这是我的链接nma_mathjax.cfg 文件使用。上面的输出是

在此处输入图片描述

也许我做得不够好。

随着新的 Maple Latex 软件得到更广泛的使用,并且人们尝试使用 tex4ht 将其转换为 HTML,我确信其他人也会遇到我现在遇到的同样的问题。

我的问题是:为什么 tex4ht 不支持这种样式文件,就像 pdf 一样?到底需要做什么才能Mathjax从这个样式文件中使用这些命令?如果我知道如何对其中一个命令执行此操作,我就可以对这个样式文件中的其他命令执行此操作。

TL 2020

答案1

您不能在 MathJax 配置中放置空行。这会导致 JavaScript 解析错误,因此您的定义根本不会被使用。以下是更正后的版本:

\Preamble{xhtml,p-width}

%This below does not work. see https://tex.stackexchange.com/questions/543919/what-are-the-limitations-of-using-tikz-with-tex4ht
%\tikzset{every node/.style={/pgf/tex4ht node/escape=true}}

%this disables make4ht loading mathjax
\Configure{MathjaxSource}{}


%\Configure{@HEAD}{\HCode{ <script type="text/javascript" src="/scripts/MathJax-2.7.3/latest.js?config=TeX-AMS-MML_HTMLorMML"></script> \Hnewline}}        

%this loads mathjax  

\Configure{MathjaxSource}{https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js}

%V3.0
\Configure{MathJaxConfig}{{  
  tex: {
    maxBuffer: 40*1024,
    packages: {'[+]': ['textmacros']},
    \unexpanded{%
    macros: {      
        sp: "^",
        sb: "_",      
      noalign: ["\#1", 1],
      myadjustbox: ["\#1", 1],      
      medskip: "",
      sc: "\\small\\rm",
      sl: "\\it",
      symbfit: "\\boldsymbol",
      LommelS: ["\\operatorname{LommelS\#1}",1],
      sinc: ["\\operatorname{sinc}"],
      dag: ["\\dagger"],
      ddag: ["\\ddagger"],
      tauL: "\\tau L",
      relax: "{}",
      setlength: ["{}", 2],
      allowbreak: "{}",
      sech: ["\\operatorname{sech}"],
      csch: ["\\operatorname{csch}"],
      arcsec: ["\\operatorname{arcsec}"],
      arccot: ["\\operatorname{arccot}"],
      arccsc: ["\\operatorname{arccsc}"],
      arccosh: ["\\operatorname{arccosh}"],
      arcsinh: ["\\operatorname{arcsinh}"],
      arctanh: ["\\operatorname{arctanh}"],
      arcsech: ["\\operatorname{arcsech}"],
      arccsch: ["\\operatorname{arccsch}"],
      arccoth: ["\\operatorname{arccoth}"],
      erf: ["\\operatorname{erf}"],
      erfi: ["\\operatorname{erfi}"],      
      AiryAi: ["\\operatorname{AiryAi}"],
      AiryBi: ["\\operatorname{AiryBi}"],
      BesselJ: ["\\operatorname{BesselJ}"],
      BesselY: ["\\operatorname{BesselY}"],
      BesselK: ["\\operatorname{BesselK}"],
      BesselI: ["\\operatorname{BesselI}"],
      WhittakerM: ["\\operatorname{WhittakerM}"],
      WhittakerW: ["\\operatorname{WhittakerW}"],
      LambertW: ["\\operatorname{LambertW}"],
      RootOf: ["\\operatorname{RootOf}"],
      Ei: ["\\operatorname{Ei}"],
      Si: ["\\operatorname{Si}"],
      Ci: ["\\operatorname{Ci}"],
      Ssi: ["\\operatorname{Ssi}"],
      Shi: ["\\operatorname{Shi}"],
      Chi: ["\\operatorname{Chi}"],
      Li: ["\\operatorname{Li}"],
      HeunC: ["\\operatorname{HeunC}"],
      HeunCPrime: ["\\operatorname{HeunCPrime}"],
      FresnelC: ["\\operatorname{FresnelC}"],
      EllipticE: ["\\operatorname{EllipticE}"],
      EllipticCE: ["\\operatorname{EllipticCE}"],
      EllipticF: ["\\operatorname{EllipticF}"],
      EllipticK: ["\\operatorname{EllipticK}"],
      EllipticCK: ["\\operatorname{EllipticCK}"],
      EllipticPi: ["\\operatorname{EllipticPi}"],
      EllipticCPi: ["\\operatorname{EllipticCPi}"],
      LegendreP: ["\\operatorname{LegendreP}"],
      LegendreQ: ["\\operatorname{LegendreQ}"],
      dilog: ["\\operatorname{dilog}"],
      polylog: ["\\operatorname{polylog}"],
      StruveH: ["\\operatorname{StruveH}"],
      StruveL: ["\\operatorname{StruveL}"],
      ParabolicCylinderD: ["\\operatorname{ParabolicCylinderD}"],
      hypergeom: ["\\operatorname{hypergeom}"],
      WeierstrassP: ["\\operatorname{WeierstrassP}"],
      MathieuS: ["\\operatorname{MathieuS}"],
      MathieuC: ["\\operatorname{MathieuC}"],
      MathieuSPrime: ["\\operatorname{MathieuSPrime}"],
      MathieuCPrime: ["\\operatorname{MathieuCPrime}"],
      logintegral: ["\\operatorname{log\\_integral}"],
      Mapleoverset: ["\\mathop{\#2}\\limits^{\#1}",2],
      Mapleunderset: ["\\mathop{\#2}\\limits_{\#1}",2]
    }},
    autoload: {
      color: [],
      colorV2: ['color']
    },
    packages: {'[+]': ['noerrors','textmacros']}
  },
  options: {
    ignoreHtmlClass: 'tex2jax_ignore',
    processHtmlClass: 'tex2jax_process'
  },
  loader: {
    load: ['[tex]/noerrors','[tex]/textmacros']
  }
};
}




%added oct 4,2019
%\Configure{@HEAD}{\HCode{
%<script async src="https://www.googletagmanager.com/gtag/js?id=UA-149430386-1"></script>
%<script>
%  window.dataLayer = window.dataLayer || [];
%  function gtag(){dataLayer.push(arguments);}
%  gtag('js', new Date());
%  gtag('config', 'UA-149430386-1');
%</script>}}

         
\Configure{@HEAD}{\HCode{<SCRIPT TYPE="text/javascript">
function popup(mylink, windowname)
{
if (! window.focus)return true;
var href;
if (typeof(mylink) == "string")
   href=mylink;
else
   href=mylink.href;
window.open(href, windowname, "width=600,height=200,scrollbars=yes");
return false;
}
</SCRIPT>\Hnewline}}

\Configure{@HEAD}{\HCode{
<link rel="shortcut icon" href="\#" />\Hnewline
}}

\Configure{@HEAD}{\HCode{
    <script type="text/javascript" src="/scripts/gifffer-master/lib/gifffer.js"></script>\Hnewline 
<script>
   window.onload = function() {
   Gifffer();
   }
</script>\Hnewline  
}}

%added March 1, 2020
\Configure{@HEAD}{\HCode{
    <script type="text/javascript" src="/scripts/libgif-js-master/libgif.js"></script>\Hnewline
    <script type="text/javascript" src="/scripts/libgif-js-master/rubbable.js"></script>\Hnewline
}
}

\Configure{@HEAD}{\HCode{
<script type="text/javascript" src="/styles/syntaxhighlighter/scripts/shCore.js"></script>\Hnewline
<script type="text/javascript" src="/styles/syntaxhighlighter/scripts/shBrushMatlab.js"></script>\Hnewline
<script type="text/javascript" src="/styles/syntaxhighlighter/scripts/shBrushPlain.js"></script>\Hnewline
<script type="text/javascript" src="/styles/syntaxhighlighter/scripts/shBrushPython.js"></script>\Hnewline
<script type="text/javascript" src="/styles/syntaxhighlighter/scripts/shBrushRuby.js"></script>\Hnewline
<script type="text/javascript" src="/styles/syntaxhighlighter/scripts/shBrushPerl.js"></script>\Hnewline
<script type="text/javascript" src="/styles/syntaxhighlighter/scripts/shBrushCpp.js"></script>\Hnewline
<script type="text/javascript" src="/styles/syntaxhighlighter/scripts/shBrushBash.js"></script>\Hnewline
<script type="text/javascript" src="/styles/syntaxhighlighter/scripts/shBrushXml.js"></script>\Hnewline
<script type="text/javascript">SyntaxHighlighter.all()</script>\Hnewline
<link href="/styles/syntaxhighlighter/styles/shCore.css" rel="stylesheet" type="text/css" />\Hnewline
<link href="/styles/syntaxhighlighter/styles/shThemeDefault.css" rel="stylesheet" type="text/css"/>\Hnewline
}}

         
\makeatletter
\@ifpackageloaded{graphicx}{%
  \DeclareGraphicsExtensions{.svg,.png}

  %this below to make it resize the SVG image, if it is there, to
  %what is in the includegraphics.
  %thanks to @Michal.h21 for this trick
  \newcommand\emwidth{10}
  \newcommand\CalcRem[1]{\strip@pt\dimexpr(#1)/\emwidth}
  \Configure{graphics*}
           {svg}
            {\Picture[pict]{\csname Gin@base\endcsname.svg \space style="width:\CalcRem{\Gin@req@width}em;"}%
            \special{t4ht+@File: \csname Gin@base\endcsname.svg}
            }
            
  %make sure this below is here, this will make it resize the png image
  %to what is in the includegraphics command
   \Configure{graphics*}
        {png}
        {%the special command below so it will copy the png over  
           \special{t4ht+@File: \csname Gin@base\endcsname.png}
           \Picture[pict]{\csname Gin@base\endcsname .png
              \space width="\expandafter\the\csname Gin@req@width\endcsname"
            }%  
        }%
            
}{}
\makeatother
  
%see https://tex.stackexchange.com/questions/490873/problem-with-vertical-alignment-of-text-and-images-in-long-table-when-using-tex4
\makeatletter
\@ifpackageloaded{adjustbox}{%
\Configure{halignTR}{}
\Configure{AdjustboxValignTop}{\Css{\#TBL-\TableNo-\HRow-{vertical-align:top;}}}
\Configure{AdjustboxValignMiddle}{\Css{\#TBL-\TableNo-\HRow-{vertical-align:middle;}}}
\Configure{AdjustboxValignCenter}{\Css{\#TBL-\TableNo-\HRow-{vertical-align:middle;}}}
\Configure{AdjustboxValignBottom}{\Css{\#TBL-\TableNo-\HRow-{vertical-align:bottom;}}}
}{}
\makeatother

  
%see   https://tex.stackexchange.com/questions/249179/tex4ht-how-to-create-fixed-width-table-columns
\catcode`\:=11
\Configure{halignTD} {}{}
   {<}{\HCode{ style="white-space:nowrap; text-align:left;"}}
   {-}{\HCode{ style="white-space:nowrap; text-align:center;"}}
   {>}{\HCode{ style="white-space:nowrap; text-align:right;"}}
   {^}{\HCode{ style="vertical-align:top; white-space:nowrap;"}}
   {=}{\HCode{ style="vertical-align:baseline; white-space:nowrap;"}}
   {||}{\HCode{ style="vertical-align:middle; white-space:nowrap;"}}
   {_}{\HCode{ style="vertical-align:bottom; white-space:nowrap;"}}
   {p}{\HCode{ style="white-space:wrap; text-align:left;"}\Protect\a:HColWidth}
   {m}{\HCode{ style="white-space:wrap; text-align:left; vertical-align:middle;"}\Protect\a:HColWidth}
   {b}{\HCode{ style="white-space:wrap; text-align:left; vertical-align:baseline;"}}
   {}
\catcode`\:=12

%see https://tex.stackexchange.com/questions/370308/why-tex4ht-adds-an-extra-newline-when-using-begindescription-after-item
\Css{dl:after {content:"";display:table;clear:both;}}
\Css{dt{float:left;min-width:1em;clear:left;}}
\Css{dd{float:left;}}

  
\begin{document}

%-------------------------------
%this remove lines above graphics and below them in HTML
\ConfigureEnv{figure} 
    {\HCode{}}{\HCode{}}{}{}    

% This one removes the rulers. Taking a look at html4.4ht should make 
% clear what has been changed.
\Configure{float}
   {\ifOption{refcaption}{}{\csname par\endcsname\ShowPar \leavevmode}}
   {\HCode{}}
{\ifvmode \IgnorePar \fi\EndP \HCode{}\csname par\endcsname\ShowPar}

%----------------------------------




\Css{html{
    font-size: 100.0\%;    
}} 

\Css{body{margin-top: 1em; 
          margin-bottom: 1em; 
          width: 92\%;
          max-width: 65em;
          margin-left: auto; 
          margin-right: auto; 
          padding: 0em;
          color: \#444; 
          font-family: arial, sans-serif;
          %line-height: 16px;
          font-style: normal;
          font-size: 1.0em;           
          %border: 1px solid \#F0F0F0 ;
          text-align:left;
          background: \#FFFFFF;}}
          
\Css{li img{vertical-align:middle;}}
\Css{div.caption{text-align:center;}}
\Configure{float}{\csname par\endcsname\ShowPar}
{\ifvmode\IgnorePar\fi\EndP\HCode{<div class="float">}}
{\ifvmode\IgnorePar\fi\EndP\HCode{</div>}\ShowPar}

\Css{table.longtable{margin-left: auto;margin-right:auto;}}

%added august 22, 2020 to force table to have fixed width columns. 
%see https://stackoverflow.com/questions/4185814/fixed-table-cell-width
%does not work
%\Css{table.longtable{width:65em; word-break:break-all;}}

%added feb 10, 2019 to center graphics
%see https://tex.stackexchange.com/questions/474282/tex4ht-css-code-works-using-standard-book-class-but-has-no-effect-using-koma-sc

\Css{div.fbox {display:table;margin-left:auto; margin-right: auto;}}

\Css{div.caption{text-align:center;}}
\Css{div.figure img{text-align:center;display:block;margin-left:auto; margin-right: auto;}}
\Css{div.float img{text-align:center;display:block;margin-left:auto; margin-right: auto;}}
\Css{div.fbox img{text-align:center;display:block;margin-left:auto; margin-right: auto;}}
\Css{div.caption table{margin: auto;}}

%added april 7, 2019 to make underline works with mathjax for math. Thanks
%to Michal Hoftich and Bill Hammond
\Css{span.underline {border-bottom: 0.15ex solid black;text-decoration:none;}}
          
\Css{tr {vertical-align:top;}}

\Css{div.titlepage{text-align:center;}}

%\Css{ td { padding: 10px; }} %bug in texh4t

\EndPreamble

生成的 HTML:

在此处输入图片描述

相关内容