Originally published at Beckman.io

Two of my best friends and I have been running a WhatsApp group chat for almost four years now. Three years ago we started turning these chats into printed books, and as I’m about to complete the third book I’ve written this hackers guide of sorts.

It might seem like a strange thing to do, but it’s really fun and rewarding. Our conversations range from lolcats to the very personal — just like life itself — and I’m really glad we’ll be able to read them many years from now.

Doing this isn’t hard per se, but I would say it requires familiarity with a terminal, basic python scripting, and a willingness to put some effort into detailing — this is a Hackers guide after all 😉.

The wa2latex.py Python script and LaTeX sources are available at github.com/pbeck/whatsbook

1. Text formatting

WhatsApp has an export chat feature (found in Chat InfoExport Chat) that will email you a zip archive containing a chat log and all posted media. The text sent from WhatsApp is just a raw text dump, so we need to do some reformatting for it to be useable; remove all empty lines, timestamps, adjust chat names, fix emojis, remove all superflous dates, and adjust image links.

This is what wa2latex.py does; it takes your chatlog text file as input and echoes a nicely formatted LaTeX document.

python wa2latex.py your-chatlog.txt > whatsbook-folio.tex

Once you’ve generated whatsbook-folio.tex I recommend the cross-platform TeXstudio for editing and compiling. It is cross-platform, has many features that makes working with LaTeX easier, and comes with the XeTeX compiler included. If you feel like working in the cloud there’s ShareLaTeX. I haven’t tried using it for this project, but it should probably work fine.

Regarding Emojis

For emojis to work in LaTeX documents I use code from Henning Pohls latex-emoji and Sean Dolinars socialmediaparse. Most standard emojis work, but I haven’t implemented support for all kinds of emojis and emoji modifiers so you’ll have to do some manual adjustments to get everything in order.

If you want to read more on emojis in software there’s a very interesing post on the Instagram Engineering blog.

2. Layout & template

I use a minimal layout for these books. Digital conversations is almost a stream of consciousness, so I feel the layout should reflect that. The only elements that break the flow of text and images are dates and monthly chapters. Dates gives context to discussions, and monthly chapters adds a gentle but needed structure to the layout. In previous books I’ve experimented with coloring names and speech bubbles to visually indicate which person is talking, but I’ve found it only adds a layer of complexity.

I usually start by making a mockup design in InDesign to get type, margins, etc. set up properly. Here’s the one I created for whatsbook.tex:

InDesign mockup for whatsbook.tex

It’s based on a 9pt base font and has neatly set margins and footers. In the example above I’ve used Hoefler&Co’s fonts Ideal Sans and Tungsten, but it’s an easy thing to change to your liking.

whatsbook.tex is the LaTeX template created from the mockup above. It includes the whatsbook-folio.tex for contents (the \include command at line 216), so unless you’ve renamed any of the files you only need to open whatsbook.tex and hit ‘Build & View’ in TeXstudio.

Cover & Back

Cover and back mockup

The cover and back are not a part of the TeX template, so you’ll have to create those manually. I designed the cover and back in Indesign as it’s quicker than LaTeX for working with single pages, and Blurb provides a nifty InDesign plugin. If you don’t have access to InDesign there are plenty of other options.

3. Manual adjustments

  • If you chat history is too large WhatsApp won’t include all images in the exported zip-file. You’ll have to manually download them and insert image references in the .tex-file.
  • Videos are naturally not included, but it’s easy to grab a frame from the video and insert that as an image.
  • If you want formatted names (bold small caps) you should search and replace chat names with TeX-commands. \chas, \dudley, and \margot are predefined, but you could rename them to anything. See wa2latex.py line 152–154
\margot I think we're just gonna to have to be secretly in love with each other and leave it at that, Richie.\\*
  • Chapters are not inserted automatically (that’s were the structure browser in TeXstudio comes in handy!), so you’ll have to enter them by hand. If you want one chapter per page, include the \clearpage command.
\chapter*{<chapter name>}
  • The chat logs include information on when someone changes the group chat title and icon — those are easily removed or edited with a simple search and replace.

4. Print!

I printed our first books on a regular office printer and bound with single ring-binders (the kind used for corporate presentations). The end result worked, but this book I’m sending off to on-demand printers Blurb. A 200 pages “Trade Book” in color at 8 × 5 inches will cost me no more than $20 / book + shipping costs (here’s a pricing calculator).

The TeX template is made specifically for the 8 × 5 in trade book, but it wouldn’t be hard to adjust for other sizes; it’s only a matter of changing the stock size and margins. See lines 37–41 in whatsbook.tex.

Once you’ve generated both folio (the contents of the book) and the cover+back you just have to upload them to Blurb and you’re good to go!

Printing with Blurb required some special PDF/X-3 LaTeX code — thanks to Enrico Maria Crisostomo for doing the research!

If you helped spreading the word by hitting the recommend button below, or share it on Twitter or Facebook I would be very grateful! Thanks!

Images used © copyright respective owners.