LaTeX forum ⇒ LyXHow to prevent LyX from using natbib commands - Tufte Handout layout bug

Information and discussion about LyX, a WYSIWYM editor, available for Linux, Windows and Mac OS X systems.
Posts: 8
Joined: Sat Aug 27, 2016 1:46 pm

How to prevent LyX from using natbib commands - Tufte Handout layout bug

Postby juliendutant » Sun Jan 13, 2019 10:13 pm

LyX's new bibliography management is great, but it seems to have broken down the Tufte Handout layout. I think the solution would be to update the layout to tell LyX to use \cite instead of \citep and \citet commands, or at least to make available "Basic Numerical" variant in the Settings, or "[#ID]" citations in the citation dialog box. And to do so even though the tufte-handout class loads natbib. Does anyone know how to do this?

The bug with Tufte Handout

Create a new document with a BibTex bibliography that uses the Natbib (BibTex) engine. Put a citation in your document. Now change the document class to Tufte Handout. Compile. You will notice that the citation appears in your text, e.g. as [1] or (Author 2012). But Tufte Handout citations should appear in full as margin notes.

Now in the LyX file insert a raw LaTeX box with a cite command: \cite{AuthorXXX}, where AuthorXXX is a bibtex key from your bibliography. Compile. You will see that the citation appears as a margin note, as desired in this layout.

I also encounter a bug when I start with a document with a Bibtex bibliography using the Basic (BibTex) engine. When I convert it to Tufte Handout, in the Document Settings the biblio engine is locked to Natbib (BibTex), but the variant remains empty. In my case, this document doesn't compile: I get a LaTeX error of option clash on the package textcomp ("The package textcomp has already been loaded with options: [], There has now been an attempt to load it with options [full]). Selecting one of the natbib variants doesn't help.

The old Tufte Handout document that works

If you load the LyX example file for Tufte Handout, however, you'll see that it compiles well. The citations, in particular, appear in full in margin notes as they should. If you export the document as LaTeX (pdflatex), you will notice that it uses \cite commands, not natbib's \citet and \citep. This is how the tufte-handout class works: it loads natbib to typeset full citations, it leaves \citet and \citep as inline citations, but it uses \cite for its preferred way of citing: full citation in a margin note.

For LyX to handle that well, it must accept that natbib is loaded, but allow the "Basic numerical" citing style. This is what happens with that old lyx file works. If you look at its Document settings > Bibliography, you'll notice something strange: the citation format is locked on "Natbib (BibTex)" with the variant "Basic Numerical". Somehow this allows LyX to know that Natbib is loaded, but still use \cite commands.

The problem is that it's not possible to enter that set-up manually. If you start from a new file, as I explained above, you won't get the desired citations unless you enter them as raw latex code.

So as it stands the only way to use Tufte-Handout is to load the example file and modify it.

How to solve the bug?

Ideally we would want the tufte-handout.layout file to:

(a) lock Natbib (Bibtex) as the engine, but
(b) enforce, or at least make available, basic \cite commands in the citation dialog.

Does anyone know if that can be done? Tufte Handout is a great layout, it'd be great to make it work out of the box again.

Posts: 8
Joined: Sat Aug 27, 2016 1:46 pm

Postby juliendutant » Sat Jan 26, 2019 9:15 pm

A quick fix..

Update: this is solved by adding the following line in Document > Settings > Local Layout:

  1. Input ../citeengines/basic.citeengine

(note This is in MacOS. In Windows you may have to use forward slashes.)

Here's my understanding of why this works. Because the Tufte layout includes "Provides natbib-internal 1", Lyx automatically loads the natbib.citeengine file. This comes with natbib citations styles 'author-year' and 'author-numerical' that don't issue the basic "\cite" LaTeX command that we want. By adding this line in the local layout, LyX loads the basic.citeengine file after having loaded natbib.citeengine, which in effect overrides the definitions in natbib.citeengine. So we end up with the default numerical style and the desired "\cite" commands.

... but not solved yet

Strangely, adding that line in the layout file doesn't work.

I have tried adding "Input ../citeengines/basic.citeengine"at the end of tufte-book.layout. It doesn't work. (I have reconfigured, closed and reopened LyX.) The document opens with the natbib citation engine: in Document > Settings > Biblio, you see the choice between author-year and author-numerical, and the LaTeX code issued contains the natbib commands \citep , \citealp instead of the basic \cite command. If you then apply the fix, adding the line in Local layout, the problem disappears: in Document > Settings > Biblio, the citation style is empty and can't be selected, and the document generates \cite commands.

Does LyX choose its citation engine *after* having loaded the document layout but *before* loading the local layout? This would explain why loading basic.citeengine works in the local layout but not in the class layout file.

What would solve the problem would be to be able to specify the cite engine in the layout file. However, reading the documentation on the .layout file format (in the Customization help) I don't see any parameter that does that.
Last edited by juliendutant on Sun Feb 03, 2019 5:13 pm, edited 1 time in total.

Posts: 8
Joined: Sat Aug 27, 2016 1:46 pm

Postby juliendutant » Sat Jan 26, 2019 9:33 pm

Another quick but temporary fix

Here's another fix. Create a new document, put it in the Tufte class, save it. If you have a look at Document > Settings > Biblio you'll see that the only choice of citation style is "author year" or "author numerical".

Open the .lyx file in a text editor and replace:

  1. \cite_engine natbib
  2. \cite_engine_type authoryear

(you may see "numerical" instead of "authoryear") by:

  1. \cite_engine basic
  2. \cite_engine_type default

Save it. Open it in LyX again. Now if you check Document > Settings > Biblio the citation style is locked to "basic numerical". The document will issue "\cite" LaTeX commands, which will result in citations in the margin, as desired with the Tufte class.

So again the problem is that with LyX's new bibliography management, we can't use the (admittedly weird) combination of settings that the Tufte class requires: natbib with the basic \cite command. The best would be to somehow indicate in the layout file that the cite engine must be basic.citeengine.

User avatar
Stefan Kottwitz
Site Admin
Posts: 9413
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Sun Jan 27, 2019 11:15 am

Thank you for this lot of information!

I guess I would try to deactivate natbib (take it out of the tufte class/template) and go with biblatex.

Site admin

Posts: 8
Joined: Sat Aug 27, 2016 1:46 pm

Postby juliendutant » Sun Feb 03, 2019 5:11 pm

Thanks for having a look and thanks for your suggestion.

As it happens the tufte class hasn't be updated to interact with biblatex. There is a way to make them work together, namely tell biblatex to put all citations in footnote ( But that requires modifying the tufte class, so it's not a solution that could be provided out of the box to LyX users.

So (for those who land here looking for a fix) the best is still to add the following line to Document > Settings > Local layout:

  1. Input ../citeengines/basic.citeengine

Return to “LyX”

Who is online

Users browsing this forum: No registered users and 1 guest