[Tex/LaTex] BibLaTex, Biber and Lyx: how to resolve \bibliographystyle error

biberbiblatexlyx

I want to learn to use biper and biblatex in Lyx. This is how I would do it in LaTeX traditionally with biblatex and biber

\documentclass[12pt,a4paper,oneside,pdftex]{report}
\usepackage[backend=biber]{biblatex}
\addbibresource{minCuts.bib}
...
\printbibliography
\end{document}

The error is apparently originating from the \bibliographystyle command and biblatex package getting mixed, by this. But I have no \bibliographystyle command in Preamble so they should not be mixed unless Lyx is somehow importing the \bibliographystyle.

How to resolve the biblioraphystyle error in Lyx with Biber and Biblatex?


Settings by the instructions here and Error

  1. Document > Settings > Bibliography > Biber

enter image description here

  1. In Document > Settings > LaTeX Preamble

enter image description here

  1. Insert > List / TOC > BibTeX Bibliography…

enter image description here

enter image description here

  1. Package biblatex Error : '\bibliographystyle' invalid.

enter image description here

Best Answer

When adding a BibTeX bibliography via Insert --> List/ToC --> BibTeX bibliography you need to put this into a comment (Insert --> Note --> Comment) or LyX note (Insert --> Note --> LyX note). If not, \bibliography and \bibliographystyle will be active in the generated LaTeX code and that is incompatible with biblatex. To quote the wiki page you refer to:

In the document, insert the BibTeX inset (Insert→List/TOC→BibTeX Bibliography...) in a LyX note or comment, such that LyX finds the citations, but no \bibliography command is output to LaTeX.

(Emphasis mine.)

Note that it is not really required to insert the BibTeX bibliography, but it makes things much easier at it makes LyX aware of your .bib file, and you can therefore add citations via the GUI. If you don't do this I think you need to use TeX code boxes/ERTs (Ctrl/Cmd + L) and add e.g. \autocite{dude2015} as code.


So to quickly repeat the instructions from the wiki:

  1. In Document --> Settings --> LaTeX preamble add

    \usepackage[style=authoryear]{biblatex}
    \addbibresource{/path/to/bibfile.bib} 
    

    close the settings.

  2. Do Insert --> Note --> Comment followed by Insert --> List/ToC --> BibTeX bibliography. Find your .bib file.

  3. Move the cursor outside the Comment inset. Add a TeX code inset (Cmd/Ctrl + L) and write \printbibliography here.

    (A TeX code inset is often called an ERT, for "evil red text".)

It might look like

enter image description here