htlatex 与 tcolorbox 忽略框内的左侧空白

htlatex 与 tcolorbox 忽略框内的左侧空白

我正在使用 tcolorbox 包,我需要生成 html 输出和 pdf 输出。当我将 tcolorbox 与 pdflatex 一起使用时,它工作正常,并生成一个两边都有空格的漂亮框。当我使用 htlatex (make4ht mwe.tex) 时,它会忽略左侧的空格。这是 htlatex 中的错误吗?有人知道是否有修复方法吗?

生成图像的最小工作示例:

\documentclass[12pt, a4paper]{article}
\usepackage{tcolorbox}

\begin{document}

Here is an example.
\begin{tcolorbox}[title=Example 1]
The should display as a nice box with some white space on the left and the right. 
It works fine with latex2pdf but when I use it with htlatex (make4ht) it ignores the space on the left.
\end{tcolorbox}
\end{document}

由 make4ht mws.tex 制作 由 pdflatex mws.tex 制作

答案1

尝试这个配置文件:

\Preamble{xhtml}
\catcode`\:=11
\makeatletter
\def\calc:tcbpadding#1{\strip@pt\dimexpr \kvtcb@boxsep+#1\relax px}
\pend:def\a:tcolorbox{\Css{\#\:tcbcolid\space div{
  padding-top:\calc:tcbpadding{\kvtcb@top};
  padding-bottom:\calc:tcbpadding{\kvtcb@bottom};
  padding-left:\calc:tcbpadding{\kvtcb@leftupper};
  padding-right:\calc:tcbpadding{\kvtcb@rightupper};
}}}
\makeatother
\catcode`\:=12
\begin{document}
\EndPreamble

它使用 Tcolorbox 用于 CSS 填充的尺寸。为了说明这一点,我在您的示例中添加了几个框:

\documentclass[12pt, a4paper]{article}
\usepackage{tcolorbox}

\begin{document}

Here is an example.
\begin{tcolorbox}[title=Example 1]
The should display as a nice box with some white space on the left and the right. 
It works fine with latex2pdf but when I use it with htlatex (make4ht) it ignores the space on the left.
\end{tcolorbox}

\begin{tcolorbox}[title=Example 2, boxsep=1em]
The should display as a nice box with some white space on the left and the right. 
It works fine with latex2pdf but when I use it with htlatex (make4ht) it ignores the space on the left.
\end{tcolorbox}

\begin{tcolorbox}[title=Example 3, left=2cm]
The should display as a nice box with some white space on the left and the right. 
It works fine with latex2pdf but when I use it with htlatex (make4ht) it ignores the space on the left.
\end{tcolorbox}
\end{document}

结果如下:

在此处输入图片描述

相关内容