วิธีรับระยะขอบของตัวแบ่งหน้าแทรกแบบไดนามิกภายในรูป ebook ของ tex4ht

Aug 17 2020

สรุป

ฉันกำลังสร้าง ebook โดยใช้ LaTeX และ tex4ht ฉันมีข้อความบางอย่างที่ฉันต้องการจะถือว่าเป็นรูปเป็นร่าง บางครั้งข้อความนี้ครอบคลุมหลายหน้า เมื่อเป็นเช่นนั้นหน้าที่แทรกแบบไดนามิกจะแตกออกจากโปรแกรมดู ebook จะแยกข้อความออกโดยไม่คำนึงถึงระยะขอบ (อย่างน้อยฉันก็คิดไม่ออกว่าจะควบคุมอย่างไร) กล่าวอีกนัยหนึ่งการแบ่งหน้าสามารถเกิดขึ้นตรงกลางแนวตั้งของบรรทัดข้อความ

นี่คือตัวอย่างของบรรทัดดังกล่าวจาก MWE ของฉันด้านล่าง

ฉันได้ลองเพิ่มระยะขอบและช่องว่างใน CSS แล้ว แต่ก็ไม่ได้ผล ฉันจะป้องกันไม่ให้สิ่งนี้เกิดขึ้นได้อย่างไร

ฉันใช้ ebook-convert ของ Calibre เพื่อสร้าง 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

น่าเสียดายที่ Calibre เสียในระบบของฉันเนื่องจากการปะทะกันของไลบรารี Python แต่ฉันสามารถยืนยันปัญหานี้ได้ใน Foliate ซึ่งเป็นโปรแกรมดู Ebook สำหรับ Gnome

ปัญหาหนึ่งที่ฉันเห็นคือเนื้อหาทั้งหมดของโฟลทข้อความของคุณอยู่ใน<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;เส้นจะแสดงอย่างถูกต้อง คำประกาศนี้มีจุดประสงค์อะไร?