6

I currently have a quote in my tex file like this:

\begin{quote}
blabla
\end{quote}

Now I want to refer to this quote inline. Adding a label works but I cannot get the caption to work, in order to show that this quote is actually number x.y. As this environment does not seem to be a float environment, which is apparently a requirement for \caption{}.

So I have tried the following:

\begin{quote}
blabla
\label{quote:one}
\end{quote}

And addint \caption{test} right before the label does not work.

2
  • 6
    A quote environment does not have a counter, therefore labelling is useless, in this case. Your request requires some setup ;-)
    – user31729
    Feb 23, 2016 at 14:37
  • The accepted solution is defective. See the answer at tex.stackexchange.com/a/563217/202780 for a simpler and more flexible solution.
    – Don Hosek
    Sep 18, 2020 at 15:47

3 Answers 3

6

See below for Alternate Appearance. See ADDENDUM for version that uses aux file to allow future referencing

As Christian noted in a comment, a quote has no counter (and thus no identifying label). However, we could introduce one to the lquote environment, which requires a label as the argument, reference-able by \quoteref.

The implementation given below can be altered to suit the needs for quotation marks, numbering scheme and appearance, etc.

\documentclass{article}
\newcounter{numquote}
\newenvironment{lquote}[1]{%
  \stepcounter{numquote}%
  \expandafter\xdef\csname#1\endcsname{\fbox{\thenumquote}}%
  \quote``\ignorespaces}{\unskip''\fbox{\thenumquote}\endquote}
\newcommand\quoteref[1]{\csname#1\endcsname}
\begin{document}
Compare this quote
\begin{lquote}{quote:one}
blabla
\end{lquote}
to this one
\begin{lquote}{quote:two}
moreblabla
\end{lquote}
In quotation \quoteref{quote:one}, we see a difference from quote \quoteref{quote:two}.
\end{document}

enter image description here

Alternate Appearance

\documentclass{article}
\newcounter{numquote}
\newenvironment{lquote}[1]{%
  \stepcounter{numquote}
  \expandafter\xdef\csname#1\endcsname{\thenumquote}%
  \quote Quote \thenumquote: ``\ignorespaces}{\unskip''\endquote}
\newcommand\quoteref[1]{\csname#1\endcsname}
\begin{document}
Compare this quote
\begin{lquote}{quote:one}
blabla
\end{lquote}
to this one
\begin{lquote}{quote:two}
moreblabla
\end{lquote}
In quotation \quoteref{quote:one}, we see a difference from quote \quoteref{quote:two}.
\end{document}

enter image description here

ADDENDUM:

It seemed from the OP's comment that he may be using the \quoteref prior to the label definition in the lquote environment. To account for that, I have in this addendum implemented a system of writing out to the aux file to make the labels available even before they are defined.

\documentclass{article}
\makeatletter
\long\def \protected@iwrite#1#2#3{%
     \begingroup
     \let\thepage\relax
     #2%
     \let\protect\@unexpandable@protect
     \edef\reserved@a{\immediate\write#1{#3}}%
     \reserved@a
     \endgroup
     \if@nobreak\ifvmode\nobreak\fi\fi
    }
\newcounter{numquote}
\newenvironment{lquote}[1]{%
  \stepcounter{numquote}%
  \protected@iwrite\@auxout{\def\nex{\noexpand\noexpand\noexpand}}{%
    \nex\expandafter\xdef%
    \nex\csname #1%
    \nex\endcsname{\thenumquote}%
  }%
  \quote Quote \thenumquote: ``\ignorespaces}{\unskip''\endquote}
\makeatother
\newcommand\quoteref[1]{\csname#1\endcsname}
\begin{document}
In the future quotation \quoteref{quote:one}, 
  we see a difference from quote \quoteref{quote:two}.

Compare this quote
\begin{lquote}{quote:one}
blabla
\end{lquote}
to this one
\begin{lquote}{quote:two}
moreblabla
\end{lquote}
In quotation \quoteref{quote:one}, we see a difference from quote \quoteref{quote:two}.

\end{document}

enter image description here


Note: the \protected@iwrite macro came from egreg's answer at Writing \\ to a File.

14
  • At least one that takes note of my comments ;-)
    – user31729
    Feb 23, 2016 at 15:01
  • 1
    @Someguy I have provided something more in line with your comments. Feb 23, 2016 at 15:12
  • 1
    @Someguy I have added an addendum to make use of the aux file to allow you to use \quoteref before the invocation of lquote. Feb 23, 2016 at 18:56
  • 1
    @LucasAzevedo I have no quick answer for you. Perhaps this could be asked as a new Question on the site. Sep 18, 2020 at 14:28
  • 1
    @LucasAzevedo Yes, and I've already upvoted it. Sep 18, 2020 at 14:55
1

Only a \pageref makes sense:

\documentclass{article}
\usepackage{caption}
\begin{document}

\begingroup
\begin{quote}
    blabla
\end{quote} 
\captionof*{figure}{Test}\label{quote:one}
\endgroup

See quote on page~\pageref{quote:one}
\end{document}
1

The accepted solution is defective in a lot of ways. LaTeX already has its own referencing mechanism and that bypasses it which causes problems as you've seen.

Instead, I would define the lquote environment as follows:

\newcounter{numquote}
\newenvironment{lquote}{%
  \refstepcounter{numquote}%
  \quote}{\unskip~\thenumquote\endquote}

You would use this by something like

\begin{lquote}
  blah blah
  \label{quote:one}
\end{lquote}
...
quote~\ref{quote:one}.

Then, if you put

\usepackage{hyperref}

at the end of your preamble you'll automatically get the desired result with hyperlinks on the reference.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .