Avoid \printbibliography being swallowed by Org-mode headings

前端 未结 5 605
梦谈多话
梦谈多话 2021-02-06 03:43

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

5条回答
  •  太阳男子
    2021-02-06 04:32

    Another solution would be to put the bibliography under a heading named "References" like so:

    * Heading
    Some text
    * References
    \printbibliography
    

    and remove the \section{References} from the resulting latex file by adding this to your emacs init file

    (defun org-export-latex-remove-references-heading (contents backend info)
        (if (not (eq backend 'latex))
            contents
          (replace-regexp-in-string "\\\\section\\*?{References}\\s-*\\\\label{.*?}" "" contents)
          ))
    
    (add-hook 'org-export-filter-final-output-functions 'org-export-latex-remove-references-heading)
    

    Note 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:

    \section{References}
    \label{}
    \printbibliography
    

    For other formats you need to change the regular expression in the org-export-latex-remove-references-heading function.

提交回复
热议问题