This looks very interesting. Books really are code: I now have 10+ conditional flags in my book: ifPG13, ifPRINT, ifEBOOK, ifEREADER, etc. I'm looking to add more, but the basic \ifthenelse macro in LaTeX won't be enough... How hard would it be to implement things like \ref and \pageref and support more of the LaTeX environments supported by MathJax? I think a triple output format HTML + ePub + LaTeX|PDF|print would…
Makefiles can be your friend... in the file `Makefile` put
.PHONY: all pg13 print ebook ereader
all: pg13 print ebook ereader
pg13: book-pg13.pdf
book-pg13.pdf: mainfile.tex
pdflatex "\setstuffforethisversion\input{mainfile}"
print: book-print.pdf
[etc...]
Then type `make print` or `make ebook` etc at the command line. (This version is almost certainly too simplistic, but I hope the point is clear.)