1

I am a LyX user.

I am using back-references to refer to the cited pages, as seen in the figure below. However, in the last reference, there is a bug: the back-reference text skips to the next line ("Cited on page 45" in this case). Does anyone know how to fix this bug?

enter image description here

The style format of the bibliography in my document is Basic (BibTex). The code I am using for the back-references is the following (taken from this source, http://lyx.475766.n2.nabble.com/backref-td478438.html):

%************************************************
%** hyperref and backref  
%************************************************

   % redefinition of the used \backrefalt
   \renewcommand*{\backrefalt}[4]{%
     \ifcase #1 %
         % case: not cited
     \or
         % case: cited on exactly one page
         Cited on page~#2.
     \else
         % case: cited on multiple pages
         Cited on pages~#2.
     \fi}

The configurations of my Bibliography and Hyperreff Support are shown in the two images below. I've tried several configurations of both, but nothing has worked.

enter image description here

enter image description here

A minimal example of my problem as .lyx file: https://drive.google.com/file/d/1JueGZujTldPF1cZjiW7PyyKPOOXjVp63/view?usp=sharing

#LyX 2.3 created this file. For more info see http://www.lyx.org/
\lyxformat 544
\begin_document
\begin_header
\textclass article
\begin_preamble
%*****************************************************
%** hyperref and backref  
%*****************************************************

   % redefinition of the used \backrefalt
   \renewcommand*{\backrefalt}[4]{%
     \ifcase #1 %
         % case: not cited
     \or
         % case: cited on exactly one page
         Cited on page~#2.
     \else
         % case: cited on multiple pages
        Cited on pages~#2.
     \fi}
\end_preamble
\use_hyperref true
\pdf_backref page
\end_header

\begin_body

\begin_layout Standard
Citations: 
\begin_inset CommandInset citation
LatexCommand cite
key "Ref 1,Ref 2,Ref 3"
literal "false"

\end_inset

.
\end_layout

\begin_layout Bibliography
\begin_inset CommandInset bibitem
LatexCommand bibitem
key "Ref 1"
literal "false"

\end_inset

 Reference 1.
\end_layout

\begin_layout Bibliography
\begin_inset CommandInset bibitem
LatexCommand bibitem
key "Ref 2"
literal "false"

\end_inset

 Reference 2.
\end_layout

\begin_layout Bibliography
\begin_inset CommandInset bibitem
LatexCommand bibitem
key "Ref 3"
literal "false"

\end_inset

 Reference 3.

\end_layout

\end_body

\end_document

A minimal example as a .tex file:

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage[pdftex, pagebackref=true, hyperindex=true]{hyperref}
   \hypersetup{%
     breaklinks    = true,
     colorlinks    = true
  }

   % redefinition of the used \backrefalt
   \renewcommand*{\backrefalt}[4]{%
     \ifcase #1 %
         % case: not cited
     \or
         % case: cited on exactly one page
         Cited on page~#2.
     \else
         % case: cited on multiple pages
        Cited on pages~#2.
     \fi}

\begin{document}

Citations: \cite{Ref 1,Ref 2,Ref 3}.

\begin{thebibliography}{9}

\bibitem{Ref 1} Reference 1.

\bibitem{Ref 2} Reference 2.

\bibitem{Ref 3} 
Reference 3.
\end{thebibliography}

\end{document}

Please let me know if there is any other information needed.

Thanks :)

Edit: As egreg pointed out in his answer, in the .tex file a blank line must exist before the code

\end{thebibliography}

Creating this line solves the problem, that is, changing the last lines of the .tex file to

\bibitem{Ref 3} Reference 3.

\end{thebibliography}

However, I don't know how to make this on LyX. Does anyone know?

8
  • Welcome to tex.se! Please upload a (complete) minimal example .lyx and corresponding .tex file. See here for more information: wiki.lyx.org/FAQ/MinimalExample
    – scottkosty
    Commented Nov 29, 2020 at 22:40
  • Thanks for the advice, scottkosty! I have put a working minimal example (as .lyx and .tex files). Commented Nov 30, 2020 at 15:50
  • Thanks for your simple example file! I can reproduce. Even if I remove the LaTeX preamble, it still shows a bug. Unfortunately, I don't know enough more than that. Hopefully a TeX expert has an idea. For the future (and now if motivated), I suggest to put especially the .tex file as code in your question. it's preferred to not depend on extra links. Also a .lyx file is just a text file so you can actually open it with a text editor and copy/paste into the question and mark as "code". Good luck figuring out the issue! I hope someone comes along who knows more than I on this.
    – scottkosty
    Commented Nov 30, 2020 at 15:56
  • I added the contents as code in the question. Avoid external links that could expire. Just paste the code, select it and click on the {} icon. We'd also need the BibTeX entries.
    – egreg
    Commented Nov 30, 2020 at 16:12
  • Raise an issue at the LyX site: the blank line after any bibliography item has been necessary from day 1 and, indeed, BibTeX always produces it.
    – egreg
    Commented Nov 30, 2020 at 17:48

1 Answer 1

1

You must have a blank line before the line with

\end{thebibliography}

No bug: the requirement of a blank line after every bibliography item is known. Without the blank line the back reference mechanism cannot work properly.

5
  • Thanks for your answer egreg! This solved the problem in the .tex file. However, I don't know how to make this line skip in the .lyx code. Do you happen to know? I've put the BibTex entries in my question, as you suggested. Let me know if you need any other information. Commented Nov 30, 2020 at 17:48
  • @MartimZurita Since this appears to be a LyX bug, you need to trick LyX: place the cursor at the end of the last reference. Go to Insert > TeX Code. Then press <Return>. Does that work for you?
    – scottkosty
    Commented Dec 1, 2020 at 3:08
  • @scottkosty I had to press <Return> twice in order for it to work.
    – Daniel
    Commented Dec 1, 2020 at 10:11
  • @Daniel Good to know! Thanks for the correction
    – scottkosty
    Commented Dec 1, 2020 at 15:35
  • @scottkosty It worked for me, pressing <Return> twice, as Daniel pointed out. Thanks so much, guys!! Commented Dec 1, 2020 at 17:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .