LaTeX 到 Epub 的转换

LaTeX 到 Epub 的转换

我想将epub文件从LaTeX或转换XML。您能建议哪种方法最好吗?

  1. LaTeX 到 EPUB 的转换?
  2. XML 到 EPUB 的转换。

TeX4HTMake4HTPandoc

最好的转换方法是什么EPUB

LaTeX文件基于自定义 LaTeX 模板并具有许多\usepackage选项。

我的 MWE 是:

\providecommand{\pgfsyspdfmark}[3]{}
\documentclass{acm-book}

\usepackage{showframe}
\usepackage{balance}
\usepackage{amsmath}
\usepackage{booktabs,hyperref,listings,xcolor,colortbl}
\usepackage[inactive]{fancytooltips}
\usepackage{wrapfig}
\usepackage{afterpage}
\usepackage{makeidx}

\hypersetup{
pdftitle={A Technical History},
pdfauthor={W. Trcy -- Rose-Hulman, IN, USA},
pdfkeywords={Morgan \& Claypool},%
}

\newcommand\BookSeries[1]{#1}
\newcommand\BookAffil[1]{#1}
\newcommand\HalfTitle[1]{#1}
\newcommand\Author[1]{#1}
\newcommand\Affiliation[1]{#1}
\definecolor{titlecolor}{cmyk}{0, 0.7808, 0.4429, 0.1412}

\makeindex
\begin{document}

\chapter*{Preface}

Furthermore, legacy software systems are notoriously difficult to replace. As noted experienced by this author as a chief information officer, legacy systems take considerable effort and money to replace and tend to be built upon, rather than replaced. So, those working on systems for complex organizations are likely to have to deal with these existing software systems. US Social Security Administration still dependencies on legacy software further entrenches its use. Other systems used by the US government have software sub-systems.

\begin{quote}
But we [historians] remain largely ignorant about the origins and development of the dynamic processes running on those devices [computers], but primarily they will be histories of software.
\end{quote}

In the last couple of decades, software has gotten attention as a distinct topic from computer history. In particular there are wide-scoping works on the software industry. There's also been work on the evolved.

\begin{figure}[!h] 
{\includegraphics{graphics/chapter_01/Figure_05.pdf}}
\caption{\label{fig:1.19}The Atanasoff--Berry Computer (ABC) with a drum memory\index{Atanasoff--Berry Computer (ABC)!drum memory@with drum memory} (circa 1942). (Source: Iowa State Univ. Library Special Collections and Univ. Archives.)}
\end{figure}

Software\index{Software|(} is a relatively recent technology, really only beginning in its own right in the 1950s. In the time since then, it's taken many forms, evolved immensely in the tools used, and in the purposes to which it has been put. Interestingly, software has become so varied and so complex that many current students of technology do not have a basic knowledge of the history of software. As a result, students and practitioners are sometimes repeating mistakes of the past and often relearning how to build successful systems. Additionally, some areas of software require a working knowledge of previously deployed software systems and their design decisions, such as software security\index{Software!security}. 

$$
{e}_{D}{({v})}=max{\{{D}{({{u},{v}})}:{u}∈{V}\}}
$$

When reusing existing software, it is wise to evaluate the relevance of the techniques and assumptions that were used in building that original software. This book focuses on software as a technology and how it has evolved over time. We will look at the trends, important innovations, and events, as well as the ever-broadening world of software.

\printindex

\end{document}

答案1

由于您已经使用 TeX4ht,因此可以使用tex4ebook基于 TeX4ht 的命令进行转换。我只发现您的文件存在一些问题。首先,您使用的命令也\Author被使用tex4ebook。当您在文档中定义它时,您将收到运行时错误,因为它已经定义。为了正确运行,您必须改用以下命令:

 \providecommand\Author[1]{#1\def\Author{#1}}

之所以\def\Author使用,是因为tex4ebook在保存文档元数据时需要在文档末尾添加作者信息。

我还发现该命令存在问题\caption。可以使用以下版本修复nameref.4ht

% nameref.4ht (2022-06-27-11:59), generated from tex4ht-4ht.tex
% Copyright 2005-2009 Eitan M. Gurari
% Copyright 2009-2022 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 2022-06-27-11:59}

   \let\NR:Type\relax
\let\ltx@label\label
\def\prf:label{{\ifx \NR:Title\:UnDef \else \NR:Title\fi}%
               {\ifx \NR:Type\relax \else \NR:Type .1\fi}{}}%
\let\NR:StartSec\:StartSec
\let\NR:no@sect\no@sect
\def\no@sect#1#2#3#4#5#6[#7]#8{\gdef\NR:Title{\a:newlabel{#7}}%
    \gdef\NR:Type{#1}%
    \NR:no@sect{#1}{#2}{#3}{#4}{#5}{#6}[{#7}]{#8}}
\def\:StartSec#1#2#3{%
   \gdef\NR:Title{\a:newlabel{#3}}%
   \gdef\NR:Type{#1}%
   \NR:StartSec{#1}{#2}{#3}%
}

\def\:tempc#1#2#3#4#5#6[#7]#8{%
   \gdef\NR:Title{\a:newlabel{#7}}%
   \gdef\NR:Type{#1}%
   \o:NR@sect:{#1}{#2}{#3}{#4}{#5}{#6}[{#7}]{#8}}
\HLet\NR@sect\:tempc

\def\:tempc#1#2#3#4#5{%
   \gdef\NR:Title{\a:newlabel\ssect:ttl}%
   \gdef\NR:Type{#1}%
   \o:NR@ssect:{#1}{#2}{#3}{#4}{#5}%
}
\HLet\NR@ssect\:tempc

\def\:tempc[#1]#2{%
   \gdef\NR:Title{\a:newlabel{#1}}%
   \gdef\NR:Type{part}%
   \o:no@part:[{#1}]{#2}}

% this definition clashes with asmart and amsproc classes, so we
% need to skip if these are active
\@ifundefined{[email protected]}{%
\@ifundefined{[email protected]}{%
\HLet\no@part\:tempc
}{}}{}


\def\:tempc#1{%
   \gdef\NR:Title{\a:newlabel{#1}}%
   \gdef\NR:Type{part}%
   \o:no@spart:{#1}}
\HLet\no@spart\:tempc

\def\:tempc[#1]#2{%
   \gdef\NR:Title{\a:newlabel{#1}}%
   \gdef\NR:Type{chapter}%
   \o:NR@chapter:[{#1}]{#2}}
\HLet\NR@chapter\:tempc

\def\:tempc#1{%
   \gdef\NR:Title{\a:newlabel\sch:ttl}%
   \o:NR@schapter:{#1}%
   \gdef\NR:Type{chapter}%
}
\HLet\NR@schapter\:tempc

\let\o:NR@@caption\@caption
%
%
% Keith Andrews <[email protected]> reported that \@captype as
% \NR:Type threw an undefined control sequence error. I think
% \@currenvir is safe, there is nothing special about \@captype.
%
% use of \index and \label inside caption results in a fatal error
% we need to disable them in \NR:Title
\long\def\@caption#1[#2]{%
    \gdef\NR:Type{\@currenvir}%
    \begingroup%
    \let\index\:gobble%
    \let\label\:gobble%
    \xdef\NR:Title{\a:newlabel{#2}}%
    \endgroup%
   \o:NR@@caption{#1}[{#2}]%
}

\let\o:NRorg@opargbegintheorem\@opargbegintheorem
  \def\@opargbegintheorem#1#2#3{%
    \gdef\NR:Title{\a:newlabel{#3}}%
    \gdef\NR:Type{\@currenvir}%
    \NR@gettitle{#3}%
    \defineautorefname{\@currenvir}{#1}%
    \o:NRorg@opargbegintheorem{#1}{#2}{#3}%
  }%

\let\o:NRorg@begintheorem\@begintheorem
  \def\@begintheorem#1#2{%
    \gdef\NR:Title{\a:newlabel{#1 #2}}%
    \gdef\NR:Type{\@currenvir}%
    \defineautorefname{\@currenvir}{#1}%
    \NR@gettitle{}%
    \o:NRorg@begintheorem{#1}{#2}%
  }%

% I don't know if this was useful for anything
% but we cannot use it anymore
% \AtBeginDocument{%
\@ifpackageloaded{listings}{%
      \def\:tempc#1{%
         \gdef\NR:Title{\a:newlabel{listing}}%
         \gdef\NR:Type{lstlisting}%
         \o:NROrg@lst@MakeCaption:{#1}%
         \gdef\@currentlabelname{listing}}
      \HLet\NROrg@lst@MakeCaption\:tempc
}{}%
  % bug [348]
\def\:tempams{%
    \gdef\NR:Title{\a:newlabel{equation}}%
    \gdef\NR:Type{equation}%
    \gdef\@currentlabelname{equation}%
}

% https://tex.stackexchange.com/a/581856/2891
\@ifpackageloaded{caption}{
  \pend:defIII\caption@beginex{%
    \gdef\NR:Type{\@currenvir}%
    \gdef\NR:Title{\a:newlabel{##2}}%
  }
}{}


\@ifpackageloaded{amsmath}{%
     \Configure{@begin}{align}{\:tempams}
     \Configure{@begin}{multline}{\:tempams}
     \Configure{@begin}{equation}{\:tempams}
     \Configure{@begin}{boxed}{\:tempams}
     \Configure{@begin}{equations}{\:tempams}
     \Configure{@begin}{equation}{\:tempams}
     \Configure{@begin}{gather*}{\:tempams}
     \Configure{@begin}{gather}{\:tempams}
     \Configure{@begin}{genfrac}{\:tempams}
     \Configure{@begin}{measure@}{\:tempams}
     \Configure{@begin}{multline*}{\:tempams}
     \Configure{@begin}{multline}{\:tempams}
     \Configure{@begin}{overset}{\:tempams}
     \Configure{@begin}{smallmatrix}{\:tempams}
     \Configure{@begin}{split}{\:tempams}
     \Configure{@begin}{subarray}{\:tempams}
     \Configure{@begin}{substack}{\:tempams}
     \Configure{@begin}{underset}{\:tempams}
     \Configure{@begin}{xleftarrow}{\:tempams}
     \Configure{@begin}{xrightarrow}{\:tempams}
  }{
     \Configure{@begin}{equation}{\:tempams}
}

\let\T:ref=\::ref
\def\::ref{\@ifstar{\protect\T@ref}{\protect\T@ref}}
\def\T@ref#1{%
  \@safe@activestrue
  \let\::ref \T:ref
  \expandafter\@setref\csname r@#1\endcsname\@firstoffive{#1}%
  \def\::ref{\@ifstar{\protect\T@ref}{\protect\T@ref}}
  \@safe@activesfalse
}

\gdef\defineautorefname#1#2{%
    \expandafter\gdef\csname #1autorefname\endcsname{#2}}
\defineautorefname{theorem}{Theorem}

\Configure{newlabel}
   {\csname cur:th\endcsname \csname :currentlabel\endcsname}
   {\string\csname\space :autoref\string\endcsname
     {\NR:Type}#1}

\ifx \@currentlabelname\:UnDef
   \let\@currentlabelname\empty
\fi

\pend:defIII\@setref{\edef\RefArg{##3}}
\append:defIII\@setref{\let\:autoref\:gobble}
\let\:autoref\:gobble


\Hinput{nameref}
\endinput

然后,您可以使用以下方法编译您的文档:

tex4ebook -lf epub3 sample.tex

这是 Calibre 中的结果:

在此处输入图片描述

相关内容