Sunday, 20 February 2011

How to import a new citation style in LyX

This post is for my own future reference, and for the use of any other users of LyX for Windows, because there seems to be very little documentation out there that doesn't assume a lot of prior knowledge.

I had an extended essay to write over the Christmas holidays: 3000-5000 words, roughly 10% of my final grade, and most relevantly, it needed proper references, and LOTS of them. The guidelines stated citations should use the style found in the journal Cell - Harvard-style referencing, which I personally hate, never mind. The default citation style in LyX is bracketed numbers, like so [1]. It took me some trial and error and far too much time to figure out how to change this, so hopefully this will save other people some bother.



  • You will need to find the .sty and .bst files for the citation style you would like to use. I found mine here, but I'm sure there are other resources around. Google is your friend.
  • These should be saved in the same locations as existing .sty and .bst files. For me, these were:
    • .sty: User/AppData/Roaming/MiKTex/2.9/tex/latex
    • .bst: User/AppData/Roaming/MiKTex/2.9/bibtex/bst
  • Save each file in its own folder. Don't put any spaces in the file or folder name, because BibTeX can't cope with spaces!
  • To check that LyX has found these files, use Tools --> Tex info --> BibTex styles and look for the .bst file.
  • When inserting your bibliography, select the style you want to use by browsing for the appropriate .bst file.
  • I had to use the Natbib citation style (Document --> Settings --> Bibliography); this may vary depending on the style you use.
  • Important note: this actually didn't work as it should do, and I (read = my more programming-knowledgeable boyfriend) had to mess with the LaTeX source code.
  • In the source code, you need to switch two lines in the preamble, so that "babel" comes before "natbib", like so:
    • \usepackage{babel}
      \usepackage[authoryear]{natbib}
  •  I also found that my bibliography didn't appear in the output file unless I edited that, as well, so that the code (this time at the end of the document) looks like this:
    • \bibliographystyle{path to your .bst file here}
      \addcontentsline{toc}{section}{\refname}
      \bibliography{path to your .bib file here}
In the end, it worked, and looked as nice as I had hoped, but it didn't simplify the process of adding citations at all, just gave me different problems! Next time round, when I write up my lab project report, I will be using straightforward LaTeX and muddling through as best as I can. LyX was supposed to make things easier, but it didn't for me.

Disclaimer: This worked for me, but I don't know how it works. Hopefully it will help other people, but I claim no responsibility if it doesn't fix your problem. Sorry!

5 comments:

  1. I had the same problem with LyX 2.0. However after failing several times, in the end I discovered that what was necessary to have it working was to chose "natbib" and "author-year" in the Bibliography settings, in Document settings, without adding anything related in the preamble.
    The LyX wiki is somehow misleading.

    ReplyDelete
  2. thanks so much, this was really helpful! don't ever take this page down, i'm bookmarking it. :)

    ReplyDelete
  3. thanks for the tips, having trouble getting the bibliography to appear in the output, which is starting to annoy me. Can anyone point me to another guide like this?

    ReplyDelete
  4. Thanks this was really helpful!

    ReplyDelete
  5. Remarkable blog! I have no words to praise, it has really allured me.best sitation service

    ReplyDelete