AI Driven e-books (as a code) with Pandoc

AI Driven e-books (as a code) with Pandoc

August 31, 2025

TL;DR

I love R language and its knitt package

Would it be possible to make ebooks as a code?

Intro

I got inspired recently by the concept of: https://readmake.com/

Some people are selling this kind of things on social media: https://altagency.com/guide/

People with PRO tech knowledge, like: https://kerkour.com/books

Others, just publish freely, like https://github.com/treeman/why_cryptocurrencies, which builds with Pollen and touches the crypto ecosystem

Together with the build in public, which it seems to be a thing.

How about selling an ebook be all about: having an stripe account and proper content that people want to read?

A landing page for your eBook

ℹ️
The original theme I forket it from the MIT from candidosales, where I brought makefile and dockercompose for easier deployment + easier configuration via json.
#https://github.com/candidosales/landing-page-book-astro-tailwind
#https://github.com/zenorocha/14habits.com
git clone https://github.com/JAlcocerT/sell-your-ebook
#npm install
npm run dev -- --host 0.0.0.0 --port 4321 #http://192.168.1.11:4321/
#npm run build
#npm install -g serve #serve with npm
#serve -s dist #http://localhost:3000

The original theme (also MIT) is awsome and brings a lot of content costomization via config.json

The theme is oriented towards one book selling, but you could adapt it so that it becomes, for example, your knitting patterns shop https://morecaknit.com/, and wow, that’d be a shopify competitor!

Ping comparison from selfhosted astro x300 vs local ping vs shopify vs cloudflare pages You know what to tell, its just that… time matters.

So why not accelerating the time to ship ebooks by understanding how to have their skeleton code driven?

And maybe get LLM help for charts creation, data driven parts etc.

Stripe Payment Links

Go to: https://dashboard.stripe.com/payment-links

Using Sell Your Ebook

You will need containers and a server to deploy this.

The idea to make it as simple as possible is that the docker compose environment variables send information to the config.json of the astro ssg theme that we have been tinkering above.

The result?

You now just need to tweak one place and enjoy the theme, with your stripe payment link included.

git clone https://github.com/JAlcocerT/sell-your-ebook
#cd sell-your-ebook
#make quick-dev #to spin dev server inside container and see :4321 still
#docker compose up astro-prod -d
make quick-prod #to bring the real statically generated prod version to 8090

You might just need to adjust the port mapped to the server: http://192.168.1.11:8099/

But for CF tunnels its just: astro-prod:4321, configure it via Zero Trust after you connect to the cf network: https://one.dash.cloudflare.com/

#docker network ls | grep cloudflared_tunnel
docker network connect cloudflared_tunnel astro-prod #connect

#verify
#docker inspect astro-prod --format '{{json .NetworkSettings.Networks}}' | jq

eBook Astro and Cloudflare Tunnels

Aaaand this is it: https://ebook.jalcocertech.com/

Ebook Landing + Umami Web Analytics

ℹ️
You can make epubs and pdf from png/html/md files, all programatically!

I could not resist to create a quick FlaskCMS to edit the config.json…

#uv init
#......
make quick-config 

…this was literally one prompt with Cursor. A flask CMS JSON editor:

Flask CMS Editor for Ebook Landing JSON

So you can go back to your server and do:

#git stash push -m "backup before force pull"
#git pull origin main
# If you need your changes back: git stash pop
# If you don't need them: git stash drop
make quick-prod
docker network connect cloudflared_tunnel astro-prod #connect

At this point, you have your ebook published via cf network, like: ebook.jalcocertech.com


eBooks

Making ebooks is possible with pandoc or MKDoc

Pandoc can write a PDF/epub from .Rmd or ipynb, that will be for a future post.

See this script

Maybe someone will do something with financial ,miss-conceptions'?

But hey, some people use latex, so if its possible to make a code driven CV in overleaf with Latex

Why not ebooks?

And how about creating the ebook with R?

If we can create markdown driven websites (thanks to SSGs), even presentations…

We dont need crazy components, nor shortcodes

Just text, images, graphs…How are we not going to create ebooks powered with R?

Lets just Setup R and see how:

# Core R environment
sudo apt install -y r-base r-base-dev

# LaTeX and PDF generation
sudo apt install -y texlive-latex-base texlive-fonts-recommended texlive-fonts-extra texlive-latex-extra

# Pandoc and citation processing
sudo apt install -y pandoc pandoc-citeproc

# Development libraries for R packages
sudo apt install -y libcurl4-openssl-dev libssl-dev libxml2-dev libudunits2-dev

We can try knitting a bit, but we have also: https://bookdown.org/yihui/rmarkdown/

FeatureR Markdown + knitrbookdown
ScopeSingle documentMulti-chapter book
StructureOne fileMultiple files + configuration
Cross-referencesLimitedFull support
Table of contentsBasicAdvanced with navigation
Figure numberingPer documentAcross entire book
BibliographyBasicAdvanced with citations
Output formatsPDF, HTML, WordPDF, HTML, EPUB
ComplexitySimpleMore complex setup
Use caseReports, papersBooks, manuals, documentation

Creating an Ebook

I mean, an AI Assisted e-book.

After chating a while with cursor, we got this kind of workflow working.

See mermaid

We can go the simple knitt way or the bookdown with proper chapters etc:

#cd example-pdf-knit
#Rscript -e "rmarkdown::render('simple-example.Rmd', 'pdf_document')"

cd example-pdf-bookdown
# Generate PDF
Rscript -e "bookdown::render_book('index.Rmd', 'bookdown::pdf_book')"
# Generate HTML  
#Rscript -e "bookdown::render_book('index.Rmd', 'bookdown::gitbook')"
# Generate EPUB
#Rscript -e "bookdown::render_book('index.Rmd', 'bookdown::epub_book')"

R Markdown Ebook Workflow Summary:

  1. Write Chapters as .Rmd files (R Markdown with embedded R code)
  2. Knit Process converts .Rmd.md (Markdown + executed R output)
  3. Pandoc Processing converts .md → LaTeX → PDF
  4. Final Output is a professional PDF ebook in the docs/ folder

Key Technologies:

  • R Markdown (.Rmd) - Write content with embedded R code
  • knitr - Execute R code and generate output
  • bookdown - Organize multiple chapters into a book
  • Pandoc - Convert between document formats
  • LaTeX - Professional typesetting for PDF output
  • ggplot2/dplyr - Data analysis and visualization

Simple Flow: R Markdown (.Rmd)knitrMarkdown (.md)PandocLaTeXPDF

💡 When to Use Each

Use R Markdown + knitr when:

  • ✅ Writing a single report or paper
  • ✅ Creating a presentation or slides
  • ✅ Making a simple analysis document
  • ✅ Need quick output without complex structure
  • ✅ Working on a one-off project

Use bookdown when:

  • ✅ Writing a multi-chapter book
  • ✅ Creating documentation or manuals
  • ✅ Need cross-references between sections
  • ✅ Want professional book formatting
  • ✅ Planning to publish the work
  • ✅ Need multiple output formats (PDF, HTML, EPUB)

Conclusions

This is it for now.

We’ve got a landing page to share ebooks.

And a draft on ways to create them with RKnit/Pandoc.

But im happy I could link this to my last year thought with the assistant agent for open ai driven ebooks.

How people send eBooks

  1. Via Stripe: https://shop.acquisition.com/products/100m-money-models?utm_campaign=13261424-%24100M%20Money%20Models&utm_source=hs_email&utm_medium=email&utm_content=376228484&_hsmi=376228484

  2. I guess via stripe + SSR and obfuscation technique that gets clear if your email is in the proper Stripe driven table of users who bought: https://readmake.com/

You can also sell ebooks via amazon or ko-fi.


FAQ

Pandoc and (ipynb or RMD)… 📌

In fact, they all use Pandoc as the core conversion engine.

How the Systems Interrelate

  • R Markdown & knitr: In the R ecosystem, you write a document with a mix of text and R code chunks in an .Rmd file. When you “knit” the document, the knitr package first processes the file. It executes the R code chunks, collects the output (text, tables, plots), and creates a new, pure Markdown file that includes the results.

  • Pandoc: This is where the magic happens. The Markdown file generated by knitr is then passed to Pandoc. Pandoc is a standalone, command-line tool that can convert documents between a vast number of formats. It takes the Markdown file and converts it to the final output format, whether that’s HTML, PDF, Word, or another type.

  • Jupyter Notebooks: The workflow for Jupyter Notebooks is very similar, though it’s often more integrated. The Jupyter nbconvert tool handles the initial processing of the .ipynb file. It executes the code cells (if they haven’t been already) and prepares the content, including code and outputs, for conversion. nbconvert then uses Pandoc to perform the final conversion from the prepared intermediate format to the desired output format, such as PDF or EPUB.

Essentially, both systems use a two-step process: first, an engine (knitr for R Markdown, nbconvert for Jupyter) processes the code and generates an intermediate Markdown-like file, and second, Pandoc takes that intermediate file and converts it to the final document format.

The primary difference is the front-end tool and the language-specific processing, but Pandoc is the shared, underlying engine that makes the final document conversion possible.

Kindle Notes to AI

Kindle notes are saved into a .txt in the device.

I was storing notes for few years already and im really curious to see whats inside.

I gave it a try with Google’s NotebookLLM, but…custom is custom

ℹ️
Kindles are not recognized on ubuntu, but you can access their content via https://read.amazon.com/landing

More Books Stuff

Epub to AudioBook with Python: https://github.com/C-Loftus/QuickPiperAudiobook

Converting to epub

A simple Docker-based REST API that converts Markdown to EPUB format using Pandoc. Send markdown content via JSON, get an EPUB file back.