* [ANN] org-bibtex.el --- convert between Org headings and bibtex entries @ 2011-04-19 23:52 Eric Schulte 2011-04-20 1:01 ` Jeff Horn ` (3 more replies) 0 siblings, 4 replies; 33+ messages in thread From: Eric Schulte @ 2011-04-19 23:52 UTC (permalink / raw) To: Org Mode Hi, In an attempt to organize my reading notes, I've written the following tool which allows both for exporting Org-mode headlines with bibtex meta-data to bibtex entries, and for reading existing bibtex entries into Org-mode headings. One nice feature of these functions is the ability to check that all required fields are present in a given headline based on the bibtex type (e.g., :article, :inproceedings), and prompt for missing fields. See the top of the elisp file for more usage information. https://github.com/eschulte/org-bibtex/blob/master/org-bibtex.el Cheers -- Eric -- Eric Schulte http://cs.unm.edu/~eschulte/ ^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [ANN] org-bibtex.el --- convert between Org headings and bibtex entries 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 ` (2 subsequent siblings) 3 siblings, 1 reply; 33+ messages in thread From: Jeff Horn @ 2011-04-20 1:01 UTC (permalink / raw) To: Eric Schulte; +Cc: Org Mode This looks great! I haven't quite read all the code, but I wonder how this would work on files where bib entries are in their own headline or mixed into the document ad hoc. Is this designed for a document with *only* bibtex headlines? On Tue, Apr 19, 2011 at 7:52 PM, Eric Schulte <schulte.eric@gmail.com> wrote: > Hi, > > In an attempt to organize my reading notes, I've written the following > tool which allows both for exporting Org-mode headlines with bibtex > meta-data to bibtex entries, and for reading existing bibtex entries > into Org-mode headings. > > One nice feature of these functions is the ability to check that all > required fields are present in a given headline based on the bibtex type > (e.g., :article, :inproceedings), and prompt for missing fields. > > See the top of the elisp file for more usage information. > https://github.com/eschulte/org-bibtex/blob/master/org-bibtex.el > > Cheers -- Eric > > -- > Eric Schulte > http://cs.unm.edu/~eschulte/ > > -- Jeffrey Horn http://www.failuretorefrain.com/jeff/ ^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [ANN] org-bibtex.el --- convert between Org headings and bibtex entries 2011-04-20 1:01 ` Jeff Horn @ 2011-04-20 1:13 ` Eric Schulte 0 siblings, 0 replies; 33+ messages in thread From: Eric Schulte @ 2011-04-20 1:13 UTC (permalink / raw) To: Jeff Horn; +Cc: Org Mode Jeff Horn <jrhorn424@gmail.com> writes: > This looks great! I haven't quite read all the code, but I wonder how > this would work on files where bib entries are in their own headline > or mixed into the document ad hoc. Is this designed for a document > with *only* bibtex headlines? > If a headline doesn't have a "type" property, then it will be skipped by the `org-bibtex' function which writes out the .bib file and the `org-bibtex-check' functions. So it should be possible to arbitrarily include/nest bibliography headlines and non-bib headlines in a document. -- Eric Schulte http://cs.unm.edu/~eschulte/ ^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [ANN] org-bibtex.el --- convert between Org headings and bibtex entries 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 7:54 ` Thomas S. Dye 2011-04-20 13:25 ` Matt Lundin 2011-04-20 19:00 ` Eric Schulte 2011-04-20 9:26 ` Christian Moe 2011-04-20 12:10 ` Matt Lundin 3 siblings, 2 replies; 33+ messages in thread From: Thomas S. Dye @ 2011-04-20 7:54 UTC (permalink / raw) To: Eric Schulte; +Cc: Org Mode Hi Eric, This could be very useful and a significant enhancement to Org-mode for note taking. With it, library time can be spent almost entirely within Org-mode, capturing bibliographic information and taking reading notes. It feels like the right level of functionality-- lightweight and easy to use, with lots of prompting material. I created an entry with org-bibtex-create and then another with org- bibtex-read/write. When I ran org-bibtex, only the second entry was exported. Also, the org-bibtex-read/write process mangled the bibtex entry a bit, so the resulting .bib file wasn't useful. Note the addition of {} around the publisher and year, and the truncation of multi-line entries. Can I suggest some changes? 1) In our multi-user environment, where several authors are contributing to a master bibtex file, we depend on the key generating algorithm of bibtex-mode to help weed out duplicate entries. This isn't 100% effective, but it catches lots of duplicates and saves us time. Would it be possible to lift this mechanism and use it in org- bibtex to generate the CUSTOM_ID? 2) It might be better to use the (generated) key as the Org headline, instead of the title. Titles can be longer than I find comfortable for an Org-mode headline, whereas keys are usually about the right length. 3) org-bibtex-cite seems like a natural next step, especially if it offers a list of keys in the Org-mode buffer. Here are the details of my test run: Existing bibtex entry: @Book{tuggle94:_cultur_resour_naval_air_station_barber_point, author = {H. David Tuggle and M. J. Tomonari-Tuggle and D. Colt Denfeld}, title = {Cultural Resources of Naval Air Station, Barbers Point: Summary, Assessment, and Inventory Research Design: Task 1b: Archaeological Research Services for the Proposed Cleanup, Disposal, and Reuse of Naval Air Station, Barbers Point, O`ahu, Hawai`i}, publisher = iarii, year = 1994, series = {Prepared for Belt Collins Hawaii}, address = {Honolulu}, month = {December}} Org-mode tree: * Schulte bibtex ** A journal title :PROPERTIES: :type: article :AUTHOR: A. N. Author :JOURNAL: Journal of Statistical Software :YEAR: 1998 :CUSTOM_ID: author_10:article :END: ** {Cultural Resources of Naval Air Station, Barbers :PROPERTIES: :TYPE: book :CUSTOM_ID: tuggle94:_cultur_resour_naval_air_station_barber_point :MONTH: December} :ADDRESS: Honolulu :SERIES: Prepared for Belt Collins Hawaii :YEAR: 1994 :PUBLISHER: iarii :AUTHOR: {H. David Tuggle and M. J. Tomonari-Tuggle and :END: Org-bibtex output: @book{tuggle94:_cultur_resour_naval_air_station_barber_point, author={{H. David Tuggle and M. J. Tomonari-Tuggle and}, title={{Cultural Resources of Naval Air Station, Barbers}, publisher={iarii}, year={1994}, series={Prepared for Belt Collins Hawaii}, address={Honolulu}, month={December}} } hth, Tom On Apr 19, 2011, at 1:52 PM, Eric Schulte wrote: > Hi, > > In an attempt to organize my reading notes, I've written the following > tool which allows both for exporting Org-mode headlines with bibtex > meta-data to bibtex entries, and for reading existing bibtex entries > into Org-mode headings. > > One nice feature of these functions is the ability to check that all > required fields are present in a given headline based on the bibtex > type > (e.g., :article, :inproceedings), and prompt for missing fields. > > See the top of the elisp file for more usage information. > https://github.com/eschulte/org-bibtex/blob/master/org-bibtex.el > > Cheers -- Eric > > -- > Eric Schulte > http://cs.unm.edu/~eschulte/ > ^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [ANN] org-bibtex.el --- convert between Org headings and bibtex entries 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 1 sibling, 2 replies; 33+ messages in thread From: Matt Lundin @ 2011-04-20 13:25 UTC (permalink / raw) To: Thomas S. Dye; +Cc: Org Mode "Thomas S. Dye" <tsd@tsdye.com> writes: > This could be very useful and a significant enhancement to Org-mode > for note taking. With it, library time can be spent almost entirely > within Org-mode, capturing bibliographic information and taking > reading notes. It feels like the right level of functionality-- > lightweight and easy to use, with lots of prompting material. > > I created an entry with org-bibtex-create and then another with org- > bibtex-read/write. When I ran org-bibtex, only the second entry was > exported. Also, the org-bibtex-read/write process mangled the bibtex > entry a bit, so the resulting .bib file wasn't useful. Note the > addition of {} around the publisher and year, and the truncation of > multi-line entries. Just as with auto-generated keys, I wonder whether some of these problems might be remedied by plugging into existing bibtex-mode functions, especially bibtex-parse-entry and the bibtex string cleanup functions. I am always amazed by the ability of bibtex-mode to do the right thing when cleaning up entries (e.g., remove delimiters from dates, string abbreviations, etc.). Also, it might be nice to allow a way to one's existing bibtex entry type and field definitions---i.e., bibtex-entry-field-alist. Best, Mat ^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [ANN] org-bibtex.el --- convert between Org headings and bibtex entries 2011-04-20 13:25 ` Matt Lundin @ 2011-04-20 14:29 ` Matt Lundin 2011-04-20 19:59 ` Eric Schulte 1 sibling, 0 replies; 33+ messages in thread From: Matt Lundin @ 2011-04-20 14:29 UTC (permalink / raw) To: Thomas S. Dye; +Cc: Org Mode Matt Lundin <mdl@imapmail.org> writes: > Also, it might be nice to allow a way to one's existing bibtex entry ^ use ----- > type and field definitions---i.e., bibtex-entry-field-alist. ^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [ANN] org-bibtex.el --- convert between Org headings and bibtex entries 2011-04-20 13:25 ` Matt Lundin 2011-04-20 14:29 ` Matt Lundin @ 2011-04-20 19:59 ` Eric Schulte 1 sibling, 0 replies; 33+ messages in thread From: Eric Schulte @ 2011-04-20 19:59 UTC (permalink / raw) To: Matt Lundin; +Cc: Org Mode Matt Lundin <mdl@imapmail.org> writes: > "Thomas S. Dye" <tsd@tsdye.com> writes: > >> This could be very useful and a significant enhancement to Org-mode >> for note taking. With it, library time can be spent almost entirely >> within Org-mode, capturing bibliographic information and taking >> reading notes. It feels like the right level of functionality-- >> lightweight and easy to use, with lots of prompting material. >> >> I created an entry with org-bibtex-create and then another with org- >> bibtex-read/write. When I ran org-bibtex, only the second entry was >> exported. Also, the org-bibtex-read/write process mangled the bibtex >> entry a bit, so the resulting .bib file wasn't useful. Note the >> addition of {} around the publisher and year, and the truncation of >> multi-line entries. > > Just as with auto-generated keys, I wonder whether some of these > problems might be remedied by plugging into existing bibtex-mode > functions, especially bibtex-parse-entry and the bibtex string cleanup > functions. I am always amazed by the ability of bibtex-mode to do the > right thing when cleaning up entries (e.g., remove delimiters from > dates, string abbreviations, etc.). > Ah, this is a great suggestions and I wish I had thought to look for existing support before rolling my own versions of these functions. org-bibtex is now using both of the functions you mentioned above to good effect. > > Also, it might be nice to allow a way to one's existing bibtex entry > type and field definitions---i.e., bibtex-entry-field-alist. > It shouldn't be difficult to add items to the two defvars used by org-bibtex to manage bibtex entries, namely bibtex-types and bibtex-fields Best -- Eric > > Best, > Mat > -- Eric Schulte http://cs.unm.edu/~eschulte/ ^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [ANN] org-bibtex.el --- convert between Org headings and bibtex entries 2011-04-20 7:54 ` Thomas S. Dye 2011-04-20 13:25 ` Matt Lundin @ 2011-04-20 19:00 ` Eric Schulte 2011-04-21 16:36 ` Thomas S. Dye 1 sibling, 1 reply; 33+ messages in thread From: Eric Schulte @ 2011-04-20 19:00 UTC (permalink / raw) To: Thomas S. Dye; +Cc: Org Mode Hi Tom, "Thomas S. Dye" <tsd@tsdye.com> writes: > Hi Eric, > > This could be very useful and a significant enhancement to Org-mode > for note taking. With it, library time can be spent almost entirely > within Org-mode, capturing bibliographic information and taking > reading notes. It feels like the right level of functionality-- > lightweight and easy to use, with lots of prompting material. > Thanks, I hope so. > > I created an entry with org-bibtex-create and then another with org- > bibtex-read/write. When I ran org-bibtex, only the second entry was > exported. Also, the org-bibtex-read/write process mangled the bibtex > entry a bit, so the resulting .bib file wasn't useful. Note the > addition of {} around the publisher and year, and the truncation of > multi-line entries. > I /believe/ I have fixed this issue. I am now using pre-existing bibtex functions for reading in entries, and for cleaning up entries written by org-bibtex. > > Can I suggest some changes? > > 1) In our multi-user environment, where several authors are > contributing to a master bibtex file, we depend on the key generating > algorithm of bibtex-mode to help weed out duplicate entries. This > isn't 100% effective, but it catches lots of duplicates and saves us > time. Would it be possible to lift this mechanism and use it in org- > bibtex to generate the CUSTOM_ID? > I've added a new variable `org-bibtex-autogen-keys' which when set to t will result in auto-generated keys being used instead of prompting the user to input such keys. > > 2) It might be better to use the (generated) key as the Org headline, > instead of the title. Titles can be longer than I find comfortable > for an Org-mode headline, whereas keys are usually about the right > length. > Hmm, I would tend to disagree here, but I think it may be a matter of taste. Note that if you include a TITLE property in a headline then it will be used instead of the contents of the headline, leaving you free to put whatever information you want into the headline. I've just updated the headline creation so that it will create such a title property as well as using the title as the headline, leaving you free to subsequently change the headline. > > 3) org-bibtex-cite seems like a natural next step, especially if it > offers a list of keys in the Org-mode buffer. > Meaning a function to allow tab-completion on keys... I could see this being useful but I would imagine that the bib entries would generally not live in the same buffer as the Org-mode text... rather I'd think some sort of global registry would be preferable. Thanks for the suggestions, bug reports, and examples! Please do let me know if any of these issues remain -- Eric > > Here are the details of my test run: > > Existing bibtex entry: > > @Book{tuggle94:_cultur_resour_naval_air_station_barber_point, > author = {H. David Tuggle and M. J. Tomonari-Tuggle and > D. Colt Denfeld}, > title = {Cultural Resources of Naval Air Station, Barbers > Point: Summary, Assessment, and Inventory Research > Design: Task 1b: Archaeological Research Services > for the Proposed Cleanup, Disposal, and Reuse of > Naval Air Station, Barbers Point, O`ahu, Hawai`i}, > publisher = iarii, > year = 1994, > series = {Prepared for Belt Collins Hawaii}, > address = {Honolulu}, > month = {December}} > > Org-mode tree: > > > * Schulte bibtex > > ** A journal title > :PROPERTIES: > :type: article > :AUTHOR: A. N. Author > :JOURNAL: Journal of Statistical Software > :YEAR: 1998 > :CUSTOM_ID: author_10:article > :END: > > ** {Cultural Resources of Naval Air Station, Barbers > :PROPERTIES: > :TYPE: book > :CUSTOM_ID: tuggle94:_cultur_resour_naval_air_station_barber_point > :MONTH: December} > :ADDRESS: Honolulu > :SERIES: Prepared for Belt Collins Hawaii > :YEAR: 1994 > :PUBLISHER: iarii > :AUTHOR: {H. David Tuggle and M. J. Tomonari-Tuggle and > :END: > > Org-bibtex output: > > @book{tuggle94:_cultur_resour_naval_air_station_barber_point, > author={{H. David Tuggle and M. J. Tomonari-Tuggle and}, > title={{Cultural Resources of Naval Air Station, Barbers}, > publisher={iarii}, > year={1994}, > series={Prepared for Belt Collins Hawaii}, > address={Honolulu}, > month={December}} > } > > hth, > Tom > > On Apr 19, 2011, at 1:52 PM, Eric Schulte wrote: > >> Hi, >> >> In an attempt to organize my reading notes, I've written the following >> tool which allows both for exporting Org-mode headlines with bibtex >> meta-data to bibtex entries, and for reading existing bibtex entries >> into Org-mode headings. >> >> One nice feature of these functions is the ability to check that all >> required fields are present in a given headline based on the bibtex >> type >> (e.g., :article, :inproceedings), and prompt for missing fields. >> >> See the top of the elisp file for more usage information. >> https://github.com/eschulte/org-bibtex/blob/master/org-bibtex.el >> >> Cheers -- Eric >> >> -- >> Eric Schulte >> http://cs.unm.edu/~eschulte/ >> > > -- Eric Schulte http://cs.unm.edu/~eschulte/ ^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [ANN] org-bibtex.el --- convert between Org headings and bibtex entries 2011-04-20 19:00 ` Eric Schulte @ 2011-04-21 16:36 ` Thomas S. Dye 2011-04-21 21:06 ` Eric Schulte 0 siblings, 1 reply; 33+ messages in thread From: Thomas S. Dye @ 2011-04-21 16:36 UTC (permalink / raw) To: Eric Schulte; +Cc: Org Mode Hi Eric, On Apr 20, 2011, at 9:00 AM, Eric Schulte wrote: > Hi Tom, > > "Thomas S. Dye" <tsd@tsdye.com> writes: > >> Hi Eric, >> >> This could be very useful and a significant enhancement to Org-mode >> for note taking. With it, library time can be spent almost entirely >> within Org-mode, capturing bibliographic information and taking >> reading notes. It feels like the right level of functionality-- >> lightweight and easy to use, with lots of prompting material. >> > > Thanks, I hope so. > >> >> I created an entry with org-bibtex-create and then another with org- >> bibtex-read/write. When I ran org-bibtex, only the second entry was >> exported. Also, the org-bibtex-read/write process mangled the bibtex >> entry a bit, so the resulting .bib file wasn't useful. Note the >> addition of {} around the publisher and year, and the truncation of >> multi-line entries. >> > > I /believe/ I have fixed this issue. I am now using pre-existing > bibtex > functions for reading in entries, and for cleaning up entries > written by > org-bibtex. > The org-bibtex-read/write process doesn't work on the example I sent. The read appears to work (though I can't find a buffer *org-bibtex- entries* afterwards), but the write inserts the headline asterisk then fails with progn: Wrong type argument: char-or-string-p, nil. >> >> Can I suggest some changes? >> >> 1) In our multi-user environment, where several authors are >> contributing to a master bibtex file, we depend on the key generating >> algorithm of bibtex-mode to help weed out duplicate entries. This >> isn't 100% effective, but it catches lots of duplicates and saves us >> time. Would it be possible to lift this mechanism and use it in org- >> bibtex to generate the CUSTOM_ID? >> > > I've added a new variable `org-bibtex-autogen-keys' which when set > to t > will result in auto-generated keys being used instead of prompting the > user to input such keys. > Beautiful! >> >> 2) It might be better to use the (generated) key as the Org headline, >> instead of the title. Titles can be longer than I find comfortable >> for an Org-mode headline, whereas keys are usually about the right >> length. >> > > Hmm, I would tend to disagree here, but I think it may be a matter of > taste. Note that if you include a TITLE property in a headline then > it > will be used instead of the contents of the headline, leaving you free > to put whatever information you want into the headline. I've just > updated the headline creation so that it will create such a title > property as well as using the title as the headline, leaving you > free to > subsequently change the headline. > That sounds right to me. Thanks. >> >> 3) org-bibtex-cite seems like a natural next step, especially if it >> offers a list of keys in the Org-mode buffer. >> > > Meaning a function to allow tab-completion on keys... I could see > this > being useful but I would imagine that the bib entries would generally > not live in the same buffer as the Org-mode text... rather I'd think > some sort of global registry would be preferable. > I guess it depends on how one uses the software. The use I envision is for note taking while doing background reading for a project. First, enter a reference with org-bibtex-create, then take notes while reading, and finally write a summary that might later be used in the project document. At this stage, org-bibtex hasn't been called, so the only place the key is present is in the Org-mode buffer. Inserting a reference then involves jumping back to the headline, opening the properties drawer, selecting the value of CUSTOM_ID, navigating back to the reference point and pasting in the key. A function that collects keys and then presents them in a list like the one used to choose TYPE would make this process very easy. Do you mind my asking what your workflow is with org-bibtex? All the best, Tom > Thanks for the suggestions, bug reports, and examples! > > Please do let me know if any of these issues remain -- Eric > >> >> Here are the details of my test run: >> >> Existing bibtex entry: >> >> @Book{tuggle94:_cultur_resour_naval_air_station_barber_point, >> author = {H. David Tuggle and M. J. Tomonari-Tuggle and >> D. Colt Denfeld}, >> title = {Cultural Resources of Naval Air Station, Barbers >> Point: Summary, Assessment, and Inventory Research >> Design: Task 1b: Archaeological Research Services >> for the Proposed Cleanup, Disposal, and Reuse of >> Naval Air Station, Barbers Point, O`ahu, Hawai`i}, >> publisher = iarii, >> year = 1994, >> series = {Prepared for Belt Collins Hawaii}, >> address = {Honolulu}, >> month = {December}} >> >> Org-mode tree: >> >> >> * Schulte bibtex >> >> ** A journal title >> :PROPERTIES: >> :type: article >> :AUTHOR: A. N. Author >> :JOURNAL: Journal of Statistical Software >> :YEAR: 1998 >> :CUSTOM_ID: author_10:article >> :END: >> >> ** {Cultural Resources of Naval Air Station, Barbers >> :PROPERTIES: >> :TYPE: book >> :CUSTOM_ID: tuggle94:_cultur_resour_naval_air_station_barber_point >> :MONTH: December} >> :ADDRESS: Honolulu >> :SERIES: Prepared for Belt Collins Hawaii >> :YEAR: 1994 >> :PUBLISHER: iarii >> :AUTHOR: {H. David Tuggle and M. J. Tomonari-Tuggle and >> :END: >> >> Org-bibtex output: >> >> @book{tuggle94:_cultur_resour_naval_air_station_barber_point, >> author={{H. David Tuggle and M. J. Tomonari-Tuggle and}, >> title={{Cultural Resources of Naval Air Station, Barbers}, >> publisher={iarii}, >> year={1994}, >> series={Prepared for Belt Collins Hawaii}, >> address={Honolulu}, >> month={December}} >> } >> >> hth, >> Tom >> >> On Apr 19, 2011, at 1:52 PM, Eric Schulte wrote: >> >>> Hi, >>> >>> In an attempt to organize my reading notes, I've written the >>> following >>> tool which allows both for exporting Org-mode headlines with bibtex >>> meta-data to bibtex entries, and for reading existing bibtex entries >>> into Org-mode headings. >>> >>> One nice feature of these functions is the ability to check that all >>> required fields are present in a given headline based on the bibtex >>> type >>> (e.g., :article, :inproceedings), and prompt for missing fields. >>> >>> See the top of the elisp file for more usage information. >>> https://github.com/eschulte/org-bibtex/blob/master/org-bibtex.el >>> >>> Cheers -- Eric >>> >>> -- >>> Eric Schulte >>> http://cs.unm.edu/~eschulte/ >>> >> >> > > -- > Eric Schulte > http://cs.unm.edu/~eschulte/ ^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [ANN] org-bibtex.el --- convert between Org headings and bibtex entries 2011-04-21 16:36 ` Thomas S. Dye @ 2011-04-21 21:06 ` Eric Schulte 2011-04-23 16:23 ` Thomas S. Dye 0 siblings, 1 reply; 33+ messages in thread From: Eric Schulte @ 2011-04-21 21:06 UTC (permalink / raw) To: Thomas S. Dye; +Cc: Org Mode "Thomas S. Dye" <tsd@tsdye.com> writes: > Hi Eric, > > On Apr 20, 2011, at 9:00 AM, Eric Schulte wrote: > >> Hi Tom, >> >> "Thomas S. Dye" <tsd@tsdye.com> writes: >> >>> Hi Eric, >>> >>> This could be very useful and a significant enhancement to Org-mode >>> for note taking. With it, library time can be spent almost entirely >>> within Org-mode, capturing bibliographic information and taking >>> reading notes. It feels like the right level of functionality-- >>> lightweight and easy to use, with lots of prompting material. >>> >> >> Thanks, I hope so. >> >>> >>> I created an entry with org-bibtex-create and then another with org- >>> bibtex-read/write. When I ran org-bibtex, only the second entry was >>> exported. Also, the org-bibtex-read/write process mangled the bibtex >>> entry a bit, so the resulting .bib file wasn't useful. Note the >>> addition of {} around the publisher and year, and the truncation of >>> multi-line entries. >>> >> >> I /believe/ I have fixed this issue. I am now using pre-existing >> bibtex >> functions for reading in entries, and for cleaning up entries >> written by >> org-bibtex. >> > > The org-bibtex-read/write process doesn't work on the example I sent. > The read appears to work (though I can't find a buffer *org-bibtex- > entries* afterwards), but the write inserts the headline asterisk then > fails with progn: Wrong type argument: char-or-string-p, nil. > Hmm, I can't re-create this error, the read and write work for me... Are you placing the point immediately before the bibtex entry before calling org-bibtex-read? After calling the read, does the `*org-bibtex-entries*' variable appear to hold the information for the bibtex entry? Could you set `debug-on-error' to t, and then send me the entire error backtrace so I could see where this is going wrong? > >>> >>> Can I suggest some changes? >>> >>> 1) In our multi-user environment, where several authors are >>> contributing to a master bibtex file, we depend on the key generating >>> algorithm of bibtex-mode to help weed out duplicate entries. This >>> isn't 100% effective, but it catches lots of duplicates and saves us >>> time. Would it be possible to lift this mechanism and use it in org- >>> bibtex to generate the CUSTOM_ID? >>> >> >> I've added a new variable `org-bibtex-autogen-keys' which when set to >> t will result in auto-generated keys being used instead of prompting >> the user to input such keys. >> > > Beautiful! > >>> >>> 2) It might be better to use the (generated) key as the Org headline, >>> instead of the title. Titles can be longer than I find comfortable >>> for an Org-mode headline, whereas keys are usually about the right >>> length. >>> >> >> Hmm, I would tend to disagree here, but I think it may be a matter of >> taste. Note that if you include a TITLE property in a headline then >> it will be used instead of the contents of the headline, leaving you >> free to put whatever information you want into the headline. I've >> just updated the headline creation so that it will create such a >> title property as well as using the title as the headline, leaving >> you free to subsequently change the headline. >> > > That sounds right to me. Thanks. > >>> >>> 3) org-bibtex-cite seems like a natural next step, especially if it >>> offers a list of keys in the Org-mode buffer. >>> >> >> Meaning a function to allow tab-completion on keys... I could see >> this >> being useful but I would imagine that the bib entries would generally >> not live in the same buffer as the Org-mode text... rather I'd think >> some sort of global registry would be preferable. >> > > I guess it depends on how one uses the software. The use I envision > is for note taking while doing background reading for a project. > First, enter a reference with org-bibtex-create, then take notes while > reading, and finally write a summary that might later be used in the > project document. At this stage, org-bibtex hasn't been called, so > the only place the key is present is in the Org-mode buffer. > Inserting a reference then involves jumping back to the headline, > opening the properties drawer, selecting the value of CUSTOM_ID, > navigating back to the reference point and pasting in the key. A > function that collects keys and then presents them in a list like the > one used to choose TYPE would make this process very easy. > > Do you mind my asking what your workflow is with org-bibtex? > Currently I'm just using org-bibtex to collect all of my scattered reading notes into a single monolithic .org file, but I anticipate dumping out .bib files from here when writing in the future. I do see how an automated method of collecting bibtex keys, and then offering a tab-completing insertion could be useful... I'll make a note to this effect in my task file for org-bibtex. Best -- Eric > > All the best, > Tom >> Thanks for the suggestions, bug reports, and examples! >> >> Please do let me know if any of these issues remain -- Eric >> >>> >>> Here are the details of my test run: >>> >>> Existing bibtex entry: >>> >>> @Book{tuggle94:_cultur_resour_naval_air_station_barber_point, >>> author = {H. David Tuggle and M. J. Tomonari-Tuggle and >>> D. Colt Denfeld}, >>> title = {Cultural Resources of Naval Air Station, Barbers >>> Point: Summary, Assessment, and Inventory Research >>> Design: Task 1b: Archaeological Research Services >>> for the Proposed Cleanup, Disposal, and Reuse of >>> Naval Air Station, Barbers Point, O`ahu, Hawai`i}, >>> publisher = iarii, >>> year = 1994, >>> series = {Prepared for Belt Collins Hawaii}, >>> address = {Honolulu}, >>> month = {December}} >>> >>> Org-mode tree: >>> >>> >>> * Schulte bibtex >>> >>> ** A journal title >>> :PROPERTIES: >>> :type: article >>> :AUTHOR: A. N. Author >>> :JOURNAL: Journal of Statistical Software >>> :YEAR: 1998 >>> :CUSTOM_ID: author_10:article >>> :END: >>> >>> ** {Cultural Resources of Naval Air Station, Barbers >>> :PROPERTIES: >>> :TYPE: book >>> :CUSTOM_ID: tuggle94:_cultur_resour_naval_air_station_barber_point >>> :MONTH: December} >>> :ADDRESS: Honolulu >>> :SERIES: Prepared for Belt Collins Hawaii >>> :YEAR: 1994 >>> :PUBLISHER: iarii >>> :AUTHOR: {H. David Tuggle and M. J. Tomonari-Tuggle and >>> :END: >>> >>> Org-bibtex output: >>> >>> @book{tuggle94:_cultur_resour_naval_air_station_barber_point, >>> author={{H. David Tuggle and M. J. Tomonari-Tuggle and}, >>> title={{Cultural Resources of Naval Air Station, Barbers}, >>> publisher={iarii}, >>> year={1994}, >>> series={Prepared for Belt Collins Hawaii}, >>> address={Honolulu}, >>> month={December}} >>> } >>> >>> hth, >>> Tom >>> >>> On Apr 19, 2011, at 1:52 PM, Eric Schulte wrote: >>> >>>> Hi, >>>> >>>> In an attempt to organize my reading notes, I've written the >>>> following >>>> tool which allows both for exporting Org-mode headlines with bibtex >>>> meta-data to bibtex entries, and for reading existing bibtex entries >>>> into Org-mode headings. >>>> >>>> One nice feature of these functions is the ability to check that all >>>> required fields are present in a given headline based on the bibtex >>>> type >>>> (e.g., :article, :inproceedings), and prompt for missing fields. >>>> >>>> See the top of the elisp file for more usage information. >>>> https://github.com/eschulte/org-bibtex/blob/master/org-bibtex.el >>>> >>>> Cheers -- Eric >>>> >>>> -- >>>> Eric Schulte >>>> http://cs.unm.edu/~eschulte/ >>>> >>> >>> >> >> -- >> Eric Schulte >> http://cs.unm.edu/~eschulte/ > > -- Eric Schulte http://cs.unm.edu/~eschulte/ ^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [ANN] org-bibtex.el --- convert between Org headings and bibtex entries 2011-04-21 21:06 ` Eric Schulte @ 2011-04-23 16:23 ` Thomas S. Dye 2011-04-23 22:59 ` Alan E. Davis 0 siblings, 1 reply; 33+ messages in thread From: Thomas S. Dye @ 2011-04-23 16:23 UTC (permalink / raw) To: Eric Schulte; +Cc: Org Mode Hi Eric, After tests on a variety of bibtex entries, using both point before the entry and selecting an entry, I can't reproduce the problem I had late the other night with org-bibtex-read/write. Perhaps it was user error :( Also, thanks for the text file patch. My mail client and git am don't seem to cooperate. I have a library session scheduled next week and am looking forward to taking my reading notes, including bibtex entries, entirely with Org- mode. All the best, Tom On Apr 21, 2011, at 11:06 AM, Eric Schulte wrote: > "Thomas S. Dye" <tsd@tsdye.com> writes: > >> Hi Eric, >> >> On Apr 20, 2011, at 9:00 AM, Eric Schulte wrote: >> >>> Hi Tom, >>> >>> "Thomas S. Dye" <tsd@tsdye.com> writes: >>> >>>> Hi Eric, >>>> >>>> This could be very useful and a significant enhancement to Org-mode >>>> for note taking. With it, library time can be spent almost >>>> entirely >>>> within Org-mode, capturing bibliographic information and taking >>>> reading notes. It feels like the right level of functionality-- >>>> lightweight and easy to use, with lots of prompting material. >>>> >>> >>> Thanks, I hope so. >>> >>>> >>>> I created an entry with org-bibtex-create and then another with >>>> org- >>>> bibtex-read/write. When I ran org-bibtex, only the second entry >>>> was >>>> exported. Also, the org-bibtex-read/write process mangled the >>>> bibtex >>>> entry a bit, so the resulting .bib file wasn't useful. Note the >>>> addition of {} around the publisher and year, and the truncation of >>>> multi-line entries. >>>> >>> >>> I /believe/ I have fixed this issue. I am now using pre-existing >>> bibtex >>> functions for reading in entries, and for cleaning up entries >>> written by >>> org-bibtex. >>> >> >> The org-bibtex-read/write process doesn't work on the example I sent. >> The read appears to work (though I can't find a buffer *org-bibtex- >> entries* afterwards), but the write inserts the headline asterisk >> then >> fails with progn: Wrong type argument: char-or-string-p, nil. >> > > Hmm, I can't re-create this error, the read and write work for me... > > Are you placing the point immediately before the bibtex entry before > calling org-bibtex-read? > > After calling the read, does the `*org-bibtex-entries*' variable > appear > to hold the information for the bibtex entry? > > Could you set `debug-on-error' to t, and then send me the entire error > backtrace so I could see where this is going wrong? > >> >>>> >>>> Can I suggest some changes? >>>> >>>> 1) In our multi-user environment, where several authors are >>>> contributing to a master bibtex file, we depend on the key >>>> generating >>>> algorithm of bibtex-mode to help weed out duplicate entries. This >>>> isn't 100% effective, but it catches lots of duplicates and saves >>>> us >>>> time. Would it be possible to lift this mechanism and use it in >>>> org- >>>> bibtex to generate the CUSTOM_ID? >>>> >>> >>> I've added a new variable `org-bibtex-autogen-keys' which when set >>> to >>> t will result in auto-generated keys being used instead of prompting >>> the user to input such keys. >>> >> >> Beautiful! >> >>>> >>>> 2) It might be better to use the (generated) key as the Org >>>> headline, >>>> instead of the title. Titles can be longer than I find comfortable >>>> for an Org-mode headline, whereas keys are usually about the right >>>> length. >>>> >>> >>> Hmm, I would tend to disagree here, but I think it may be a matter >>> of >>> taste. Note that if you include a TITLE property in a headline then >>> it will be used instead of the contents of the headline, leaving you >>> free to put whatever information you want into the headline. I've >>> just updated the headline creation so that it will create such a >>> title property as well as using the title as the headline, leaving >>> you free to subsequently change the headline. >>> >> >> That sounds right to me. Thanks. >> >>>> >>>> 3) org-bibtex-cite seems like a natural next step, especially if it >>>> offers a list of keys in the Org-mode buffer. >>>> >>> >>> Meaning a function to allow tab-completion on keys... I could see >>> this >>> being useful but I would imagine that the bib entries would >>> generally >>> not live in the same buffer as the Org-mode text... rather I'd think >>> some sort of global registry would be preferable. >>> >> >> I guess it depends on how one uses the software. The use I envision >> is for note taking while doing background reading for a project. >> First, enter a reference with org-bibtex-create, then take notes >> while >> reading, and finally write a summary that might later be used in the >> project document. At this stage, org-bibtex hasn't been called, so >> the only place the key is present is in the Org-mode buffer. >> Inserting a reference then involves jumping back to the headline, >> opening the properties drawer, selecting the value of CUSTOM_ID, >> navigating back to the reference point and pasting in the key. A >> function that collects keys and then presents them in a list like the >> one used to choose TYPE would make this process very easy. >> >> Do you mind my asking what your workflow is with org-bibtex? >> > > Currently I'm just using org-bibtex to collect all of my scattered > reading notes into a single monolithic .org file, but I anticipate > dumping out .bib files from here when writing in the future. > > I do see how an automated method of collecting bibtex keys, and then > offering a tab-completing insertion could be useful... I'll make a > note > to this effect in my task file for org-bibtex. > > Best -- Eric > >> >> All the best, >> Tom >>> Thanks for the suggestions, bug reports, and examples! >>> >>> Please do let me know if any of these issues remain -- Eric >>> >>>> >>>> Here are the details of my test run: >>>> >>>> Existing bibtex entry: >>>> >>>> @Book{tuggle94:_cultur_resour_naval_air_station_barber_point, >>>> author = {H. David Tuggle and M. J. Tomonari-Tuggle and >>>> D. Colt Denfeld}, >>>> title = {Cultural Resources of Naval Air Station, Barbers >>>> Point: Summary, Assessment, and Inventory Research >>>> Design: Task 1b: Archaeological Research Services >>>> for the Proposed Cleanup, Disposal, and Reuse of >>>> Naval Air Station, Barbers Point, O`ahu, Hawai`i}, >>>> publisher = iarii, >>>> year = 1994, >>>> series = {Prepared for Belt Collins Hawaii}, >>>> address = {Honolulu}, >>>> month = {December}} >>>> >>>> Org-mode tree: >>>> >>>> >>>> * Schulte bibtex >>>> >>>> ** A journal title >>>> :PROPERTIES: >>>> :type: article >>>> :AUTHOR: A. N. Author >>>> :JOURNAL: Journal of Statistical Software >>>> :YEAR: 1998 >>>> :CUSTOM_ID: author_10:article >>>> :END: >>>> >>>> ** {Cultural Resources of Naval Air Station, Barbers >>>> :PROPERTIES: >>>> :TYPE: book >>>> :CUSTOM_ID: tuggle94:_cultur_resour_naval_air_station_barber_point >>>> :MONTH: December} >>>> :ADDRESS: Honolulu >>>> :SERIES: Prepared for Belt Collins Hawaii >>>> :YEAR: 1994 >>>> :PUBLISHER: iarii >>>> :AUTHOR: {H. David Tuggle and M. J. Tomonari-Tuggle and >>>> :END: >>>> >>>> Org-bibtex output: >>>> >>>> @book{tuggle94:_cultur_resour_naval_air_station_barber_point, >>>> author={{H. David Tuggle and M. J. Tomonari-Tuggle and}, >>>> title={{Cultural Resources of Naval Air Station, Barbers}, >>>> publisher={iarii}, >>>> year={1994}, >>>> series={Prepared for Belt Collins Hawaii}, >>>> address={Honolulu}, >>>> month={December}} >>>> } >>>> >>>> hth, >>>> Tom >>>> >>>> On Apr 19, 2011, at 1:52 PM, Eric Schulte wrote: >>>> >>>>> Hi, >>>>> >>>>> In an attempt to organize my reading notes, I've written the >>>>> following >>>>> tool which allows both for exporting Org-mode headlines with >>>>> bibtex >>>>> meta-data to bibtex entries, and for reading existing bibtex >>>>> entries >>>>> into Org-mode headings. >>>>> >>>>> One nice feature of these functions is the ability to check that >>>>> all >>>>> required fields are present in a given headline based on the >>>>> bibtex >>>>> type >>>>> (e.g., :article, :inproceedings), and prompt for missing fields. >>>>> >>>>> See the top of the elisp file for more usage information. >>>>> https://github.com/eschulte/org-bibtex/blob/master/org-bibtex.el >>>>> >>>>> Cheers -- Eric >>>>> >>>>> -- >>>>> Eric Schulte >>>>> http://cs.unm.edu/~eschulte/ >>>>> >>>> >>>> >>> >>> -- >>> Eric Schulte >>> http://cs.unm.edu/~eschulte/ >> >> > > -- > Eric Schulte > http://cs.unm.edu/~eschulte/ ^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [ANN] org-bibtex.el --- convert between Org headings and bibtex entries 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 0:52 ` Eric Schulte 0 siblings, 2 replies; 33+ messages in thread From: Alan E. Davis @ 2011-04-23 22:59 UTC (permalink / raw) To: Eric Schulte; +Cc: Org Mode [-- Attachment #1: Type: text/plain, Size: 2735 bytes --] Some notes on initially trying out this new tool. I have some reservations as to whether it use it. There are certain good reasons in its favor. This works to both store bibtex database entries and export to .bib files. I REALLY like the automagical harvesting of data using cb2Bib. It is unique, and I don't see how to recruit it to produce a database in an org file, or pipe it into this org-bibtex tool. The need to represent the bibtex database entry as a PROPERTY list would appear to me to limit its usefulness to me. A nit: I would prefer to be free to enter any optional field type I wished, when I am entering the data. Of course, the tool as it stands helped me to filter out duplicate fields and unused optional fields from the one bibtex entry I tried using org-bibtex-read: the output of org-bibtex-write was cleaner, and correctly incorporated aligning tabs where I'd carelessly left them out.) My INPUT ENTRY @INCOLLECTION{AED-IER-CR, author = {Junior Noitall}, title = {Specific disruption strategies}, booktitle = {How to annoy the teacher}, publisher = {Noitall Notes}, year = {2011}, editor = {Senior Noitall}, chapter = {13}, pages = {218--243}, address = {Concentric Orbit}, altauthor = {John Smith}, alteditor = {Carl Pumpkin}, isbn = {1-8777753-31-9}, optaddress = {Room X777}, optpages = {\frac{1}{2}} } In the following output, the isbn field is missing. OUTPUT from org-bibtex-write @incollection{AED-IER-CR, author = {Junior Noitall}, title = {Specific disruption strategies}, booktitle = {How to annoy the teacher}, publisher = {Noitall Notes}, year = 2011, editor = {Senior Noitall}, type = {incollection}, chapter = 13, pages = {218--243}, address = {Concentric Orbit} } 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. Somewhere there is code that does that. It would be a huge and excellent addition to be able to pass other types, while checking for proper formatting. Bibtex itself, and the .bst files (at least for bibtex itself; I don't know about biblatex, etc.) will cherry pick the needed fields. Am I wrong about this? I am confused by the duplication of file names, though I can see that at some point one of the two will lose. (Gauss's law of competitive exclusion, referring to the biological case of two species occupying the same ecological niche). Alan Davis [-- Attachment #2: Type: text/html, Size: 3032 bytes --] ^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [ANN] org-bibtex.el --- convert between Org headings and bibtex entries 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 0:52 ` Eric Schulte 1 sibling, 1 reply; 33+ messages in thread From: Matt Lundin @ 2011-04-24 0:40 UTC (permalink / raw) To: Alan E. Davis; +Cc: Org Mode "Alan E. Davis" <lngndvs@gmail.com> writes: > This works to both store bibtex database entries and export to .bib > files. I REALLY like the automagical harvesting of data using cb2Bib. > It is unique, and I don't see how to recruit it to produce a database > in an org file, or pipe it into this org-bibtex tool. Could one perhaps call org-bibtex-read on entries in harvested via cb2Bib? > 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. > I am confused by the duplication of file names, though I can see that > at some point one of the two will lose. (Gauss's law of competitive > exclusion, referring to the biological case of two species occupying > the same ecological niche). Eric, the more I think about this, the more my vote would be to package this new functionality separately. IMO, hyperlinking to external data in bib files is somewhat orthogonal to storing bib data within org files. In other words, the current org-bibtex.el complements bibtex-mode use, whereas the new org-bibtex functions, for the most part, are substitutes for bibtex-mode---i.e., they re-implement much of its configuration and basic functionality. By packaging the new functionality separately perhaps we could lay the groundwork for internal, backend agnostic bibliographical export and formatting---not unlike the way in which org-contacts.el replaces bbdb. Wishful thinking?... :) Best, Matt ^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [ANN] org-bibtex.el --- convert between Org headings and bibtex entries 2011-04-24 0:40 ` Matt Lundin @ 2011-04-24 14:21 ` Eric Schulte 2011-04-24 16:53 ` Christian Moe 2011-04-25 15:15 ` Matt Lundin 0 siblings, 2 replies; 33+ messages in thread From: Eric Schulte @ 2011-04-24 14:21 UTC (permalink / raw) To: Matt Lundin; +Cc: Org Mode 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 am confused by the duplication of file names, though I can see that >> at some point one of the two will lose. (Gauss's law of competitive >> exclusion, referring to the biological case of two species occupying >> the same ecological niche). > > Eric, the more I think about this, the more my vote would be to package > this new functionality separately. > > IMO, hyperlinking to external data in bib files is somewhat orthogonal > to storing bib data within org files. In other words, the current > org-bibtex.el complements bibtex-mode use, whereas the new org-bibtex > functions, for the most part, are substitutes for bibtex-mode---i.e., > they re-implement much of its configuration and basic functionality. > > By packaging the new functionality separately perhaps we could lay the > groundwork for internal, backend agnostic bibliographical export and > formatting---not unlike the way in which org-contacts.el replaces bbdb. > Alright, I think I agree that separate packaging would be the best way forward given the existing conventions wrt linking to functionality rather than implementing said functionality. Also, some integration with the existing org-bibtex linking functions (as you've mentioned) would probably address some of Tom's earlier requests for an easy means of inserting bibtex entries. The only question now is the one which originally lead me to simply dump this into org-bibtex, namely, what is a good name? The first options that occur to me are - org-bib - org-reference - org-cite What do you think? Any better suggestions? Thanks -- Eric > > Wishful thinking?... :) > > Best, > Matt -- Eric Schulte http://cs.unm.edu/~eschulte/ ^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [ANN] org-bibtex.el --- convert between Org headings and bibtex entries 2011-04-24 14:21 ` Eric Schulte @ 2011-04-24 16:53 ` Christian Moe 2011-04-25 13:19 ` Matt Lundin 2011-04-25 15:15 ` Matt Lundin 1 sibling, 1 reply; 33+ messages in thread From: Christian Moe @ 2011-04-24 16:53 UTC (permalink / raw) To: Eric Schulte; +Cc: Matt Lundin, Org Mode On 4/24/11 4:21 PM, Eric Schulte wrote: > Matt Lundin<mdl@imapmail.org> writes: >> (...) >> Eric, the more I think about this, the more my vote would be to package >> this new functionality separately. >> >> IMO, hyperlinking to external data in bib files is somewhat orthogonal >> to storing bib data within org files. In other words, the current >> org-bibtex.el complements bibtex-mode use, whereas the new org-bibtex >> functions, for the most part, are substitutes for bibtex-mode---i.e., >> they re-implement much of its configuration and basic functionality. >> >> By packaging the new functionality separately perhaps we could lay the >> groundwork for internal, backend agnostic bibliographical export and >> formatting---not unlike the way in which org-contacts.el replaces bbdb. >> > > Alright, I think I agree that separate packaging would be the best way > forward given the existing conventions wrt linking to functionality > rather than implementing said functionality. The *conclusion* (where Eric Schulte's new bibtex functions should go) is not a big concern to me, but FWIW, the *premise* strikes me as unnecessarily restrictive. I submit that, for any non-Org format or application "foo", the module org-foo.el does not have to be restricted to providing an Org link type for foo. It seems a sensible namespace for e.g. foo-Org/Org-foo conversion functions as well. The fact that several modules so named *at present* only provide link functionality does not, I think, amount to a convention that this is all they should do. > By packaging the new functionality separately perhaps we could lay the > groundwork for internal, backend agnostic bibliographical export and > formatting---not unlike the way in which org-contacts.el replaces bbdb. That's a great aim. Still, a future bibliography module (be it "org-bib", "org-cite" or whatever) could just as well rely, for bits of bibtex functionality, on some utilities packaged in org-bibtex. Yours, Christian ^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [ANN] org-bibtex.el --- convert between Org headings and bibtex entries 2011-04-24 16:53 ` Christian Moe @ 2011-04-25 13:19 ` Matt Lundin 2011-04-25 13:34 ` Eric Schulte 0 siblings, 1 reply; 33+ messages in thread From: Matt Lundin @ 2011-04-25 13:19 UTC (permalink / raw) To: mail; +Cc: Org Mode Hi Eric and Christian, Christian Moe <mail@christianmoe.com> writes: > The *conclusion* (where Eric Schulte's new bibtex functions should go) > is not a big concern to me, but FWIW, the *premise* strikes me as > unnecessarily restrictive. > > I submit that, for any non-Org format or application "foo", the module > org-foo.el does not have to be restricted to providing an Org link > type for foo. It seems a sensible namespace for e.g. foo-Org/Org-foo > conversion functions as well. The fact that several modules so named > *at present* only provide link functionality does not, I think, amount > to a convention that this is all they should do. Christian, you are right. I stand corrected. I agree that the namespace can accommodate import/export/conversion features in addition to hyperlinking. Apologies (especially to Eric) for my wavering on where to put this. This functionality is indeed not a generic bib backend, but rather tightly integrated with bibtex-mode and the bibtex format. So a full +1 for adding this to org-bibtex.el. And that's my final answer... :) >> By packaging the new functionality separately perhaps we could lay the >> groundwork for internal, backend agnostic bibliographical export and >> formatting---not unlike the way in which org-contacts.el replaces bbdb. > > That's a great aim. Still, a future bibliography module (be it > "org-bib", "org-cite" or whatever) could just as well rely, for bits > of bibtex functionality, on some utilities packaged in org-bibtex. Agreed. Best, Matt ^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [ANN] org-bibtex.el --- convert between Org headings and bibtex entries 2011-04-25 13:19 ` Matt Lundin @ 2011-04-25 13:34 ` Eric Schulte 0 siblings, 0 replies; 33+ messages in thread From: Eric Schulte @ 2011-04-25 13:34 UTC (permalink / raw) To: Matt Lundin; +Cc: Org Mode, mail Matt Lundin <mdl@imapmail.org> writes: > Hi Eric and Christian, > > Christian Moe <mail@christianmoe.com> writes: > >> The *conclusion* (where Eric Schulte's new bibtex functions should go) >> is not a big concern to me, but FWIW, the *premise* strikes me as >> unnecessarily restrictive. >> >> I submit that, for any non-Org format or application "foo", the module >> org-foo.el does not have to be restricted to providing an Org link >> type for foo. It seems a sensible namespace for e.g. foo-Org/Org-foo >> conversion functions as well. The fact that several modules so named >> *at present* only provide link functionality does not, I think, amount >> to a convention that this is all they should do. > > Christian, you are right. I stand corrected. I agree that the namespace > can accommodate import/export/conversion features in addition to > hyperlinking. > > Apologies (especially to Eric) for my wavering on where to put this. > This functionality is indeed not a generic bib backend, but rather > tightly integrated with bibtex-mode and the bibtex format. So a full +1 > for adding this to org-bibtex.el. And that's my final answer... :) > No problem here, this is the sort of question I'm happy to defer on, especially as it shouldn't really affect the final functionality. Given that I hadn't yet started to extract the code this is no skin off my nose. I'll go ahead and leave this code where it is. Cheers -- Eric -- Eric Schulte http://cs.unm.edu/~eschulte/ ^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [ANN] org-bibtex.el --- convert between Org headings and bibtex entries 2011-04-24 14:21 ` Eric Schulte 2011-04-24 16:53 ` Christian Moe @ 2011-04-25 15:15 ` Matt Lundin 2011-04-27 22:16 ` Eric Schulte 1 sibling, 1 reply; 33+ messages in thread From: Matt Lundin @ 2011-04-25 15:15 UTC (permalink / raw) To: Eric Schulte; +Cc: Org Mode 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--- ^ permalink raw reply related [flat|nested] 33+ messages in thread
* Re: [ANN] org-bibtex.el --- convert between Org headings and bibtex entries 2011-04-25 15:15 ` Matt Lundin @ 2011-04-27 22:16 ` Eric Schulte 0 siblings, 0 replies; 33+ messages in thread From: Eric Schulte @ 2011-04-27 22:16 UTC (permalink / raw) To: Matt Lundin; +Cc: Org Mode Hi Matt, Matt Lundin <mdl@imapmail.org> writes: > 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.) > This looks great thanks. > > 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 think this is the best approach. > > I also made the key property configurable. > Nice, I think this is also an improvement. > > 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. > Oh, I should have read this last paragraph. Having received confirmation from Bastien that it was alright to include this code into org-bibtex in the core, I have applied your patch on top of my own patches. The results are now in the Org-mode git repository. Please do let me know if anything looks amiss --- I mainly just expanded your patch to take into account my intervening changes, and to avoid lines longer than 80 characters. Thanks! -- Eric > > Best, > Matt > > 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) -- Eric Schulte http://cs.unm.edu/~eschulte/ ^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [ANN] org-bibtex.el --- convert between Org headings and bibtex entries 2011-04-23 22:59 ` Alan E. Davis 2011-04-24 0:40 ` Matt Lundin @ 2011-04-24 0:52 ` Eric Schulte 2011-04-24 4:49 ` Alan E. Davis 1 sibling, 1 reply; 33+ messages in thread From: Eric Schulte @ 2011-04-24 0:52 UTC (permalink / raw) To: Alan E. Davis; +Cc: Org Mode [-- Attachment #1: Type: text/plain, Size: 4956 bytes --] "Alan E. Davis" <lngndvs@gmail.com> writes: > Some notes on initially trying out this new tool. I have some reservations > as to whether it use it. There are certain good reasons in its favor. > > This works to both store bibtex database entries and export to .bib files. > I REALLY like the automagical harvesting of data using cb2Bib. It is > unique, and I don't see how to recruit it to produce a database in an org > file, or pipe it into this org-bibtex tool. > Org-bibtex can be used to collect bibtex entries from .bib files, and (with this most recent attached version) directly from the clipboard with `org-bibtex-yank'. Is there a more natural way that this could integrate with external tools like cb2bib? I've just now installed cb2bib, and I'm not sure I fully grasp its usage. > > The need to represent the bibtex database entry as a PROPERTY list would > appear to me to limit its usefulness to me. > in any particular way? > > A nit: I would prefer to be free to enter any optional field type I wished, > when I am entering the data. It is possible to add arbitrary properties to a headline with `org-set-property'. Or you could customize the variables holding bibtex field and entry types. For example to add a personal :mynotes field to every bibtex type just execute the following elisp code (or add it to your configuration). You will then be prompted for a mynotes field on every bibtex entry. You could also change the :required keyword to add your field as an option field. #+begin_src emacs-lisp (dolist (type org-bibtex-types) (push :mynotes (cdr (assoc :required (cdr type))))) (push (cons :mynotes "My personal field for notes") org-bibtex-fields) #+end_src > Of course, the tool as it stands helped me to filter out duplicate > fields and unused optional fields from the one bibtex entry I tried > using org-bibtex-read: the output of org-bibtex-write was cleaner, and > correctly incorporated aligning tabs where I'd carelessly left them > out.) > This functionality is all due to the formatting functions provided by the existing bibtex.el package. > > My INPUT ENTRY > > @INCOLLECTION{AED-IER-CR, > author = {Junior Noitall}, > title = {Specific disruption strategies}, > booktitle = {How to annoy the teacher}, > publisher = {Noitall Notes}, > year = {2011}, > editor = {Senior Noitall}, > chapter = {13}, > pages = {218--243}, > address = {Concentric Orbit}, > altauthor = {John Smith}, > alteditor = {Carl Pumpkin}, > isbn = {1-8777753-31-9}, > optaddress = {Room X777}, > optpages = {\frac{1}{2}} > } > > In the following output, the isbn field is missing. > > OUTPUT from org-bibtex-write > > @incollection{AED-IER-CR, > author = {Junior Noitall}, > title = {Specific disruption strategies}, > booktitle = {How to annoy the teacher}, > publisher = {Noitall Notes}, > year = 2011, > editor = {Senior Noitall}, > type = {incollection}, > chapter = 13, > pages = {218--243}, > address = {Concentric Orbit} > } > > > 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? If a type is added as with the code given above, then it will be exported to .bib files along with the default fields. > I think the emacs bibtex-mode may recognize erroneous bibtex entries. > Somewhere there is code that does that. I do not know if bibtex-mode does that or not. I think that bibtex itself is supposed to simply ignore any fields which it does not recognize allowing extensibility. > It would be a huge and excellent addition to be able to pass other > types, while checking for proper formatting. Bibtex itself, and the > .bst files (at least for bibtex itself; I don't know about biblatex, > etc.) will cherry pick the needed fields. Am I wrong about this? > The above sounds correct to me. Given that org properties will likely contain non-bibtex content, I wouldn't want the default behavior to be exporting every property entry to bibtex. However if the above solution of adding to the org-bibtex-types/fields variables is not sufficient, it shouldn't be difficult to change the org-bibtex command so that if it is called with a prefix argument it will export *all* properties to the .bib file. > > > I am confused by the duplication of file names, though I can see that at > some point one of the two will lose. (Gauss's law of competitive exclusion, > referring to the biological case of two species occupying the same > ecological niche). > I think that rather than competing these files may be merging into a single file (as with the attached patch). However this remains to be seen. Thanks for the feedback and suggestions -- Eric > > > Alan Davis [-- Attachment #2: 0001-org-bibtex-translating-between-Org-mode-headings-and.patch --] [-- Type: text/x-diff, Size: 21144 bytes --] From c9e76873e346e3eaf0a99c07458dfac28200490b Mon Sep 17 00:00:00 2001 From: Eric Schulte <schulte.eric@gmail.com> Date: Sat, 23 Apr 2011 08:05:08 -0600 Subject: [PATCH] org-bibtex: translating between Org-mode headings and Bibtex entries * lisp/org-bibtex.el: Updating Copyright dates, author information, commentary and history notes. (org-bibtex-types): List of bibtex types with descriptions and required and optional fields. (org-bibtex-fields): List of bibtex fields with descriptions. (*org-bibtex-entries*): Special variable to hold parsed bibtex entries. (org-bibtex-autogen-keys): Custom variable controlling whether bibtex keys are automatically generated (org-bibtex-prefix): Custom variable allowing use of optional prefix for bibtex properties in Org-mode headlines. (org-bibtex-get): Helper function for accessing bibtex elements of a property list. (org-bibtex-put): Helper function for inserting bibtex element into a property list. (org-bibtex-headline): Return a bibtex entry of the given headline as a string. (org-bibtex-ask): Prompt the user to fill in the value of a bibtex field. (org-bibtex-autokey): Generate a bibtex key for the current headline. (org-bibtex-fleshout): Fill in missing bibtex properties of the current headline. (org-bibtex): Export the current Org-mode buffer to a bibtex buffer. (org-bibtex-check): Check that all bibtex properties are present in the current headline. (org-bibtex-check-all): Check all headlines in the current buffer. (org-bibtex-create): Create a new bibtex headline at the current level. (org-bibtex-read): Read the current bibtex entry from a bibtex file. (org-bibtex-write): Write the most recently read bibtex entry into an Org-mode file. --- lisp/org-bibtex.el | 331 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 317 insertions(+), 14 deletions(-) diff --git a/lisp/org-bibtex.el b/lisp/org-bibtex.el index b7b7416..818be67 100644 --- a/lisp/org-bibtex.el +++ b/lisp/org-bibtex.el @@ -1,9 +1,10 @@ ;;; org-bibtex.el --- Org links to BibTeX entries ;; -;; Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc. +;; Copyright (C) 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc. ;; ;; Author: Bastien Guerry <bzg at altern dot org> ;; Carsten Dominik <carsten dot dominik at gmail dot com> +;; Eric Schulte <schulte dot eric at gmail dot com> ;; Keywords: org, wp, remember ;; Version: 7.5 ;; @@ -66,12 +67,30 @@ ;; ===================================================================== ;; * READ <== [point here] ;; -;; [[file:/file.bib::dolev83][Dolev & Yao 1983: security of public key protocols]] +;; [[file:file.bib::dolev83][Dolev & Yao 1983: security of public key protocols]] ;; ;; Danny Dolev and Andrew C. Yao (1983): On the security of public-key protocols ;; In IEEE Transaction on Information Theory, 198--208. ;; ===================================================================== ;; +;; Additionally, the following functions are now available for storing +;; bibtex entries within Org-mode documents. +;; +;; - Run `org-bibtex' to export the current file to a .bib. +;; +;; - Run `org-bibtex-check' or `org-bibtex-check-all' to check and +;; fill in missing field of either the current, or all headlines +;; +;; - Run `org-bibtex-create' to add a bibtex entry +;; +;; - Use `org-bibtex-read' to read a bibtex entry after `point' or in +;; the active region, then call `org-bibtex-write' in a .org file to +;; insert a heading for the read bibtex entry +;; +;; - All Bibtex information is taken from the document compiled by +;; Andrew Roberts from the Bibtex manual, available at +;; http://www.andy-roberts.net/misc/latex/sessions/bibtex/bibentries.pdf +;; ;;; History: ;; ;; The link creation part has been part of Org-mode for a long time. @@ -80,12 +99,17 @@ ;; of Austin Frank: http://article.gmane.org/gmane.emacs.orgmode/4112 ;; and then implemented by Bastien Guerry. ;; +;; Eric Schulte eventually added the functions for translating between +;; Org-mode headlines and Bibtex entries, and for fleshing out the Bibtex +;; fields of existing Org-mode headlines. +;; ;; Org-mode loads this module by default - if this is not what you want, ;; configure the variable `org-modules'. ;;; Code: (require 'org) +(require 'bibtex) (defvar description nil) ; dynamically scoped from org.el @@ -93,21 +117,209 @@ (declare-function bibtex-generate-autokey "bibtex" ()) (declare-function bibtex-parse-entry "bibtex" (&optional content)) (declare-function bibtex-url "bibtex" (&optional pos no-browse)) +(declare-function longlines-mode "longlines" (&optional arg)) + +\f +;;; Bibtex data +(defvar org-bibtex-types + '((:article + (:description . "An article from a journal or magazine") + (:required :author :title :journal :year) + (:optional :volume :number :pages :month :note)) + (:book + (:description . "A book with an explicit publisher") + (:required (:editor :author) :title :publisher :year) + (:optional (:volume :number) :series :address :edition :month :note)) + (:booklet + (:description . "A work that is printed and bound, but without a named publisher or sponsoring institution.") + (:required :title) + (:optional :author :howpublished :address :month :year :note)) + (:conference + (:description . "") + (:required :author :title :booktitle :year) + (:optional :editor :pages :organization :publisher :address :month :note)) + (:inbook + (:description . "A part of a book, which may be a chapter (or section or whatever) and/or a range of pages.") + (:required (:author :editor) :title (:chapter :pages) :publisher :year) + (:optional (:volume :number) :series :type :address :edition :month :note)) + (:incollection + (:description . "A part of a book having its own title.") + (:required :author :title :booktitle :publisher :year) + (:optional :editor (:volume :number) :series :type :chapter :pages :address :edition :month :note)) + (:inproceedings + (:description . "An article in a conference proceedings") + (:required :author :title :booktitle :year) + (:optional :editor (:volume :number) :series :pages :address :month :organization :publisher :note)) + (:manual + (:description . "Technical documentation.") + (:required :title) + (:optional :author :organization :address :edition :month :year :note)) + (:mastersthesis + (:description . "A Master’s thesis.") + (:required :author :title :school :year) + (:optional :type :address :month :note)) + (:misc + (:description . "Use this type when nothing else fits.") + (:required) + (:optional :author :title :howpublished :month :year :note)) + (:phdthesis + (:description . "A PhD thesis.") + (:required :author :title :school :year) + (:optional :type :address :month :note)) + (:proceedings + (:description . "The proceedings of a conference.") + (:required :title :year) + (:optional :editor (:volume :number) :series :address :month :organization :publisher :note)) + (:techreport + (:description . "A report published by a school or other institution.") + (:required :author :title :institution :year) + (:optional :type :address :month :note)) + (:unpublished + (:description . "A document having an author and title, but not formally published.") + (:required :author :title :note) + (:optional :month :year))) + "Bibtex entry types with required and optional parameters.") + +(defvar org-bibtex-fields + '((:address . "Usually the address of the publisher or other type of institution. For major publishing houses, van Leunen recommends omitting the information entirely. For small publishers, on the other hand, you can help the reader by giving the complete address.") + (:annote . "An annotation. It is not used by the standard bibliography styles, but may be used by others that produce an annotated bibliography.") + (:author . "The name(s) of the author(s), in the format described in the LaTeX book. Remember, all names are separated with the and keyword, and not commas.") + (:booktitle . "Title of a book, part of which is being cited. See the LaTeX book for how to type titles. For book entries, use the title field instead.") + (:chapter . "A chapter (or section or whatever) number.") + (:crossref . "The database key of the entry being cross referenced.") + (:edition . "The edition of a book for example, 'Second'. This should be an ordinal, and should have the first letter capitalized, as shown here; the standard styles convert to lower case when necessary.") + (:editor . "Name(s) of editor(s), typed as indicated in the LaTeX book. If there is also an author field, then the editor field gives the editor of the book or collection in which the reference appears.") + (:howpublished . "How something strange has been published. The first word should be capitalized.") + (:institution . "The sponsoring institution of a technical report.") + (:journal . "A journal name.") + (:key . "Used for alphabetizing, cross-referencing, and creating a label when the author information is missing. This field should not be confused with the key that appears in the \cite command and at the beginning of the database entry.") + (:month . "The month in which the work was published or, for an unpublished work, in which it was written. You should use the standard three-letter abbreviation,") + (:note . "Any additional information that can help the reader. The first word should be capitalized.") + (:number . "Any additional information that can help the reader. The first word should be capitalized.") + (:organization . "The organization that sponsors a conference or that publishes a manual.") + (:pages . "One or more page numbers or range of numbers, such as 42-111 or 7,41,73-97 or 43+ (the ‘+’ in this last example indicates pages following that don’t form simple range). BibTEX requires double dashes for page ranges (--).") + (:publisher . "The publisher’s name.") + (:school . "The name of the school where a thesis was written.") + (:series . "The name of a series or set of books. When citing an entire book, the the title field gives its title and an optional series field gives the name of a series or multi-volume set in which the book is published.") + (:title . "The work’s title, typed as explained in the LaTeX book.") + (:type . "The type of a technical report for example, 'Research Note'.") + (:volume . "The volume of a journal or multi-volume book.") + (:year . "The year of publication or, for an unpublished work, the year it was written. Generally it should consist of four numerals, such as 1984, although the standard styles can handle any year whose last four nonpunctuation characters are numerals, such as '(about 1984)'")) + "Bibtex fields with descriptions.") + +(defvar *org-bibtex-entries* nil + "List to hold parsed bibtex entries.") + +(defcustom org-bibtex-autogen-keys nil + "Set to a truthy value to use `bibtex-generate-autokey' to generate keys." + :group 'org-bibtex + :type 'boolean) + +(defcustom org-bibtex-prefix nil + "Optional prefix for all bibtex property names. +For example setting to 'BIB_' would allow interoperability with fireforg." + :group 'org-bibtex + :type 'string) + +\f +;;; Utility functions +(defun org-bibtex-get (property) + (or (org-entry-get (point) (upcase property)) + (org-entry-get (point) (concat org-bibtex-prefix (upcase property))))) +(defun org-bibtex-put (property value) + (let ((prop (upcase (if (keywordp property) + (substring (symbol-name property) 1) + property)))) + (org-set-property + (concat (unless (string= "CUSTOM_ID" prop) org-bibtex-prefix) prop) + value))) + +(defun org-bibtex-headline () + "Return a bibtex entry of the given headline as a string." + (flet ((get (key lst) (cdr (assoc key lst))) + (to-k (string) (intern (concat ":" string))) + (from-k (key) (substring (symbol-name key) 1)) + (flatten (&rest lsts) + (apply #'append (mapcar + (lambda (e) + (if (listp e) (apply #'flatten e) (list e))) + lsts)))) + (let ((notes (buffer-string)) + (id (org-bibtex-get "custom_id")) + (type (org-bibtex-get "type"))) + (when type + (let ((entry (format + "@%s{%s,\n%s\n}\n" type id + (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))))) + ",\n")))) + (with-temp-buffer + (insert entry) + (bibtex-reformat) (buffer-string))))))) + +(defun org-bibtex-ask (field) + (unless (assoc field org-bibtex-fields) + (error "field:%s is not known" field)) + (save-window-excursion + (let* ((name (substring (symbol-name field) 1)) + (buf-name (format "*Bibtex Help %s*" name))) + (with-output-to-temp-buffer buf-name + (princ (cdr (assoc field org-bibtex-fields)))) + (with-current-buffer buf-name (longlines-mode t)) + (org-fit-window-to-buffer (get-buffer-window buf-name)) + ((lambda (result) (when (> (length result) 0) result)) + (read-from-minibuffer (format "%s: " name)))))) + +(defun org-bibtex-autokey () + "Generate an autokey for the current headline" + (org-bibtex-put "CUSTOM_ID" + (if org-bibtex-autogen-keys + (let ((entry (org-bibtex-headline))) + (with-temp-buffer + (insert entry) + (bibtex-generate-autokey))) + (read-from-minibuffer "id: ")))) + +(defun org-bibtex-fleshout (type &optional optional) + "Fleshout the current heading, ensuring that all required fields are present. +With optional argument OPTIONAL, also prompt for optional fields." + (flet ((get (key lst) (cdr (assoc key lst))) + (keyword (name) (intern (concat ":" (downcase name)))) + (name (keyword) (upcase (substring (symbol-name keyword) 1)))) + (dolist (field (append + (remove :title (get :required (get type org-bibtex-types))) + (when optional (get :optional (get type org-bibtex-types))))) + (when (consp field) ; or'd pair of fields e.g., (:editor :author) + (let ((present (first (remove nil + (mapcar + (lambda (f) (when (org-bibtex-get (name f)) f)) + field))))) + (setf field (or present (keyword (org-icompleting-read + "Field: " (mapcar #'name field))))))) + (let ((name (name field))) + (unless (org-bibtex-get name) + (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"))) + (org-bibtex-autokey))) + +\f +;;; Bibtex link functions (org-add-link-type "bibtex" 'org-bibtex-open) (add-hook 'org-store-link-functions 'org-bibtex-store-link) -;; (defun org-bibtex-publish (path) -;; "Build the description of the BibTeX entry for publishing." -;; (let* ((search (when (string-match "::\\(.+\\)\\'" path) -;; (match-string 1 path))) -;; (path (substring path 0 (match-beginning 0))) -;; key) -;; (with-temp-buffer -;; (org-open-file path t nil search) -;; (setq key (org-create-file-search-functions))) -;; (or description key))) - (defun org-bibtex-open (path) "Visit the bibliography entry on PATH." (let* ((search (when (string-match "::\\(.+\\)\\'" path) @@ -192,12 +404,103 @@ (goto-char p) (bibtex-url))) (recenter 0)) ; Move entry start to beginning of window - ;; return t to indicate that the search is done. + ;; return t to indicate that the search is done. t)) ;; Finally add the link search function to the right hook. (add-hook 'org-execute-file-search-functions 'org-execute-file-search-in-bibtex) +\f +;;; Bibtex <-> Org-mode headline translation functions +(defun org-bibtex () + "Export each headline in the current file to a bibtex entry. +Headlines are exported using `org-bibtex-export-headline'." + (interactive) + (let ((bibtex-entries (remove nil (org-map-entries #'org-bibtex-headline)))) + (with-temp-file (concat (file-name-sans-extension (buffer-file-name)) ".bib") + (insert (mapconcat #'identity bibtex-entries "\n"))))) + +(defun org-bibtex-check (&optional optional) + "Check the current headline for required fields. +With prefix argument OPTIONAL also prompt for optional fields." + (interactive "P") + (save-restriction + (org-narrow-to-subtree) + (let ((type ((lambda (name) (when name (intern (concat ":" name)))) + (org-bibtex-get "TYPE")))) + (when type (org-bibtex-fleshout type optional))))) + +(defun org-bibtex-check-all (&optional optional) + "Check all headlines in the current file. +With prefix argument OPTIONAL also prompt for optional fields." + (interactive) (org-map-entries (lambda () (org-bibtex-check optional)))) + +(defun org-bibtex-create (type) + "Create a new entry at the given level." + (interactive + (list (org-icompleting-read + "Type: " + (mapcar (lambda (type) (symbol-name (car type))) org-bibtex-types)))) + (let ((type (if (keywordp type) type (intern type)))) + (unless (assoc type org-bibtex-types) + (error "type:%s is not known" type)) + (org-insert-heading) + (let ((title (org-bibtex-ask :title))) + (insert title) (org-bibtex-put "TITLE" title)) + (org-bibtex-put "TYPE" (substring (symbol-name type) 1)) + (org-bibtex-fleshout type))) + +(defun org-bibtex-read () + "Read a bibtex entry and save to `*org-bibtex-entries*'. +This uses `bibtex-parse-entry'." + (interactive) + (flet ((keyword (str) (intern (concat ":" (downcase str)))) + (clean-space (str) (replace-regexp-in-string + "[[:space:]\n\r]+" " " str)) + (strip-delim (str) ; strip enclosing "..." and {...} + (dolist (pair '((34 . 34) (123 . 125) (123 . 125))) + (when (and (= (aref str 0) (car pair)) + (= (aref str (1- (length str))) (cdr pair))) + (setf str (subseq str 1 (1- (length str)))))) str)) + (push (mapcar + (lambda (pair) + (cons (let ((field (keyword (car pair)))) + (case field + (:=type= :type) + (:=key= :key) + (otherwise field))) + (clean-space (strip-delim (cdr pair))))) + (save-excursion (bibtex-beginning-of-entry) (bibtex-parse-entry))) + *org-bibtex-entries*))) + +(defun org-bibtex-write () + "Insert a heading built from the first element of `*org-bibtex-entries*'." + (interactive) + (when (= (length *org-bibtex-entries*) 0) + (error "No entries in `*org-bibtex-entries*'.")) + (let ((entry (pop *org-bibtex-entries*)) + (org-special-properties nil)) ; avoids errors with `org-entry-put' + (flet ((get (field) (cdr (assoc field entry)))) + (org-insert-heading) + (insert (get :title)) + (org-bibtex-put "TITLE" (get :title)) + (org-bibtex-put "TYPE" (downcase (get :type))) + (dolist (pair entry) + (case (car pair) + (:title nil) + (:type nil) + (:key (org-bibtex-put "CUSTOM_ID" (cdr pair))) + (otherwise (org-bibtex-put (car pair) (cdr pair)))))))) + +(defun org-bibtex-yank () + "If kill ring holds a bibtex entry yank it as an Org-mode headline." + (interactive) + (let (entry) + (with-temp-buffer (yank 1) (setf entry (org-bibtex-read))) + (if entry + (org-bibtex-write) + (error "yanked text does not appear to contain a bibtex entry")))) + (provide 'org-bibtex) ;; arch-tag: 83987d5a-01b8-41c7-85bc-77700f1285f5 -- 1.7.1 [-- Attachment #3: Type: text/plain, Size: 47 bytes --] -- Eric Schulte http://cs.unm.edu/~eschulte/ ^ permalink raw reply related [flat|nested] 33+ messages in thread
* Re: [ANN] org-bibtex.el --- convert between Org headings and bibtex entries 2011-04-24 0:52 ` Eric Schulte @ 2011-04-24 4:49 ` Alan E. Davis 2011-04-24 14:29 ` Eric Schulte 0 siblings, 1 reply; 33+ messages in thread From: Alan E. Davis @ 2011-04-24 4:49 UTC (permalink / raw) To: Eric Schulte; +Cc: Org Mode [-- Attachment #1: Type: text/plain, Size: 1497 bytes --] Comments below On Sun, Apr 24, 2011 at 10:52 AM, Eric Schulte <schulte.eric@gmail.com>wrote: > > Is there a more natural way that this could integrate with external > tools like cb2bib? I've just now installed cb2bib, and I'm not sure I > fully grasp its usage. > > I also found cb2Bib pretty opaque when I first installed it. It's not hard to understand the basics, though. Anything in your clipboard is queued up to import into cb2Bib. The easiest way, for example, to import a bibtex database entry from Google Scholar is to highlight the entire entry in the browser with a mouse, and it's parts are already displayed in cb2Bib. If, for example, one is trying to save from a text-based bibliography entry, it may be copied to the clipboard. Highlight, for example, the title, and right click, then select "title". And so on. This is the automagical part that I have found so very useful. It is important to 'unplug' cb2Bib if the entry needs to be edited. If not, any action in the fields and displayed will be lost. Then save using the save icons. I have to say, though, that a little explanation would go a long way, when trying to use it. Once this process is complete, I can see that being able to, in turn copy this entry to the clipboard would indeed be useful with org-bibtex . I wonder if it's possible to set a pipe or one of those cryptic file types (fifo?) I cannot remember would either work, or whether the developers would agree to enabling this ability. Alan [-- Attachment #2: Type: text/html, Size: 1898 bytes --] ^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [ANN] org-bibtex.el --- convert between Org headings and bibtex entries 2011-04-24 4:49 ` Alan E. Davis @ 2011-04-24 14:29 ` Eric Schulte 2011-04-24 20:40 ` Alan E. Davis 0 siblings, 1 reply; 33+ messages in thread From: Eric Schulte @ 2011-04-24 14:29 UTC (permalink / raw) To: Alan E. Davis; +Cc: Org Mode "Alan E. Davis" <lngndvs@gmail.com> writes: [...] > > Once this process is complete, I can see that being able to, in turn copy > this entry to the clipboard would indeed be useful with org-bibtex . I > wonder if it's possible to set a pipe or one of those cryptic file types > (fifo?) I cannot remember would either work, or whether the developers would > agree to enabling this ability. > It sounds like asking the cb2bib developers to either automatically copy completed entries to the clipboard, or to add a button implementing this behavior would be ideal. Barring that there is an existing xclip utility (on debian: apt-get install xclip) which allows for piping data to the clipboard, e.g. with cat ~/references.bib |xclip -selection clipboard will copy the entirety of the references.bib file to the clipboard. As for using xclip to automatically copy any changes to a file to the clipboard, I'm not sure if that is possible, but this may be useful [1]. Best -- Eric Footnotes: [1] http://www.howtoforge.com/triggering-commands-on-file-or-directory-changes-with-incron -- Eric Schulte http://cs.unm.edu/~eschulte/ ^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [ANN] org-bibtex.el --- convert between Org headings and bibtex entries 2011-04-24 14:29 ` Eric Schulte @ 2011-04-24 20:40 ` Alan E. Davis 2011-04-25 13:31 ` Eric Schulte 0 siblings, 1 reply; 33+ messages in thread From: Alan E. Davis @ 2011-04-24 20:40 UTC (permalink / raw) To: Eric Schulte; +Cc: Org Mode [-- Attachment #1: Type: text/plain, Size: 1309 bytes --] On Mon, Apr 25, 2011 at 12:29 AM, Eric Schulte <schulte.eric@gmail.com>wrote: > > It sounds like asking the cb2bib developers to either automatically copy > completed entries to the clipboard, or to add a button implementing this > behavior would be ideal. Indeed, this is about what cb2Bib does, to a good extent, depending on the nature of the reference. A simple text reference, like S J Hickson. On the Sexual Cells and the Early Stages in the Development of Millepora plicata. Philosophical Transactions of the Royal Society of London. B 179, 193 - 204 (1888). may not completely be resolved (not sure in this case): the template on cb2Bib will be partially filled in, and it may require a couple of quick steps to complete the template and save. Unplugging, one may then enter the abstract or other fields, then save. > cat ~/references.bib |xclip -selection clipboard > > will copy the entirety of the references.bib file to the clipboard. > > This is good. Thank you. This will certainly be helpful in some cases. The case for cb2Bib is somewhat different, as once the template is filled in, one may save it to .bib file, and one may select which file. If one were able to use a pipe, xclip, or a fifo file, perhaps this could be made immediately available to org-bibtex-read. Alan [-- Attachment #2: Type: text/html, Size: 2599 bytes --] ^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [ANN] org-bibtex.el --- convert between Org headings and bibtex entries 2011-04-24 20:40 ` Alan E. Davis @ 2011-04-25 13:31 ` Eric Schulte 0 siblings, 0 replies; 33+ messages in thread From: Eric Schulte @ 2011-04-25 13:31 UTC (permalink / raw) To: Alan E. Davis; +Cc: Org Mode "Alan E. Davis" <lngndvs@gmail.com> writes: [...] >> cat ~/references.bib |xclip -selection clipboard >> >> will copy the entirety of the references.bib file to the clipboard. >> >> This is good. Thank you. This will certainly be helpful in some cases. > > The case for cb2Bib is somewhat different, as once the template is filled > in, one may save it to .bib file, and one may select which file. If one > were able to use a pipe, xclip, or a fifo file, perhaps this could be made > immediately available to org-bibtex-read. > With the `org-bibtex-yank' function mentioned (briefly) in one of my previous responses, it is possible to read directly from the top of the kill ring, which (assuming your kill ring is integrated with your clipboard --- which is the case for me, but I don't know if it is a common setup) means that entries can be "yanked" directly from your clipboard into an Org-mode file as a headline. -- Eric Schulte http://cs.unm.edu/~eschulte/ ^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [ANN] org-bibtex.el --- convert between Org headings and bibtex entries 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 7:54 ` Thomas S. Dye @ 2011-04-20 9:26 ` Christian Moe 2011-04-20 20:15 ` Eric Schulte 2011-04-20 12:10 ` Matt Lundin 3 siblings, 1 reply; 33+ messages in thread From: Christian Moe @ 2011-04-20 9:26 UTC (permalink / raw) To: Eric Schulte; +Cc: Org Mode Cool! Thanks for this. I understand the Fireforg project provides part of this functionality (integrated with Zotero), but this free-standing tool looks helpful. Three quick comments: - I tried to just put this on my load path and require it, but there seems to be a name conflict with the existing org-bibtex.el, which provides for BibTeX links. - Trying to create a book type entry, I get prompted only for `:editor', not for `:author'. - Fireforg namespaces the property names with a `BIB_', e.g. `:BIB_author:', and some people might find that useful as an option. - I'd find it helpful with a user option for org-bibtex-fleshout to prompt for optional fields as well. Yours, Christian On 4/20/11 1:52 AM, Eric Schulte wrote: > Hi, > > In an attempt to organize my reading notes, I've written the following > tool which allows both for exporting Org-mode headlines with bibtex > meta-data to bibtex entries, and for reading existing bibtex entries > into Org-mode headings. > > One nice feature of these functions is the ability to check that all > required fields are present in a given headline based on the bibtex type > (e.g., :article, :inproceedings), and prompt for missing fields. > > See the top of the elisp file for more usage information. > https://github.com/eschulte/org-bibtex/blob/master/org-bibtex.el > > Cheers -- Eric > ^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [ANN] org-bibtex.el --- convert between Org headings and bibtex entries 2011-04-20 9:26 ` Christian Moe @ 2011-04-20 20:15 ` Eric Schulte 0 siblings, 0 replies; 33+ messages in thread From: Eric Schulte @ 2011-04-20 20:15 UTC (permalink / raw) To: mail; +Cc: Org Mode Christian Moe <mail@christianmoe.com> writes: > Cool! Thanks for this. I understand the Fireforg project provides part > of this functionality (integrated with Zotero), but this free-standing > tool looks helpful. Three quick comments: > > - I tried to just put this on my load path and require it, but there > seems to be a name conflict with the existing org-bibtex.el, which > provides for BibTeX links. > Oh, good point, I suppose if this is ever winds up in the contrib directory of Org-mode it will need a name change (although no alternate options immediately jump to mind). In the interim I guess you are best off explicitly loading the file with `load'. > > - Trying to create a book type entry, I get prompted only for > :editor', not for `:author'. > Thanks, this is now fixed. > > - Fireforg namespaces the property names with a `BIB_', > e.g. `:BIB_author:', and some people might find that useful as an > option. > I just added a new variable `org-bibtex-prefix' which could be set to e.g., "BIB_" to use such a name prefix. > > - I'd find it helpful with a user option for org-bibtex-fleshout to > prompt for optional fields as well. > Agreed, when `org-bibtex-check' or `org-bibtex-check-all' are called with a prefix argument, they will call `org-bibtex-fleshout' with an optional argument which will result in the inclusion of optional fields. Best -- Eric > > Yours, > Christian > > > On 4/20/11 1:52 AM, Eric Schulte wrote: >> Hi, >> >> In an attempt to organize my reading notes, I've written the following >> tool which allows both for exporting Org-mode headlines with bibtex >> meta-data to bibtex entries, and for reading existing bibtex entries >> into Org-mode headings. >> >> One nice feature of these functions is the ability to check that all >> required fields are present in a given headline based on the bibtex type >> (e.g., :article, :inproceedings), and prompt for missing fields. >> >> See the top of the elisp file for more usage information. >> https://github.com/eschulte/org-bibtex/blob/master/org-bibtex.el >> >> Cheers -- Eric >> > > -- Eric Schulte http://cs.unm.edu/~eschulte/ ^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [ANN] org-bibtex.el --- convert between Org headings and bibtex entries 2011-04-19 23:52 [ANN] org-bibtex.el --- convert between Org headings and bibtex entries Eric Schulte ` (2 preceding siblings ...) 2011-04-20 9:26 ` Christian Moe @ 2011-04-20 12:10 ` Matt Lundin 2011-04-20 20:16 ` Eric Schulte 2011-04-22 14:05 ` [PATCH] " Eric Schulte 3 siblings, 2 replies; 33+ messages in thread From: Matt Lundin @ 2011-04-20 12:10 UTC (permalink / raw) To: Eric Schulte; +Cc: Org Mode Hi Eric, "Eric Schulte" <schulte.eric@gmail.com> writes: > In an attempt to organize my reading notes, I've written the following > tool which allows both for exporting Org-mode headlines with bibtex > meta-data to bibtex entries, and for reading existing bibtex entries > into Org-mode headings. > > One nice feature of these functions is the ability to check that all > required fields are present in a given headline based on the bibtex type > (e.g., :article, :inproceedings), and prompt for missing fields. > > See the top of the elisp file for more usage information. > https://github.com/eschulte/org-bibtex/blob/master/org-bibtex.el Thanks for announcing this! One note: I believe the name conflicts with a core org-module (org-bibtex.el), which is used to store and open bibtex links. Best, Matt ^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [ANN] org-bibtex.el --- convert between Org headings and bibtex entries 2011-04-20 12:10 ` Matt Lundin @ 2011-04-20 20:16 ` Eric Schulte 2011-04-22 14:05 ` [PATCH] " Eric Schulte 1 sibling, 0 replies; 33+ messages in thread From: Eric Schulte @ 2011-04-20 20:16 UTC (permalink / raw) To: Matt Lundin; +Cc: Org Mode Matt Lundin <mdl@imapmail.org> writes: > Hi Eric, > > "Eric Schulte" <schulte.eric@gmail.com> writes: > >> In an attempt to organize my reading notes, I've written the following >> tool which allows both for exporting Org-mode headlines with bibtex >> meta-data to bibtex entries, and for reading existing bibtex entries >> into Org-mode headings. >> >> One nice feature of these functions is the ability to check that all >> required fields are present in a given headline based on the bibtex type >> (e.g., :article, :inproceedings), and prompt for missing fields. >> >> See the top of the elisp file for more usage information. >> https://github.com/eschulte/org-bibtex/blob/master/org-bibtex.el > > Thanks for announcing this! One note: I believe the name conflicts with > a core org-module (org-bibtex.el), which is used to store and open > bibtex links. > Yes, if this is ever included in the contrib directory of Org, the name will have to be changed, although currently I can't think of a good option. Cheers -- Eric > > Best, > Matt > > > -- Eric Schulte http://cs.unm.edu/~eschulte/ ^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [PATCH] org-bibtex.el --- convert between Org headings and bibtex entries 2011-04-20 12:10 ` Matt Lundin 2011-04-20 20:16 ` Eric Schulte @ 2011-04-22 14:05 ` Eric Schulte 2011-04-22 15:45 ` Matt Lundin 1 sibling, 1 reply; 33+ messages in thread From: Eric Schulte @ 2011-04-22 14:05 UTC (permalink / raw) To: Matt Lundin; +Cc: Org Mode [-- Attachment #1: Type: text/plain, Size: 1258 bytes --] Matt Lundin <mdl@imapmail.org> writes: > Hi Eric, > > "Eric Schulte" <schulte.eric@gmail.com> writes: > >> In an attempt to organize my reading notes, I've written the following >> tool which allows both for exporting Org-mode headlines with bibtex >> meta-data to bibtex entries, and for reading existing bibtex entries >> into Org-mode headings. >> >> One nice feature of these functions is the ability to check that all >> required fields are present in a given headline based on the bibtex type >> (e.g., :article, :inproceedings), and prompt for missing fields. >> >> See the top of the elisp file for more usage information. >> https://github.com/eschulte/org-bibtex/blob/master/org-bibtex.el > > Thanks for announcing this! One note: I believe the name conflicts with > a core org-module (org-bibtex.el), which is used to store and open > bibtex links. > As one possible solution to this name conflict, I've folded my org-bibtex.el into the existing org-bibtex.el in the Org-mode core. The attached patch performs this integration adding the functionality in my version of org-bibtex.el into the Org-mode core. Does this seem like an appropriate addition? Thanks -- Eric (p.s. created with "git format-patch" and can be applied using "git am") [-- Attachment #2: 0001-org-bibtex-translating-between-Org-mode-headings-and.patch --] [-- Type: text/x-diff, Size: 20239 bytes --] From d0ec36c11152c342584d5a2145871ebb2b195127 Mon Sep 17 00:00:00 2001 From: Eric Schulte <schulte.eric@gmail.com> Date: Fri, 22 Apr 2011 06:19:30 -0600 Subject: [PATCH] org-bibtex: translating between Org-mode headings and Bibtex entries * lisp/org-bibtex.el: Updating Copyright dates, author information, commentary and history notes. (org-bibtex-types): List of bibtex types with descriptions and required and optional fields. (org-bibtex-fields): List of bibtex fields with descriptions. (*org-bibtex-entries*): Special variable to hold parsed bibtex entries. (org-bibtex-autogen-keys): Custom variable controlling whether bibtex keys are automatically generated (org-bibtex-prefix): Custom variable allowing use of optional prefix for bibtex properties in Org-mode headlines. (org-bibtex-get): Helper function for accessing bibtex elements of a property list. (org-bibtex-put): Helper function for inserting bibtex element into a property list. (org-bibtex-headline): Return a bibtex entry of the given headline as a string. (org-bibtex-ask): Prompt the user to fill in the value of a bibtex field. (org-bibtex-autokey): Generate a bibtex key for the current headline. (org-bibtex-fleshout): Fill in missing bibtex properties of the current headline. (org-bibtex): Export the current Org-mode buffer to a bibtex buffer. (org-bibtex-check): Check that all bibtex properties are present in the current headline. (org-bibtex-check-all): Check all headlines in the current buffer. (org-bibtex-create): Create a new bibtex headline at the current level. (org-bibtex-read): Read the current bibtex entry from a bibtex file. (org-bibtex-write): Write the most recently read bibtex entry into an Org-mode file. --- lisp/org-bibtex.el | 317 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 304 insertions(+), 13 deletions(-) diff --git a/lisp/org-bibtex.el b/lisp/org-bibtex.el index b7b7416..5667a4d 100644 --- a/lisp/org-bibtex.el +++ b/lisp/org-bibtex.el @@ -1,9 +1,10 @@ ;;; org-bibtex.el --- Org links to BibTeX entries ;; -;; Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc. +;; Copyright (C) 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc. ;; ;; Author: Bastien Guerry <bzg at altern dot org> ;; Carsten Dominik <carsten dot dominik at gmail dot com> +;; Eric Schulte <schulte dot eric at gmail dot com> ;; Keywords: org, wp, remember ;; Version: 7.5 ;; @@ -66,12 +67,30 @@ ;; ===================================================================== ;; * READ <== [point here] ;; -;; [[file:/file.bib::dolev83][Dolev & Yao 1983: security of public key protocols]] +;; [[file:file.bib::dolev83][Dolev & Yao 1983: security of public key protocols]] ;; ;; Danny Dolev and Andrew C. Yao (1983): On the security of public-key protocols ;; In IEEE Transaction on Information Theory, 198--208. ;; ===================================================================== ;; +;; Additionally, the following functions are now available for storing +;; bibtex entries within Org-mode documents. +;; +;; - Run `org-bibtex' to export the current file to a .bib. +;; +;; - Run `org-bibtex-check' or `org-bibtex-check-all' to check and +;; fill in missing field of either the current, or all headlines +;; +;; - Run `org-bibtex-create' to add a bibtex entry +;; +;; - Use `org-bibtex-read' to read a bibtex entry after `point' or in +;; the active region, then call `org-bibtex-write' in a .org file to +;; insert a heading for the read bibtex entry +;; +;; - All Bibtex information is taken from the document compiled by +;; Andrew Roberts from the Bibtex manual, available at +;; http://www.andy-roberts.net/misc/latex/sessions/bibtex/bibentries.pdf +;; ;;; History: ;; ;; The link creation part has been part of Org-mode for a long time. @@ -80,12 +99,17 @@ ;; of Austin Frank: http://article.gmane.org/gmane.emacs.orgmode/4112 ;; and then implemented by Bastien Guerry. ;; +;; Eric Schulte eventually added the functions for translating between +;; Org-mode headlines and Bibtex entries, and for fleshing out the Bibtex +;; fields of existing Org-mode headlines. +;; ;; Org-mode loads this module by default - if this is not what you want, ;; configure the variable `org-modules'. ;;; Code: (require 'org) +(require 'bibtex) (defvar description nil) ; dynamically scoped from org.el @@ -94,20 +118,206 @@ (declare-function bibtex-parse-entry "bibtex" (&optional content)) (declare-function bibtex-url "bibtex" (&optional pos no-browse)) +\f +;;; Bibtex data +(defvar org-bibtex-types + '((:article + (:description . "An article from a journal or magazine") + (:required :author :title :journal :year) + (:optional :volume :number :pages :month :note)) + (:book + (:description . "A book with an explicit publisher") + (:required (:editor :author) :title :publisher :year) + (:optional (:volume :number) :series :address :edition :month :note)) + (:booklet + (:description . "A work that is printed and bound, but without a named publisher or sponsoring institution.") + (:required :title) + (:optional :author :howpublished :address :month :year :note)) + (:conference + (:description . "") + (:required :author :title :booktitle :year) + (:optional :editor :pages :organization :publisher :address :month :note)) + (:inbook + (:description . "A part of a book, which may be a chapter (or section or whatever) and/or a range of pages.") + (:required (:author :editor) :title (:chapter :pages) :publisher :year) + (:optional (:volume :number) :series :type :address :edition :month :note)) + (:incollection + (:description . "A part of a book having its own title.") + (:required :author :title :booktitle :publisher :year) + (:optional :editor (:volume :number) :series :type :chapter :pages :address :edition :month :note)) + (:inproceedings + (:description . "An article in a conference proceedings") + (:required :author :title :booktitle :year) + (:optional :editor (:volume :number) :series :pages :address :month :organization :publisher :note)) + (:manual + (:description . "Technical documentation.") + (:required :title) + (:optional :author :organization :address :edition :month :year :note)) + (:mastersthesis + (:description . "A Master’s thesis.") + (:required :author :title :school :year) + (:optional :type :address :month :note)) + (:misc + (:description . "Use this type when nothing else fits.") + (:required) + (:optional :author :title :howpublished :month :year :note)) + (:phdthesis + (:description . "A PhD thesis.") + (:required :author :title :school :year) + (:optional :type :address :month :note)) + (:proceedings + (:description . "The proceedings of a conference.") + (:required :title :year) + (:optional :editor (:volume :number) :series :address :month :organization :publisher :note)) + (:techreport + (:description . "A report published by a school or other institution.") + (:required :author :title :institution :year) + (:optional :type :address :month :note)) + (:unpublished + (:description . "A document having an author and title, but not formally published.") + (:required :author :title :note) + (:optional :month :year))) + "Bibtex entry types with required and optional parameters.") + +(defvar org-bibtex-fields + '((:address . "Usually the address of the publisher or other type of institution. For major publishing houses, van Leunen recommends omitting the information entirely. For small publishers, on the other hand, you can help the reader by giving the complete address.") + (:annote . "An annotation. It is not used by the standard bibliography styles, but may be used by others that produce an annotated bibliography.") + (:author . "The name(s) of the author(s), in the format described in the LaTeX book. Remember, all names are separated with the and keyword, and not commas.") + (:booktitle . "Title of a book, part of which is being cited. See the LaTeX book for how to type titles. For book entries, use the title field instead.") + (:chapter . "A chapter (or section or whatever) number.") + (:crossref . "The database key of the entry being cross referenced.") + (:edition . "The edition of a book for example, 'Second'. This should be an ordinal, and should have the first letter capitalized, as shown here; the standard styles convert to lower case when necessary.") + (:editor . "Name(s) of editor(s), typed as indicated in the LaTeX book. If there is also an author field, then the editor field gives the editor of the book or collection in which the reference appears.") + (:howpublished . "How something strange has been published. The first word should be capitalized.") + (:institution . "The sponsoring institution of a technical report.") + (:journal . "A journal name.") + (:key . "Used for alphabetizing, cross-referencing, and creating a label when the author information is missing. This field should not be confused with the key that appears in the \cite command and at the beginning of the database entry.") + (:month . "The month in which the work was published or, for an unpublished work, in which it was written. You should use the standard three-letter abbreviation,") + (:note . "Any additional information that can help the reader. The first word should be capitalized.") + (:number . "Any additional information that can help the reader. The first word should be capitalized.") + (:organization . "The organization that sponsors a conference or that publishes a manual.") + (:pages . "One or more page numbers or range of numbers, such as 42-111 or 7,41,73-97 or 43+ (the ‘+’ in this last example indicates pages following that don’t form simple range). BibTEX requires double dashes for page ranges (--).") + (:publisher . "The publisher’s name.") + (:school . "The name of the school where a thesis was written.") + (:series . "The name of a series or set of books. When citing an entire book, the the title field gives its title and an optional series field gives the name of a series or multi-volume set in which the book is published.") + (:title . "The work’s title, typed as explained in the LaTeX book.") + (:type . "The type of a technical report for example, 'Research Note'.") + (:volume . "The volume of a journal or multi-volume book.") + (:year . "The year of publication or, for an unpublished work, the year it was written. Generally it should consist of four numerals, such as 1984, although the standard styles can handle any year whose last four nonpunctuation characters are numerals, such as '(about 1984)'")) + "Bibtex fields with descriptions.") + +(defvar *org-bibtex-entries* nil + "List to hold parsed bibtex entries.") + +(defcustom org-bibtex-autogen-keys nil + "Set to a truthy value to use `bibtex-generate-autokey' to generate keys." + :group 'org-bibtex + :type 'boolean) + +(defcustom org-bibtex-prefix nil + "Optional prefix for all bibtex property names. +For example setting to 'BIB_' would allow interoperability with fireforg." + :group 'org-bibtex + :type 'string) + +\f +;;; Utility functions +(defun org-bibtex-get (property) + (or (org-entry-get (point) (upcase property)) + (org-entry-get (point) (concat org-bibtex-prefix (upcase property))))) + +(defun org-bibtex-put (property value) + (let ((prop (upcase (if (keywordp property) + (substring (symbol-name property) 1) + property)))) + (org-set-property + (concat (unless (string= "CUSTOM_ID" prop) org-bibtex-prefix) prop) + value))) + +(defun org-bibtex-headline () + "Return a bibtex entry of the given headline as a string." + (flet ((get (key lst) (cdr (assoc key lst))) + (to-k (string) (intern (concat ":" string))) + (from-k (key) (substring (symbol-name key) 1)) + (flatten (&rest lsts) + (apply #'append (mapcar + (lambda (e) + (if (listp e) (apply #'flatten e) (list e))) + lsts)))) + (let ((notes (buffer-string)) + (id (org-bibtex-get "custom_id")) + (type (org-bibtex-get "type"))) + (when type + (let ((entry (format + "@%s{%s,\n%s\n}\n" type id + (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))))) + ",\n")))) + (with-temp-buffer + (insert entry) + (bibtex-reformat) (buffer-string))))))) + +(defun org-bibtex-ask (field) + (unless (assoc field org-bibtex-fields) + (error "field:%s is not known" field)) + (save-window-excursion + (with-temp-buffer + (setf (buffer-name) (format "*Bibtex Help %s*" field)) + (insert (cdr (assoc field org-bibtex-fields))) + (fill-paragraph) + (pop-to-buffer (current-buffer)) + ((lambda (result) (when (> (length result) 0) result)) + (read-from-minibuffer (format "%s " field)))))) + +(defun org-bibtex-autokey () + "Generate an autokey for the current headline" + (org-bibtex-put "CUSTOM_ID" + (if org-bibtex-autogen-keys + (let ((entry (org-bibtex-headline))) + (with-temp-buffer + (insert entry) + (bibtex-generate-autokey))) + (read-from-minibuffer "id: ")))) + +(defun org-bibtex-fleshout (type &optional optional) + "Fleshout the current heading, ensuring that all required fields are present. +With optional argument OPTIONAL, also prompt for optional fields." + (flet ((get (key lst) (cdr (assoc key lst))) + (name (keyword) (upcase (substring (symbol-name keyword) 1)))) + (dolist (field (append + (remove :title (get :required (get type org-bibtex-types))) + (when optional (get :optional (get type org-bibtex-types))))) + (when (consp field) ; or'd pair of fields e.g., (:editor :author) + (let ((present (first (remove nil + (mapcar + (lambda (f) (when (org-bibtex-get (name f)) f)) + field))))) + (setf field (or present + (intern (org-icompleting-read + "Field: " (mapcar #'symbol-name field))))))) + (let ((name (name field))) + (unless (org-bibtex-get name) + (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"))) + (org-bibtex-autokey))) + +\f +;;; Bibtex link functions (org-add-link-type "bibtex" 'org-bibtex-open) (add-hook 'org-store-link-functions 'org-bibtex-store-link) -;; (defun org-bibtex-publish (path) -;; "Build the description of the BibTeX entry for publishing." -;; (let* ((search (when (string-match "::\\(.+\\)\\'" path) -;; (match-string 1 path))) -;; (path (substring path 0 (match-beginning 0))) -;; key) -;; (with-temp-buffer -;; (org-open-file path t nil search) -;; (setq key (org-create-file-search-functions))) -;; (or description key))) - (defun org-bibtex-open (path) "Visit the bibliography entry on PATH." (let* ((search (when (string-match "::\\(.+\\)\\'" path) @@ -198,6 +408,87 @@ ;; Finally add the link search function to the right hook. (add-hook 'org-execute-file-search-functions 'org-execute-file-search-in-bibtex) +\f +;;; Bibtex <-> Org-mode headline translation functions +(defun org-bibtex () + "Export each headline in the current file to a bibtex entry. +Headlines are exported using `org-bibtex-export-headline'." + (interactive) + (let ((bibtex-entries (remove nil (org-map-entries #'org-bibtex-headline)))) + (with-temp-file (concat (file-name-sans-extension (buffer-file-name)) ".bib") + (insert (mapconcat #'identity bibtex-entries "\n"))))) + +(defun org-bibtex-check (&optional optional) + "Check the current headline for required fields. +With prefix argument OPTIONAL also prompt for optional fields." + (interactive "P") + (save-restriction + (org-narrow-to-subtree) + (let ((type ((lambda (name) (when name (intern (concat ":" name)))) + (org-bibtex-get "TYPE")))) + (when type (org-bibtex-fleshout type optional))))) + +(defun org-bibtex-check-all (&optional optional) + "Check all headlines in the current file. +With prefix argument OPTIONAL also prompt for optional fields." + (interactive) (org-map-entries (lambda () (org-bibtex-check optional)))) + +(defun org-bibtex-create (type) + "Create a new entry at the given level." + (interactive + (list (org-icompleting-read + "Type:" + (mapcar (lambda (type) (symbol-name (car type))) org-bibtex-types)))) + (let ((type (if (keywordp type) type (intern type)))) + (unless (assoc type org-bibtex-types) + (error "type:%s is not known" type)) + (org-insert-heading) + (let ((title (org-bibtex-ask :title))) + (insert title) (org-bibtex-put "TITLE" title)) + (org-bibtex-put "TYPE" (substring (symbol-name type) 1)) + (org-bibtex-fleshout type))) + +(defun org-bibtex-read () + "Read a bibtex entry and save to `*org-bibtex-entries*'. +This uses `bibtex-parse-entry'." + (interactive) + (flet ((keyword (str) (intern (concat ":" (downcase str)))) + (clean-space (str) (replace-regexp-in-string + "[[:space:]\n\r]+" " " str)) + (strip-delim (str) ; strip enclosing "..." and {...} + (dolist (pair '((34 . 34) (123 . 125))) + (when (and (= (aref str 0) (car pair)) + (= (aref str (1- (length str))) (cdr pair))) + (setf str (subseq str 1 (1- (length str)))))) str)) + (push (mapcar + (lambda (pair) + (cons (let ((field (keyword (car pair)))) + (case field + (:=type= :type) + (:=key= :key) + (otherwise field))) + (clean-space (strip-delim (cdr pair))))) + (save-excursion (bibtex-beginning-of-entry) (bibtex-parse-entry))) + *org-bibtex-entries*))) + +(defun org-bibtex-write () + "Insert a heading built from the first element of `*org-bibtex-entries*'." + (interactive) + (when (= (length *org-bibtex-entries*) 0) + (error "No entries in `*org-bibtex-entries*'.")) + (let ((entry (pop *org-bibtex-entries*))) + (flet ((get (field) (cdr (assoc field entry)))) + (org-insert-heading) + (insert (get :title)) + (org-bibtex-put "TITLE" (get :title)) + (org-bibtex-put "TYPE" (downcase (get :type))) + (dolist (pair entry) + (case (car pair) + (:title nil) + (:type nil) + (:key (org-bibtex-put "CUSTOM_ID" (cdr pair))) + (otherwise (org-bibtex-put (car pair) (cdr pair)))))))) + (provide 'org-bibtex) ;; arch-tag: 83987d5a-01b8-41c7-85bc-77700f1285f5 -- 1.7.1 [-- Attachment #3: Type: text/plain, Size: 47 bytes --] -- Eric Schulte http://cs.unm.edu/~eschulte/ ^ permalink raw reply related [flat|nested] 33+ messages in thread
* Re: [PATCH] org-bibtex.el --- convert between Org headings and bibtex entries 2011-04-22 14:05 ` [PATCH] " Eric Schulte @ 2011-04-22 15:45 ` Matt Lundin 2011-04-23 0:03 ` Matt Lundin 0 siblings, 1 reply; 33+ messages in thread From: Matt Lundin @ 2011-04-22 15:45 UTC (permalink / raw) To: Eric Schulte; +Cc: Org Mode Hi Eric, "Eric Schulte" <schulte.eric@gmail.com> writes: > Matt Lundin <mdl@imapmail.org> writes: > >> "Eric Schulte" <schulte.eric@gmail.com> writes: >> >>> In an attempt to organize my reading notes, I've written the following >>> tool which allows both for exporting Org-mode headlines with bibtex >>> meta-data to bibtex entries, and for reading existing bibtex entries >>> into Org-mode headings. >>> >>> One nice feature of these functions is the ability to check that all >>> required fields are present in a given headline based on the bibtex type >>> (e.g., :article, :inproceedings), and prompt for missing fields. >>> >>> See the top of the elisp file for more usage information. >>> https://github.com/eschulte/org-bibtex/blob/master/org-bibtex.el >> >> Thanks for announcing this! One note: I believe the name conflicts with >> a core org-module (org-bibtex.el), which is used to store and open >> bibtex links. >> > > As one possible solution to this name conflict, I've folded my > org-bibtex.el into the existing org-bibtex.el in the Org-mode core. The > attached patch performs this integration adding the functionality in my > version of org-bibtex.el into the Org-mode core. > > Does this seem like an appropriate addition? +1 (or maybe +.75 -- see below) I think this could finally tempt me to move all my bibliographical data into org-mode files. (I've been keeping all my data in a central bibtex file and using reftex to generate links to citations.) My only reservation: modules such as org-bibtex.el, org-gnus.el, org-wl.el. (i.e., modules that contain the name of another emacs package) are conventionally reserved for hyperlinks. I have no idea whether this is a fixed convention, but we might want to ask Bastien or Carsten. I know the linking features would be untouched by the addition of this new functionality, but I wonder whether org <-> bibtex conversion occupies a distinct space. I can see now how the variables org-bibtex-types and org-bibtex-fields are a major improvement over bibtex-entry-field-alist, which contains a whole bunch of redundant field descriptions. This will make it much easier to configure my bibtex setup. Best, Matt ^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [PATCH] org-bibtex.el --- convert between Org headings and bibtex entries 2011-04-22 15:45 ` Matt Lundin @ 2011-04-23 0:03 ` Matt Lundin 2011-04-23 14:07 ` Eric Schulte 0 siblings, 1 reply; 33+ messages in thread From: Matt Lundin @ 2011-04-23 0:03 UTC (permalink / raw) To: Eric Schulte; +Cc: Org Mode Matt Lundin <mdl@imapmail.org> writes: > "Eric Schulte" <schulte.eric@gmail.com> writes: >> As one possible solution to this name conflict, I've folded my >> org-bibtex.el into the existing org-bibtex.el in the Org-mode core. The >> attached patch performs this integration adding the functionality in my >> version of org-bibtex.el into the Org-mode core. >> >> Does this seem like an appropriate addition? > > +1 (or maybe +.75 -- see below) > > I think this could finally tempt me to move all my bibliographical data > into org-mode files. (I've been keeping all my data in a central bibtex > file and using reftex to generate links to citations.) I've been testing the patch and have a few comments. 1. The prompt for the completing-read on line 440 is missing a space. It shows "Type:" rather than "Type: ". 2. In addition, since the symbols in org-bibtex-types are keywords, the completions are in the form ":article", ":book", etc. Might I ask why everything is org-bibtex-type is a keyword? Could we use strings or plain symbols instead? (Note: I haven't read the code carefully enough to see if there is a reason.) 3. The tooltip/help pop-up for org-bibtex-create takes up half a frame. Thanks, Matt ^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [PATCH] org-bibtex.el --- convert between Org headings and bibtex entries 2011-04-23 0:03 ` Matt Lundin @ 2011-04-23 14:07 ` Eric Schulte 2011-04-23 22:46 ` Matt Lundin 0 siblings, 1 reply; 33+ messages in thread From: Eric Schulte @ 2011-04-23 14:07 UTC (permalink / raw) To: Matt Lundin; +Cc: Org Mode [-- Attachment #1: Type: text/plain, Size: 2057 bytes --] Matt Lundin <mdl@imapmail.org> writes: > Matt Lundin <mdl@imapmail.org> writes: > >> "Eric Schulte" <schulte.eric@gmail.com> writes: >>> As one possible solution to this name conflict, I've folded my >>> org-bibtex.el into the existing org-bibtex.el in the Org-mode core. The >>> attached patch performs this integration adding the functionality in my >>> version of org-bibtex.el into the Org-mode core. >>> >>> Does this seem like an appropriate addition? >> >> +1 (or maybe +.75 -- see below) >> >> I think this could finally tempt me to move all my bibliographical data >> into org-mode files. (I've been keeping all my data in a central bibtex >> file and using reftex to generate links to citations.) > > I've been testing the patch and have a few comments. > > 1. The prompt for the completing-read on line 440 is missing a space. It > shows "Type:" rather than "Type: ". > Fixed, Thanks > > 2. In addition, since the symbols in org-bibtex-types are keywords, the > completions are in the form ":article", ":book", etc. Might I ask why > everything is org-bibtex-type is a keyword? Could we use strings or > plain symbols instead? (Note: I haven't read the code carefully > enough to see if there is a reason.) > I tend to prefer keywords for items which are primarily used as keys (e.g., for alist lookup w/assoc), I like that keywords are only interned once and are clearly not variables or functions, however you're right that it may add some extra complexity to this code. I've changed the code which prompts for fields so that it now strips the leading ":" from the keyword names, leading to nicer prompts. > > 3. The tooltip/help pop-up for org-bibtex-create takes up half a frame. > The pop-up buffer with field information should now only be as large as required for the text (although if you have a vertically split frame the buffer will not shrink). It is using the same code used to minimize the help buffer presented by `org-export'. > > Thanks, > Matt > The updated version is contained in the attached patch. [-- Attachment #2: 0001-org-bibtex-translating-between-Org-mode-headings-and.patch --] [-- Type: text/x-diff, Size: 20514 bytes --] From 34f5036409fe77e20c0444ccfcc13cc4be250d92 Mon Sep 17 00:00:00 2001 From: Eric Schulte <schulte.eric@gmail.com> Date: Sat, 23 Apr 2011 08:05:08 -0600 Subject: [PATCH] org-bibtex: translating between Org-mode headings and Bibtex entries * lisp/org-bibtex.el: Updating Copyright dates, author information, commentary and history notes. (org-bibtex-types): List of bibtex types with descriptions and required and optional fields. (org-bibtex-fields): List of bibtex fields with descriptions. (*org-bibtex-entries*): Special variable to hold parsed bibtex entries. (org-bibtex-autogen-keys): Custom variable controlling whether bibtex keys are automatically generated (org-bibtex-prefix): Custom variable allowing use of optional prefix for bibtex properties in Org-mode headlines. (org-bibtex-get): Helper function for accessing bibtex elements of a property list. (org-bibtex-put): Helper function for inserting bibtex element into a property list. (org-bibtex-headline): Return a bibtex entry of the given headline as a string. (org-bibtex-ask): Prompt the user to fill in the value of a bibtex field. (org-bibtex-autokey): Generate a bibtex key for the current headline. (org-bibtex-fleshout): Fill in missing bibtex properties of the current headline. (org-bibtex): Export the current Org-mode buffer to a bibtex buffer. (org-bibtex-check): Check that all bibtex properties are present in the current headline. (org-bibtex-check-all): Check all headlines in the current buffer. (org-bibtex-create): Create a new bibtex headline at the current level. (org-bibtex-read): Read the current bibtex entry from a bibtex file. (org-bibtex-write): Write the most recently read bibtex entry into an Org-mode file. --- lisp/org-bibtex.el | 319 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 306 insertions(+), 13 deletions(-) diff --git a/lisp/org-bibtex.el b/lisp/org-bibtex.el index b7b7416..9ee30f1 100644 --- a/lisp/org-bibtex.el +++ b/lisp/org-bibtex.el @@ -1,9 +1,10 @@ ;;; org-bibtex.el --- Org links to BibTeX entries ;; -;; Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc. +;; Copyright (C) 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc. ;; ;; Author: Bastien Guerry <bzg at altern dot org> ;; Carsten Dominik <carsten dot dominik at gmail dot com> +;; Eric Schulte <schulte dot eric at gmail dot com> ;; Keywords: org, wp, remember ;; Version: 7.5 ;; @@ -66,12 +67,30 @@ ;; ===================================================================== ;; * READ <== [point here] ;; -;; [[file:/file.bib::dolev83][Dolev & Yao 1983: security of public key protocols]] +;; [[file:file.bib::dolev83][Dolev & Yao 1983: security of public key protocols]] ;; ;; Danny Dolev and Andrew C. Yao (1983): On the security of public-key protocols ;; In IEEE Transaction on Information Theory, 198--208. ;; ===================================================================== ;; +;; Additionally, the following functions are now available for storing +;; bibtex entries within Org-mode documents. +;; +;; - Run `org-bibtex' to export the current file to a .bib. +;; +;; - Run `org-bibtex-check' or `org-bibtex-check-all' to check and +;; fill in missing field of either the current, or all headlines +;; +;; - Run `org-bibtex-create' to add a bibtex entry +;; +;; - Use `org-bibtex-read' to read a bibtex entry after `point' or in +;; the active region, then call `org-bibtex-write' in a .org file to +;; insert a heading for the read bibtex entry +;; +;; - All Bibtex information is taken from the document compiled by +;; Andrew Roberts from the Bibtex manual, available at +;; http://www.andy-roberts.net/misc/latex/sessions/bibtex/bibentries.pdf +;; ;;; History: ;; ;; The link creation part has been part of Org-mode for a long time. @@ -80,12 +99,17 @@ ;; of Austin Frank: http://article.gmane.org/gmane.emacs.orgmode/4112 ;; and then implemented by Bastien Guerry. ;; +;; Eric Schulte eventually added the functions for translating between +;; Org-mode headlines and Bibtex entries, and for fleshing out the Bibtex +;; fields of existing Org-mode headlines. +;; ;; Org-mode loads this module by default - if this is not what you want, ;; configure the variable `org-modules'. ;;; Code: (require 'org) +(require 'bibtex) (defvar description nil) ; dynamically scoped from org.el @@ -93,21 +117,209 @@ (declare-function bibtex-generate-autokey "bibtex" ()) (declare-function bibtex-parse-entry "bibtex" (&optional content)) (declare-function bibtex-url "bibtex" (&optional pos no-browse)) +(declare-function longlines-mode "longlines" (&optional arg)) + +\f +;;; Bibtex data +(defvar org-bibtex-types + '((:article + (:description . "An article from a journal or magazine") + (:required :author :title :journal :year) + (:optional :volume :number :pages :month :note)) + (:book + (:description . "A book with an explicit publisher") + (:required (:editor :author) :title :publisher :year) + (:optional (:volume :number) :series :address :edition :month :note)) + (:booklet + (:description . "A work that is printed and bound, but without a named publisher or sponsoring institution.") + (:required :title) + (:optional :author :howpublished :address :month :year :note)) + (:conference + (:description . "") + (:required :author :title :booktitle :year) + (:optional :editor :pages :organization :publisher :address :month :note)) + (:inbook + (:description . "A part of a book, which may be a chapter (or section or whatever) and/or a range of pages.") + (:required (:author :editor) :title (:chapter :pages) :publisher :year) + (:optional (:volume :number) :series :type :address :edition :month :note)) + (:incollection + (:description . "A part of a book having its own title.") + (:required :author :title :booktitle :publisher :year) + (:optional :editor (:volume :number) :series :type :chapter :pages :address :edition :month :note)) + (:inproceedings + (:description . "An article in a conference proceedings") + (:required :author :title :booktitle :year) + (:optional :editor (:volume :number) :series :pages :address :month :organization :publisher :note)) + (:manual + (:description . "Technical documentation.") + (:required :title) + (:optional :author :organization :address :edition :month :year :note)) + (:mastersthesis + (:description . "A Master’s thesis.") + (:required :author :title :school :year) + (:optional :type :address :month :note)) + (:misc + (:description . "Use this type when nothing else fits.") + (:required) + (:optional :author :title :howpublished :month :year :note)) + (:phdthesis + (:description . "A PhD thesis.") + (:required :author :title :school :year) + (:optional :type :address :month :note)) + (:proceedings + (:description . "The proceedings of a conference.") + (:required :title :year) + (:optional :editor (:volume :number) :series :address :month :organization :publisher :note)) + (:techreport + (:description . "A report published by a school or other institution.") + (:required :author :title :institution :year) + (:optional :type :address :month :note)) + (:unpublished + (:description . "A document having an author and title, but not formally published.") + (:required :author :title :note) + (:optional :month :year))) + "Bibtex entry types with required and optional parameters.") + +(defvar org-bibtex-fields + '((:address . "Usually the address of the publisher or other type of institution. For major publishing houses, van Leunen recommends omitting the information entirely. For small publishers, on the other hand, you can help the reader by giving the complete address.") + (:annote . "An annotation. It is not used by the standard bibliography styles, but may be used by others that produce an annotated bibliography.") + (:author . "The name(s) of the author(s), in the format described in the LaTeX book. Remember, all names are separated with the and keyword, and not commas.") + (:booktitle . "Title of a book, part of which is being cited. See the LaTeX book for how to type titles. For book entries, use the title field instead.") + (:chapter . "A chapter (or section or whatever) number.") + (:crossref . "The database key of the entry being cross referenced.") + (:edition . "The edition of a book for example, 'Second'. This should be an ordinal, and should have the first letter capitalized, as shown here; the standard styles convert to lower case when necessary.") + (:editor . "Name(s) of editor(s), typed as indicated in the LaTeX book. If there is also an author field, then the editor field gives the editor of the book or collection in which the reference appears.") + (:howpublished . "How something strange has been published. The first word should be capitalized.") + (:institution . "The sponsoring institution of a technical report.") + (:journal . "A journal name.") + (:key . "Used for alphabetizing, cross-referencing, and creating a label when the author information is missing. This field should not be confused with the key that appears in the \cite command and at the beginning of the database entry.") + (:month . "The month in which the work was published or, for an unpublished work, in which it was written. You should use the standard three-letter abbreviation,") + (:note . "Any additional information that can help the reader. The first word should be capitalized.") + (:number . "Any additional information that can help the reader. The first word should be capitalized.") + (:organization . "The organization that sponsors a conference or that publishes a manual.") + (:pages . "One or more page numbers or range of numbers, such as 42-111 or 7,41,73-97 or 43+ (the ‘+’ in this last example indicates pages following that don’t form simple range). BibTEX requires double dashes for page ranges (--).") + (:publisher . "The publisher’s name.") + (:school . "The name of the school where a thesis was written.") + (:series . "The name of a series or set of books. When citing an entire book, the the title field gives its title and an optional series field gives the name of a series or multi-volume set in which the book is published.") + (:title . "The work’s title, typed as explained in the LaTeX book.") + (:type . "The type of a technical report for example, 'Research Note'.") + (:volume . "The volume of a journal or multi-volume book.") + (:year . "The year of publication or, for an unpublished work, the year it was written. Generally it should consist of four numerals, such as 1984, although the standard styles can handle any year whose last four nonpunctuation characters are numerals, such as '(about 1984)'")) + "Bibtex fields with descriptions.") + +(defvar *org-bibtex-entries* nil + "List to hold parsed bibtex entries.") + +(defcustom org-bibtex-autogen-keys nil + "Set to a truthy value to use `bibtex-generate-autokey' to generate keys." + :group 'org-bibtex + :type 'boolean) + +(defcustom org-bibtex-prefix nil + "Optional prefix for all bibtex property names. +For example setting to 'BIB_' would allow interoperability with fireforg." + :group 'org-bibtex + :type 'string) + +\f +;;; Utility functions +(defun org-bibtex-get (property) + (or (org-entry-get (point) (upcase property)) + (org-entry-get (point) (concat org-bibtex-prefix (upcase property))))) +(defun org-bibtex-put (property value) + (let ((prop (upcase (if (keywordp property) + (substring (symbol-name property) 1) + property)))) + (org-set-property + (concat (unless (string= "CUSTOM_ID" prop) org-bibtex-prefix) prop) + value))) + +(defun org-bibtex-headline () + "Return a bibtex entry of the given headline as a string." + (flet ((get (key lst) (cdr (assoc key lst))) + (to-k (string) (intern (concat ":" string))) + (from-k (key) (substring (symbol-name key) 1)) + (flatten (&rest lsts) + (apply #'append (mapcar + (lambda (e) + (if (listp e) (apply #'flatten e) (list e))) + lsts)))) + (let ((notes (buffer-string)) + (id (org-bibtex-get "custom_id")) + (type (org-bibtex-get "type"))) + (when type + (let ((entry (format + "@%s{%s,\n%s\n}\n" type id + (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))))) + ",\n")))) + (with-temp-buffer + (insert entry) + (bibtex-reformat) (buffer-string))))))) + +(defun org-bibtex-ask (field) + (unless (assoc field org-bibtex-fields) + (error "field:%s is not known" field)) + (save-window-excursion + (let* ((name (substring (symbol-name field) 1)) + (buf-name (format "*Bibtex Help %s*" name))) + (with-output-to-temp-buffer buf-name + (princ (cdr (assoc field org-bibtex-fields)))) + (with-current-buffer buf-name (longlines-mode t)) + (org-fit-window-to-buffer (get-buffer-window buf-name)) + ((lambda (result) (when (> (length result) 0) result)) + (read-from-minibuffer (format "%s: " name)))))) + +(defun org-bibtex-autokey () + "Generate an autokey for the current headline" + (org-bibtex-put "CUSTOM_ID" + (if org-bibtex-autogen-keys + (let ((entry (org-bibtex-headline))) + (with-temp-buffer + (insert entry) + (bibtex-generate-autokey))) + (read-from-minibuffer "id: ")))) + +(defun org-bibtex-fleshout (type &optional optional) + "Fleshout the current heading, ensuring that all required fields are present. +With optional argument OPTIONAL, also prompt for optional fields." + (flet ((get (key lst) (cdr (assoc key lst))) + (keyword (name) (intern (concat ":" (downcase name)))) + (name (keyword) (upcase (substring (symbol-name keyword) 1)))) + (dolist (field (append + (remove :title (get :required (get type org-bibtex-types))) + (when optional (get :optional (get type org-bibtex-types))))) + (when (consp field) ; or'd pair of fields e.g., (:editor :author) + (let ((present (first (remove nil + (mapcar + (lambda (f) (when (org-bibtex-get (name f)) f)) + field))))) + (setf field (or present (keyword (org-icompleting-read + "Field: " (mapcar #'name field))))))) + (let ((name (name field))) + (unless (org-bibtex-get name) + (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"))) + (org-bibtex-autokey))) + +\f +;;; Bibtex link functions (org-add-link-type "bibtex" 'org-bibtex-open) (add-hook 'org-store-link-functions 'org-bibtex-store-link) -;; (defun org-bibtex-publish (path) -;; "Build the description of the BibTeX entry for publishing." -;; (let* ((search (when (string-match "::\\(.+\\)\\'" path) -;; (match-string 1 path))) -;; (path (substring path 0 (match-beginning 0))) -;; key) -;; (with-temp-buffer -;; (org-open-file path t nil search) -;; (setq key (org-create-file-search-functions))) -;; (or description key))) - (defun org-bibtex-open (path) "Visit the bibliography entry on PATH." (let* ((search (when (string-match "::\\(.+\\)\\'" path) @@ -198,6 +410,87 @@ ;; Finally add the link search function to the right hook. (add-hook 'org-execute-file-search-functions 'org-execute-file-search-in-bibtex) +\f +;;; Bibtex <-> Org-mode headline translation functions +(defun org-bibtex () + "Export each headline in the current file to a bibtex entry. +Headlines are exported using `org-bibtex-export-headline'." + (interactive) + (let ((bibtex-entries (remove nil (org-map-entries #'org-bibtex-headline)))) + (with-temp-file (concat (file-name-sans-extension (buffer-file-name)) ".bib") + (insert (mapconcat #'identity bibtex-entries "\n"))))) + +(defun org-bibtex-check (&optional optional) + "Check the current headline for required fields. +With prefix argument OPTIONAL also prompt for optional fields." + (interactive "P") + (save-restriction + (org-narrow-to-subtree) + (let ((type ((lambda (name) (when name (intern (concat ":" name)))) + (org-bibtex-get "TYPE")))) + (when type (org-bibtex-fleshout type optional))))) + +(defun org-bibtex-check-all (&optional optional) + "Check all headlines in the current file. +With prefix argument OPTIONAL also prompt for optional fields." + (interactive) (org-map-entries (lambda () (org-bibtex-check optional)))) + +(defun org-bibtex-create (type) + "Create a new entry at the given level." + (interactive + (list (org-icompleting-read + "Type: " + (mapcar (lambda (type) (symbol-name (car type))) org-bibtex-types)))) + (let ((type (if (keywordp type) type (intern type)))) + (unless (assoc type org-bibtex-types) + (error "type:%s is not known" type)) + (org-insert-heading) + (let ((title (org-bibtex-ask :title))) + (insert title) (org-bibtex-put "TITLE" title)) + (org-bibtex-put "TYPE" (substring (symbol-name type) 1)) + (org-bibtex-fleshout type))) + +(defun org-bibtex-read () + "Read a bibtex entry and save to `*org-bibtex-entries*'. +This uses `bibtex-parse-entry'." + (interactive) + (flet ((keyword (str) (intern (concat ":" (downcase str)))) + (clean-space (str) (replace-regexp-in-string + "[[:space:]\n\r]+" " " str)) + (strip-delim (str) ; strip enclosing "..." and {...} + (dolist (pair '((34 . 34) (123 . 125))) + (when (and (= (aref str 0) (car pair)) + (= (aref str (1- (length str))) (cdr pair))) + (setf str (subseq str 1 (1- (length str)))))) str)) + (push (mapcar + (lambda (pair) + (cons (let ((field (keyword (car pair)))) + (case field + (:=type= :type) + (:=key= :key) + (otherwise field))) + (clean-space (strip-delim (cdr pair))))) + (save-excursion (bibtex-beginning-of-entry) (bibtex-parse-entry))) + *org-bibtex-entries*))) + +(defun org-bibtex-write () + "Insert a heading built from the first element of `*org-bibtex-entries*'." + (interactive) + (when (= (length *org-bibtex-entries*) 0) + (error "No entries in `*org-bibtex-entries*'.")) + (let ((entry (pop *org-bibtex-entries*))) + (flet ((get (field) (cdr (assoc field entry)))) + (org-insert-heading) + (insert (get :title)) + (org-bibtex-put "TITLE" (get :title)) + (org-bibtex-put "TYPE" (downcase (get :type))) + (dolist (pair entry) + (case (car pair) + (:title nil) + (:type nil) + (:key (org-bibtex-put "CUSTOM_ID" (cdr pair))) + (otherwise (org-bibtex-put (car pair) (cdr pair)))))))) + (provide 'org-bibtex) ;; arch-tag: 83987d5a-01b8-41c7-85bc-77700f1285f5 -- 1.7.1 [-- Attachment #3: Type: text/plain, Size: 266 bytes --] Thanks for your feedback. I hope to hear from Carsten or Bastien (the authors of the current org-bibtex) about whether this is the right place for this functionality or if it should live somewhere else. Best -- Eric -- Eric Schulte http://cs.unm.edu/~eschulte/ ^ permalink raw reply related [flat|nested] 33+ messages in thread
* Re: [PATCH] org-bibtex.el --- convert between Org headings and bibtex entries 2011-04-23 14:07 ` Eric Schulte @ 2011-04-23 22:46 ` Matt Lundin 0 siblings, 0 replies; 33+ messages in thread From: Matt Lundin @ 2011-04-23 22:46 UTC (permalink / raw) To: Eric Schulte; +Cc: Org Mode "Eric Schulte" <schulte.eric@gmail.com> writes: >> 2. In addition, since the symbols in org-bibtex-types are keywords, the >> completions are in the form ":article", ":book", etc. Might I ask why >> everything is org-bibtex-type is a keyword? Could we use strings or >> plain symbols instead? (Note: I haven't read the code carefully >> enough to see if there is a reason.) > > I tend to prefer keywords for items which are primarily used as keys > (e.g., for alist lookup w/assoc), I like that keywords are only interned > once and are clearly not variables or functions, however you're right > that it may add some extra complexity to this code. > > I've changed the code which prompts for fields so that it now strips the > leading ":" from the keyword names, leading to nicer prompts. > Thanks for the fixes! My chief interest in using strings instead of keywords is to make it easier to generate the value of bibtex-entry-field-alist from org-bibtex-types and org-bibtex-fields. But if I'm already going to go the trouble of rearranging the lists, changing the keywords to strings shouldn't be too much trouble. :) Best, Matt ^ permalink raw reply [flat|nested] 33+ messages in thread
end of thread, other threads:[~2011-04-28 1:48 UTC | newest] Thread overview: 33+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 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 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
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).