Avoid \printbibliography being swallowed by Org-mode headings

前端 未结 5 602
梦谈多话
梦谈多话 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:36

    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 advising org-end-of-subtree the last heading never cycles with tab because it thinks it's not hidden, so it hides it and then org-cycle-hook unhides it. It calls org-end-of-subtree before running org-pre-cycle-hook so that's not an option either.

    (defvar org-footer-regexp "^\\\\printbibliography\\[.*\\]$"
      "Regexp to match the whole line of the first line of the footer which should always be shown.")
    
    (defun show-org-footer (&rest ignore)
      (save-excursion
        (goto-char (point-max))
        (when (re-search-backward org-footer-regexp nil t)
          (outline-flag-region (1- (point)) (point-max) nil))))
    
    (add-hook 'org-cycle-hook 'show-org-footer)
    (add-hook 'org-occur-hook 'show-org-footer)
    
    (defadvice org-end-of-subtree (after always-show-org-footer
                                         ()
                                         activate)
      (when (>= (point) (1- (point-max)))
        (re-search-backward org-footer-regexp nil t)
        (setq ad-return-value (point))))
    

提交回复
热议问题