tex4htebookの図内に動的に挿入された改ページのマージンを取得する方法

Aug 17 2020

概要

LaTeXとtex4htを使用して電子書籍を作成しています。図として扱いたいテキストがあります。このテキストは複数のページにまたがる場合があります。その場合、電子ブックビューアから動的に挿入された改ページは、余白に関係なくテキストを分割します(少なくとも、それを制御する方法がわかりません)。つまり、改ページはテキスト行の垂直方向の中央で発生する可能性があります。

以下は私のMWEからのそのような行の例です。

CSSにさまざまな余白とパディングを追加しようとしましたが、何も機能しませんでした。どうすればこれを防ぐことができますか?

私はCalibreのebook-convertを使用してebookを作成していますが、複数の作成プログラム、複数の形式、および複数のebookビューアを試しました。試したものはすべて、この問題に関して同様に動作します。

MWE

mwe.tex

\documentclass[ebook]{book}

%% Do-nothing environments that provide CSS hooks
\newenvironment{wrap-html-outer}{}{}
\newenvironment{wrap-html-inner}{}{}

\newenvironment{textfigure}{%
  \begin{figure}%
  \begin{wrap-html-outer}%
  \begin{wrap-html-inner}%
}
{
  \end{wrap-html-inner}%
  \end{wrap-html-outer}%
  \end{figure}%
}

\usepackage{lipsum}

\begin{document}

Some text before the figure.

\begin{textfigure}%
\lipsum
\end{textfigure}

Some text after the figure.

\end{document}

tex4ht.cfg

\RequirePackage{include4ht}
\Preamble{xhtml}

\AddCss{custom.css}
\ConfigureEnv{wrap-html-outer}{\HCode{<div class="wrap-html-outer">}}{\HCode{</div>}}{}{}
\ConfigureEnv{wrap-html-inner}{\HCode{<div class="wrap-html-inner">}}{\HCode{</div>}}{}{}

\begin{document}
\EndPreamble

custom.css

p.noindent {
    text-indent: 0;
}

div.figure {
  margin-top: 1em;
  margin-bottom: 1em;
}

div.wrap-html-outer {
    text-align: center;
    padding: 1em 2em;
}

div.wrap-html-inner {
    display: inline-block;
    text-align: left;
}

コマンド

% htxelatex mwe "tex4ht.cfg,xhtml,charset=utf-8" " -cunihtf -utf8" ""
% /Applications/calibre.app/Contents/MacOS/ebook-convert mwe.html mwe.epub --extra-css custom.css

回答

1 michal.h21 Aug 17 2020 at 15:53

残念ながら、いくつかのPythonライブラリの衝突により、Calibreが私のシステムで壊れています。しかし、この問題はGnomeの電子ブックビューアであるFoliateで確認できます。

私が見ることができる1つの問題は、テキストフロートのコンテンツ全体が<p>要素に囲まれていることです。これは無効なHTMLです。一般に、などのブロックレベルの要素を挿入する前に、段落を閉じる必要があります<div>。次のコマンドを使用して実行できます。

\ifvmode\IgnorePar\fi\EndP

これは、それぞれの前に実行する必要があります\HCode{<div ...>}。次に、を使用して新しい段落を要求でき\parます。更新された構成ファイルは次のようになります。

\RequirePackage{include4ht}
\Preamble{xhtml}

\AddCss{custom.css}
\def\closecurrentpar{\ifvmode\IgnorePar\fi\EndP}
\ConfigureEnv{wrap-html-outer}{\closecurrentpar\HCode{<div class="wrap-html-outer">}\par}{\closecurrentpar\HCode{</div>}}{}{}
\ConfigureEnv{wrap-html-inner}{\closecurrentpar\HCode{<div class="wrap-html-inner">}\par}\closecurrentpar{\HCode{</div>}}{}{}

\begin{document}
\EndPreamble

ただし、これで実際の問題が解決するわけではありません。それはあなたのCSSのこの宣言によって引き起こされているようです:

div.wrap-html-inner {
    display: inline-block;
    text-align: left;
}

を削除するdisplay: inline-block;と、線が正しく表示されます。この宣言の目的は何ですか?