Leanpub is a great platform for self publishing your book. It offers a good web editor for typing directly in the browser. But if you are reading this article it is probable that you don’t usually edit text in a web browser. No. You use emacs. And if you use emacs, it is also probable that you
love use org-mode. Lakshmi Narasimhan already wrote a post explaining how to write a book with org-mode and publish it on Leanpub. But he is using Dropbox: it is a nice pipeline, but I don’t really like Dropbox.
Leanpub offers you the possibility to link a GitHub or BitBucket repository to your book. Choosing BitBucket allows you to have a private repository for free and this could be a desirable feature if you don’t want to have all your drafts publicly accessible and also if you don’t want to pay 5 $ for a private GitHub repository.
So, Leanpub + BitBucket + Emacs org-mode
First, follow Leanpub’s tutorial for starting a book using BitBucket.
Done? Great. Now, we are going to write our book in a single
org file and then we will:
- export the book as a single markdown file containing all the chapters
- push to BitBucket
- wait for Leanpub to process all the files
So, if you followed Leanpub’s tutorial, then your book repository should look like this:
- book-repo/ - manuscript/ + Book.txt + chapter1.txt
Leanpub will look for the
manuscript folder in the repository. The
Book.txt file will contain, in the order that you specify, the single chapters of the book. So, if you want
chapter1.txt to be included in your book, then add the file name to
Now, how to write with org-mode? You can start by cloning my sample repository from here. This is a very simple setup that will get you started soon and it will probably work for simple works, but you might want to modify it later (e.g. to create separate parts, front matter, back matter, and so on). In my setup you can find a single
text.org file: this is the main source. Open
text.org with emacs and write your masterwork. When you are done, simply export it as markdown to
Book.txt only contains the single
text.md file, and the single sections of your org file are going to be the chapters of your book. Stage you changes, push to BitBucket and head to Leanpub’s site to view your work.
I switched from BitBucket to GitHub because I have a free private repository thanks to GitHub’s Student Pack and anyway for this example I wanted to share the sample repository that I created.