Importing Latex file?

Has anybody figured out how to import LaTeX files into Pressbooks? There are two textbooks I’d like to remix but they’re only available as PDF & LaTeX files. I’ve converted a PDF to an epub but it’s extremely messy and would take a long time to clean up. Thanks.

There is no obvious import path, so far as I know. I imported a big chunk of a LaTeX OER book of mine a while back (a year or two?) and found it sufficiently painful that I gave up.

I would say that it goes like this – at least the way I did it that previous time:

  1. Text just goes across from LaTeX to PB, with a tiny bit of work to convert things like bold or italics, and a bit more work to convert bullet lists and a few other structures like that.
  2. Embedded images have to be handled quite differently, that’s a moderate amount of work by hand.
  3. Sectioning and so on is quite different in LaTeX and PB, and so has to be converted by hand – note LaTeX automatically assigns section numbers and that sort of thing, while PB does not.
  4. Cross references to section or figure numbers and things like that have to be done by hand in PB.
  5. Then we get to actual math in LaTeX. There are three issues here:
  • one is that the start- and end-delimeters for math are different and have to be changed
  • another is that PB math only supports some LaTeX packages, so it is possible that there is something built in LaTeX which will not transfer over at all
  • finally, and maybe the most common problem, is that it is absolutely standard in LaTeX to define macros which expand in mathematical contexts to use some more complicated bit of LaTeX … and PB doesn’t have that capability at the moment, which means that every macro in the LaTeX file must be expanded by hand when the import into PB is made (e.g., \RR might be a macro for {\mathbb R}, so every place there is \RR in the LaTeX, it must be brought over to {\mathbb R} in PB … and this is a particularly simple example of a macro!)

I might try a different approach if I had to do this again now, perhaps I would use pandoc to move the LaTeX file to markdown and then write some scripts to edit the markdown…? Anyway, I’d explore other options, if I had to do it today, because the direct way was super painful.

Is there some reason you need to us PB for this? I think PB really is a very tough choice for STEM books at the moment. I’ve been hearing that the PB team wants this to get better, and I have every confidence that eventually there will be much better ways to do STEM in PB, but I don’t think those solutions will be available in the near future, so far as I’ve heard. There are some other platforms which might be, in the short term, better, depending upon what are your priorities, constraints, and resources.

E.g., why not stay in LaTeX? (I mean, I can think of several answers to that, but I wonder what are your answers.) Or perhaps switch to PreTeXt?

Anyway, happy to chat with you about this more, even synchronously, if you like.

Jonathan

Hi Jonathan,

Thanks for sharing that info with me. I’m reaching out on behalf of one of faculty members who is exploring their options. We’re green to PB, but are interested in its feasibility as regards a tool for importing and editing LaTeX files. What you’ve described matches what I’ve read elsewhere - namely PB is not an ideal tool for what they had in mind and they are probably better off staying in LaTeX. Thanks for your feedback and taking the time to answer my post! - David

@dltully that sounds right. LaTeX is a complete typesetting engine (LaTeX - Wikibooks, open books for an open world). Pressbooks is a single-source book publishing platform that does typesetting/styling, etc. and which has LaTeX support for mathematical expressions (see Add Mathematical Notation – Pressbooks User Guide or Using LaTeX in Pressbooks – Simple Book Publishing). If the author wants a fully-featured LaTeX authoring/publishing platform, rather than a fully-featured publishing platform which supports LaTeX for specific expressions/equations, they’d be better off with something like Overleaf: https://www.overleaf.com/, LaTeX Base: LaTeX Base | Online LaTeX Editor and Compiler or Authorea: LaTeX Software - Authorea

@dtully as to your original question, I’m not sure the best way to bring a LaTeX file into Pressbooks. If you can generate HTML output from the LaTeX using a tool like Pandoc (LaTeX to HTML via Pandoc — Dan W Joyce) or htlatex (How to convert Latex to HTML? | The Data Blog), you’ll probably be able to do a standard Pressbooks import. See LaTeX to HTML for another description of someone who converted TeX/LaTeX to HTML. I haven’t done this myself, and suspect you may need to go back and retag the math expressions with LaTeX shortcodes or delimiters, but I’m guessing that would get you 90% of the way there much faster than trying other approaches (like PDF->HTML).

Hmm, I don’t know, @SteelWagstaff , do you have direct experience of LaTeX Base or Authorea? I’ve had students who used Overleaf, and it struck me as a very strange tool: it’s basically an editor and a standard LaTeX implementation … only hosted, online. All that software is FLOSS, there is absolutely zero advantage I can see to doing it on someone else’s machine rather than one’s own – it’s not even native to the web in any way, or otherwise having features which are better on someone else’s server with good uptime and load balancing. Really, I just don’t understand why people would use Overleaf rather than just downloading the software to their own machine. And LaTeX Base seems similar. Authorea might be something more, but the site to which you linked seems a little more like a publication platform for journals, maybe?
Anyway, I can’t think of any reason why someone going with pure LaTeX would go with a hosted approach.

Actually, that said, I realize that I run Linux and other FLOSS software, so I’m used to just installing and running anything out there I find in that world, while things might be different if you live in the world of a proprietary OS. (…Although the Mac OS is basically BSD under the hood, isn’t it?)

No, I don’t have much direct experience with the hosted LaTeX tools. If the author can do it themselves, locally, with FOSS software, that’s great, and I’m all for it. In my experience, it’s been a very small segment of interested authors who are capable of and interested in that. I’m in that small segment, and so are you, but we’re a definite minority :joy:

Hmm, my experience has been different: folks I’ve worked with who use LaTeX usually had no trouble installing, updating, and running the needed tools on their machines. And I include among “folks who use LaTeX” several classes of students (mid- to upper-level undergrad) who heard that word the first time when starting a class with me in which producing artifacts in LaTeX was an expected part of the course.

1 Like