Pedro Silva <psilva+...@pedrosilva.pt> writes: > Is it possible to insert text just before \end{document} on export, > similarly to org-export-html-postamble? > > I'd like to do this on a capture target file that contains the following > at the end: > > \bibliography{references} > > New capture entries keep getting inserted below it, which makes the > references section appear in the middle of the document if I forget to > move it to the end again. > > Or maybe there is another way to make this work?
Looking at the relevant code in contrib/org-exp-bibtex.el, I managed to produce the following, which *almost* works: (defun org-export-bibliography-preprocess () "Insert \bibliography and \bibliographystyle commands at end of buffer if keyword `#+BIBLIOGRAPHY <file> <style>' is present in buffer when exporting via latex backend." (interactive) (save-excursion (goto-char (point-min)) (while (re-search-forward "^#\\+BIBLIOGRAPHY:[ \t]+\\(\\S-+\\)[ \t]+\\(\\S-+\\)\\([^\r\n]*\\)" nil t) (let ((file (match-string 1)) (style (match-string 2))) (when (eq org-export-current-backend 'latex) (goto-char (point-max)) (insert (concat "\n#+LATEX: \\bibliographystyle{" style "}" "\n#+LATEX: \\bibliography{" file "}\n"))))))) (add-hook 'org-export-preprocess-hook 'org-export-bibliography-preprocess) Unfortunately, it inserts the latex directives twice, one near the top of the buffer, and the other one at its end, as expected. Any ideas why that is? Pedro -- Any government will work if authority and responsibility are equal and coordinate. This does not insure "good" government; it simply insures that it will work. But such governments are rare--most people want to run things but want no part of the blame. This used to be called the "backseat-driver syndrome." -- Lazarus Long