How I Self-Published a Technical Book

Photo by Nick Morrison on Unsplash

As I write these lines, I'm a few days away from releasing the last two chapters of my book, "Deep Learning with PyTorch Step-by-Step: A Beginner's Guide". The first two chapters were released ten months ago, in July 2020, and I've been releasing one or two chapters every month since then.

In this post, I will tell you the whole story: how it all started, how I've managed to get this far, which tools and services I used, and how it's been working for me.

Buckle up, because it's one heck of a ride :-)

How It All Started

January 2018: back then, I had already been teaching Machine Learning at a bootcamp in Berlin for two years, and I was thinking about turning one of my classes into an online course. I was pitching my idea to a good friend of mine, and I'll never forget his answer:

  • My friend: "OK, cool, I know you, and I know you can produce high-quality content, BUT…"
  • Me: "But what?"
  • My friend: "WHO are you? Why would anyone buy something from you?"

That was spot on! The market has plenty of content creators, both good and bad, it's really hard to stand out from the crowd. It all boils down to:

Building credibility: people need to know that you know what you're talking about before they even consider handing over their hard-earned money in exchange for whatever product you're offering.

The more straightforward way of building credibility is to produce content of quality and give it away for free. It allows you to reach a much wider audience and, if your audience finds your content valuable, you're on the right path. So, I decided to start writing blog posts, and publishing them on Towards Data Science, without a paywall.

To paywall or to not paywall: different people have different opinions on this but, if you're starting your writing career, I'd advise you against placing your posts behind a paywall. In my opinion, one should aim at building an audience first, and it's easier to do if anyone has free access to your content. That's what I did.

April 2018: on April 5th, 2018, I published my first blog post on Towards Data Science: "Hyper-parameters in Action! Part I — Activation Functions". In a little bit more than 24h, it got 1,000 views! I was walking on air :-)

My first 1,000 views ever!

Fast-forward 13 months…

May 2019: after publishing some more blog posts, I decided to write the one blog post that would change it all: "Understanding PyTorch with an example: a step-by-step tutorial" (currently, it is my 2nd most viewed post with more than 230,000 views).

June 2019: I was approached by an acquisition editor of a traditional publisher that was looking for an author to write a book on PyTorch. The editor read my PyTorch blog post, and he was inviting me to double down on this topic and write a whole book on the subject.

Well, that was very flattering! But I chose not to take his offer, though. I asked for more details about his proposal and he wanted me to write 300 pages in 6 to 8 months!

"300 pages?! In 6 months? No way, I can't do that, that's too much!"

That looked like a commitment I couldn't possibly live up to, and the financial details of his proposal were not very encouraging, to say the least…

That could very well be the end of it, but…

December 2019: I was spending the holidays in Granada, Spain, and, after telling the story about the book proposal to a good friend of mine, he suggested (and kinda pushed, but in a good way) I should write a book and self-publish it.

The good side is: there are no contractual obligations of any kind, you're free to choose the content, the length, when, and how you're writing it. Besides, you get to keep most of the revenue from sales (80% in self-publishing vs 10%-25% in traditional publishing). Sounds beautiful, right?

The bad side is: there are absolutely no obligations of any kind, contractual or not, so you're free to procrastinate as much as you want, too, after all, no one else is imposing deadlines on you but yourself. Not so beautiful anymore…

And so I procrastinated, one, two, three months…

April 2020: and so it begins…

Actually Writing a Book

I'm going to be completely honest with you here: I hadn't planned much ahead! I enjoyed (maybe a little too much) the freedom that only self-publishing gives you: I had the outline in my head, and I knew what I wanted to accomplish, but I didn't have to actually follow it to the letter.

So, I started writing. Writing CODE, that is!

If you're going to remember ONE THING, and one thing alone from this post, this is it: write code first!

By writing code that performs the very thing you're trying to explain in words, you'll unveil tiny details that you'd otherwise overlook. That alone will save you a lot of time because it will make it less likely that you'll find something in the code later on that requires changing the text.

Moreover, you will also learn a lot about the topic you're writing about. You don't need to be an expert on it — you do need to have a solid understanding of it — but it's perfectly valid to write about something to learn about it in more detail.

So, when I started writing, it was relatively easy because the overall structure of the first few chapters was very clear to me: it was going to be an expanded, and much, much, more detailed version of my blog post.

Text Editor

At this point, I had to make a choice of text editor, and I chose Typora.

Typora is a Markdown editor and, in my opinion, it is the best Markdown editor of all. Most Markdown editors use two panes, one for typing, one for rendering, but not Typora: it renders the text as you type it — so, if you type **this is bold**, it will immediately display this is bold after you type the last asterisk. This feature allows you to write in Markdown with the same ease as writing here on Medium.

Platform

Moreover, I could use Markdown files to generate a book using Leanpub, the platform I chose to self-publish my book. I could hook a private repository on GitHub to Leanpub and, after committing my changes, a book would be generated. That was easy enough.

Markdown?

After a couple of months, sometime in June 2020, I had written the first three chapters of my book. But I bumped into some issues with the whole Markdown + Leanpub's automatic generation: the code snippets were being rendered with alignment problems. I tried to fix it several times, to no avail. So, I had to take one step back and started researching alternatives for generating ebooks (PDF, EPUB, and MOBI).

At this point, I learned about asciidoctor, which works in a remarkably similar way to Markdown, but it is so much more flexible. It allows you to really get creative with your layout, and it can be used to generate ebooks in several formats. Then, there is asciidoctor PDF, which allows you to define a theme file that controls the fine details of your PDF: margins, font, font size, page numbering, etc.

There was a hard trade-off here: on the one hand, I could have a hassle-free and automatic generation using Markdown, GitHub, and Leanpub; on the other hand, I could have complete control over the layout of my book. I chose the latter — asciidoctor for the win!

By the way, I tried some native asciidoctor editors, but none of them got even close to matching the ease of use and flow offered by Typora. I had such a great time writing in it that I actually kept writing in Typora, and converted the Markdown files to the asciidoctor format after finishing each chapter. This is less than ideal, I know, but the fact remains:

The tools cannot get in the way of writing. I'd rather go through the pains of converting formats afterward than getting annoyed by the text editor and having my inspiration ruined by this.

And so I wrote, the first three chapters, 200 or so pages. That looks like a LOT of pages, right? Well, let me tell you something…

Formatting

While choosing which fonts, sizes, and line spacing to use, I decided to go with large sans-serif fonts and clearly spaced lines. I wanted my readers to enjoy the act of reading itself, so I tried to make it as easy as possible to visually follow the text.

Therefore, each page has 140 words on average — which is about half the number of words in a page of a typical technical book. That would double the cost of a printed book, but it has close to zero financial impact on an ebook.

But there's more…

Writing Style

I write as if I were having a conversation with you, the reader. I try to put myself in your shoes and ask questions as if I were you, and then answer them. It's kinda like teaching, but in writing instead of in person.

I do not believe every page should be densely packed with as much information as possible. For me, the main goal is to be as clear as possible. If that means a higher page count, so be it.

Besides, how do you prefer to learn about a new topic:

  • reading a five-page, formal, notation heavy, academic paper;
  • or reading a 20-page, informal, written in plain English, piece of text?

Unless you're quite used to reading academic papers, and notation is already in your blood, I'd bet you chose the second option. If you did, you're in my target audience :-)

Once the three chapters were ready, it was time to…

Publish For The First Time

So, on July 14th, 2020, I published the first two chapters of my book! You're probably thinking "two, not three?!". Yes, only two. I kept one publication-ready chapter up my sleeve!

I did it to buy myself some time… the idea was to release a new chapter every month and, by withholding one chapter, I wouldn't miss the mark if a new chapter weren't ready on time. Throughout the writing of the whole book, I always had at least one "backup" chapter so I could honor my schedule.

Once my book was out there, there was no going back! Until then, I was only committed to myself. But, once it was published, I was committed to my readers, those that had faith in my work and bought an unfinished book, trusting me to finish it :-)

Keep Writing

Writing a book is hard work! There are good days, but there are also bad days. On the bad days, everything you write looks crappy to you, and it looks like you'll never be able to finish it! But you cannot give up, your readers are counting on you to finish it!

My advice to you — actually is not mine, I read somewhere else but unfortunately cannot remember who said it — try to write 1,000 words every time you sit to write, and try sitting to write several times a week. You won't feel inspired to write every time, that's guaranteed. But when you do, your word count will go through the roof :-) Besides, you can always rewrite parts of it if you're not happy with them.

"Keep writing."

Johnny Writer

And so I wrote, day in, day out, skipping some days, for another ten months or so! Yes, ten months, and more than 1,000 hours of work (that may actually be a conservative estimate since I didn't keep detailed track of it).

That's a lot of time, I know… since I hadn’t committed upfront to a fixed outline, I ended up covering a LOT more ground than I initially expected. But I am pretty happy with the result!

The Book In Numbers

  • 4 Parts / Volumes
  • 15 chapters
  • 1,159 pages
  • +150,000 words
  • 473 images
  • 445 commits on GitHub

Whenever I look at these numbers, I'm like "how did I do that?" :-)

That 300-page proposal looks so much easier now…

How It's Been Working For Me

I released one (or two) chapters every month and, in these 10 months, the book went from 30% to 90% complete. I announced every release on Twitter and LinkedIn, and occasionally on Facebook. So far, I haven't invested much time in trying to advertise my book, but I do have some encouraging metrics so far:

  • 1 out of 10 visitors download the PDF sample
  • 1 out of 3 buy the book (from those that downloaded the sample)

I'm no expert on the matter, but a 3% conversion rate looks pretty good for an unfinished book :-)

In a few days, I will publish the final chapters of my book and a whole new chapter (pun intended!) will unfold.

I'm guessing the hardest part is actually about to begin… wish me luck :-)

Thank you!

If you have any thoughts, comments or questions, please leave a comment below or contact me on Twitter.

Data Scientist, developer, teacher and writer. Author of "Deep Learning with PyTorch Step-by-Step: A Beginner’s Guide"