6

I am thinking about writing and/publishing an ebook with the following in mind:

  • It will contain code (needs proper formatting)
  • I should be able to publish PDF and EPUB versions
  • I might need to have an HTML version of the book too

Since I am new to this stuff, I wonder if anyone could give me some points on which software (free/paid) I should use for writing/formatting the ebook.

I have used LaTeX about 8 years ago, and I really liked it, but I am not sure if I can export to the formats I want with LaTeX.

3

Pandoc is your friend here.

Pandoc can take your input file (LaTeX, markdown, other) and transform it to PDF, EPUB, HTML (and many more).

Pandoc is cross-platform and free under the GPL, although donations are appreciated.

With regards to formatting your code, both LaTeX and markdown have components that will help. LaTeX has many more layout options.

I've used both LaTeX and markdown to produce ebook (ePub) files. An example of using pandoc with LaTeX is shown in another ebooks.stackexchange.com question I posted.

It's great to have a range of options.

2

If you don't want the hassle of setting up the full LaTeX stack, as needed with the, in this respect, unfriendly pandoc, you can have a look at reStructured text and Sphinx. For these tools exists to generate ePub and PDF, the latter without having to go through LaTeX.

  • I had heard of Sphinx for producing python documentation, but I had not realized it could produce ePub files from reStructuredText. I'm going to take a look at that. Thanks! – StandardEyre Jun 2 '16 at 20:03
2

I say this as something who doesn't normally use the product, but Adobe InDesign allows for an easy export into PDF and epub. I don't know about formatting code blocks though. Adobe ID has a monthly subscription, so even though it's a premium product, in many cases you're only using it for one or two months. You might be able to buy some low cost Adobe ID templates, so you don't have to set everything up.

I use a Docbook solution (with Docbook XSLT, using the Oxygen XML editor software). This produces output very easily in html, epub and pdf, although the learning curve is high. (Also, Oxygen XML license is pricey for commercial use). Docbook can do code blocks very easily; on the other hand, when producing pdfs, you have limited formatting options. Oxygen uses the open source Apache FOP (which lets you output from Docbook XML to PDF), but there are commercial options (in the 200-500 range) which let you produce nice looking PDF files. (Check out renderx and antenna house). Docbook can do output for webhelp, javahelp, htmlhelp as well. Docbook works well, but the toolchain is hard to set up.

A "dumb but effective" solution might be to code your output in HTML, paste it into MS word (to produce a PDF), and then to use SIGIL to move the html files into epub. Or use the MS word file as the source for doing output using Calibre.

There are pros and cons for each solution. I haven't used pandoc, but it sounds like a good solution if you have lots of legacy latex content.

1

Some time ago I created a GitHub repository of eBook Writing Resources.

Specifically, this is the current list (as of the time of writing this answer - visit the link above for an up-to-date list as well as to get visual indications on whether they cost money, work offline or on the cloud etc.) of eBook writing software.

Specifically, GitBook and Scrivener do let you write code properly as well as export to PDF and EPUB.

Writing Tools

GitBook

Penflip

Scrivener

yWriter

BookWriter

WriteItNow

  • We like self contained answers here, as links will go dead over time. Please extend your answer, and use the link only to point at the source of information you provide here. – Anthon Aug 16 '16 at 10:09
  • @Anthon I understand your point of view, and I myself use it on Stack Overflow (in which I'm more active than here) but this case is different. I don't know if you've seen that link or just automatically responded. Have a look at that repository I linked to. It's a curated list exactly for addressing the question at hand. As a source, it's more canonical than this answer and the best is to refer to it, as copying-pasting it would not result in a comprehensible answer, and worse than that - would more likely rot than the canonical source I linked to. And please reconsider the downvote, thanks. – Ofer Zelig Aug 17 '16 at 0:49
  • @Anthon reconsidering, I've edited my answer to add a short list, but I still think the GitHub repo is better (from the reasons I detailed in my edited answer). – Ofer Zelig Aug 17 '16 at 1:21
  • Thanks for updating. As it stood your answer was up for deletion help, fifth bullet item. That has nothing to do with the quality of the material linked to. – Anthon Aug 17 '16 at 4:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.