我怎样才能用 & 排版 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 是一个非常糟糕的想法,它会破坏一些东西,但是如果你要这样做,你需要把握好时机。

在此处输入图片描述

\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}

问候,尼克

相关内容