Markdown to PDF — convert MD files with syntax highlighting

Convert Markdown to PDF with code highlighting, GFM tables, math, and Mermaid diagrams.

9 min read

Markdown to PDF — convert MD files with syntax highlighting (2026)

By ScoutMyTool Editorial Team · Last updated: 2026-05-19

Introduction

I write nearly everything in Markdown first — technical docs, design specs, blog posts, even meeting agendas. Markdown is fast to type, version-controllable, and renders cleanly on GitHub. The moment I need to share something outside GitHub, though, the question becomes: which tool turns my .md into a presentable PDF without breaking the code blocks, mangling the tables, or rendering the math as ASCII gibberish? After a year of using six different converters, the answer is that two or three of them handle the basics well and the differences only matter when you stretch the edge cases. This article walks through the variants, the tools, and the specific features (syntax highlighting, math, Mermaid) that decide which converter is right for your job.

Markdown flavours, in plain English

There is no single Markdown spec — there are several, and which one your converter speaks affects what survives. The four most-common variants in 2026:

FlavourSpecTable supportNotable features
CommonMarkcommonmark.org/spec (current 0.31)No (tables are an extension)The strict, unambiguous baseline. Headings, lists, links, images, fenced code blocks, inline code, emphasis, blockquotes, horizontal rules.
GitHub Flavored Markdown (GFM)github.github.com/gfm (extends CommonMark)Yes — pipe tables with --- alignment rowCommonMark + tables, strikethrough, task lists, autolinks, mention/issue references, code-block language hints.
MultiMarkdownfletcher.github.io/MultiMarkdown-6 referenceYes — multi-row headers, cell spansTables with merged cells, footnotes, math via MathJax/LaTeX, citations, definition lists, abbreviations.
Pandoc Markdownpandoc.org/MANUAL.html#pandocs-markdownYes — pipe, grid, multi-line, and simple tablesMost expressive variant. Adds raw LaTeX/HTML pass-through, fenced divs, attribute syntax, citations via .bib, MathML.

CommonMark is the most-portable baseline — every Markdown converter speaks it.1 GitHub Flavored Markdown adds the bits most users actually want (tables, task lists) and is supported by every converter in the table below.2 Pandoc Markdown is the most expressive and is the only variant that survives all of Pandoc's features.3

Five tools compared

ToolInstallSyntax highlightMathMermaidBest for
ScoutMyTool Markdown to PDFNone — runs in browserYes (highlight.js themes)Yes (KaTeX)YesQuick conversions of GFM-flavoured Markdown with no install
PandocCLI install (brew, apt, choco, MacPorts)Yes (kate-highlight)Yes (multiple math engines)Via filter onlyPower users; academic papers; complex multi-format workflows
VS Code "Markdown PDF" extensionCode + extensionYes (highlight.js themes)Yes (KaTeX)YesDevelopers who already author Markdown in VS Code
wkhtmltopdfCLI binaryVia highlight.js pre-renderNo (drop-in)No (drop-in)Server-side automation where Pandoc is too heavy
Headless Chrome / ChromiumChrome / chromedriverWhatever the source HTML providesYes (any browser-based renderer)YesProgrammatic pipelines that need exact browser-fidelity output

Syntax highlighting that actually works

The single most-asked-for feature in Markdown-to-PDF tooling is good code-block highlighting. Three things have to line up for it to work:

  1. Fenced code blocks with a language hint. Use three backticks and the language identifier on the opening fence. Without a language, the highlighter has nothing to colour against.
  2. A highlighter that supports the language. highlight.js (used by ScoutMyTool and VS Code) supports nearly 200 languages out of the box. Pandoc uses the Kate-highlight engine with similarly broad coverage. Both engines fall back to plain monospace for unknown languages rather than crashing.
  3. A theme that prints legibly. Dark themes look great on screen but waste toner and reduce contrast in printed PDF. The "GitHub" or "atom-one-light" themes are the safest choice for printable output; switch to dark themes only for screen-only PDFs.

For programming-heavy documents (technical specs, runbooks, code-review notes), ScoutMyTool's Code to PDF tool can produce a syntax-highlighted PDF directly from a source file — no Markdown wrapping needed. Use it when the document is mostly code with light annotation.

Math, diagrams, and front matter

Three more features that matter for the kinds of documents people write in Markdown:

  • LaTeX math. Surround inline math with single dollar signs ($E = mc^2$) and display math with double dollar signs. KaTeX renders most undergraduate math correctly and is fast enough for browser-based pipelines. Pandoc supports MathJax (slower but more complete) and MathML (best for accessibility tools that speak math).
  • Mermaid diagrams. Fenced blocks with the language hint mermaid are interpreted as flowcharts, sequence diagrams, ER diagrams, or Gantt charts and rendered as embedded SVG in the PDF. The native support in ScoutMyTool and VS Code Markdown PDF makes Mermaid the simplest way to embed a flowchart in a Markdown source.
  • YAML front matter. A block of YAML at the very top of the file (delimited by --- on both sides) carries metadata. Most modern tools read fields like title, author, date, and toc, and use them for the PDF metadata, cover page, or running header. The same convention is used by Jekyll, Hugo, Astro, and most static site generators.

Converting via ScoutMyTool — five steps

  1. Open the tool. Go to scoutmytool.com/pdf/markdown-to-pdf. The page loads as static HTML; the conversion runs entirely in your browser tab.
  2. Drop in the .md file or paste the Markdown. The tool parses with markdown-it (which speaks CommonMark and GFM by default).
  3. Pick a theme. Default (GitHub-style), Academic (Times-style with numbered headings), Minimal (single-column body, narrow margins). Custom CSS upload is available for branded output.
  4. Enable optional features. Math (KaTeX), Mermaid diagrams, syntax-highlighted code (highlight.js with theme picker), front-matter cover page, and page numbering.
  5. Convert. The tool renders to HTML, applies the chosen CSS, then uses pdf-lib to compose the paginated PDF. The result downloads to your machine. No network round-trip means even multi-megabyte Markdown files convert in seconds.

When to use Pandoc instead

Pandoc is the heavyweight of Markdown-to-PDF conversion and the right pick for three specific scenarios:

  • Academic papers with citations. Pandoc accepts a .bib file via --bibliography and renders citations + bibliography in the chosen style (APA, MLA, Chicago, etc.). No browser-based tool comes close.
  • Complex multi-format pipelines. Pandoc converts between Markdown, LaTeX, HTML, EPUB, DOCX, and more in any combination. If you produce the same document in multiple formats (e.g., LaTeX paper + EPUB book + PDF preprint), Pandoc is the single tool to learn.
  • Custom templates with full LaTeX control. Pandoc's template system gives you complete control over the PDF output — page geometry, headers, footers, custom commands. The learning curve is steeper than a CSS theme but the ceiling is higher.

For everything else — README files, design docs, runbooks, blog drafts, meeting minutes — a browser-based or VS Code extension is faster to set up, faster to run, and produces equally good output.

Frequently asked questions

Which Markdown flavour should I write in for PDF output?
GitHub Flavored Markdown (GFM) is the right default for most users — it is the variant GitHub README files use, has wide tool support, and adds pipe tables and task lists to CommonMark. For academic writing with footnotes, citations, and complex tables, Pandoc Markdown is more expressive. For documents where you need to share the .md source with non-technical readers, stick to plain CommonMark — its restrictions make it the most-portable variant. The good news: every PDF converter discussed in this article supports CommonMark and GFM. Pandoc Markdown is supported only by Pandoc itself.
Will fenced code blocks have syntax highlighting in the PDF?
Yes, if your converter supports it and you specify the language. Use the three-backtick fence with a language hint: ```python (or javascript, typescript, rust, go, bash, sql, css, html). The highlighter recognises the language and colours keywords, strings, numbers, and comments according to the chosen theme. ScoutMyTool uses highlight.js with the GitHub theme by default; pandoc uses the Kate-highlight engine; VS Code's Markdown PDF extension uses highlight.js with the editor's current theme. For Markdown without language hints, code blocks render as monospace without colour.
How do I include LaTeX math equations?
Use $ inline$ or $$display$$ delimiters with LaTeX expressions. For example, $E = mc^2$ inline, or $$\\int_0^1 x^2 \\, dx = \\tfrac{1}{3}$$ for a display equation. ScoutMyTool renders these with KaTeX, which supports a sizeable subset of LaTeX. Pandoc has multiple math engines (MathML, MathJax, KaTeX) selectable via --mathml/--mathjax/--katex. The output PDF embeds the equations as vector graphics, so they remain crisp at any zoom level. Limitations: not every LaTeX package is supported (no TikZ in KaTeX, for example) — for very advanced math, use Pandoc with the appropriate engine.
Can I render Mermaid diagrams?
Yes, with the right tool. ScoutMyTool's Markdown converter recognises ```mermaid fenced blocks and renders them as embedded SVG diagrams in the PDF. The same workflow works in VS Code with the Markdown PDF extension. Pandoc requires a filter (mermaid-filter or equivalent). Plain wkhtmltopdf and basic pandoc do not handle Mermaid out of the box. For a presentation-quality flowchart in your README, fenced ```mermaid blocks are usually the simplest path.
Are my Markdown files uploaded anywhere when I use a free converter?
Only if the converter is server-based. ScoutMyTool's Markdown-to-PDF tool runs entirely in your browser tab — your .md file is parsed locally with markdown-it, the resulting HTML is laid out with pdf-lib + a built-in CSS engine, and the PDF is downloaded directly. Nothing leaves your machine. Some server-side "MD to PDF" services upload your file, render it on their infrastructure, and stream back the result; for confidential design docs, RFC drafts, internal product specs, the client-side path is the only one that keeps the source off third-party servers.
How do I add a custom theme or stylesheet?
Most browser-based and editor-based tools let you supply a CSS file that styles the rendered HTML before the PDF pass. ScoutMyTool exposes a theme picker (default, GitHub-style, academic, minimal) and accepts a custom CSS upload that overrides the defaults. Pandoc accepts --css for HTML-then-PDF pipelines and a wide range of templates via --template. For corporate documents that need brand fonts, colours, headers and footers, building a small custom CSS once and applying it on every conversion is usually faster than configuring a full template.
What about front matter (YAML at the top of the .md file)?
Front matter is a YAML block at the start of a Markdown file (delimited by --- on both sides) that carries metadata like title, author, date, and tags. Most modern Markdown-to-PDF tools recognise it and use it for the PDF metadata (title, author shown in the viewer) and optionally for a cover page or running header. ScoutMyTool reads front-matter title/author/date and renders them as a title block at the top of the first page; pandoc consumes the same fields and supports custom templating via Pandoc variables.

Convert Markdown to PDF, free

Syntax-highlighted code, KaTeX math, Mermaid diagrams. Browser-only — nothing is uploaded.

Open the free Markdown to PDF tool →

References

  1. CommonMark, CommonMark Spec, version 0.31. spec.commonmark.org (accessed May 2026). The strict baseline for Markdown semantics.
  2. GitHub Inc., GitHub Flavored Markdown Spec. github.github.com/gfm (accessed May 2026). Extends CommonMark with tables, task lists, strikethrough, autolinks.
  3. John MacFarlane, Pandoc User's Guide. pandoc.org/MANUAL.html (accessed May 2026). Documents Pandoc Markdown and the conversion pipeline between formats.
  4. ISO 32000-1:2008, Document management — Portable document format — Part 1: PDF 1.7. opensource.adobe.com PDF32000_2008. Reference for the underlying PDF format that every Markdown converter targets.