我正在使用给出的解决方案tex4ht 使用 dmath 时在 mathjax 模式下生成无效数学运算它允许人们使用breqn
tex4ht 中的包,这非常有用。
我现在正在尝试使用上面的方法,但是没有使用,mathjax
为了对编译速度慢的情况进行计时,我必须看看使用是否mathjax
是原因。所以我需要在非 mathjax 模式下编译文档。
我不知道必须使用mathjax
上述过滤器才能工作?
由于某种原因,我在使用新安装的 TL 2022 时不断收到此错误dmath
。
(/usr/local/texlive/2022/texmf-dist/tex/generic/tex4ht/html5.4ht)) (./index.aux
) (/usr/local/texlive/2022/texmf-dist/tex/latex/base/ts1cmr.fd)
! TeX capacity exceeded, sorry [input stack size=50000].
<everymath> \check@mathfonts
\the \everymath
l.7 \begin{dmath*}
! ==> Fatal error occurred, bad output DVI file produced!
No pages of output.
下面,我展示了重现它所需的一切,同时我还把所有需要和生成的文件放在了一个 zip 文件里。
我肯定做错了什么。我花了 3 个小时尝试了所有可能的方法,但还是不断出现这个错误。如果我不使用dmath
,当然可以编译成功。这是 MWE
\documentclass[12pt]{book}%ext
\usepackage{amsmath}
\usepackage{breqn}
\begin{document}
\begin{dmath*}
y(x) = x^{2}+x +3
\end{dmath*}
\end{document}
现在
>which make4ht
/usr/local/texlive/2022/bin/x86_64-linux/make4ht
>make4ht --version
make4ht version v0.3l
>which dvilualatex
/usr/local/texlive/2022/bin/x86_64-linux/dvilualatex
>dvilualatex --version
This is LuaTeX, Version 1.15.0 (TeX Live 2022)
Development id: 7509
然后
make4ht -ulm default -a debug -e filter.lua index.tex "htm"
注意,我没有使用mathjax
选项。.cfg
两者都没有使用。只有过滤器,这正是上述答案中的过滤器,感谢 Michal.h2。以下是结果
>make4ht -ulm default -a debug -e filter.lua index.tex "htm"
[INFO] mkparams: Output dir:
[INFO] mkparams: Compiler: dvilualatex
[INFO] mkparams: Latex options: -jobname='index'
[INFO] mkparams: tex4ht.sty: xhtml,htm,charset=utf-8
[INFO] mkparams: tex4ht: -cmozhtf -utf8
[INFO] mkparams: build_file: filter.lua
[INFO] mkparams: Output format: html5
[STATUS] make4ht: Conversion started
[STATUS] make4ht: Input file: index.tex
[INFO] mkutils: Load extension common_domfilters
[INFO] mkutils: Using build file filter.lua
[INFO] make4ht-lib: setting param correct_exit
[INFO] make4ht-lib: setting param correct_exit
[INFO] make4ht-lib: setting param correct_exit
[INFO] make4ht-lib: setting param ext
[INFO] make4ht-lib: Adding: ext dvi
[INFO] htlatex: LaTeX call: dvilualatex --interaction=errorstopmode -jobname='index' '\makeatletter\def\HCode{\futurelet\HCode\HChar}\def\HChar{\ifx"\HCode\def\HCode"##1"{\Link##1}\expandafter\HCode\else\expandafter\Link\fi}\def\Link#1.a.b.c.{\AddToHook{class/before}{\RequirePackage[#1,html]{tex4ht}}\let\HCode\documentstyle\def\documentstyle{\let\documentstyle\HCode\expandafter\def\csname tex4ht\endcsname{#1,html}\def\HCode####1{\documentstyle[tex4ht,}\@ifnextchar[{\HCode}{\documentstyle[tex4ht]}}}\makeatother\HCode xhtml,htm,charset=utf-8,html5.a.b.c.\input "\detokenize{index.tex}"'
This is LuaTeX, Version 1.15.0 (TeX Live 2022)
restricted system commands enabled.
LaTeX2e <2021-11-15> patch level 1
L3 programming layer <2022-04-20> (./index.tex
(/usr/local/texlive/2022/texmf-dist/tex/generic/tex4ht/tex4ht.sty)
(/usr/local/texlive/2022/texmf-dist/tex/latex/base/book.cls
....
(/usr/local/texlive/2022/texmf-dist/tex/generic/tex4ht/html4-math.4ht)
(/usr/local/texlive/2022/texmf-dist/tex/generic/tex4ht/html5.4ht)) (./index.aux
) (/usr/local/texlive/2022/texmf-dist/tex/latex/base/ts1cmr.fd)
! TeX capacity exceeded, sorry [input stack size=50000].
<everymath> \check@mathfonts
\the \everymath
l.7 \begin{dmath*}
335479 words of node memory still in use:
16 hlist, 2 vlist, 2 rule, 4 local_par, 3 dir, 33330 math, 16 glue, 4 kern,
7 penalty, 3 glyph, 16852 attribute, 72 glue_spec, 16852 attribute_list, 3 temp
, 16665 if_stack, 2 write, 200 special nodes
avail lists: 1:3,3:2,4:1,5:4,8:4
! ==> Fatal error occurred, bad output DVI file produced!
No pages of output.
Transcript written on index.log.
[FATAL] make4ht-lib: Fatal error. Command htlatex returned exit code 1
>
哪里filter.lua
local filter = require "make4ht-filter"
local function process_options(options)
-- convert [number={foo}] to \tag{foo}
local number = options:match("number%s*=%s*{?(%w+)")
if number then
return "\\tag{" .. number .. "}"
end
return ""
end
local function escape_equal(str)
-- there can be multiple equal characters in the string. we should put the & character
-- just before the one which is not inside any group
-- escape nested equal signs
str = str:gsub("({[^{^}]+)=([^{^}]+})", "%1:EQUAL:%2")
-- replace remaining =
str = str:gsub("=", "& =")
-- return escaped =
str = str:gsub(":EQUAL:", "=")
return str
end
local function make_align(dgroup, new_env)
-- change breqn environment contents to align*
-- change = to &=
-- local dgroup = escape_equal(dgroup) <- we don't do this anymore, it leads only to problems
local new_env = new_env or "\\begin{align*}\n%s\n\\end{align*}"
-- return the fixed text in align* environment
-- return "\\begin{".. new_env .."}" .. dgroup .. "\\end{" .. new_env .. "}"
return string.format(new_env, dgroup)
end
local function process_dgroup(s, env_name)
return s:gsub("\\begin%s*{" .. env_name .. "}(.-)\\end%s*{" .. env_name .. "}",
function(dgroup)
-- remove environemnts
-- change dmath[...,number={label}] to \tag{label}
dgroup = dgroup:gsub("\\begin%s*{dmath}%s*(%b[])", process_options)
-- remove all other environemnts
dgroup = dgroup:gsub("\\begin%s*{.-}","")
dgroup = dgroup:gsub("\\end%s*{.-}", "\\\\")
return make_align(dgroup)
end)
end
-- process remaining dmath environments
local function process_dmath(s, env_name, new_env)
return s:gsub("\\begin%s*{" .. env_name .. "}(.-)\\end%s*{" .. env_name .. "}",
function(dmath)
-- options can be still here
local dmath = dmath:gsub("^%s*(%b[])", process_options)
return make_align(dmath, new_env)
end)
end
local process = filter {
-- find all dgroup* environments and convert them to align*
function(s)
local s = process_dgroup(s,"dgroup%*")
s = process_dgroup(s, "dgroup")
-- process remaining dmath environments in the document
s = process_dmath(s, "dmath%*", "\\[\n%s\n\\]")
s = process_dmath(s, "dmath", "\\begin{equation}\n%s\n \\end{equation}")
return s
end
}
-- install filter to match HTML files
Make:match("html?$", process)
我确保我的 ~/.config/ 文件夹中没有安装其他默认加载的过滤器。
问题是:是否需要使用 mathjax 配置文件和mathjax
选项,以便上述过滤器允许 dmath 在 tex4ht 中工作?如果不是,那么为什么会出现此错误?我需要特殊的 .cfg 才能使其工作吗?
我尝试编辑 texmf.cnf 以增加一些值,希望摆脱这个错误,但没有任何效果。这是我当前的 TL 2022 texmf.cnf
>cat /usr/local/texlive/2022/texmf.cnf
buf_size=9000000
pool_size=9000000
main_memory=8000000
save_size=1000000
max_strings = 5000000
strings_free = 1000000
hash_extra=10000000
stack_size=500000
>
以下 zip 文件包含所有文件。
有人可以尝试上述操作,看看是否会出现同样的错误吗?可能是我的安装有问题。
答案1
Breqn 包目前还不支持 TeX4ht。使用 Lua 过滤器构建的文件无法在 MathJax 模式之外工作,因为原始 LaTeX 代码未保留在 HTML 代码中。
我创建了一个简单版本breqn.4ht
,它似乎支持基本功能并且没有错误:
\renewenvironment{dmath*}[1][]{\[}{\]}
\renewenvironment{dmath}[1][]{\begin{equation}}{\end{equation}}
\renewenvironment{dsuspend}{}{\par}
% enumerate equation for \begin{dseries}
\def\@dseries[#1]{%
\if\eq@hasNumber%
\refstepcounter{equation}%
\fi
\begingroup%
\a:equation%
\ignorespaces%
}
% mimic the equatio environment
\def\end@dseries{%
\b:equation
\if\eq@hasNumber%
(\arabic{equation})%
\fi%
\c:equation%
}
% this macro prints spurious equation number to the document, so we just reset it
\def\grp@finish{%
\setbox\GRP@wholebox\vbox{%
\let\breqn@elt\eqgrp@elt
\the\GRP@queue
}%
\unvbox\GRP@wholebox
}
\def\eq@nulldisplay{%
\xdef\EQ@displayinfo{%
\relax}%
}
%% commands
% fix wrong handling of fonts in \condition
\newcommand\:condition@a[2][\conditionpunct]{%
\unpenalty\unskip\unpenalty\unskip % BRM Added
\mbox{#1}%
\hskip\conditionsep
\ \if@tempswa\mbox{#2}\else\mbox{$\textmath@setup #2$}\fi
\endgroup
}
\HLet\condition@a\:condition@a
\Hinput{breqn}
\endinput
它适用于以下非 MWE:
\documentclass[12pt]{book}%ext
\usepackage{amsmath}
\usepackage{breqn}
\begin{document}
\begin{dmath*}
y(x) = x^{2}+x +3
\end{dmath*}
\begin{dmath}
y(x) = x^{2}+x +3
\end{dmath}
\begin{dseries}
\begin{math}A\end{math},
\begin{math}B\end{math},
and
\begin{math}C\end{math}.
\end{dseries}
\begin{dmath}
y(x) = x^{2}+x +3
\end{dmath}
\begin{dseries*}
\begin{math}A\end{math},
\begin{math}B\end{math},
and
\begin{math}C\end{math}.
\end{dseries*}
\begin{dgroup}
\begin{dmath}
f(x)=\frac{1}{x} \condition{for $x\neq 0$}
\end{dmath}
\begin{dmath}
T(n) \hiderel{\leq} T(2^n) \leq c(3^n - 2^n)
\end{dmath}
\end{dgroup}
\begin{dgroup*}
\begin{dmath}
f(x)=\frac{1}{x} \condition{for $x\neq 0$}
\end{dmath}
\begin{dmath}
T(n) \hiderel{\leq} T(2^n) \leq c(3^n - 2^n)
\end{dmath}
\end{dgroup*}
\begin{dgroup*}[frame={0.4pt},framesep=0pt,compact]
\begin{dmath*}
(x+\cdots+y+\cdots + z) - (x+\cdots +2) = 0
\end{dmath*}
\begin{dsuspend}
and
\end{dsuspend}
\begin{dmath*}[frame={0pt}]
a=0
\end{dmath*}
\end{dgroup*}
\end{document}