When using Org-mode and its LaTeX export BibTeX or Biblatex is often used to handle references. In that case the LaTeX command \printbibliography
is often included in the org file. \printbibliography
is placed in the org file where LaTeX is supposed to write out the reference list. What \printbibliography
does is to insert a LaTeX header along with the reference list. In most cases \printbibliography
is placed at the end of the org file simply because in most documents the reference list is to be placed last. This means that \printbibliography
will be included under the last heading in the org file, e.g.
* Heading
\printbibliography
It also means that when that heading is folded the \printbibliography
will be swallowed:
* Heading...
But this goes against the meaning of \printbibliography
because it includes its own heading in the output. Also, it will be confusing when \printbibliography
is swallowed and a new heading is placed after it because then the reference list will no longer appear last in the document.
How can I make it so that \printbibliography
is not swallowed by sections in Org-mode? A bonus question: how can I make it so that Org-mode does not create headings after \printbibliography
unless C-Ret is pressed when the cursor is after it?
In searching for a solution to this problem I found http://comments.gmane.org/gmane.emacs.orgmode/49545.
One solution would be the following:
Like this you end up with a blank heading at the bottom of the document. The macro expands to a blank block of text so you end up with
This also ensures you cannot accidentally add headlines after your bibliography, since it is it's own (empty) headline. It might be (seems to be actually) included in the table of contents, which is unfortunate but I would suspect the solution would be at worst run a post-export to remove the empty headline from the file (or manually do so before converting to PDF).
The following is lightly tested but works for me using tab and shift-tab to hide and display things. Those are the only hiding and showing commands that I use, so if you use other commands they may have to be advised or fixed in some other way.
You can of course change
org-footer-regexp
to anything you want. I was hoping to not have to use any advice, but without advisingorg-end-of-subtree
the last heading never cycles with tab because it thinks it's not hidden, so it hides it and thenorg-cycle-hook
unhides it. It callsorg-end-of-subtree
before runningorg-pre-cycle-hook
so that's not an option either.A workaround for this problem is to make
\printbibliography
not return a LaTeX heading so that it can appropriately be placed under an Org-mode heading.With biblatex this can be done by supplying
\printbibliography
with the optionheading=none
and placing it under an appropriate heading. Here is an example:This way references can be kept in a heading of its own and
\printbibliography
being swallowed by a heading is not a problem because it is being swallowed by its own heading.Another solution would be to put the bibliography under a heading named "References" like so:
and remove the
\section{References}
from the resulting latex file by adding this to your emacs init fileNote that this assumes you only have one heading that's named "References", as it replaces all occurrences of it. It also assumes the sections are in this format:
For other formats you need to change the regular expression in the
org-export-latex-remove-references-heading
function.There is an easier way to solve this. Just add an "unnumbered" properties to the heading and it will be exported without any numbering.