# Single LyX file with multiple bib file

I am writing my thesis in LyX. It's a collection with 3 separate .bib files with jab ref. I inserted the three bib file in three different places. But the pdf output seem to only use the first bib file at all three different places. I can merge the bib file into one. I am just curious if there is a way to avoid doing that.

• – moewe Mar 11 '16 at 15:17
• I am using lyx. How should I do it depending on that answer? – Yan Song Mar 11 '16 at 15:53
• If you want a per-section bibliography have a look at how to create separate bibliography per chapter in lyx – moewe Mar 11 '16 at 15:56
• I don't see a solution in that thread. – Yan Song Mar 11 '16 at 16:11
• Well, you have to be a bit creative ;-). Have you read the links in my comment there? Can you answer the questions in the comment (i.e. do you want to use biblatex, etc.)? – moewe Mar 11 '16 at 16:17

This assumes you have already set up your LyX document to use biblatex (with Biber). Please see the LyX wiki for more. In short you will have to have

1. Biber set up (No Bibliography is printed and citations shown bibtex key) via "Document→Settings→Bibliography" or "Tools→Preferences→Output→LaTeX"
2. Call biblatex in the preamble. Go to "Document→Settings→LaTeX Preamble" and load biblatex with all the needed options

\usepackage[style=authoryear,backend=biber,refsection=section]{biblatex}


for example

3. Add your .bib file to the preamble. Go to "Document→Settings→LaTeX Preamble" and add a call to \addbibresource{full/path/of/your/bib/file}. Note that you will have to give an absolute path, relative paths are only supported for files in the local texmf tree.

If you want a per-chapter bibliography, all you need to do is to add the refsection option to the biblatex call in "Document→Settings→LaTeX Preamble".

4. Insert a BibTeX bibliography "Insert→List/TOC→BibTeX Bibliography..." in a note (see BibLaTex, Biber and Lyx: how to resolve \bibliographystyle error?), but still using the correct database. This is to make sure that LyX finds the citations.

5. Add \printbibliography in an ERT block.

If you want a per-section bibliography, call biblatex in the preamble with

\usepackage[style=authoryear,backend=biber,refsection=section]{biblatex}


The document then is straightforward. Each section will be in its own refsection.

You will need one \printbibliography in the ERT block for each chapter

gives

Manual refsections are as easy as well. You just need to make sure to not call biblatex with anything other than refsection=none (not giving the argument is equivalent to refsection=none), that is important since refsections cannot be nested.

You will just have to insert \newrefsection and \begin{refsection}...\end{refsection}in ERT blocks in the appropriate places.

gives

• Thanks a lot for the detailed answer. I did every step. But there still seem to be some errors. It says package biblatex error: nested refsection environment. I used \begin{refsection} at the beginning of chapter one,ended that refsection at the end of chapter one. and used \newrefsection at chapter 2. – Yan Song Mar 11 '16 at 18:21
• @YanSong If you use refsection=section as in the first example there is no need for manual refsections. Everything will be done per \section (or \chapter if you choose refsection=chapter.) Otherwise I would need to see what you are doing. You can't have \begin{refsection}\newrefsection\end{refsection}. – moewe Mar 11 '16 at 18:33
• Ok. I figured out what's wrong. Since I used refsection in the preamble, I don't need to manually set it again. I removed the begin refsection and the document is compiling. But the output pdf does not have any citations shown at all now. – Yan Song Mar 11 '16 at 18:34
• @YanSong Can you compile a normal biblatex example without problems, i.e. is LyX set up correctly to deal with biblatex and Biber? – moewe Mar 11 '16 at 18:37
• A minimal working example failed. I need to check what's wrong. – Yan Song Mar 11 '16 at 18:47

You can add all three files in the one place. In the dialogue box just keep clicking on the "add" button, even though there's one already there. But then you get a single bibliography typeset into your document. Is that what you want? Having three different bibliography sections might be more complicated.

• I was hoping to get three different bibliography sections. This is a essay based thesis so it makes more sense to have a reference section for each paper. – Yan Song Mar 11 '16 at 15:33