4
  1. I would like to typeset a catalog of all my BibTeX entries.

  2. I have been using & in many bibkey's such as Author&Editor:2000.

  3. But I cannot \catcode38=12 globally.

My question is: how can I typeset such a bibkey both in a section heading, and in the table of contents, and also cite it?

This is what I want to achieve:

enter image description here

With:

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

\entry{Author&Editor:2000}

But I get:

! Misplaced alignment tab character &.

For example:

\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}
n.r.
  • 4,942

3 Answers3

7

No need to change category codes; we just need a robust version of \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}

Note that you have to add the extension in \addbibresource{foo.bib}

egreg
  • 1,121,712
  • Even if this works is it good practise to do it? (And whats biker in your comment …?) – Tobi Apr 03 '13 at 21:21
  • @Tobi I'd like to start going out with my motorbike, but the weather is still bad. :( This should explain the lapsus calami. Regarding the question, I don't think it's good practice, if you want my opinion. :) But this may come handy in different situations. – egreg Apr 03 '13 at 21:38
6

Changing catcodes mid document is a really bad idea, it will break stuff, but if you are going to do it, you need to get the timing right.

enter image description here

\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}
David Carlisle
  • 757,742
0

how can I typeset such a bibkey

I'm pretty sure you can't do that as & will always be interpreted as Alignment Character before you can change it.

But you can use \&. See also your corrected (and now working) example:

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

Regards, Nick

MrD
  • 2,716
  • Did you try it? I did, and it doesn't work. By the way, what's the purpose of the category code change? – egreg Apr 03 '13 at 20:20