Michal, I've come back to your suggestions, and am implementing them. Maybe this will suggest I should switch to newer software, b/c ...
(1) when I compiled your sample in isolation (first bit of text below), I got an error from epubcheck. The generated epub looked fine, and the internal references worked, but this error worries me, because epubcheck is the only tool I know of to verify that an epub is well-formatted. (2) I then transferred your suggestions to my actual book, and ..... the references didn't work. I'm in the process of boiling this down to an MWE, but figured I'd report this, just in case the answer is "you need to update your software". Thanks, --che-- == 1 == $ ls config.cfg Makefile sample.tex $ make sample.FULL tex4ebook -c config.cfg sample.tex [STATUS] tex4ebook: Conversion started [STATUS] tex4ebook: Input file: sample.tex HTML Tidy for Linux version 5.6.0 [STATUS] tex4ebook: Conversion finished make[1]: Leaving directory '/home/chet/Hack/jcfilliatre/sample' epubcheck sample.epub /usr/bin/epubcheck: 1: PK : not found /usr/bin/epubcheck: 2: Syntax error: word unexpected (expecting ")") make: *** [Makefile:9: sample.FULL] Error 2 $ On Thu, Feb 20, 2025 at 5:14 AM Michal Hoftich <[email protected]> wrote: > Hi Chet, > > > >> I've been fighting a perplexing problem with internal refs when >> generating an ebook. I've boiled it down to an MWE, but really don't know >> how to proceed. It seems that people attach MWE as MIME attachments, and >> that's what I'll do. >> >> I'm not a real expert in TeX, so perhaps I've left a few things in this >> MWE that I could/should have left out. I hope it's small enough. Also, I >> should ask if there are any good tutorials or references for how to get >> \label/\ref to work well with tex4ebook/tex4ht, esp. in the presence of >> figure, minipage, listinputlisting environments. I left in the chapters, >> so that the generated EPUB would have multiple pages (so I could verify >> that the links were broken by testing them in ebook-viewer, as well as by >> epubcheck). >> >> Environment: >> >> I'm using: >> Ubuntu 24.04 LTS >> texlive 2023.20240207-1 >> >> and the tex4ht and tex4ebook that come with the packages >> texlive-extra-utils and texlive-binaries. >> > > > it seems there are multiple problems: > > 1. you are probably using too old version of TeX4ht and TeX4ebook, you > shouldn't get epubcheck errors about colons in id with the up-to-date > version. > 2. I would change your TeX code. First of all, I would use a custom > environment that would replace the minipage, update the program counter, > and print the program title. > > The declaration can look like this: > > \newcounter{program} > \renewcommand{\theprogram}{\arabic{program}} > \newcommand\printprogram[1]{\theprogram\space #1\par} > > \newenvironment{program}[1]{\refstepcounter{program}\minipage{\textwidth}\printprogram{#1}}{\endminipage} > > You can then simplify your listings: > > \begin{figure}[tp] > \begin{program}{Title} > \label{fig:label} > \lstinputlisting{/usr/share/texlive/README}% > \end{program} > \caption{Caption} > \end{figure} > > Note that you need to use \label directly after \begin{program}, because > \lstinputlisting internally updates reference counters so that the link > would be wrong. > > For TeX4ht, you will need to use a config file: > > %%%%%%%%%%%% > \Preamble{xhtml} > \ConfigureEnv{program} > {\ifvmode\IgnorePar\fi\EndP\HCode{<div > class="program">}\Configure{minipage}{}{}{}{}} > {\ifvmode\IgnorePar\fi\EndP\HCode{</div>}}{}{} > \renewcommand\printprogram[1]{\ifvmode\IgnorePar\fi\EndP > \HCode{<div > class="programname">}\AnchorLabel\theprogram\quad#1\HCode{</div>}\par} > > \begin{document} > \EndPreamble > %%%%%%%%%%%% > > It adds some HTML tags for the program and program title, to enable CSS > styling. For example, if you want to make the title bold, you could add > something like: > > \Css{.programname{text-weight: bold;}} > > to the config file. Also, note the \AnchorLabel command. It will insert a > destination link for the current label. This will ensure that \ref and > \pageref will point to the right place. > > The full example is attached. Compile using: > > $ tex4ebook -c config.cfg sample.tex > > Best regards, > Michal > > >
