0

In one of the answers here: How to make only cited bibitems appear?

user @UlrikeFischer gives a short solution to provide automation when not using bibtex, I copy her code here and it works for citing individual items. However it does not work for me when citing multiple items. I have added "\cite{a,b}" to her code snippet here, and this does not work for me, i.e. there is a question mark where I put b and reference b is not listed

Can Ulrike or anyone else help me out by adapting the code snippet so that also \cite{a,b} e.g. works? I don't really understand the latex code well enough to try and adapt it myself

Thanks a lot for your help, Hercule Poirot

ps: I know that I should use Bibtex or another automated package in future, so telling me that will not be helpful.

\documentclass{article}
\usepackage{xpatch}
\makeatletter
\xpretocmd\@citex{\csgdef{used@cite@#2}{x}}{}{\failed}
\newcommand\checkbibentry[2]{\ifcsdef{used@cite@#1}{\bibitem{#1}{#2}}{}}
\makeatletter
\begin{document}

\cite{a} \cite{c} \cite{a,b}

\begin{thebibliography}{99}

\checkbibentry{a}{some text to a}

\checkbibentry{b}{some text to b}

\checkbibentry{c}{some text to c}
\end{thebibliography}

\end{document}

1 Answer 1

1

You can map through the key list:

\documentclass{article}
\usepackage{xpatch}
\ExplSyntaxOn\makeatletter
\cs_new_protected:Npn\__poirot_mark_cite_as_used:n #1
 {
   \clist_map_inline:nn {#1}
    {
      \tl_gclear_new:c{g__poirot_cite_used_##1_tl}
    }
 }
\newcommand\checkbibentry[2]
 {
  \tl_if_exist:cT {g__poirot_cite_used_#1_tl}
   { \bibitem{#1}{#2} }
 }  

\ExplSyntaxOff
\xpretocmd\@citex{\csname __poirot_mark_cite_as_used:n\endcsname{#2}}{}{\failed} 

\makeatother
\begin{document}

\cite{a} \cite{c} \cite{a,b}

\begin{thebibliography}{99}

\checkbibentry{a}{some text to a}

\checkbibentry{b}{some text to b}

\checkbibentry{c}{some text to c}
\end{thebibliography}

\end{document}

enter image description here

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.