emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Pedro Silva <psilva+org@pedrosilva.pt>
To: emacs-orgmode@gnu.org
Subject: Re: Latex export postamble
Date: Sun, 15 Apr 2012 00:40:16 +0100	[thread overview]
Message-ID: <877gxh287z.fsf@pedrosilva.pt> (raw)
In-Reply-To: <871unr3jyk.fsf@pedrosilva.pt> (Pedro Silva's message of "Fri, 13 Apr 2012 13:16:51 +0100")

Pedro Silva <psilva+org@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

      reply	other threads:[~2012-04-14 23:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-13 12:16 Latex export postamble Pedro Silva
2012-04-14 23:40 ` Pedro Silva [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=877gxh287z.fsf@pedrosilva.pt \
    --to=psilva+org@pedrosilva.pt \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).