I am using the tex4ht
package to compile EPUB documents with LaTeX. However, I am also using the same base .tex
files to compile PDF documents with pdflatex
. Since there are some significant differences between how EPUB and PDF files work and compile, I've found myself wishing for functions that allow me to switch certain text fragments on and off based on some global variables (i.e. whether I compile it as an EPUB or a PDF).
Use Case 1:
I use imakeidx
for generating indices. When I compile an index with PdfLaTeX, it "merges" several instances of \index
that appear on the same page. Thus, an index entry could appear as:
walrider, 49-61, 142
I thus have been fairly "generous" with my \index
placements, putting them in every new paragraph where a certain word appears.
However, when I compile an index with tex4ebook
(using tex4ht
package) it doesn't have distinct pages (since, of course, the output is a reflowing text format). Instead, every single instance shows up in the index:
walrider, 693, 695, 701, 708, 719, 734, 736, 742, 743, 747, 752, 763, 777, 792, 794, 796, 798, 802, 804, 819, 828, 837, 840, 848, 855, 867, 877, 880, 915, 920, 935, 946, 956, 960, 961, 983, 1003, 1006, 1009, 1012, 1017, 1021, 1029, 1030, 2683
Which is making the index excessively long. Thus, it would be useful if I could make some of these \index
instances disappear - but only when I compile it with tex4ebook
(or set some global variable).
Use case 2:
While both the PDFs and the EPUB files I am compiling at the moment are hyperlinked, eventually I want to prepare a PDF version for Print On Demand - which of course will not have any hyperlinks. Thus, I need to insert page references at strategic locations. Now, LaTeX can easily do page references:
(see p. \ref{walrider})
But I only need these page references when compiling the PDF version for Print On Demand, so again some kind of function would be useful which allowed me to set a global variable that decides if these page references are actually compiled or not.
Since I don't have much experience with writing new LaTeX, I was wondering what the most elegant way of doing this is.