2

I need to maintain many documents which need to be able to be viewed as 2 different types of format: PDF & HTML. The document will be mostly text, but may contain some images or mathematical formulas.

My current approach is to maintain 2 files for each document. However, this approach is tiresome, as if the content needs to change, I need to modify BOTH versions of the file.

I want to find a way to easily keep both versions of the file in sync. Preferably (but not necessary), the approach should allow me to use tools like git, or svn.

A solution that comes to my mind is to use latex. Represent the document in latex, then export it to HTML/PDF. This way, whenever there is a change, I need only to modify one file (the latex file).

But I have zero experience working with latex. I'm not sure whether latex is suitable for this, I need advice. What do you guys think? Is latex suitable for this task? If not, what alternatives do I have?

Teddy
  • 95
  • 1
  • 7
  • _If_ you can write your contents in LaTeX, than you can mantain one single .tex file and then, every time you make a change to it, compile it to pdf _and_ translate it to html using https://www.ctan.org/pkg/latex2html or some other tool – MattAllegro Aug 01 '15 at 11:37
  • 3
    If you are comfortable with HTML, why don't you use that as your basis and use something like jspdf to convert it to pdf. You only have to maintain the HTML and the jspdf automatically converts it to pdf whenever you need it. http://stackoverflow.com/questions/18191893/generate-pdf-from-html-in-div-using-javascript – OSDM Aug 01 '15 at 11:48

3 Answers3

1

First of all,

yes, LaTeX is suitable for this (and it works particularly well with formulæ).

The main processing paths are:

  • Use pdflatex to create a pdf directly from LaTeX
  • Use latex2html or tex4ht to convert your LaTeX source to HTML

I am biased (having authored a text book for LaTeX in German language), but I think LaTeX is definitely worth learning.

Sir Cornflakes
  • 675
  • 13
  • 26
1

restructuredText (Python docutils) is good for this. There are a couple of paths from text to PDF; one of them goes through LaTeX and the other one is a pure Python rst2pdf.

If you have a lot of formulas, it might be worth doing it in LaTeX, but restructuredText source is a lot more readable than LaTeX source.

Patrick Maupin
  • 8,024
  • 2
  • 23
  • 42
0

Sounds like a good candidate scenario for working in markdown and using pandoc to convert to both LaTeX and HTML. Formulas can be essentially written in LaTeX (thus making the maintenance of that output painless) and the markdown-to-HTML conversion can be expressed with the --mathjax option to yield proper display in HTML.

Thomas
  • 43,637
  • 12
  • 109
  • 140