backref 在第一个引用前添加 'writefilebrfwritefilebrfwritefilebrfwritefilebrfwritefilebrf'

backref 在第一个引用前添加 'writefilebrfwritefilebrfwritefilebrfwritefilebrfwritefilebrf'

我想使用 hyperref 包中的 backref 选项。但在使用它时,我注意到了奇怪的行为。首先,当我在文档中添加引用时,它在文档中可见,但在writefilebrfwritefilebrfwritefilebrfwritefilebrfwritefilebrf它之前:

在此处输入图片描述

这是我Pdflatex+ BibTex+ Pdflatex+Pdflatex

我不确定是什么导致了该问题,因此我粘贴了一个简单的示例,但包含所有包。

其次,如果我取消注释

\chapter*{\normalfont\huge\bfseries Bibliography} % Add title to bibliography 

我收到此错误:

Chapter 1.
(./bu1.aux)
No file bul.bbl.
[1{/usr/local/texlive/2023/texmf-var/fonts/map/pdftex/updmap/
pdftex.map}{/usr/l
ocal/texlive/2023/texmf-dist/fonts/enc/dvips/base/8r.enc}][2](./
bul.aux
•/bu1. aux:7: You can't use "\spacefactor' in vertical mode.
1@->\spacefactor
1.7 \Q
writefile{brf}{\backcite{goossens93}{{1}{1.1}{section.1.1}}}
?

这是一个可重现的例子

\documentclass[12pt,oneside]{report} 

\usepackage{filecontents}

\begin{filecontents*}{mycitations.bib}
@book{goossens93,
    author = "Frank Mittelbach and Michel Goossens  and Johannes Braams and David Carlisle  and Chris Rowley",
    title = "The {LaTeX} Companion",
    year = "1993",
    publisher = "Addison-Wesley",
    address = "Reading, Massachusetts"
}
@article{fujita2010economic,
    title={Economic effects of the unemployment insurance benefit},
    author={Fujita, Shigeru},
    journal={FRB Phil. Business Review},
    volume={4},
    year={2010}
}
@article{rothstein2011unemployment,
    title={Unemployment insurance and job search in the {Great Recession}},
    author={Rothstein, Jesse},
    journal={NBER},
    volume={w17534},
    year={2011}
}
@article{test,
    title={sup dude},
    author={Me, You},
    journal={Greatest Journal},
    volume={inf},
    year={2156}
}

\end{filecontents*}

\usepackage[top=1truein,bottom=1truein,left=1truein,right=1truein, showframe]{geometry}
\usepackage{color}
\usepackage[hidelinks, linktoc=all, pdftex, pdfpagelabels=false, backref=page]{hyperref}
\usepackage[bf,rm,medium,compact, explicit]{titlesec}
\titleformat{\chapter}[display]
{\normalfont\LARGE\bfseries\raggedright}{\chaptertitlename\ \thechapter}{20pt}{\huge #1}
\titleformat{name = \chapter, numberless}
  {\normalfont\huge\bfseries\color{black}}
  {}
  {0em}
  {#1}%
\titlespacing*{name = \chapter, numberless}{0pt}{50pt}{40pt}
\usepackage{indentfirst}
\usepackage{makeidx}
\usepackage[acronym]{glossaries}
\usepackage[automake]{glossaries-extra}
\usepackage[round]{natbib}
\usepackage[sectionbib,globalcitecopy]{bibunits}
\defaultbibliographystyle{apalike} 
\defaultbibliography{mycitations.bib}
\def\urlprefix{}

\setlength{\parindent}{3em} % indentation length =3em ~1.05cm
\setlength{\parskip}{0pt} % Vertical space between paragraphs
\DeclareMathOperator{\pdf}{pdf}
\DeclareMathOperator{\average}{average}
\newcommand*{\tabindent}{ \hspace{5.6mm}} 



\renewcommand{\bibpreamble}{%
  [Citing pages are listed after each reference.]%
  \par\bigskip}

\usepackage{etoolbox}
\makeatletter
\patchcmd{\BR@backref}{\newblock}{\newblock[}{}{}
\patchcmd{\BR@backref}{\par}{]\par}{}{}
\makeatother

\makeglossaries

\begin{document}
\bibliographyunit[\chapter]

\chapter{title}\label{ch:test}
\section{Introduction}
this is a test \cite{goossens93}. for citations \citep{fujita2010economic},  \citep{rothstein2011unemployment}.
\cite{goossens93}
\phantomsection
\addcontentsline{toc}{section}{\protect\numberline{\thesection}Bibliography}

\putbib

\cleardoublepage

\cite{test}
\cleardoublepage


\addtocounter{chapter}{1}
\phantomsection % <- added
%\chapter*{\normalfont\huge\bfseries Bibliography} % Add title to bibliography 
\addcontentsline{toc}{chapter}{Bibliography} % Add to toc 
%\renewcommand{\bibsection}{}

\bibliographystyle{apalike}
\bibliography{mycitations}

\end{document}

答案1

bibunits 读取文档中的辅助文件。如果辅助文件包含名称中带有 @ 的命令,则此操作会失败。

您可以尝试以下操作:

\def\@startbibunit{%
  \global\let\@startbibunitorrelax\relax
  \global\let\@finishbibunit\@finishstartedbibunit
  \global\advance\@bibunitauxcnt 1
  \if@filesw
    {\endlinechar-1
     \makeatletter % new
    \@input{\@bibunitname.aux}}%
    \immediate\openout\@bibunitaux\@bibunitname.aux
    \immediate\write\@bibunitaux{\string\bibstyle{\@localbibstyle}}%
  \fi
}

\def\@finishstartedbibunit{%
  \if@filesw
    \immediate\closeout\@bibunitaux
  \fi
  \ifx\bibunits@rerun@warning\@empty
    \if@filesw
       {\endlinechar-1
        \makeatletter %new
       \let\@namedef\@xtestdef
       \@input{\@bibunitname.aux}}%
    \fi
  \fi
}

但一般来说,bibunits 上次更新是在 2004 年,并没有真正考虑到 hyperref 和 backref。我建议使用 biblatex + biber,这样这些东西就可以正常工作。

相关内容