# How to avoid citations being placed on a new line when \blockcquote ends with a list?

When csquotes's \blockquote and displaycquote ends with a list the citation is put on the next line after the list rather than directly after the last list item. Can one force csquotes to place the citation directly after the last list item?

The following is an example that illustrates the problem:

\documentclass{article}

\usepackage{biblatex}
\usepackage{csquotes}
\usepackage{filecontents}

\begin{filecontents*}{database.bib}
@book{texbook,
author    = {Donald E. Knuth},
title     = {The {{\TeX}book}},
date      = {1984}
}
\end{filecontents*}

\bibliography{database.bib}

\begin{document}

\blockcquote{texbook}{%
Some cited text:
\begin{itemize}
\item item 1
\item item 2
\end{itemize}%
}

\begin{displaycquote}{texbook}
Some cited text:
\begin{itemize}
\item item 1
\item item 2
\end{itemize}
\end{displaycquote}

% Correct placement of citation
\begin{quote}
Some cited text:
\begin{itemize}
\item item 1
\item item 2 \cite{texbook}
\end{itemize}
\end{quote}

\end{document}


The following is the output of the example. Note how the first and second citations are badly placed while the third one is correctly placed.

-
The problem is actually more general. I have the same situation when I use csquotes' \MakeBlockQuote function and try to add a footnote. –  Simifilm May 10 '12 at 17:24
You're telling to end an itemize environment, what else are you expecting? An \end{itemize} always ends a paragraph. –  egreg May 10 '12 at 18:54
@egreg If I end itemize after \blockcquote or displaycquote I get an error. I would simply like to typeset quotations with \blockcquote and displaycquote, even those that end with the last list item. –  N.N. May 10 '12 at 19:50
@N.N. It's quite hard to understand what you want: just write ...\cite{textbook}\end{blockquote}. –  egreg May 10 '12 at 20:59
Quite a tough problem. I believe that a \citehere command similar to \qedhere of amsthm could be a good way to solve the problem, but this probably requires rewriting many parts of csquotes. –  egreg May 11 '12 at 8:51

You can locally make itemize (and other display list environments) look ahead and see if they are at the end of the quote construct, and if so, do the cite and locally disable the cite command so that it does nothing when the csquotes command executes \cite after the display.

\documentclass{article}

\usepackage{biblatex}
\usepackage{csquotes}
\usepackage{filecontents}

\begin{filecontents*}{database.bib}
@book{texbook,
author    = {Donald E. Knuth},
title     = {The {{\TeX}book}},
date      = {1984}
}
\end{filecontents*}
\makeatletter
\let\oldbcq\blockcquote
\let\oldendlist\endlist
\def\csq@@z{\csq@z{\csq@z}}
\def\csq@@@z{\end{displaycquote}}
\long\def\cqendlist#1\fi#2\fi#3#4{%
\def\z{#3{#4}}%
\ifx\z\csq@@@z\let\z\csq@@z\fi
\ifx\z\csq@@z
\ifhmode\unskip\fi
\leavevmode
\space \zcsqcite
\gdef\cs@next{\let\csq@cite\@gobble}%
\else
\global\let\cs@next\relax
\fi
\oldendlist#1\fi#2\fi#3{#4}%
\cs@next
}
\enditemize
\let\csq@z\relax
\def\blockcquote#1#2{\begingroup
\def\zcsqcite{\csq@cite{#1}}%
\let\enditemize\cqendlist
\oldbcq{#1}{#2\csq@z\csq@z}\endgroup}

\let\olddcq\displaycquote
\def\displaycquote#1{%
\def\zcsqcite{\csq@cite{#1}}%
\let\enditemize\cqendlist
\olddcq{#1}}

\let\oldedcq\enddisplaycquote
\def\enddisplaycquote{%
\cs@next
\oldedcq}

\makeatother
\bibliography{database.bib}

\begin{document}

\blockcquote{texbook}{%
Some cited text:
\begin{itemize}
\item item 1
\item item 2
\end{itemize}}%

%\tracingall
\begin{displaycquote}{texbook}
Some cited text:
\begin{itemize}
\item item 1
\item item 2
\end{itemize}
\end{displaycquote}

% Correct placement of citation
\begin{quote}
Some cited text:
\begin{itemize}
\item item 1
\item item 2 \cite{texbook}
\end{itemize}
\end{quote}

\end{document}

-