# How to combine Markdown files into one book

> Keep one file per chapter while you write, then concatenate them in order with a page break between each. The commands, the heading trap, and what not to merge.

Canonical: https://buk.press/blog/combine-markdown-files

30 August 2026 · 4 min read

Keep chapters as separate files while you write, named so they sort in book order, then concatenate them into one manuscript with a page-break marker between each file. Do this as a last step, not as a working habit: the combined file is what you typeset; the per-chapter files stay the thing you edit.

A book is an awkward size for a single text file while it is being written, and an awkward size for fifty files when it is being typeset. The working arrangement is both: chapters as files, the book as a concatenation you generate when you want to see the whole thing.

## Name the files so order is free

The only trick that matters before any command. Zero-pad the numbers and put nothing in front of them that sorts alphabetically in the wrong place.

```
<code>00-title-and-copyright.md
01-introduction.md
02-the-first-mistake.md
03-a-worked-example.md
14-appendix.md</code>
```

`chapter-2.md` and `chapter-10.md` will sort as 10 then 2, which you will notice exactly once, in the exported PDF, after you have already proofed the wrong order. `02` and `10` will not. Front matter starts at `00` so it stays first without a special case.

## Concatenate, then typeset

On a Mac or Linux machine, from the folder of chapters:

```
<code>for f in *.md; do
  cat "$f"
  printf '\n\n---\n\n'
done > book.md</code>
```

That prints each file, then a blank line, a `---` page-break marker, and another blank line. The last `---` makes an empty trailing page, so delete it. Windows PowerShell is the same idea: `Get-ChildItem *.md | ForEach-Object { Get-Content $_; "`n`n---`n`n" } | Set-Content book.md`.

Pandoc will do this in one step if you are already in that toolchain (`pandoc *.md -o book.pdf`), and it has its own ways to insert breaks. If the destination is a tool that wants one Markdown file, concatenate first and hand it `book.md`.

The combined file is an export, like a PDF is an export. Edit the chapter files, regenerate `book.md`, and do not fix typos only in the combined copy. That is how the sources drift and the next concatenation undoes an afternoon of proofing.

## The heading trap

Each chapter file was probably written with its own `# Chapter title` at the top, because in isolation that is the title. Concatenate ten of those and the book now has ten `#` headings. In a renderer that starts a new page on every `#` (as [bukpress](https://buk.press/) does, except for the first), you get the page breaks you wanted for a different reason, and an EPUB whose navigation is ten top-level entries with no book title.

Pick a convention and apply it before you merge:

- `#` only in `00-title-and-copyright.md`, once, for the book title.
- `##` at the top of every chapter file.
- `###` for sections inside a chapter.

A one-line check after concatenating: count the `# ` headings that are not `##` or `###`. There should be one. [The contents page](https://buk.press/blog/markdown-table-of-contents) is generated from this outline, so a messy merge is a messy table of contents in every format at once.

## What not to merge

- **Notes, scraps, unused chapters.** If it is in the folder, it is in the book. Keep a `_drafts/` or `notes/` directory that the glob does not see.
- **A README.** `README.md` sorts in the middle of a case-sensitive glob on some systems and at the start on others. Either way it is not a chapter.
- **Cover artwork.** A cover is not Markdown. Attach it as a cover; [do not inline it as the first image](https://buk.press/blog/markdown-pdf-cover).
- **Per-chapter bibliographies** unless you have a real citation tool. Ten copies of the same reference list is the usual result of merging academic chapters that each ended with "References".

## Obsidian, Notion, and other vaults

If the chapters are notes in a vault, the merge is the same and the export is the extra step. Obsidian: a plugin or a simple `cat` on the vault folder, after you have resolved `[[wikilinks]]` to something a normal Markdown renderer will accept (see [the longer Obsidian path](https://buk.press/blog/obsidian-to-pdf)). Notion: export the pages as Markdown, then concatenate; Notion's export is messy in predictable ways, covered in [Notion to a book](https://buk.press/blog/notion-to-book).

Do not try to typeset the vault directly. A vault is a graph. A book is a sequence. The concatenation is the moment you admit which one you are making.

## Then it is one manuscript

From here the pipeline is the same as if you had written in one file all along: structure, design, export, proof. [The whole map](https://buk.press/blog/self-publish-from-markdown). In [bukpress](https://buk.press/) you paste or drop that combined file into a project; there is no multi-file book format, which is why the concatenation lives on your side. The preview will show whether the `---` between chapters is doing what you meant, and whether a leftover `#` just started a blank page you will otherwise find in the PDF.

**About this article.** Written by the team that builds bukpress, which turns Markdown into print-ready PDF and EPUB books. Spotted something wrong or out of date? Write to [support@buk.press](mailto:support@buk.press).

## Read next

Tools 30 August 2026 · 5 min read

## [Obsidian to PDF: getting a book out of your vault](https://buk.press/blog/obsidian-to-pdf)

Obsidian's Export to PDF prints the note the way your current theme draws it on screen, which is why the result looks like a screenshot of an app rather than a book. To get a real book you have to decide first whether you are exporting one note or assembling a manuscript. They are different problems with different fixes.

[Read it](https://buk.press/blog/obsidian-to-pdf)

Tools 30 August 2026 · 4 min read

## [Notion to a book: turning a workspace into a manuscript](https://buk.press/blog/notion-to-book)

Export as Markdown & CSV rather than PDF: the PDF export prints Notion's screen styling, while the Markdown export gives you the text in a portable form. Then expect a cleanup pass (hashed filenames, URL-encoded image paths, callouts flattened to blockquotes and databases split off as CSV) before you have a manuscript.

[Read it](https://buk.press/blog/notion-to-book)

How-to 21 August 2026 · 4 min read

## [How to control page breaks in Markdown](https://buk.press/blog/markdown-page-breaks)

Markdown has no page break because it describes structure, not pages, so every method is really an instruction to whatever renders it. The three that work are a raw HTML div with a CSS page-break rule, a LaTeX \newpage command through Pandoc, or a renderer that assigns a meaning to a plain-text marker.

[Read it](https://buk.press/blog/markdown-page-breaks)

## Write it in Markdown. Ship a book.

bukpress turns the file you are already writing into a typeset PDF and EPUB: your type, your covers, no watermark, ever.

[Get Lifetime, $27 once](https://app.buk.press/signup)
