Answers.Body: <p><a href="http://pandoc.org/" rel="nofollow noreferrer">Pandoc</a> is your friend here.  </p>
  
  <p>Pandoc can take your input file (LaTeX, markdown, other) and transform it to PDF, EPUB, HTML (and many more).</p>
  
  <p>Pandoc is cross-platform and free under the GPL, although donations are appreciated.</p>
  
  <p>With regards to formatting your code, both <a href="https://tex.stackexchange.com/">LaTeX</a> and <a href="https://daringfireball.net/projects/markdown/syntax" rel="nofollow noreferrer">markdown</a> have components that will help.  LaTeX has many more layout options.</p>
  
  <p>I've used both LaTeX and markdown to produce ebook (ePub) files.  An example of using <code>pandoc</code> with LaTeX is shown in <a href="https://ebooks.stackexchange.com/questions/6092/how-to-create-epub-with-title-page-from-latex-source-using-pandoc">another ebooks.stackexchange.com question I posted</a>.   </p>
  
  <p>It's great to have a range of options.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-06-02T00:07:40.790Z
Answers.LastActivityDate: 2016-06-02T20:01:47.093Z
Answers.LastEditDate: 2017-04-13T13:00:05.480Z
Answers.UserDisplayName: StandardEyre
Answers.Body: <p>If you don't want the hassle of setting up the full LaTeX stack, as needed with the, in this respect, unfriendly <code>pandoc</code>, you can have a look at <a href="http://docutils.sourceforge.net/rst.html" rel="nofollow">reStructured tex</a>t and <a href="http://sphinx-doc.org/" rel="nofollow">Sphinx</a>. For these tools exists to generate ePub and PDF, the latter without having to go through LaTeX.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-06-02T20:03:25.273Z
Answers.Text: 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!
Answers.UserDisplayName: StandardEyre
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-06-02T10:24:21.423Z
Answers.LastActivityDate: 2016-06-02T10:24:21.423Z
Answers.UserDisplayName: Anthon
Answers.Body: <p>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. </p>
  
  <p>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. </p>
  
  <p>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. </p>
  
  <p>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. </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-06-02T19:12:35.463Z
Answers.LastActivityDate: 2016-06-02T19:12:35.463Z
Answers.UserDisplayName: idiotprogrammer
Answers.Body: <p>Some time ago I created a <a href="https://github.com/oferze/book-and-ebook-writing-resources" rel="nofollow noreferrer">GitHub repository</a> of eBook Writing Resources.</p>
  <p>Specifically, this is the current list <em>(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.)</em> of eBook writing software.</p>
  <p>Specifically, <strong>GitBook</strong> and <strong>Scrivener</strong> do let you write code properly as well as export to PDF and EPUB.</p>
  <blockquote>
  <h3>Writing Tools</h3>
  <p><a href="https://www.gitbook.com" rel="nofollow noreferrer">GitBook</a></p>
  <p><a href="https://www.penflip.com" rel="nofollow noreferrer">Penflip</a></p>
  <p><a href="https://www.literatureandlatte.com/scrivener.php" rel="nofollow noreferrer">Scrivener</a></p>
  <p><a href="http://www.spacejock.com/yWriter5.html" rel="nofollow noreferrer">yWriter</a></p>
  <p><a href="http://www.fastpencil.com/company/book_writing_software" rel="nofollow noreferrer">BookWriter</a></p>
  <p><a href="http://www.ravensheadservices.com" rel="nofollow noreferrer">WriteItNow</a></p>
  </blockquote>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-16T10:09:24.003Z
Answers.Text: 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.
Answers.UserDisplayName: Anthon
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-17T00:49:19.123Z
Answers.Text: @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.
Answers.UserDisplayName: Ofer Zelig
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-17T01:21:35.310Z
Answers.Text: @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).
Answers.UserDisplayName: Ofer Zelig
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-17T04:53:32.363Z
Answers.Text: Thanks for updating. As it stood your answer was up for deletion [help, fifth bullet item](http://ebooks.stackexchange.com/help/deleted-answers). That has nothing to do with the quality of the material linked to.
Answers.UserDisplayName: Anthon
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-15T13:23:12.707Z
Answers.LastActivityDate: 2016-08-17T01:20:22.670Z
Answers.LastEditDate: 2020-06-18T08:36:04.683Z
Answers.UserDisplayName: Ofer Zelig
Body: <p>I am thinking about writing and/publishing an ebook with the following in mind:</p>
  
  <ul>
  <li>It will contain code (needs proper formatting)</li>
  <li>I should be able to publish PDF and EPUB versions</li>
  <li>I might need to have an HTML version of the book too</li>
  </ul>
  
  <p>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.</p>
  
  <p>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.</p>
  
Tags: <epub><pdf><html><formatting><writing>
Title: Software recommendation for writing ebook and exporting to multiple formats
UserDisplayName: Omid Kamangar
ThreadText: # Software recommendation for writing ebook and exporting to multiple formats
  
  (Asked by: username_0 on 2016-06-01)
  
  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.
  
  **Tags:** epub, pdf, html, formatting, writing
  
  
  ---
  
  ## 4 answers
  
  ### Answer by username_1 on 2016-06-02. Score: 3 | Accepted answer
  
  [Pandoc](http://pandoc.org/) 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](https://tex.stackexchange.com/) and [markdown](https://daringfireball.net/projects/markdown/syntax) 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](https://ebooks.stackexchange.com/questions/6092/how-to-create-epub-with-title-page-from-latex-source-using-pandoc).
  
  It's great to have a range of options.
  
  
  ---
  
  ### Answer by username_2 on 2016-06-02. Score: 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 tex](http://docutils.sourceforge.net/rst.html)t and [Sphinx](http://sphinx-doc.org/). For these tools exists to generate ePub and PDF, the latter without having to go through LaTeX.
  
  > **Comments:**
  > **username_1**: 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!  
  
  ---
  
  ### Answer by username_3 on 2016-06-02. Score: 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.
  
  
  ---
  
  ### Answer by username_4 on 2016-08-15. Score: 1
  
  Some time ago I created a [GitHub repository](https://github.com/oferze/book-and-ebook-writing-resources) 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](https://www.gitbook.com)
  >
  > [Penflip](https://www.penflip.com)
  >
  > [Scrivener](https://www.literatureandlatte.com/scrivener.php)
  >
  > [yWriter](http://www.spacejock.com/yWriter5.html)
  >
  > [BookWriter](http://www.fastpencil.com/company/book_writing_software)
  >
  > [WriteItNow](http://www.ravensheadservices.com)
  
  > **Comments:**
  > **username_2**: 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.  
  > **username_4**: @username_2 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.  
  > **username_4**: @username_2 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).  
  > **username_2**: Thanks for updating. As it stood your answer was up for deletion [help, fifth bullet item](http://ebooks.stackexchange.com/help/deleted-answers). That has nothing to do with the quality of the material linked to.  
  
  ---
  
  