From: Matt Lundin <mdl@imapmail.org>
To: Eric Schulte <schulte.eric@gmail.com>
Cc: Org Mode <emacs-orgmode@gnu.org>
Subject: Re: [ANN] org-bibtex.el --- convert between Org headings and bibtex entries
Date: Mon, 25 Apr 2011 11:15:39 -0400 [thread overview]
Message-ID: <87oc3uweec.fsf@fastmail.fm> (raw)
In-Reply-To: <871v0rzp8v.fsf@gmail.com> (Eric Schulte's message of "Sun, 24 Apr 2011 08:21:16 -0600")
Hi Eric,
"Eric Schulte" <schulte.eric@gmail.com> writes:
> Matt Lundin <mdl@imapmail.org> writes:
>
> [...]
>>> I understand I may add to the types variable. When using
>>> org-bibtex-create, I can enter any arbitrary field as a PROPERTY;
>>> however, org-bibtex ignores anything outside of the universe it knows
>>> about. Would it be bad practice to allow the export of any arbitrary
>>> field type one has recorded? I think the emacs bibtex-mode may
>>> recognize erroneous bibtex entries.
>>
>> Bibtex-mode does indeed allow for arbitrary fields, as do bibtex and
>> biblatex. AFAIK, they are simply ignored when processing a bib file. One
>> limitation that arises when storing bibtex data as org properties is
>> that properties drawers are used for much more. For instance, one would
>> probably not want to see "logging = {lognoterepeat}," in one's exported
>> bibtex file.
>>
>> But for biblatex users, it would indeed be prohibitively expensive to
>> have to inform org-mode ahead of time about the innumerable odd fields
>> that various biblatex backends define.
>
> There is already an option for an org-bibtex specific property name
> prefix, (namely `org-bibtex-prefix'). Perhaps when this prefix is used,
> and the `org-bibtex' functions is called with a prefix argument (note:
> entirely different usage of the term "prefix") then only entries which
> begin with the `org-bibtex-prefix' would be exported... I believe that
> should provide a natural way for arbitrary fields to pass through
> org-bibtex without the user needing to explicitly name them, or there
> being any danger of contamination from existing org-mode properties.
I went ahead and implemented this. (Alas, it meant cluttering up your
very elegant org-bibtex-headline with another mapcar.)
Assuming that not all users who use a prefix will want to export
arbitrary fields, I made the functionality dependent on two variables:
org-bibtex-prefix and a org-bibtex-export-arbitrary-fields. But this
could be simplified.
I also made the key property configurable.
The patch was created against a patched org-bibtex.el, so I will wait
until your changes get merged into the repo before sending a formal
patch. But I thought I'd send it along to see if you think the changes
are appropriate.
Best,
Matt
--8<---------------cut here---------------start------------->8---
diff --git a/lisp/org-bibtex.el b/lisp/org-bibtex.el
index 9ee30f1..afa3764 100644
--- a/lisp/org-bibtex.el
+++ b/lisp/org-bibtex.el
@@ -221,6 +221,24 @@ For example setting to 'BIB_' would allow interoperability with fireforg."
:group 'org-bibtex
:type 'string)
+(defcustom org-bibtex-export-arbitrary-fields nil
+ "When converting to bibtex allow fields not defined in `org-bibtex-fields'.
+This only has effect if org-bibtex-prefix is defined, so as to
+ensure that other org-properties, such as CATEGORY or LOGGING are
+not placed in the exported bibtex entry."
+ :group 'org-bibtex
+ :type 'boolean)
+
+;; TODO if ID, test to make sure ID is unique
+(defcustom org-bibtex-key-property "CUSTOM_ID"
+ "Property that holds the bibtex key.
+By default, this is CUSTOM_ID, which enables easy linking to
+bibtex headlines from within an org file. This can be set to ID
+to enable global links, but only with great caution, as global
+IDs must be unique."
+ :group 'org-bibtex
+ :type 'string)
+
\f
;;; Utility functions
(defun org-bibtex-get (property)
@@ -232,7 +250,7 @@ For example setting to 'BIB_' would allow interoperability with fireforg."
(substring (symbol-name property) 1)
property))))
(org-set-property
- (concat (unless (string= "CUSTOM_ID" prop) org-bibtex-prefix) prop)
+ (concat (unless (string= org-bibtex-key-property prop) org-bibtex-prefix) prop)
value)))
(defun org-bibtex-headline ()
@@ -246,7 +264,7 @@ For example setting to 'BIB_' would allow interoperability with fireforg."
(if (listp e) (apply #'flatten e) (list e)))
lsts))))
(let ((notes (buffer-string))
- (id (org-bibtex-get "custom_id"))
+ (id (org-bibtex-get org-bibtex-key-property))
(type (org-bibtex-get "type")))
(when type
(let ((entry (format
@@ -254,15 +272,23 @@ For example setting to 'BIB_' would allow interoperability with fireforg."
(mapconcat
(lambda (pair) (format " %s={%s}" (car pair) (cdr pair)))
(remove nil
- (mapcar
- (lambda (field)
- (let ((value (or (org-bibtex-get (from-k field))
- (and (equal :title field)
- (org-get-heading)))))
- (when value (cons (from-k field) value))))
- (flatten
- (get :required (get (to-k type) org-bibtex-types))
- (get :optional (get (to-k type) org-bibtex-types)))))
+ (if (and org-bibtex-export-arbitrary-fields org-bibtex-prefix)
+ (mapcar
+ (lambda (kv)
+ (when (string-match org-bibtex-prefix (car kv))
+ (cons (downcase (replace-regexp-in-string
+ org-bibtex-prefix "" (car kv)))
+ (cdr kv))))
+ (org-entry-properties nil 'standard))
+ (mapcar
+ (lambda (field)
+ (let ((value (or (org-bibtex-get (from-k field))
+ (and (equal :title field)
+ (org-get-heading)))))
+ (when value (cons (from-k field) value))))
+ (flatten
+ (get :required (get (to-k type) org-bibtex-types))
+ (get :optional (get (to-k type) org-bibtex-types))))))
",\n"))))
(with-temp-buffer
(insert entry)
@@ -283,7 +309,7 @@ For example setting to 'BIB_' would allow interoperability with fireforg."
(defun org-bibtex-autokey ()
"Generate an autokey for the current headline"
- (org-bibtex-put "CUSTOM_ID"
+ (org-bibtex-put org-bibtex-key-property
(if org-bibtex-autogen-keys
(let ((entry (org-bibtex-headline)))
(with-temp-buffer
@@ -312,7 +338,7 @@ With optional argument OPTIONAL, also prompt for optional fields."
(let ((prop (org-bibtex-ask field)))
(when prop (org-bibtex-put name prop)))))))
(when (and type (assoc type org-bibtex-types)
- (not (org-bibtex-get "CUSTOM_ID")))
+ (not (org-bibtex-get org-bibtex-key-property)))
(org-bibtex-autokey)))
\f
@@ -488,7 +514,7 @@ This uses `bibtex-parse-entry'."
(case (car pair)
(:title nil)
(:type nil)
- (:key (org-bibtex-put "CUSTOM_ID" (cdr pair)))
+ (:key (org-bibtex-put org-bibtex-key-property (cdr pair)))
(otherwise (org-bibtex-put (car pair) (cdr pair))))))))
(provide 'org-bibtex)
--8<---------------cut here---------------end--------------->8---
next prev parent reply other threads:[~2011-04-25 15:15 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-04-19 23:52 [ANN] org-bibtex.el --- convert between Org headings and bibtex entries Eric Schulte
2011-04-20 1:01 ` Jeff Horn
2011-04-20 1:13 ` Eric Schulte
2011-04-20 7:54 ` Thomas S. Dye
2011-04-20 13:25 ` Matt Lundin
2011-04-20 14:29 ` Matt Lundin
2011-04-20 19:59 ` Eric Schulte
2011-04-20 19:00 ` Eric Schulte
2011-04-21 16:36 ` Thomas S. Dye
2011-04-21 21:06 ` Eric Schulte
2011-04-23 16:23 ` Thomas S. Dye
2011-04-23 22:59 ` Alan E. Davis
2011-04-24 0:40 ` Matt Lundin
2011-04-24 14:21 ` Eric Schulte
2011-04-24 16:53 ` Christian Moe
2011-04-25 13:19 ` Matt Lundin
2011-04-25 13:34 ` Eric Schulte
2011-04-25 15:15 ` Matt Lundin [this message]
2011-04-27 22:16 ` Eric Schulte
2011-04-24 0:52 ` Eric Schulte
2011-04-24 4:49 ` Alan E. Davis
2011-04-24 14:29 ` Eric Schulte
2011-04-24 20:40 ` Alan E. Davis
2011-04-25 13:31 ` Eric Schulte
2011-04-20 9:26 ` Christian Moe
2011-04-20 20:15 ` Eric Schulte
2011-04-20 12:10 ` Matt Lundin
2011-04-20 20:16 ` Eric Schulte
2011-04-22 14:05 ` [PATCH] " Eric Schulte
2011-04-22 15:45 ` Matt Lundin
2011-04-23 0:03 ` Matt Lundin
2011-04-23 14:07 ` Eric Schulte
2011-04-23 22:46 ` Matt Lundin
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=87oc3uweec.fsf@fastmail.fm \
--to=mdl@imapmail.org \
--cc=emacs-orgmode@gnu.org \
--cc=schulte.eric@gmail.com \
/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).