How to write a Math or Data Science eBook?


When studying, I like to take notes, usually, I do it on my Blog, but often I use Jupyter notebooks which I commit to GitHub. If I am writing a paper I use Google Docs. Having my writing in 3 different places is not optimal. 
On top of that, using math formulas complicates things as it is not supported everywhere.

Example of a formula written using LaTeX:

$$ LogLoss = - \frac{1}{n} \sum_{i=1}^{n}
( y_i \cdot log(\hat{y_i}) + ( 1 - y_i ) \cdot \log(1 - \hat{y_i}) ) $$

So, how should I write a Math, or a Data Science, eBook?

First, publishing papers as PDF is most common, I read tons of them, but they are hard to digest unless you print them, or view them on a big screen. I do not want to sit in front of the computer any longer than I already do.  I like using Kindle reader, so an eBook format is much more user-friendly. I can set font sizes, and spacing, take notes, etc. The PDFs on Kindle are a really bad experience. Also, I would like to distribute my papers over the Amazon Kindle store (for free or not). Not everyone has a university or a work subscription to access papers on ieee.org, sciencedirect.com, proquest.com, etc.




Below, I will investigate different approaches and hopefully, come to a good conclusion.

How to send documents to Kindle:
  • Every Kindle account has an associated (secret) email, you can attach a file to it and it will show in your Kindle.
  • Make sure the file name is human-readable!
  • HTML (export from Jupyter Lab) sent to Kindle:
    • PRO:
      • it is readable, good for text-only pages
    • CON:
      • LaTeX is not converted to math formulas
      • Images are missing
  • PDF (of the same HTML) sent to Kindle:
    • PRO:
      • images show up
      • LaTeX formulas show up
      • good enough to publish a "paper"
    • CON:
      • still the problem with PDF in general -- no font size adjustment
  • ePUB (of the same HTML) sent to Kindle:
    • conversion is done with convertio.co
      • PRO
        • font adjustable
        • plots included
      • CONS:
        • missing images
        • LaTeX not converted to math formulas 
    • conversion with  calibre-ebook.com

Is Blogger (Blogspot) good for writing papers and articles?

Pro:
  • searchable 
  • easy to manage and edit
  • use of tags (labels) for finding related articles
  • support for LaTeX math notation
Cons: 
  • No good ways to "clean" export to ePub, PDF, or Markdown
    • I could write embedded JavaScript in Blogger that creates "print" version of article text only

Using Jupyter Notebook

Pro:

  • inline and current code (Julia, Python)
  • incline and current plots 
  • export to HTML, PDF, Markdown with pandoc.org/
Cons
  • no spellcheck while writing (Grammarly)
    • conda install -c conda-forge jupyterlab-spellchecker
  • GitHub Diff is garbage

How to install brew?

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

How to install pandoc? 

[see reference 5]
brew install pandoc


[see reference 1]


Using Markdown

Pros:

  • GitHub diff is readable


Using Google Docs

Pros:

  • Available on all devices, online and offline


[see reference 2]



References

  1. https://towardsdatascience.com/transform-jupyter-notebook-to-an-ebook-ef3a9d32ac4f
  2. https://workspace.google.com/marketplace/app/autolatex_equations/850293439076
  3. https://tug.org/mactex/mactex-download.html
  4. https://nbconvert.readthedocs.io/en/latest/install.html#installing-tex
  5. https://pandoc.org/installing.html



As an Amazon Associate I earn from qualifying purchases.

My favorite quotations..


“A man should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly. Specialization is for insects.”  by Robert A. Heinlein

"We are but habits and memories we chose to carry along." ~ Uki D. Lucas


Popular Recent Articles