抑制 Tex4HT 中的脚注标记配置

抑制 Tex4HT 中的脚注标记配置

我尝试通过 TeX4HT 获取以下脚注输出

<p class="indent">Some Text<fn id="sample_fn_001" symbol="1"><p class="noindent">language has evolved gradually: as the need arose for actions beyond</p></fn> some text text</p>

我刚刚尝试重新配置footnotefootnote-mark

\newbox\footnotebox

\Configure{footnote-mark}{\Configure{textsuperscript}{}{}}{}



\Configure{footnotetext}{\global\setbox\footnotebox=\vtop\bgroup\NoFonts%
                         \ifvoid\footnotebox\else\unvbox\footnotebox\fi%
                         \IgnorePar\HCode{<fn id="\jobname_fn_00\thefootnote" symbol="\FNnum">}\par\ShowPar\IgnoreIndent%
                         \Configure{textsuperscript}{}{}%
                        }%
                        {\Configure{textsuperscript}{\HCode{<sup>}\bgroup}{\egroup\HCode{</sup>}}}%
                        {\ifvmode \IgnorePar\fi \EndP\HCode{</fn>}\egroup\box\footnotebox} 

我得到了以下输出

<p class="noindent">Some Text1<a id="x1-1001f1"></a>    </p><fn id="sample_fn_001" symbol="1">   1language has evolved gradually: as the need arose for actions beyond</fn>                     
    some text text

在脚注标记处和脚注中打印脚注编号?如何抑制脚注编号和链接ID<a id="x1-2f1"></a>

段落在错误的地方</p>结束<fn>

请建议如何配置以获得预期的输出

平均能量损失

\documentclass{article}

\title{Sample TeX4HT}

\begin{document}
\maketitle

\section{A Head}\label{sec1}

Some Text\footnote{language has evolved gradually: as the need arose for actions beyond} some text text

\end{document}

答案1

编辑:

我找到了一个修复这个虚假<a>命令的方法。可以使用该命令禁用交叉引用的下一个链接目标\SkipRefstepAnchor。以下配置使用该命令修补了该\footnote命令。其余代码的描述位于配置文件下方的原始答案中。

\Preamble{xhtml}

\makeatletter

% remove the footnote number in text
\Configure{footnotemark}{\setbox0=\vbox\bgroup}{\egroup}

% the <fnlabel> element is used to enclose the <a> element inserted by the referencing mechanism
% it will be then removed using Lua post-processing


\Configure{footnotetext}{%
\SaveEndP% don't print </p> in the next \EndP
\HCode{<fn id="\jobname_fn_00\thefootnote" symbol="\FNnum">}%
\IgnorePar% ignore next paragraph
\setbox0=\vbox\bgroup% remove the footnote number from footnote text
}%
{\egroup\par\IgnoreIndent\ShowPar}% start the paragraph in footnote
{\EndP% insert the closing </p>
\HCode{</fn>}\RecallEndP}% insert </p> in the next \EndP

\let\oldfootnote\footnote
\def\footnote{\SkipRefstepAnchor\oldfootnote}
\makeatother

\begin{document}
\EndPreamble

原始答案:

您请求的结构是无效的 HTML,因为<p>元素不能包含任何块级元素,包括<p>其本身。但如果您不介意,这里有一个解决方案:

\Preamble{xhtml}

\makeatletter

% remove the footnote number in text
\Configure{footnotemark}{\setbox0=\vbox\bgroup}{\egroup\HCode{<fnlabel>}}

% the <fnlabel> element is used to enclose the <a> element inserted by the referencing mechanism
% it will be then removed using Lua post-processing


\Configure{footnotetext}{%
\HCode{</fnlabel>}%
\SaveEndP% don't print </p> in the next \EndP
\HCode{<fn id="\jobname_fn_00\thefootnote" symbol="\FNnum">}%
\IgnorePar% ignore next paragraph
\setbox0=\vbox\bgroup% remove the footnote number from footnote text
}%
{\egroup\par\IgnoreIndent\ShowPar}% start the paragraph in footnote
{\EndP% insert the closing </p>
\HCode{</fn>}\RecallEndP}% insert </p> in the next \EndP

\begin{document}
\EndPreamble

配置footnotemark会丢弃文本中插入的脚注编号。它使用了一个技巧,我们将内容保存到临时框中,然后将其丢弃。配置中也使用了同样的技巧footnotetext,以删除脚注本身中的脚注标记。

脚注之前的元素<a>是由引用机制插入的,从 TeX 端很难删除。这就是它被包含在元素中的原因<fnlabel>。此阶段的结果如下:

<!--l. 10--><p class="noindent" >Some Text<fnlabel><a 
 id="x1-1001f1"></a></fnlabel><fn id="sample_fn_001" symbol="1">
<!--l. 10--><p class="noindent" ><span 
class="cmr-8">language has evolved gradually: as the need arose for actions beyond</span></p></fn>
some text text
</p>

可以<fnlabel>使用 DOM 过滤器删除make4ht。将以下内容保存为mybuild.mk4

local domfilter = require "make4ht-domfilter"

local process = domfilter {
  function(dom)
    for _, el in ipairs(dom:query_selector("fnlabel")) do
      el:remove_node()
    end
    return dom
  end
}


Make:match("html$", process)

可以使用以下方式编译

make4ht -e mybuild.mk4 -c config.cfg filename.tex

这是最终结果:

<!-- l. 10 --><p class='noindent'>Some Text<fn id='sample_fn_001' symbol='1'>
<!-- l. 10 --><p class='noindent'><span class='cmr-8'>language has evolved gradually: as the need arose for actions beyond</span></p></fn>
some text text
</p>

相关内容