Prince is a HTML-to-PDF-via-CSS converter which is often used for creating books from HTML and CSS. The most We start with very simple document, which only has one line of text:
By saving this to a file which as a If it doesn't work, make sure you use the more recent version of Prince.
These features must be turned on with command-like switches.
You can add HTML elements inside Markdown files. This allows for adding a style sheet through the Prince converts Markdown to HTML before formatting. Here's an overview of transformations:
Hello, World!
mdHello, World!
.md extension, we can make Prince read the input as Markdown:
prince sample-1.md
A real document
md# Showing off Markdown
This is a simple paragraph. Here's a list:
- **Bold** text
- *Italic* text
- `inline code`
- [Hyperlinks](https://www.markdownguide.org)
## More features
1. Hello, World!
2. Hei, verden!
Blockquotes are easy:
> I'm a blocky quote
### Links
- [Markdown Guide](https://www.markdownguide.org)
- [GitHub Markdown Docs](https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax)
Math
md# Simple Markdown with Mathematical Formulas
This document demonstrates math formulas that can be processed nicely with Prince XML.
## Inline Formulas
The area of a circle is $A = \pi r^2$, where $r$ is the radius.
Energy and mass are related by Einstein's equation: $E = mc^2$.
The speed of light is approximately $c \approx 3 \times 10^8$ m/s.
## Display (Block) Formulas
The quadratic formula is:
$$
x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}
$$
Pythagorean theorem:
$$
a^2 + b^2 = c^2
$$
The famous limit definition of $e$:
$$
e = \lim_{n \to \infty} \left(1 + \frac{1}{n}\right)^n
$$
## Another Example
The derivative of $f(x) = x^2$ is $f'(x) = 2x$.
> These formulas use standard LaTeX syntax inside Markdown.
> For best results with Prince, convert this Markdown to HTML first (using Pandoc recommended), then run Prince on the HTML file.
You can add as many formulas as you like using `$...$` or `$$...$$`.
Smart quotes, dashes, and ellipses
md# Smart Typography Demo
Straight quotes: "double quotes" and 'single quotes'.
- The **en dash** `--` is used for ranges and connections: 2020–2025, pages 45–52, or New York–London.
- The **em dash** `---` is used for interruptions or asides — like this one right here.
An ellipsis indicates a pause, omission, or trailing thought...
Styling Markdown with CSS
style element:
md<style>
@import url('https://fonts.googleapis.com/css2?family=Sorts+Mill+Goudy');
@page { size: a4 landscape; margin: 0 }
html { background: red; font: bold 10vw Sorts Mill Goudy; color: white; text-align: center }
</style>
Hello, World!
Cheat Sheet
Markdown Syntax
HTML Output
Meaning / Purpose
*italic text* or _italic text_<em>italic text</em>Italic / emphasis
**bold text** or __bold text__<strong>bold text</strong>Bold / strong importance
***bold and italic***<em><strong>bold and italic</strong></em>Bold + Italic
`inline code`<code>inline code</code>Inline code
> This is a blockquote<blockquote>...</blockquote>Blockquote
- Item or * Item<ul><li>Item</li></ul>Unordered (bullet) list
1. Item<ol><li>Item</li></ol>Ordered (numbered) list
[Link text](https://example.com)<a href="https://example.com">Link text</a>Hyperlink
<img src="image.jpg" alt="Alt text">Image with alt text
<img src="image.jpg"><img src="image.jpg">Image without any alt attribute (raw HTML)
# Heading 1<h1>Heading 1</h1>Level 1 Heading
## Heading 2<h2>Heading 2</h2>Level 2 Heading
### Heading 3<h3>Heading 3</h3>Level 3 Heading
--- or *** or ___<hr>Horizontal rule (separator line)
~~strikethrough~~<del>strikethrough</del>Strikethrough
"double quotes"“double quotes”Smart double quotes
'single quotes'‘single quotes’Smart single quotes
--–En dash (used for ranges, e.g. 2020–2025)
---—Em dash (used for interruptions — like this)
...…Ellipsis
^superscript^<sup>superscript</sup>Requires
--markdown-superscript command-line switch
^subscript^<sup>subscript</sup>Requires
--markdown-subscript command-line switch