问题

问题

问题

当段落包含块引用时,xelatex 会正确格式化引用后的部分,而无需缩进。然而,Tex4ht 会将其视为新的段落,因此会缩进。

平均能量损失

主要.tex:

%!TEX TS-program = xelatex
%!TEX encoding = UTF-8 Unicode

% Normal:
\documentclass[12pt,letterpaper,oldfontcommands,article]{memoir}

\begin{document}

\section{a section}

First paragraph.

Second paragraph. This one is indented. That is how it should be.
\begin{quote}
This is a block quote.
\end{quote}
This continuation of the paragraph after the block quote should not be indented. With xelatex it is not, but with tex4ht it is.

When a block quote comes at the end of a paragraph, by contrast, the new paragraph should be indented.
\begin{quote}
Here is another block quote.
\end{quote}

This is a new paragraph, so it \emph{should} be indented, to make clear that it is a new paragraph rather than the continuation of the paragraph containing the block quote.
\end{document}

编译命令:

make4ht -ux -a debug -f odt main.tex

xelatex 输出(正确):

在此处输入图片描述

tex4ht 输出(不正确):

在此处输入图片描述

要看的重点段落是“第二段”。

问题

我怎样才能使 tex4ht 产生正确的输出?

答案1

尝试这个配置文件:

\Preamble{xhtml}
\catcode`\:=11
\ConfigureEnv{quote}
   {\ifvmode \IgnorePar\fi \EndP
\ifnum \BegEnd:D=0
   \gHAdvance\BegEnd:N by 1
\HCode{<text:section
        text:style-name="begin-end-env"
        text:name="begin-end-env-\BegEnd:N"
       >%
       <text:p text:style-name="begin-env-p" ></text:p>}%
%
\else
   \gHAdvance\BegEnd:N by 1
\hbox{\HCode{<text:p><draw:frame
                draw:name="begin-end-env-\BegEnd:N"
                 draw:style-name="env-frame"
                 text:anchor-type="as-char"
%                 fo:min-width="0.14in"
                 svg:width="90\%"
                 draw:z-index="0"
       >
       <draw:text-box
%           fo:min-height="0.14in"
       >}}%
%
\fi
\gHAdvance\BegEnd:D by 1
}
   {\gHAdvance\BegEnd:D by -1
\ifvmode \IgnorePar\fi\EndP
\ifnum \BegEnd:D=0
   \HCode{<text:p text:style-name="end-env-p" ></text:p></text:section>}%
%
\else
   \hbox{\HCode{</draw:text-box>
</draw:frame></text:p> }}%
%
\fi
\par\noindent}
   {\EndP \ifvmode \IgnorePar\fi
    \bgroup \Configure{HtmlPar}
   {\EndP \HCode{<!--l. \the\inputlineno-->%
%
                 <text:p text:style-name="quote\if@rl-rtl\fi
"
                         >}}
   {\EndP \HCode{<!--l. \the\inputlineno-->%
%
                 <text:p text:style-name="quote\if@rl-rtl\fi
"
                          >}}
   {\HCode{</text:p>}}
   {\HCode{</text:p>}}%
%
   }
   {\IgnorePar\EndP \egroup \ShowPar \ShowIndent}
\catcode`\:=12
\begin{document}
\EndPreamble

这是 TeX4ht 源引用配置的副本。唯一的变化是它使用

par\noindent 

命令位于第三个参数的末尾,以抑制缩进。

结果如下:

在此处输入图片描述

编辑:

要删除缩进段落前的空段落,请使用此构建文件build.lua

local domfilter = require "make4ht-domfilter"


local process = domfilter {
  -- this function removes empty paragraphs after quote environment
  function(dom)
    -- test if the previous paragraph style was "quote"
    local ignored_styles = {
      ["end-env-p"] = true
    }
    local prev_style 
    for _, par in ipairs(dom:query_selector("text|p")) do
      local style = par:get_attribute("text:style-name")
      -- if the previous paragraph was quote and the current paragraph is empty,
      -- then remove it
      if prev_style == "quote" then
        if not ignored_styles[style] 
           and par:get_text():gsub("%s*", "") == "" -- test if paragraph is empty
        then
          par:remove_node()
        end
      end
      -- ignore the end-env-p style, which is inserted at the end of the quote environment
      if not ignored_styles[style] then
        prev_style = style
      end
    end

    
    return dom
  end
}

-- register the filter to process the document
Make:match("4oo", process)

编译使用:

make4ht -c config.cfg -f odt -e build.lua filename.tex

相关内容