I have a large number of org-mode files where I took my class notes. I would like to export them as PDF files.

However, I like to take notes as in the following example:

#+LaTeX_HEADER: \newcommand\RR{\mathbb{R}}
#+LaTeX_HEADER: \newcommand{\norm}[1]{\left\lVert#1\right\rVert}
* Johnson-Lindenstrauss
** concentration on projection on first $k$ coordinates
   $u \in S^{d-1}$ uniform, think $u \sim N(0, I)$, but normalized 
   each coordinate concentrates around $\frac{1}{d}$
   $g : \RR^d \to \RR^k$ projection to first $k$ coordinates
   then if $L = \mathbb E \norm{g(u)}^2$, then $L \sim \frac{k}{d}$
   and the concentration is very strong:
   $\mathbb P [L \ge \beta \frac{k}{d}] \le \exp(\frac{k}{2} (1 - \beta + \log \beta) )$

When read with org-latex-preview, it is very readable.

The issue is, when exported to pdf, it loses all readability:

The same text, but all in one line

How can I enhance the pdf export to insert linebreaks, and maybe even to render the equations which are in their own lines as if they were in an align environment? Can I insert some parser before the export?

The pdf output format is not crucial, I just want to be able to send these notes to people who don't use org-mode.

  • Can you please add the contents of your template.org so your example is self-contained? Thanks! If it is too long, then just add what's needed to compile: \RR and \norm is what I've hit so far.
    – NickD
    Commented Dec 23, 2020 at 22:53
  • I think it might be fussy to write a parser, given that LaTeX by design ignores single line breaks. You could add ` \` at the end of lines that you don't want to wrap. Similarly, adding doubled $$ on longer equations will get you proper equation environments.
    – Tyler
    Commented Dec 23, 2020 at 23:54

2 Answers 2


Your main problem seems to be that exporting does not honour your line breaks. There are two simple options to get around that.

  1. Do global replace linefeed to two linefeeds, \n to \n\n, before exporting. Every line will be treated as a paragraph. Added whitespace will be ignored in more structured regions of your file like in headers. On the other hand, the indenting of long lines will not be optimal by default. That can be changed in the LaTex export template.

  2. Turn your text lines into unordered, bulleted lists by adding - in front. This takes slightly more effort but you can structure the output more with indenting some list items.

Your note-taking style seems to favour bulleted lists since you do not write full sentences. Creating lists while you take the notes might be the best solution in the long run.


There is org-export-before-parsing-hook whose doc string says:

Hook run before parsing an export buffer.

This is run after include keywords and macros have been expanded and Babel code blocks executed, on a copy of the original buffer being exported. Visibility and narrowing are preserved. Point is at the beginning of the buffer.

Every function in this hook will be called with one argument: the back-end currently used, as a symbol.

You can try a function that replaces $ with $$, but I doubt that anything automatic will be able to deal with all situations, e.g. you will almost never want $k$ to become $$k$$.

I think you'd be better off leaving the export as is, but rephrasing the text of your notes to add the proper "meat" to the prose. IOW, I think the problem is not that that the math expressions are not readable, it's that there are too many words (and some punctuation) missing to make sense of what you wrote. So revising your notes soon after you take them might be beneficial not only to the people you send them to, but also to your future self.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.