LyX ⇒ How to prevent LyX from using natbib commands - Tufte Handout layout bug
-
- Posts: 14
- Joined: Sat Aug 27, 2016 1:46 pm
How to prevent LyX from using natbib commands - Tufte Handout layout bug
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.
NEW: TikZ book now 40% off at Amazon.com for a short time.
And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p
-
- Posts: 14
- Joined: Sat Aug 27, 2016 1:46 pm
How to prevent LyX from using natbib commands - Tufte Handout layout bug
Update: this is solved by adding the following line in Document > Settings > Local Layout:
Code: Select all
Input ../citeengines/basic.citeengine
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.
-
- Posts: 14
- Joined: Sat Aug 27, 2016 1:46 pm
How to prevent LyX from using natbib commands - Tufte Handout layout bug
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:
Code: Select all
\cite_engine natbib
\cite_engine_type authoryear
Code: Select all
\cite_engine basic
\cite_engine_type default
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
- Site Admin
- Posts: 10335
- Joined: Mon Mar 10, 2008 9:44 pm
How to prevent LyX from using natbib commands - Tufte Handout layout bug
I guess I would try to deactivate
natbib
(take it out of the tufte class/template) and go with biblatex
.Stefan
-
- Posts: 14
- Joined: Sat Aug 27, 2016 1:46 pm
How to prevent LyX from using natbib commands - Tufte Handout layout bug
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 ... te-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:
Code: Select all
Input ../citeengines/basic.citeengine