tex4ht:“wrapfig”和“caption”包之间的冲突

tex4ht:“wrapfig”和“caption”包之间的冲突

梅威瑟:

\documentclass[12pt]{book}

\usepackage{caption}
\usepackage{wrapfig}

\begin{document}
\begin{wrapfigure}{o}{1.25in}
\end{wrapfigure}
\end{document}

如果我使用tex4ebook或进行编译htlatex,则会出现错误:

! Undefined control sequence.
\b:wrapfloat ->\endWrap 

l.8 \end{wrapfigure}

请注意,使用 pdflatex 进行编译时没有错误,并且如果我更改包含captionwrapfig包的顺序,则不会出现任何错误。

我希望这些文件有所改进.4ht

(顺便问一下,有人知道如何配置tex4ebook以便它在出现错误时暂停编译,而不是像以前一样悄悄地忽略它们?)

编辑:正如michal-h21指出的那样,在较新版本中tex4ebook,使用参数运行-a debug就足够了。

带标题的示例代码:

\documentclass[12pt]{book}

\usepackage[labelformat=empty]{caption}
\usepackage{wrapfig}

\begin{document}
\begin{wrapfigure}{o}{1.25in}
\caption{Test}
\end{wrapfigure}
\end{document}

答案1

似乎 Caption 包重新定义了很多其他包的命令。它在 TeX4ht 已经修补了这些包中的命令之后这样做,导致插入的 TeX4ht 配置丢失。我认为唯一安全的解决方案是防止 Caption 修补所有这些命令。尝试这个版本的usepackage.4ht

% usepackage.4ht (2019-12-13-14:32), generated from tex4ht-4ht.tex
% Copyright 2003-2009 Eitan M. Gurari
% Copyright 2009-2019 TeX Users Group
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either
% version 1.3c of this license or (at your option) any
% later version. The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3c or later is part of all distributions
% of LaTeX version 2005/12/01 or later.
%
% This work has the LPPL maintenance status "maintained".
%
% The Current Maintainer of this work
% is the TeX4ht Project <http://tug.org/tex4ht>.
%
% If you modify this program, changing the
% version identification would be appreciated.
\immediate\write-1{version 2019-12-13-14:32}

   \def\:temp{tex4ht}\ifx \:temp\@currname
   \:warning{\string\usepackage{tex4ht} again?}
   \def\:temp#1htex4ht.def,tex4ht.sty#2!*?: {\def\:temp{#2}}
\expandafter\:temp \@filelist htex4ht.def,tex4ht.sty!*?: %
\ifx \:temp\empty  \else
   \:warning{if
    \string\RequirePackage[tex4ht]{hyperref} or
    \string\usepackage[tex4ht]{hyperref} was
    used try instead, repectively,
    \string\RequirePackage{hyperref} or
    \string\usepackage{hyperref}}
\fi

\fi
\gdef\a:usepackage{\use:package xr,xr-hyper,eso-pic,expl3,savetrees,biblatex,xeCJK,polyglossia,fontspec,tikz,pdfbase,graphics,xcolor,imakeidx,minted,fancyhdr,caption,,!*?: }
\gdef\use:package#1,{%
   \if :#1:\def\:temp##1!*?: {}\else
      \def\:temp{#1}\ifx \@currname\:temp
             \def\:temp##1!*?: {\input usepackage.4ht  }%
      \else \let\:temp=\use:package \fi
   \fi \:temp}
\def\:temp{xr}\ifx \@currname\:temp
   \AtEndOfPackage{\let\XR:\XR@
   \def\XR@[#1]#2{%
    \Configure{AtBeginDocument}{\XR:[#1]{#2}}{}}%
}

\fi
\def\:temp{xr-hyper}\ifx \@currname\:temp
   \AtEndOfPackage{\let\XR:\XR@
    \def\XR@[#1][#2]#3{%
      \AtBeginDocument{\XR:[#1][#2]{#3}}
    }%
}

\fi
\def\:temp{eso-pic}\ifx \@currname\:temp
\:dontusepackage{eso-pic}
\newcommand\AddToShipoutPicture{\@ifstar{}{}}
\let\AddToShipoutPictureBG\AddToShipoutPicture
\let\AddToShipoutPictureFG\AddToShipoutPicture
\fi
\def\:temp{expl3}\ifx \@currname\:temp
\ifdefined\XeTeXversion%
\xenunidelblock{Latin-expl3}%
\AtEndOfPackage{\xeuniuseblock{Latin-expl3}}
\fi
\fi
\def\:temp{savetrees}\ifx \@currname\:temp
\:dontusepackage{savetrees}
\fi
\def\:temp{biblatex}\ifx \@currname\:temp
\AtEndOfPackage{%
  \def\blx@mknoautolang{%
    \blx@lbxinput{\blx@languagename}%
    {}{}%
  }%
  \def\blx@lbxinput@iii#1#2{%
  \global\csundef{blx@lng@#2}%
  \:IfFileExists{#1.lbx}
    {\blx@lbxinput@iv{#2}{#1}{language '#2' -> '#1'}}
    {\ifcsdef{blx@suffmaptried@#2}
      {}
      {\blx@warning@noline{%
          File '#1.lbx' not found!\MessageBreak
          Ignoring mapping '#2' -> '#1'}%
       \global\cslet{blx@suffmaptried@#2}\@empty}%
     \blx@lbxinput@iv{#2}{#2}{language '#2'}}}

}
\fi
\def\:temp{xeCJK}\ifx \@currname\:temp
\:dontusepackage{xeCJK}
\AtEndOfPackage{%
  \RequirePackage{fontspec}
}
\DeclareDocumentCommand\setCJKmainfont{o m o}{}
\let\setCJKsansfont\setCJKmainfont
\let\setCJKmonofont\setCJKmainfont

\DeclareDocumentCommand\setCJKfamilyfont {m o m }{}
\DeclareDocumentCommand\newCJKfontfamily {o m o m}{\expandafter\gdef\csname #2\endcsname{\relax}}

\DeclareDocumentCommand\xeCJKsetup{m}{}
% }
\AtBeginDocument{%
  \xeuniuseblock{CJK}
}
\fi
\def\:temp{polyglossia}\ifx \@currname\:temp
\ExplSyntaxOn
\AtEndOfPackage{

\cs_set_eq:NN\orig_polyglossia@keys_define_lang:n\polyglossia@keys_define_lang:n
\cs_set_protected:Npn \polyglossia@keys_define_lang:n #1 {
  \orig_polyglossia@keys_define_lang:n{#1}
  \keys_define:nn {polyglossia}{
    #1 / direction
    .  code:n = {}
  }
}
\def\RequireBidi{}%
}
\ExplSyntaxOff
\fi
\def\:temp{fontspec}\ifx \@currname\:temp
  \ifdefined\fontspec
    \:dontusepackage{fontspec}
  \else
    \input usepackage-fontspec.4ht
  \fi
\fi
\def\:temp{tikz}\ifx \@currname\:temp
\AtEndOfPackage{%
\let\use:tikzlibrary\usetikzlibrary
\def\find:externalize#1external#2\@nil{%
\if\relax#2\relax\else
  \let\tikz:externalize\tikzexternalize
  \renewcommand\tikzexternalize[1][]{\tikz:externalize[##1,mode=only graphics]}
    \tikzset{%
      tex4ht inc/.style={%
        /pgf/images/include external/.code={%
          \includegraphics[]{####1.pdf}%
        }%
      }
    }
    \tikzset{tex4ht inc}
  \fi
}
\renewcommand\usetikzlibrary[1]{%
  \use:tikzlibrary{#1}%
  \find:externalize#1external\@nil%
}
}
\fi
\def\:temp{pdfbase}\ifx\@currname\:temp
\AtEndOfPackage{%
  \let\old:outputpage\@outputpage
  \def\@outputpage{\old:outputpage{}}
}
\fi
\def\:temp{graphics}\ifx\@currname\:temp
  \ifdefined\XeTeXversion
    \PassOptionsToPackage{dvips}{graphics}
  \fi
\fi
\def\:temp{xcolor}\ifx\@currname\:temp
  \ifdefined\XeTeXversion
    \PassOptionsToPackage{dvips}{xcolor}
  \fi
\fi
\def\:temp{imakeidx}\ifx\@currname\:temp
  \PassOptionsToPackage{noautomatic}{imakeidx}
\fi
\def\:temp{minted}\ifx\@currname\:temp
  \AtEndOfPackage{%
    \define@booleankey{minted@opt@g}{breaklines}{}{}{}%
  }
\fi
\def\:temp{fancyhdr}\ifx\@currname\:temp
  \AtEndOfPackage{%
  \def\ps@fancy{}%
  }
\fi

\def\:temp{caption}\ifx\@currname\:temp
\AtEndOfPackage{%
\long\def\caption@If@Package@Loaded#1[#2]#3#4{}
}
\fi

\endinput

重要的部分是这样的:

\def\:temp{caption}\ifx\@currname\:temp
\AtEndOfPackage{%
\long\def\caption@If@Package@Loaded#1[#2]#3#4{}
}
\fi

此代码在 Caption 加载时插入,使用在加载包代码后执行的代码。它重新定义负责包修补的命令,使其不执行任何操作\usepackage\AtEndOfPackage

这是示例生成的 HTML:

<body>
   <div class='wrapfig-o'>                       </div>

</body> 

相关内容