Hi,

I created a patch implementing the "bibtex-insert" function, please see 

http://www.lyx.org/trac/ticket/8368

This is an attempt to enhance the workflow with external bibliography managers, 
by providing a new LFUN command "bibtex-insert" that takes one argument, a 
BibTeX fragment (i.e. one or more entries), and

1) Update the first LyX managed bibliography file (for the moment, it checks if 
the string lyxmanagedequals true, i.e. if @string{lyxmanaged = "true"} is in 
the BibTeX file) that occurs in a bibtex inset after the cursor position.
For the moment, nothing is done if no LyX managed file exists (the function 
exits with an error).
2) Insert citations to all the bibtex entries given as an argument (or update 
if before/after a citation inset)

The patch basically refactored the code that was used to parse a BibTeX file 
(in InsetBibtex.cpp), so it can be used to parse the managed file without 
updating any buffer cache, in order to update the BibTeX file. I also changed 
the information stored for each bibtex file in order to store the last update 
timestamp as well as the "managed" flag.

I plan to enhance the patch in order to answer to suggestions and remarks, 
especially regarding improving what happens if no LyX managed bibliography 
exists (also, maybe it would be better to have a header to mark a file as "LyX 
managed" like 
% LyX managed file as the first line of the file, rather than a BibTeX string?).

Benjamin

On Jun 15, 2012, at 09:20 , Benjamin Piwowarski <benjamin.piwowar...@lip6.fr> 
wrote:

> 
> On Jun 14, 2012, at 16:10 , Richard Heck wrote:
> 
>> On 06/13/2012 07:54 AM, Rainer M Krug wrote:
>>> While we are at that subject what is missing in the citation management, I 
>>> would like to see two things:
>>> 1) the possibility to create a local .bib file (in the directory of the 
>>> .lyx file) which contains only the references used. This would make 
>>> co-operation between authors much easier. If this file could be embedded in 
>>> the .lyx file, this would be brilliant, although this is not necessary, as 
>>> other external files also exist.
>>> 
>> I'm not sure exactly how you want this to work, but it can easily enough be 
>> done with aux2bib. The downside to this method, to my mind, is that it's 
>> one-off: Once you've created this custom bib file, you've lost the ability 
>> to cite anything from your other bib file. So I tend to do this only at the 
>> end, or near it.
> 
> Here is more precisely the plan.
> 
> First, we need a function that gets the active BibTeX insets - i.e. the 
> bibliography insets that would be used by a citation at this point of the 
> file. This should deal with sectioned bibliographies, but in order to work 
> with those, would need to use a LyX inset to separate bibliographies. Once we 
> have a list of BibTex insets, we can check for LyX managed BibTeX files 
> (using a special header in the .bib file - managed bibs in the following) 
> that LyX has the right to modify. 
> 
> When we need to update a LyX managed BibTeX file, the process would go a bit 
> further, by - if needed - (1) Proposing to create a BibTeX inset at the end 
> of the file and (2) creating a managed bib in one of the insets (The first? 
> Ask the user?) 
> 
> Only one function is really needed for basic functionality, that is a 
> function that add/update one BibTeX entry
> 
> bibtex-entries-put <entry>
> 
> It would either identify a managed file where the entry exists and update it 
> (by re-writing only the entry), or add it to one of the managed bib. In order 
> to update a BibTeX file, LyX can mostly rely on the BibTeX parsing code 
> already present and copy the file up to the entry, replace the entry by the 
> one given, and then copy the rest of the file. This does seem to be difficult 
> to achieve.
> 
> If you agree on this, I will start (I would like to target 2.1) to work on it 
> and post a patch on the list when ready.
> 
> Benjamin
> 

Reply via email to