%\NewConfigure{ncxtable}{} %Configure date meta info \def\:zeropadtwo#1{% \ifnum #1<10 0\fi #1% Then output the argument }% --- \zeroPadTwo --- \def\time:round:corr{\ifnum\the\numexpr\the\time-\the\time/60*60\relax<0 1\else 0\fi} \def\:iso:date{% \the\year-% \:zeropadtwo{\the\month}-% \:zeropadtwo{\the\day}% %Timestamp will be zero seconds T\:zeropadtwo{\the\numexpr(\the\time/60)-\time:round:corr\relax}:% \:zeropadtwo{\the\numexpr\the\time-((\the\time/60)-\time:round:corr)*60\relax}:% 00Z} %General configuration \Configure{DOCTYPE}{\HCode{}} \NewConfigure{EpubVersion}{1} \Configure{EpubVersion}{2.0} \NewConfigure{UniqueIdentifier}{1} \Configure{UniqueIdentifier}{http://example.com/\jobname} % allow configuration of the document language. babel's main language is used by default % use this only if it doesn't work \NewConfigure{DocumentLanguage}[1]{\def\GetLanguage{#1}} % definitions of commands ignored in \author \def\a:@author{} \NewConfigure{@author}[1]{\concat:config\a:@author{#1}} \NewConfigure{OpfScheme}{1} \Configure{OpfScheme}{URI} \NewConfigure{OpfMetadata}[1]{ \ifx\relax#1\relax% \edef\a:OpfMetadata{} \else \edef\a:OpfMetadata{\a:OpfMetadata\HCode{\Hnewline}#1} \fi } \Configure{OpfMetadata}{} % This commands add filenames to opf item list and spine \edef\opf:htmlfiles{} \newcount\opf:htmlid \def\opf:registerfilename#1{% \ifcsdef{opf:entry#1}{}{% \global\advance\opf:htmlid by1\relax %\ifcsdef{opf:entry#1}{}{\csxdef{opf:entry#1}{Neni opf}} \csxdef{opf:entry#1}{file\the\opf:htmlid} \xdef\opf:htmlfiles{\opf:htmlfiles, #1} } } \newcommand\OpfRegisterFile[1][\FileName]{\opf:registerfilename{#1}} \NewConfigure{OpfManifest}[1]{% \ifx\relax#1\relax% \edef\a:OpfManifest{} \else \edef\a:OpfManifest{\a:OpfManifest\HCode{\Hnewline}#1} \fi } \Configure{OpfManifest}{} % This is for add properties like toc or cover image in opf manifest % Property must be added from document usinf \opf:add:property, current output filename is used \NewConfigure{OpfItemProperties}{2} \Configure{OpfItemProperties}{}{} \def\opf:properties#1{% \ifcsdef{opf:properties:#1}{ \a:OpfItemProperties\csuse{opf:properties:#1}\b:OpfItemProperties% }{}% } \def\opf:add:property#1{% \ifcsdef{opf:properties:\FileName #1}{}{% \csxdef{opf:properties:\FileName #1}{#1}% \ifcsdef{opf:properties:\FileName}{% \edef\:opf:prop:tmp{\csuse{opf:properties:\FileName}} \csxdef{opf:properties:\FileName}{\:opf:prop:tmp\space #1} }{\csxdef{opf:properties:\FileName}{#1}} } } % enable simple configuration from the .cfg file \newcommand\OpfAddProperty[1]{\opf:add:property{#1}} %Set property only once \def\opf:set:property#1{} % This code will refister \maketitle page to the opf file list \let\oldmktl\a:mktl \def\a:mktl{\oldmktl\opf:registerfilename{\FileName}} % guide element is used in epub2, it is similar to epub3 properties % in epub3, it is deprecated, but it can be present \edef\opf:guide{\HCode{\Hnewline}} % register file to the guide. first argument is optional filename, current % output name is used when empty. second is title and third type \NewConfigure{OpfGuide}{4} \newcommand\OpfGuide[3][]{% \ifx\relax#1\relax \let\opf:guide:file\FileName\else\def\opf:guide:file{#1}\fi \edef\opf:guide{\opf:guide\a:OpfGuide#3\b:OpfGuide#2\c:OpfGuide\opf:guide:file\d:OpfGuide} } \Configure{OpfGuide}{\HCode{\Hnewline}} % is NavMap used anywhere? \NewConfigure{NavMap}{2} \NewConfigure{NavSection}{4} %Interface for setting xmlns \edef\t4ht:xmlns{} \NewConfigure{xmlns}[2]{% \ifx\relax#2\relax% \edef\t4ht:xmlns{}% \else% %\def\:prefix:xmlns{\ifx\relax#1\relax\else:#1\fi} \edef\t4ht:xmlns{\t4ht:xmlns xmlns\ifx\relax#1\relax\else :#1\fi="#2"}% \fi% } \NewConfigure{CoverImage}{2} \Configure{CoverImage}{% \ifvmode\IgnorePar\fi\EndP\HCode{
\Hnewline} }{\HCode{
\Hnewline}\par} \def\CoverMetadata#1{% \special{t4ht+@File: #1}% \Configure{OpfMetadata} {\HCode{\Hnewline}} \Configure{OpfManifest} {\HCode{}} } \renewcommand\coverimage[2][]{% \edef\CoverImageName{#2}% \CoverMetadata{#2} \a:CoverImage% \includegraphics[#1]{#2}% \b:CoverImage% } \renewcommand\epubpage{\a:epubpage} \NewConfigure{epubpage}{1} \Configure{epubpage}{\ifvmode\IgnorePar\fi\EndP\HCode{
}} \Css{.newpage{page-break-before:always;}} \NewConfigure{CoverMimeType}{1} \Configure{CoverMimeType}{image/png} \TocAt-{part,chapter,section,subsection,subsubsection} \Configure{crosslinks*}{} \NewConfigure{NcxDoctype}{1} \Configure{NcxDoctype}{\HCode{\Hnewline}} %Get sanitized value of \title \ifTag{TITLE+}{\def\Title{\LikeRef{TITLE+}}}{} % If title contains macros, SafeTitle should be configured % in the custom cfg file \NewConfigure{SafeTitle}[1]{\gdef\Title{#1}} % add main html as first file in the OPF \opf:registerfilename{\jobname.\:html} % % register all sectioning commands in the OPF \def\patch:sec:register#1{% \csgappto{c:#1}{\OpfRegisterFile}% } \patch:sec:register{part} \patch:sec:register{chapter} \patch:sec:register{section} \patch:sec:register{subsection} \patch:sec:register{subsubsection} \patch:sec:register{likechapter} \patch:sec:register{likesection} \patch:sec:register{likesubsection} \patch:sec:register{likesubsubsection} \patch:sec:register{appendix} \patch:sec:register{appendixsec} \patch:sec:register{appendixsubsec} \patch:sec:register{appendixsubsubsec} \:CheckOption{epub} \if:Option %\Configure{crosslinks+}{}{}{}{} % add explicit table of contents to OPF \let\old:toc\a:tableofcontents \def\a:tableofcontents{\old:toc\OpfRegisterFile} \Configure{()}{$}{$} \fi \:CheckOption{kindle} \if:Option \fi %% % We must test, it tableofcontents is empty, if yes, we must take special care to navmap \newbool{tocnoempty} \newcount\navpoint \def\stepnavpoint{\advance\navpoint by1\relax\the\navpoint} % define points for breaking section units to html pages % we need to break long documents to smaller chunks, because e-readers are % generally pretty weak devices % use no-cut option if you don't want to break sections, or if you % use your own cutting scheme in your .cfg file \:CheckOption{no-cut}\if:Option\else \ifdef\chapter{% %\CutAt{chapter}\CutAt{likechapter} % copied from tex4ht-html4.tex \CutAt{part,appendix} \CutAt{chapter,likechapter,appendix,part} \CutAt{likechapter,appendix,part} \CutAt{appendix,chapter,likechapter,part} }{% %\CutAt{section}\CutAt{likesection}} \CutAt{section,likesection,part} \CutAt{likesection,part} } \fi % Commands for support of hiearchical table of contents % Support for: chapter, section, subsection \def\resettoclevels#1{% \def\do##1{\csgdef{nav##1finish}{}}% \docsvlist{#1}% } \def\usetoclevels#1{% \def\do##1{\csuse{nav##1finish}}% \docsvlist{#1}% } \def\finishtoclevel#1{% \csgdef{nav#1finish}{\d:NavSection}% } \def\closelevels#1{% \expandafter\usetoclevels\expandafter{#1}% \expandafter\resettoclevels\expandafter{#1}% }% % 1 - section type 2 - closed sections \def\navsection#1#2{% \ConfigureToc{#1}% {\expandafter\closelevels\expandafter{#2}% \def\curr:sect:type{#1}\a:NavSection\Ncx:Mark}% {\c:NavSection}% {}% {\b:NavSection% \expandafter\finishtoclevel\expandafter{#1}% } } % define closing groups for all levels defined in \Configure{resettoclevels} \def\tmp:processlevel#1{% \bgroup% \csxdef{tmp:resettoclevels#1}{}% \def\do##1{\csxdef{tmp:resettoclevels#1}{\csname tmp:resettoclevels#1\endcsname ##1,like##1,\appendix:type{##1}}}% \def\tmp:parse##1#1##2\nil{% \docsvlist{#1##2}% } \expandafter\tmp:parse\a:resettoclevels\nil% \egroup% \navsection{#1}{\csname tmp:resettoclevels#1\endcsname}% % define hierarchy also for starred sections \navsection{like#1}{\csname tmp:resettoclevels#1\endcsname}% % and for appendices \ifcsdef{appendix:type:#1}{\navsection{\csuse{appendix:type:#1}}{\csname tmp:resettoclevels#1\endcsname}}{}% } % define children levels for each sectioning level \def\confnavsections{% \def\do##1{% \tmp:processlevel{##1}% } \expandafter\docsvlist\expandafter{\a:resettoclevels} } % As reported by Nat Kuhn on http://tex.stackexchange.com/q/209312/2891 % zeroes were printed as section numbers when secnumdepth counter was set to negative value % so just strip then out % \TitleMark does similar thing, but this solution is simpler, I hope it works correctly \def\Ncx:Mark#1{% \edef\:temp{#1}% \def\z@ro{0}% \ifx\:temp\z@ro\else#1\fi% } % to create correct hiearchical NCX for appendices, we register corresponding appendix types % for various section types \def\appendix:type#1{\ifcsdef{appendix:type:#1}{\csuse{appendix:type:#1},}{}} \def\def:appendix:type#1#2{\csdef{appendix:type:#1}{#2}} \def:appendix:type{chapter}{appendix} \def:appendix:type{section}{appendixsec} \def:appendix:type{subsection}{appendixsubsec} \def:appendix:type{subsubsection}{appendixsubsubsec} % \def\ncx:head{% \HCode{\Hnewline}% \HCode{\Hnewline}% \HCode{\Hnewline}% \HCode{\Hnewline}% \HCode{\Hnewline}% \HCode{\Hnewline}% } \def\ncx:title{% \HCode{\Hnewline}\Title\HCode{\Hnewline\Hnewline}% } % Get filename from tableofcontents anchor \def\ncx:hfile#1{\LikeRef{)F\LikeRef{)Q#1}F-}} \ExplSyntaxOn % get filename for the section label % sometimes, TeX4ht returns list of file numbers for label. we must use just % the first number. we use the LaTeX 3 sequence list to get it. \tl_new:N\ncx:hfilename \def\ncx:newhfile#1{ \cs_if_exist:cTF{cw:)Q#1}{% % cw:)Q#1 is csname of tag from the xref file. we convert it to sequence \seq_set_from_clist:Nc\l_tmpa_seq{cw:)Q#1}% % get first item and put it to a token list \seq_get_left:NN \l_tmpa_seq \l_tmpa_tl% % \RefFileNumber returns file name for the given file number % \ncx:hfilename contains the filename for later use \tl_set:Nx \ncx:hfilename {\RefFileNumber{\l_tmpa_tl}}% }{% This shouldn't happen? \tl_set:Nn \ncx:hfilename {}% } } \ExplSyntaxOff % define toc levels which should be included in the NCX file \NewConfigure{resettoclevels}{1} \Configure{resettoclevels}{part,appendix,chapter,section,subsection,subsubsection,paragraph} \def\:tempa{% \EndP% \HtmlParOff% \setcounter{tocdepth}{3}% \special{t4ht>\jobname.ncx}% % We don't want crosslinks in xml % Basic sctructure of the ncx file \NoFonts% {\HCode{\Hnewline}}% {\a:NcxDoctype}% {\Tg}{}% % To print document map, we customize the tableofcontents. We don't want TOC title, % so: \let\contentsname=\empty% \Configure{tableofcontents}{\boolfalse{tocnoempty}\Tg}{% \usetoclevels{part,appendix,chapter,likechapter,appendixsec,section,likesection,subsection,appendixsubsec,likesubsection,subsubsection,likesubsubsection,appendixsubsubsec,subsubsubsection,paragraph}% \ifbool{tocnoempty}{}% {\HCode{% Document% % }}% \Tg}{}{}{}% % We need to configure TocLink % in navmapsrc is link to the file and anchor, where chapter or section is located \def\navmapsrc{}% \Configure{TocLink}{% \ncx:newhfile{##2}% \def\navmapsrc{\ncx:hfilename\:sharp ##2}% \opf:registerfilename{\ncx:hfilename}% ##4% } % Configuraion of entries \expandafter\resettoclevels\expandafter{\a:resettoclevels}% \confnavsections% \HtmlParOff% \Configure{toTocLink}{}{}% \Configure{NavSection}{\booltrue{tocnoempty}\HCode{\Hnewline\Hnewline\Hnewline}% }{\HCode{\Hnewline% \Hnewline}% \HCode{}% }{\HCode{}}{\HCode{\Hnewline}}% % Meta inf \ncx:head% % Book title \ncx:title% \TableOfContents[part,appendix,chapter,likechapter,appendixsec,section,likesection,appendixsubsec,subsection,likesubsection,subsubsection,likesubsubsection]% %Hack to get close tag working \HCode{}% \EndNoFonts \special{t4ht<\jobname.ncx} \HtmlParOn } \let\ncxtable\:tempa %\else %\fi \def\print:opf:scheme#1{ opf:scheme="#1"} \def\:tempa{% % French language definition makes the : character active, which can cause compilation error \ifdefined\XeTeXcharclass\XeTeXcharclass `\: \z@\fi% \bgroup \setcounter{tocdepth}{3} % Basic sctructure of the opf file \special{t4ht>content.opf} \NoFonts \HtmlParOff {\HCode{\Hnewline}} \HCode{\Hnewline} {\HCode{\Hnewline}} {\HCode{}\Title\HCode{\Hnewline}} {\HCode{}\GetLanguage\HCode{\Hnewline}} %Add interface for such things {\HCode{\a:UniqueIdentifier}\HCode{\Hnewline}} \def\and{\HCode{\Hnewline}} {\HCode{}{\a:@author\Author}\HCode{\Hnewline}} %{\HCode{\HP:file\Hnewline}} {\HCode{}\:iso:date\HCode{}} \a:OpfMetadata \Tg % To print document map, we customize the tableofcontents. We don't want TOC title, % so: \let\contentsname=\empty %\Configure{tableofcontents}{\Tg}{\usetoclevels{part,chapter,section,subsection,subsubsection}\Tg}{}{}{} % We need to configure TocLink % in navmapsrc is link to the file and anchor, where chapter or section is located \def\navmapsrc{} \HCode{\Hnewline\Hnewline} \HCode{\Hnewline} \HCode{\Hnewline} \renewcommand\do[1]{\HCode{\Hnewline}} \expandafter\docsvlist\expandafter{\opf:htmlfiles} \a:OpfManifest %\Tg \special{t4htcontent-part2.opf} \HCode{\Hnewline} \renewcommand\do[1]{\HCode{\Hnewline}} \HCode{\Hnewline\Hnewline} \expandafter\docsvlist\expandafter{\opf:htmlfiles} % Next line is pattern to be replaced by lua code \HCode{\Hnewline$\string{spine\string}\Hnewline} \HCode{\Hnewline} % insert guide \opf:guide \HCode{
} % Hack to get close tag working \HCode{} \special{t4ht} %\Configure{HTML}{}{\HCode{\Hnewline\Hnewline}}%\Hnewline}} } \let\opftable\:tempa \:CheckOption{epub3} \if:Option \input tex4ebook-epub3.4ht \fi