如何使用 & 排版 bibkey?

如何使用 & 排版 bibkey?
  1. 我想排版我所有 BibTeX 條目的目錄。

  2. 我已經&在很多bibkey地方使用過,例如Author&Editor:2000.

  3. 但我不能\catcode38=12在全球範圍內。

我的問題是:如何bibkey在章節標題和目錄中排版這樣的內容,並引用它?

這就是我想要實現的目標:

在此輸入影像描述

和:

\newcommand\entry[1]{%
 \catcode38=12\relax
 \section{#1}
 \fullcite{#1}}

\entry{Author&Editor:2000}

但我得到:

! Misplaced alignment tab character &.

例如:

\documentclass{article}

\usepackage[backend=biber]{biblatex}
\addbibresource{foo.bib}

\usepackage{filecontents}
\begin{filecontents}{foo.bib}
@book{Author&Editor:2000, author={Author}, editor={Editor}, title={Title 0}, year={2000}}
@book{Author&Editor:2001, author={Author}, editor={Editor}, title={Title 1}, year={2001}}
@book{Author&Editor:2002, author={Author}, editor={Editor}, title={Title 2}, year={2002}}
\end{filecontents}

\newcommand\entry[1]{%
 \catcode38=12\relax
 \section{#1}
 \fullcite{#1}}

\begin{document}

\tableofcontents

\entry{Author&Editor:2000}
\entry{Author&Editor:2001}
\entry{Author&Editor:2002}

\end{document}

答案1

無需更改類別代碼;我們只需要一個強大的版本\detokenize

\documentclass{article}

\usepackage[backend=biber]{biblatex}
\addbibresource{foo.bib}

\usepackage{filecontents}
\begin{filecontents}{foo.bib}
@book{Author&Editor:2000, author={Author}, editor={Editor}, title={Title 0}, year={2000}}
@book{Author&Editor:2001, author={Author}, editor={Editor}, title={Title 1}, year={2001}}
@book{Author&Editor:2002, author={Author}, editor={Editor}, title={Title 2}, year={2002}}
\end{filecontents}

\newcommand\entry[1]{%
 \section{\keep{#1}}%
 \fullcite{#1}}
%%% \newrobustcmd is from etoolbox, loaded by biblatex
\newrobustcmd{\keep}[1]{\detokenize{#1}}

\begin{document}

\tableofcontents

\entry{Author&Editor:2000}
\entry{Author&Editor:2001}
\entry{Author&Editor:2002}

\end{document}

請注意,您必須添加擴展名\addbibresource{foo.bib}

答案2

更改catcodes mid文件是一個非常糟糕的主意,它會破壞東西,但如果你要這樣做,你需要找到正確的時機。

在此輸入影像描述

\documentclass{article}

\usepackage[backend=biber]{biblatex}
\addbibresource{foo}

\usepackage{filecontents}
\begin{filecontents}{foo.bib}
@book{Author&Editor:2000, author={Author}, editor={Editor}, title={Title 0}, year={2000}}
@book{Author&Editor:2001, author={Author}, editor={Editor}, title={Title 1}, year={2001}}
@book{Author&Editor:2002, author={Author}, editor={Editor}, title={Title 2}, year={2002}}
\end{filecontents}

\newcommand\entry{\bgroup\catcode`\&=12 \xentry}
\newcommand\xentry[1]{\egroup
 \section{#1}%
 \fullcite{#1}}

\begin{document}

{\catcode`\&=12 \tableofcontents}

\entry{Author&Editor:2000}
\entry{Author&Editor:2001}
\entry{Author&Editor:2002}



\end{document}

答案3

我怎麼才能排版這樣的 bibkey

我很確定你不能這樣做,因為它&總是被解釋為對齊字符你可以改變它。

但你可以使用\&.另請參閱您更正後的(現在有效的)範例:

\documentclass{article}

\usepackage[backend=biber]{biblatex}
\addbibresource{foo}

\usepackage{filecontents}
\begin{filecontents}{foo.bib}
@book{Author\&Editor:2000, author={Author}, editor={Editor}, title={Title 0}, year={2000}}
@book{Author\&Editor:2001, author={Author}, editor={Editor}, title={Title 1}, year={2001}}
@book{Author\&Editor:2002, author={Author}, editor={Editor}, title={Title 2}, year={2002}}
\end{filecontents}

\newcommand\entry[1]{%
 \catcode38=12\relax
 \section{#1}
 \fullcite{#1}}

\begin{document}

\tableofcontents

\entry{Author\&Editor:2000}
\entry{Author\&Editor:2001}
\entry{Author\&Editor:2002}

\end{document}

問候,尼克

相關內容