26

I use org-mode to document stuff and usually export it to pdf (via latex) and html.

If the \\ characters are at the end of a line, it forces a newline character when exporting to both pdf and html.

But I would like to know how to force a newline character in-between a line when exporting to html. It would be helpful to have this solution so that I can have multi-line titles in html exports too.

Example:

#+TITLE: First Line of Title \\ Second Line of Title

The above exports to 2 lines in pdf export but the \\ characters are retained in html export (as they are not at the end of the line).

How can I format the title so that multi line titles export fine in both formats?

36

Org mode 8 no longer accepts LaTeX characters like that. The correct way to do it is embed export snippets in the title:

#+TITLE: Foo @@latex:\\@@ Bar

I assume therefore that if you want to export newlines in both LaTeX and HTML, the code might have to look like this:

#+TITLE: Foo @@latex:\\@@ @@html:<br>@@ Bar

Source: https://lists.gnu.org/archive/html/emacs-orgmode/2014-09/msg00466.html

If such newline characters are needed to be added at multiple places in the document, replacing this verbose @@latex:\\@@ @@html:<br>@@ string with an org mode MACRO would be better suited.

A MACRO definition like below can be placed at the top of the document or in a common "org config" file that's included in your org documents:

#+MACRO: NEWLINE @@latex:\\@@ @@html:<br>@@

The MACRO can then be used for formatting the title as below:

#+TITLE: Foo {{{NEWLINE}}} Bar

The advantages of using the MACRO approach are:

  • The org mode document is easier to read
  • If the need arises to change the definition of {{{NEWLINE}}} to support a new export format, then that change needs to be done at just one place.

Example:

#+MACRO: NEWLINE @@latex:\\@@ @@html:<br>@@ @@ascii:|@@

NOTE: @@ascii:|@@ won't insert a newline in ascii exports; it will simply place the pipe character | wherever {{{NEWLINE}}} was used in the org doc.

Finally, the #+SUBTITLE keyword may also help.

  • A related question: Would you know how to convey a newline for ascii exports? @@ascii:\n@@ doesn't work. – Kaushal Modi Sep 25 '14 at 19:04
  • Doesn't appear to work. I'd guess a feature request is needed to get this implemented. – mankoff Sep 26 '14 at 15:09
  • 1
    You mean the newlines in ascii don't work, correct? Otherwise your solution works for html and pdf exports. When newlines for ascii is supported, I simply have to update the NEWLINE macro. – Kaushal Modi Sep 26 '14 at 15:15
3

I'm not entirely sure there wouldn't be any unwanted side effects, but the following might work

(push (cons "\\\\\\\\" "<br />") org-html-special-string-regexps)

Kinda lucky that the list of special string expansions is extensible in the HTML exporter, because it's not in the LaTeX exporter...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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