98
votes

I am creating a pdf of markdown text file using doxygen (1.8.6). Now I want to get page break at specific stage in markdown file, I used this link.

In the given link they have mentioned to use '>' for line break. But they haven't mentioned about page break. Yes I can use '>' for page break as well but I have to write this symbol 5 or more times on markdown text file and that makes markdown file in weird look. Is there any other ways to get page breaks in markdown files?

8
Did you have a go at code like: My Main Page {#mainpage} ============ This is the text on the first page \latexonly \newpage \endlatexonly This is the text on the second pagealbert
@albert I didn't find any mainpage keyword in latex folderuser2760375
The example I gave generates a mainpage consisting of 2 pages. The important part for you would be \latexonly ....\endlatexonly. When you place my example in a file (e.g. aa.md) you can see the 2 pages when you generated the latex output.albert
@albert yeah now I got it earlier I didn't use the latexonly command in text file .Now I got it thanksuser2760375

8 Answers

239
votes

Since Markdown accepts plain HTML and CSS, simply add this line wherever you want to force page break.

<div style="page-break-after: always;"></div>

If your Markdown editor have trouble exporting PDF correctly, first try to export as HTML, then open with your browser and print as PDF.

74
votes

I encountered the same and solve it by inserting

\pagebreak

It's actually a LaTeX command, rather than a Markdown one.

22
votes

I Know that this is a dead question, but I've found a way that I think can be useful for other than me.

You can use the command \pagebreak inside an invisible element. In this way it works with latex and with html.

<div style="page-break-after: always; visibility: hidden"> 
\pagebreak 
</div>
10
votes

Blockquotes vs. line breaks

> is not used for line breaks in Markdown. It's used for blockquotes. For example, the following Markdown code

> A man provided with paper, pencil, and rubber, and
> subject to strict discipline, is in effect a universal machine.

becomes

A man provided with paper, pencil, and rubber, and subject to strict discipline, is in effect a universal machine.

(This is a quote from Alan Turing.)

Note how it is rendered with a yellow background by Stack Overflow. If you examine the generated markup you will find <blockquote> tags being used.

Line breaks can usually be inserted by ending a line with two or more spaces (Markdown syntax) or by using raw <br> tags (most Markdown processors allow inline HTML). For example (using to represent a space), this Markdown

123 Fake Street␣␣
Springfield, USA

becomes

123 Fake Street
Springfield, USA

Page breaks

Since the original specification Markdown was designed for HTML output (which doesn't have the concept of pages) there is no support for page breaks.

Doxygen uses LaTeX to generate its PDFs. It doesn't seem to support inline LaTeX¹, but you should be able to modify the intermediate .tex file and then use pdflatex to generate your PDF:

  1. Use Doxygen to generate a .tex file
  2. Edit the .tex file manually add \newpage wherever you want page breaks
  3. Run pdflatex documentation.tex
  4. Examine documentation.pdf

This question may be a useful reference for step 3 above.

¹Doxygen does support inline LaTeX formulas, but I wasn't able to find any mention of arbitrary inline LaTeX commands like \newpage that operate in the text environment.

6
votes

Though these answers work - they kind of break one of the goals of Markdown (MD), which is to be very readable as a straight text document as well as being able to be formatted into more rich presentations.

As soon as you start embedding a bunch of HTML/CSS in the text you lose the first aspect of MD. You might as well use Word, Libre, HTML/CSS, etc.

I think MD would do well to add a page break sequence. Something like: <<<<>>>> or similar to the formatting operators. I use that in my MD text. It doesn't cause a page break in the PDF or HTML converters, but it's recognizable in both those and the plain-text forms.

3
votes

A last resort workaround is to manually edit the HTML output to render to PDF as you want.

3
votes

In my Markdown document, page-break-after sometimes left a heading or two still on the same page. In those cases page-break-before worked to properly put everything after the <div> on the next page:

<div style="page-break-before:always"></div>

2
votes

To make tomodian's answer slightly cleaner, you can reference a CSS class:

words.md:

<div class="pagebreak" />

style.css:

.pagebreak { page-break-after: always; }