Publishing with GitBook
Git, Markdown, Ebook
Write and publish ebooks with the GitBook software and publishing platform.
Using Markdown and Git for producing an ebook at first seems like something that would appeal only to developers and hackers. Indeed, if you are already versed in formatting README files with Markdown and you rely on Git for managing software projects, using these technologies to write and publish an ebook makes a lot of sense. However, this approach has advantages for other users, too, and the GitBook publishing platform [1] offers everything you need to get started.
How GitBook Works
The GitBook-based publishing workflow is relatively straightforward. To begin, you use the GitBook editor to create a book and format it with Markdown. Because the book is just a regular folder containing Markdown-formatted, plain-text files, you turn it into a Git repository and use Git functionality for versioning, synchronization, and collaboration with other contributors. When the book is ready, you use the GitBook editor to push the final result to the GitBook service, which then builds the ebook in several formats and makes it available for sale (Figure 1). The service also takes the burden of processing payments off your shoulders (it charges 20 percent per transaction).
Although GitBook provides a convenient publishing platform, you are not tied to it. Using the GitBook editor, you can generate an ebook in several formats (static website, PDF, EPUB, and MOBI) and sell it through other channels like Amazon Kindle Publishing, Gumroad, and even on your own website. The editor itself is released under an open source license, and its source code is available on GitHub [2]. In fact, a lot of software that powers GitBook is released as open source.
Preparatory Work
To get started with GitBook, you need to do a few things up front: Install the GitBook editor and Git on your machine, configure a GitBook profile and create a book, and set up a Git repository for the book project. Installing the editor couldn't be easier. Just point the browser to www.gitbook.io/editor/download, and you'll be prompted to download the editor version for your particular platform. Extract the downloaded .tar.gz
archive, and make the install.sh
script in the resulting directory executable using the chmod +x install.sh
command. Then, run the script to install the GitBook editor.
You can also run the editor without installing it using the supplied run.sh
script (don't forget to make it executable first). If you plan to use the editor to generate ebooks in the supported formats locally, you also need to install the Calibre ebook suite by following the instructions on the project's download page [3].
Git is available in the official software repositories of most mainstream Linux distributions, so you can install it using your distro's package manager. On Debian and Ubuntu, you can do this by running the apt-get install git-core
command as root. Then, use the following commands to configure Git (replace the default values with your actual email and name):
git config --global user.email "you@example.com" git config --global user.name "Your Name"
Next, you can sign in to GitBook via Twitter or GitHub. Once you've done that, switch to the Settings section and configure your GitBook profile (Figure 2). GitBook conveniently pulls personal data from your Twitter or GitHub account, so you only need to note the token needed for linking the editor with the GitBook service and provide the payment information required to buy and sell books on GitBook. Next, click the plus icon to create a new book, then specify the required book info, such as title, description, visibility, price, and category. Press the Create Book button to create the book (Figure 3).
Next, you need to create a Git repository. GitBook works best with GitHub repositories, so you might want to set up a dedicated GitHub repository for the book. If you already use GitHub for managing your software project, you already know how to do this. Otherwise, the Create A Repo page on GitHub [4] provides step-by-step instructions on creating a repository. When the repository has been created, note its clone URL. It should look something like this: git@github.com:dmpop/my_book_repo.git (where my_book_repo is the actual name of the created repository).
The free plan on GitHub allows you to maintain only public repositories, so anyone can access and fork them. If you prefer to keep your book repository private, you either need to upgrade to a paid plan or use an alternative service like Bitbucket [5], which lets you create private repositories.
Alternatively, you can set up a Git repository on your own server. Instead of rolling out a full-blown Git server, however, you can opt for a quick-and-dirty solution that lets you work with Git repositories via SSH. To do this, you need a remote machine with Git and SSH installed on it. Establish an SSH connection to the server, then do
mkdir my_book_repo.git cd my_book_repo.git git init --bare
to create and initialize a bare Git repository.
Working with GitBook Editor
With all the housekeeping tasks taken care of, you can begin working on the book. Launch the GitBook editor, choose File | New Book, create a new book directory (e.g., my_book), and open it in the editor. The application features an unobtrusive interface, which is split into three panes. The left pane shows the book's structure as an outline, the pane in the middle acts as a no-frills Markdown editor, and the right pane displays the preview of the currently edited text. The toolbar in the middle pane gives you access to basic formatting options (Figure 4).
Note that GitBook supports the so-called GitHub Flavored Markdown (GFM), which includes a few additions and improvements [6]. Although the editor is rather bare-bones, it does include a couple of useful features. For example, it supports Markdown syntax highlighting, which makes editing more convenient. The application also includes the search and replace tools that can be evoked using the Ctrl+F and Ctrl+H keyboard shortcuts. Both tools can handle regular expressions, so you can perform advanced search and replace actions.
The book's structure in the GitBook editor is represented as a hierarchical tree consisting of nodes (chapters) and branches (articles). To add a chapter, choose Book | Add Chapter. You can then add articles to the chapter by right-clicking on it and choosing Add Article. Each chapter can contain an unlimited number of articles, and each article can contain other articles. You can rearrange the chapters and articles by dragging them up and down in the left pane. You can preview the online version of the book at any time by choosing Book | Preview Website.
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Juno Tab 3 Launches with Ubuntu 24.04
Anyone looking for a full-blown Linux tablet need look no further. Juno has released the Tab 3.
-
New KDE Slimbook Plasma Available for Preorder
Powered by an AMD Ryzen CPU, the latest KDE Slimbook laptop is powerful enough for local AI tasks.
-
Rhino Linux Announces Latest "Quick Update"
If you prefer your Linux distribution to be of the rolling type, Rhino Linux delivers a beautiful and reliable experience.
-
Plasma Desktop Will Soon Ask for Donations
The next iteration of Plasma has reached the soft feature freeze for the 6.2 version and includes a feature that could be divisive.
-
Linux Market Share Hits New High
For the first time, the Linux market share has reached a new high for desktops, and the trend looks like it will continue.
-
LibreOffice 24.8 Delivers New Features
LibreOffice is often considered the de facto standard office suite for the Linux operating system.
-
Deepin 23 Offers Wayland Support and New AI Tool
Deepin has been considered one of the most beautiful desktop operating systems for a long time and the arrival of version 23 has bolstered that reputation.
-
CachyOS Adds Support for System76's COSMIC Desktop
The August 2024 release of CachyOS includes support for the COSMIC desktop as well as some important bits for video.
-
Linux Foundation Adopts OMI to Foster Ethical LLMs
The Open Model Initiative hopes to create community LLMs that rival proprietary models but avoid restrictive licensing that limits usage.
-
Ubuntu 24.10 to Include the Latest Linux Kernel
Ubuntu users have grown accustomed to their favorite distribution shipping with a kernel that's not quite as up-to-date as other distros but that changes with 24.10.