## LaTeX forum ⇒ LyX ⇒ How 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.
juliendutant
Posts: 8
Joined: Sat Aug 27, 2016 1:46 pm

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

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.

juliendutant
Posts: 8
Joined: Sat Aug 27, 2016 1:46 pm
A quick fix..

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

`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.

juliendutant
Posts: 8
Joined: Sat Aug 27, 2016 1:46 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:

`\cite_engine natbib\cite_engine_type authoryear`

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

`\cite_engine basic\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.

Stefan Kottwitz
Posts: 9285
Joined: Mon Mar 10, 2008 9:44 pm
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`.

Stefan

juliendutant
Posts: 8
Joined: Sat Aug 27, 2016 1:46 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 (https://tex.stackexchange.com/questions/45934/can-i-use-biblatex-with-tufte-classes). 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:

`Input ../citeengines/basic.citeengine`