Skip to main content

Merge Markdown files into a single PDF or HTML presentation with Pandoc + XeLaTeX

Project description

mdfusion

Merge all Markdown files in a directory tree into a single PDF or HTML presentation with formatting via Pandoc + XeLaTeX.


Features

  • Recursively collects and sorts all .md files under a directory (natural sort order)
  • Merges them into one document, rewriting image links to absolute paths (so images with the same name in different folders don't collide)
  • Optionally adds a title page with configurable title, author, and date
  • Can render the title page as its own centered page with a page break after it
  • Supports both PDF (via Pandoc + XeLaTeX) and HTML presentations (via reveal.js)
  • Customizes output with your own LaTeX or HTML headers/footers
  • Configurable via TOML for repeatable builds (great for books, reports, or slides)
  • Bundles HTML presentations with all assets for easy sharing

Installation

Requirements

For HTML presentations and PDF export from HTML, you may want to install:

  • Playwright (for HTML→PDF conversion) via pip install playwright and then playwright install

pandoc is provided through the Python dependency pypandoc_binary, so you do not need a separate global Pandoc installation.

Install via pip

pip install mdfusion

Install from source

git clone https://github.com/ejuet/mdfusion.git
cd mdfusion
pip install .

Usage

mdfusion [OPTIONS]

You can also pass extra Pandoc arguments at the end of the command; any unknown flags are forwarded to Pandoc.

Common options

  • --root_dir DIR Root directory for Markdown files (default: current directory, or config file directory)
  • --output FILE Output filename (default: <root_dir>.pdf or .html for presentations)
  • --toc Include table of contents (use --notoc to disable)
  • --page_break_after_toc Insert a page break after the table of contents in PDF output (default: false)
  • --title_page Include a title page (PDF only)
  • --separate_title_page Put the title page on its own centered page (default: true; use --noseparate_title_page to disable)
  • --title TITLE Set title for title page (default: directory name)
  • --subtitle TEXT Set an optional subtitle for the title page
  • --title_page_image PATH_OR_URL Add an optional local image or remote image URL to the title page
  • --author AUTHOR Set author for title page (default: OS user)
  • --document_date TEXT Set the date text shown in metadata/title page (default: current date)
  • --date_format FORMAT strftime format used when --document_date is omitted (default: %d.%m.%Y)
  • --pandoc_args ARGS Extra Pandoc arguments (whitespace-separated)
  • --config_path FILE Path to a mdfusion.toml config file (default: mdfusion.toml in the current directory)
  • --header_tex PATH Custom LaTeX header to include (defaults to ./header.tex if present)
  • --merged_md DIR Write merged Markdown to this directory (uses a temp dir by default)
  • --exclude PATHS Whitespace-separated files, directories, or glob patterns to skip while merging
  • --remove_alt_texts TXT Comma-separated list of image alt texts to strip (default: alt text)
  • --verbose Enable verbose Pandoc output

Presentation options

  • --presentation Output as a reveal.js HTML presentation (also converts to PDF)
  • --footer_text TEXT Custom footer for presentations
  • --animate_all_lines Add reveal.js fragment animation to each line
  • --chromium_path PATH Path to Chromium for HTML→PDF conversion (default: /usr/bin/chromium)

Example: Merge docs/ into a PDF with a title page

mdfusion --root_dir docs --title_page --title "My Book" --author "Jane Doe"

Example: Create a reveal.js HTML presentation

mdfusion --root_dir slides --presentation --title "My Talk" --author "Speaker" --footer_text "My Conference 2025"

Configuration file

You can create a mdfusion.toml file in your project directory to avoid long command lines. The [mdfusion] section supports all the same options as the CLI. Presentation-only settings live under [presentation] (these can also remain under [mdfusion] for backward compatibility).

Example: Normal document (PDF)

[mdfusion]
root_dir = "docs"
output = "my-book.pdf"
toc = true
page_break_after_toc = false
title_page = true
separate_title_page = true
title = "My Book"
subtitle = "Working Draft"
title_page_image = "https://example.com/cover.png"
author = "Jane Doe"
date_format = "%d.%m.%Y"
pandoc_args = ["--number-sections", "--slide-level", "2", "--toc-depth", "4"]
exclude = ["drafts", "appendix/private.md", "notes/*.md"]
# header_tex = "header.tex"  # Optional: custom LaTeX header

Example: Presentation (HTML via reveal.js)

[mdfusion]
root_dir = "slides"
output = "my-presentation.html"
title = "My Talk"
author = "Speaker"
pandoc_args = ["--slide-level", "6", "--number-sections", "-V", "transition=fade", "-c", "custom.css"]
# You can add more reveal.js or pandoc options as needed with ["-V", "option=value"]

[presentation]
presentation = true
footer_text = "My Presentation 2025"
animate_all_lines = false
# chromium_path = "/usr/bin/chromium"

Then just run:

mdfusion

How it works

  1. Finds and sorts all Markdown files under the root directory (natural order)
  2. Merges them into one file, rewriting image links to absolute paths
  3. Optionally adds title/author/date metadata and a dedicated title page
  4. Calls Pandoc with XeLaTeX (for PDF) or reveal.js (for HTML presentations)
  5. Optionally bundles HTML output with all assets for easy sharing

Testing

Run all tests with:

pytest

Author

ejuet

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mdfusion-0.3.6.tar.gz (45.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mdfusion-0.3.6-py3-none-any.whl (43.7 kB view details)

Uploaded Python 3

File details

Details for the file mdfusion-0.3.6.tar.gz.

File metadata

  • Download URL: mdfusion-0.3.6.tar.gz
  • Upload date:
  • Size: 45.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for mdfusion-0.3.6.tar.gz
Algorithm Hash digest
SHA256 dc04b3c8da730b0a5f5e1e53c9cddb1d0a0485da25511a5292b71e5d30c08b81
MD5 cb520f778b1aca7b3ff9ccc22a618110
BLAKE2b-256 0c146a594163b99ffafd7392007641738de07b359b1c193a172f1ab55fcd4b63

See more details on using hashes here.

File details

Details for the file mdfusion-0.3.6-py3-none-any.whl.

File metadata

  • Download URL: mdfusion-0.3.6-py3-none-any.whl
  • Upload date:
  • Size: 43.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for mdfusion-0.3.6-py3-none-any.whl
Algorithm Hash digest
SHA256 e0b8cd14dff9d4c7424aee714ad03eb22a13e9fb6ec87c497254085ff14ea958
MD5 966d62e143e8dca3b55535a1dba0a719
BLAKE2b-256 6c46b12d5f97e69c8d703ec8cd8e508308a080e123b274d39c27bc98ae9d72f4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page