add tag
निरंजन
Dr. Duck is supposed to write a review of a story. She plans to list down all the quotations in an appendix and refer to them in her "quanalysis" with `\label` and `\ref`. The following is what she has tried so far, but she doesn't like the output, especially the list of quotations. She is curious to know if there is any better way to structure her review article? Is there any assisting package available for such reviews?

```
\documentclass{article}
\usepackage{csquotes}
\usepackage{lipsum}
\title{Figures of quacks found in a duck story}
\author{Duck}
\def\qref#1{\ref{quotations}\ref{#1}}
\begin{document}
\maketitle

\section{Quanalysis}

As can be seen in \qref{quack}, the author has used the
\enquote{paraducks} figure of quack in this story.

\appendix

\section{Quotations}
\label{quotations}
\begin{enumerate}
\item\label{quack}
  \begin{quotation}
    \lipsum[1-1]
  \end{quotation}
\end{enumerate}
\end{document}
```
Top Answer
निरंजन
This is what I managed to typeset with package `enotez`.

A summary of my customizations is as follows:

1. With `\renewcommand*{\enmarkstyle}[1]{[\ref{appquot}#1]}` I renew the printing style of the reference to the quotation. It doesn't look like an endnote-mark anymore.
1. With `\setenotez` command we can tinker with the printing of endnotes. I have renewed the default title of the section i.e., 'Notes' to 'Appendix of quotations' with a `\label` and by default endnote-marks are printed as superscripts, I change that by passing a blank argument to `mark-cs` parameter.
1. With `\AtNextEndnotesList` I define a line which is printed after the section-title of quotations and the actual list.
1. Lastly, with `\printendnotes`, I use `[custom]` since I need to see the `custom`ized style in the output.

```
\documentclass{article}
\usepackage{enotez}
\usepackage{csquotes}
\usepackage{lipsum}
\title{Figures of quacks found in a duck story}
\author{D.~Duck}
\usepackage[colorlinks]{hyperref}

\begin{document}
\maketitle
\section{Quanalysis}
\renewcommand*{\enmarkstyle}[1]{[\ref{appquot}#1]}
\setenotez{%
  list-heading = {%
    \section{Appendix of quotations}%
    \label{appquot}%
  },%
  mark-cs      = {}%
}
\DeclareInstance{enotez-list}{custom}{paragraph}{%
  format = {\normalfont}%
}
\AtNextEndnotesList{%
  The following is a list of all the quotations.%
}

The author has used the \enquote{paraducks} figure of quack
in this story.\endnote{\lipsum[1-1]}\endnote{\lipsum[1-1]}

\appendix

\printendnotes[custom]
\end{document}
```
Answer #2
Skillmon
I found the task interesting, but didn't want to look into a package, so I coded it myself. I didn't use LaTeX's file-writing mechanism via the .aux file, so this works in a single pass (except for the hyper targets created with `hyperref` which might be misaligned on first pass, if you move `\nirquotelist` before the first `\nirquote` it would work as well, but needs two passes). If you want to use LaTeX's writing mechanism instead I can provide code for it as well.

This also doesn't use LaTeX's `\label`-`\ref`-mechanism.

You can alter the looks of this to your liking by changing the macros

- `\thenirquote` (should be expandable)
- `\nirquote@format@text`
- `\nirquote@format@list`

```
\documentclass{article}

\makeatletter
\newcounter{nirquote}
% just for testing purposes, remove if you don't need this
\counterwithin{nirquote}{section}
\newwrite\nirquote@write
\newcommand\nirquote@openfile% >>=
  {%
    \immediate\openout\nirquote@write=\jobname.nir\relax
    \global\let\nirquote@openfile\@empty
  }% =<<
\NewDocumentCommand\nirquote{O{}m}% >>=
  {%
    \nirquote@openfile
    \refstepcounter{nirquote}%
    \begingroup
      \let\protect\@unexpandable@protect
      \let\label\@gobble
      \let\index\@gobble
      \let\glossary\@gobble
      \immediate\write\nirquote@write
        {%
          \protect\nirquote@format@list
            {\thenirquote}%
            {\thepage}%
            {#1}%
            {#2}%
        }%
    \endgroup
    \nirquote@format@text{#1}{#2}%
  }% =<<
\NewDocumentCommand\nirquotelist{}% >>=
  {%
    \immediate\closeout\nirquote@write
    \begingroup
      \makeatletter
      \input{\jobname.nir}%
    \endgroup
  }% =<<
\newcommand\nirquote@link@forth[2]% >>=
  {%
    % builds a bidirectional link, this points to the quote-list and anchors in
    % the text
    % #1 is the nirquote number
    % #2 is the text that should be displayed
    \hypertarget{nirquote:forth:#1}
      {\hyperlink{nirquote:back:#1}{#2}}%
  }% =<<
\newcommand\nirquote@link@back[2]% >>=
  {%
    % builds a bidirectional link, this points to the usage in the text and
    % anchors in the quote-list
    % #1 is the nirquote number
    % #2 is the text that should be displayed
    \hypertarget{nirquote:back:#1}
      {\hyperlink{nirquote:forth:#1}{#2}}%
  }% =<<
\newcommand\nirquote@format@text[2]% >>=
  {%
    % how the quote is formatted at the spot it is used in
    % #1 is the cited person
    % #2 is the cited quote
    \nirquote@link@forth\thenirquote{[Quote \thenirquote]}%
  }% =<<
\newcommand\nirquote@format@list[4]% >>=
  {%
    % how the quote is formatted in the quote-list
    % #1 is the nirquote number
    % #2 is the page the nirquote was used on
    % #3 is the cited person
    % #4 is the cited quote
    \noindent
    \nirquote@link@back{#1}{Quote #1\space (used on page #2)}%
    \@afterheading % kernel macro that prevents page breaks
    \begin{quote}
      #4%
      \if\relax\detokenize{#3}\relax
        \expandafter\@gobbletwo
      \fi
      \nirquote@signed{-- #3}%
    \end{quote}
    \medskip
  }% =<<
\newcommand\nirquote@signed[1]% >>=
  {%
    % code from https://tex.stackexchange.com/a/13761/117050
    \begingroup
      \leavevmode\unskip\nobreak\hfil\penalty50\hskip2em
      \hbox{}\nobreak\hfil#1%
      \parfillskip=\z@
      \finalhyphendemerits=\z@
      \endgraf
    \endgroup
  }% =<<
\makeatother

\usepackage{duckuments}
\usepackage{ducksay}

% required for `\nirquote@link@forth` and `\nirquote@link@back`
\usepackage{hyperref}

\begin{document}
\section{Ducks}
In text \nirquote[Duck]{\blindduck[1]} they look
\nirquote[Drake]{\blindduck[2]} like this
\nirquote[Duckling]{\blindduck[3]}

\section{Rabbits}
\nirquote{\ducksay[small-rabbit]{I'm a rabbit}}
\nirquote{\ducksay[rabbit]{I'm a giant hare!}}
\nirquote{\ducksay[rabbit]{I'm a cute bunny.}}

\nirquote[Myself]{This is a strange quote that is long and longer and even a}

\section*{Quotes}
\nirquotelist
\end{document}
```

![foo.png](/image?hash=f2405f103af6475a169dc868ed675b6bf3c9a233c85ac2c9c67f3099573b5c79)



-------

## Partial rewrite adding multiple usage of a single quote

The referencing only works backwards (`\nirquoteref` must be used later than the corresponding `\nirquote`, and the `\nirquote` must use the optional `label=<label>` argument). It doesn't use LaTeX's `\label`-`\ref`-mechanism.

I only coded this for educational purposes. I think it's better to use an established package or build upon LaTeX's crossreferencing mechanism instead of reinventing the wheel as I did here. Still I like the created interface... The only thing lacking is the way to customise this by changing the `@format@<thingy>` macros, but this is not meant to be package-quality code! Also, the `\penalty` used to prevent page breaks doesn't correctly work all of the time, but I'm too lazy to investigate.

```
\documentclass{article}

\usepackage{expkv-def}

\makeatletter
%% implementation stuff
\newcounter{nirquote}
\protected\ekvsetdef\nirquote@kv{nirquote}
\ekvdefinekeys{nirquote}% >>=
  {
     dataT label = \nirquote@label
    ,protected noval no-label = \let\nirquote@label\@gobble
    ,protected unknown noval = \edef\nirquote@cited{\unexpanded{#1}}
  }% =<<
\ekvcompile\nirquote@kv@defaults{nirquote}% >>=
  {
     no-label
    % smart way to set an empty noval key that'll be undefined and clear cited
    ,{}
  }% =<<
\newwrite\nirquote@write
\let\nirquote@closefile\@empty
\newcommand\nirquote@openfile% >>=
  {%
    \immediate\openout\nirquote@write=\jobname.nir\relax
    \gdef\nirquote@closefile{\immediate\closeout\nirquote@write}%
    \global\let\nirquote@openfile\@empty
  }% =<<
\newcommand\nirquote@record@usage[2]% >>=
  {%
    \begingroup
      \let\protect\@unexpandable@protect
      \immediate\write\nirquote@write
        {%
          \protect\nirquote@usage
            {#1}%
            {#2}%
        }%
    \endgroup
  }% =<<
\newcommand\nirquote@setlabel[1]% >>=
  {%
    \expandafter\xdef
      \csname nirquote@@label@\detokenize{#1}\endcsname{\thenirquote}%
  }% =<<
\newcommand\nirquote@link@forth[3]% >>=
  {%
    % builds a bidirectional link, this points to the quote-list and anchors in
    % the text
    % #1 is the nirquote number
    % #2 is the page number
    % #3 is the text that should be displayed
    \hypertarget{nirquote:forth:#1:#2}
      {\hyperlink{nirquote:back:#1}{#3}}%
  }% =<<
\newcommand\nirquote@text[4]% >>=
  {\nirquote@link@forth{#1}{#2}{\nirquote@format@text{#1}{#2}{#3}{#4}}}% =<<
\newcommand\nirquote@ref[2]% >>=
  {%
    \nirquote@record@usage{#1}{#2}%
    \nirquote@link@forth{#1}{#2}{\nirquote@format@ref{#1}{#2}}%
  }% =<<
\newcommand\nirquote@list@[3]% >>=
  {%
    \nirquote@list@active{#1}%
    \nirquote@format@list{#2}{#3}%
  }% =<<
\newcommand\nirquote@list@active[1]% >>=
  {%
    \edef\nirquote@this{\unexpanded{#1}}%
    \expandafter\nirquote@list@active@
      \csname nirquote@used@\detokenize{#1}\endcsname
      {#1}%
  }% =<<
\newcommand\nirquote@list@active@[2]% >>=
  {%
    \ifx#1\relax
      \PackageError{nirquote}{Parsing #2 went horribly wrong!}
        {Please contact me}%
    \else
      \let\nirquotepagelist@#1%
      \if
          \relax
          \detokenize\expandafter\expandafter\expandafter
            {\expandafter\@gobblethree#1}%
          \relax
        \nirquotemultipagefalse
      \else
        \nirquotemultipagetrue
      \fi
    \fi
  }% =<<
\newcommand\nirquote@usage@[1]% >>=
  {%
    \expandafter\nirquote@usage@add
      \csname nirquote@used@\detokenize{#1}\endcsname
      {#1}%
  }% =<<
\newcommand\nirquote@usage@add[3]% >>=
  {%
    \ifx#1\relax
      \edef#1{\unexpanded{\nirquote@list@page{#2}{#3}}}%
    \else
      \edef#1{\unexpanded\expandafter{#1\nirquote@list@page{#2}{#3}}}%
    \fi
  }% =<<
\newcommand\nirquote@list@page[2]% >>=
  {%
    ,
    \hyperlink{nirquote:forth:#1:#2}{#2}%
  }% =<<
\newcommand\nirquotelisthead@[1]% >>=
  {\hypertarget{nirquote:back:#1}{\nirquote@format@list@head{#1}}}% =<<

%% user front end
% pick how the counter is formatted
\counterwithin{nirquote}{section}
\NewDocumentCommand\nirquote{O{}m}% >>=
  {%
    \nirquote@openfile
    \nirquote@kv@defaults
    \nirquote@kv{#1}%
    \refstepcounter{nirquote}\nirquote@label\nirquote@setlabel
    \begingroup
      \let\protect\@unexpandable@protect
      \let\label\@gobble
      \let\index\@gobble
      \let\glossary\@gobble
      \immediate\write\nirquote@write
        {%
          \protect\nirquote@list
            {\thenirquote}%
            {\nirquote@cited}%
            {#2}%
        }%
    \endgroup
    \nirquote@record@usage\thenirquote\thepage
    \expandafter\nirquote@text\expanded
      {{\thenirquote}{\thepage}\expandafter}\expandafter{\nirquote@cited}{#2}%
  }% =<<
\NewDocumentCommand\nirquoteref{m}% >>=
  {%
    \@ifundefined{nirquote@@label@\detokenize{#1}}%
      {\PackageError{nirquote}{Undefined nirquote-label \detokenize{#1}}{}}
      {%
        \expandafter\nirquote@ref\expanded
          {{\csname nirquote@@label@\detokenize{#1}\endcsname}{\thepage}}%
      }%
  }% =<<
\NewDocumentCommand\nirquotelist{}% >>=
  {%
    \nirquote@closefile
    \IfFileExists{\jobname.nir}
      {%
        \begingroup
          \makeatletter
          % first pass to collect usages
          \let\nirquote@list\@gobblethree
          \let\nirquote@usage\nirquote@usage@
          \input{\jobname.nir}%
          % second pass to format list
          \let\nirquote@list\nirquote@list@
          \let\nirquote@usage\@gobbletwo
          \input{\jobname.nir}%
        \endgroup
      }{}%
  }% =<<
\NewDocumentCommand\nirquotepagelist{}% >>=
  {\expandafter\expandafter\expandafter\@secondoftwo\nirquotepagelist@}% =<<
\NewDocumentCommand\nirquotelisthead{}% >>=
  {\expandafter\nirquotelisthead@\expandafter{\nirquote@this}}% =<<

%% formatters (change these to customize appearance)
\newcommand\nirquote@format@text[4]% >>=
  {%
    % how the quote is formatted at the spot it is used in
    % #1 is the nirquote number
    % #2 is the page the nirquote was used on
    % #3 is the cited person
    % #4 is the cited quote
    [Quote #1]%
  }% =<<
\newcommand\nirquote@format@ref[2]% >>=
  {%
    % how a quote is formatted when it is referenced a second time
    % #1 is the nirquote number
    % #2 is the page number
    [Quote #1]%
  }% =<<
\newcommand\nirquote@format@list@head[1]% >>=
  {%
    % how the quote heading is formatted in the list of quotes
    % #1 is the nirquote number
    Quote #1%
  }% =<<
\newcommand\nirquote@format@list[2]% >>=
  {%
    % how the quote is formatted in the quote-list
    % #1 is the cited person
    % #2 is the cited quote
    % additionally use \nirquotelisthead for the quote heading
    % and \nirquotepagelist for a list of pages this appears on
    \noindent
    \nirquotelisthead\space
    (used on page\ifnirquotemultipage s\fi\space \nirquotepagelist)%
    \penalty\@M
    \begin{quote}
      #2%
      \if\relax\detokenize{#1}\relax
        \expandafter\@gobbletwo
      \fi
      \signed{-- #1}%
    \end{quote}
    \medskip
  }% =<<
\newif\ifnirquotemultipage
\makeatother

\makeatletter
% used in one of the formatters
% code from https://tex.stackexchange.com/a/13761/117050
\newcommand\signed[1]% >>=
  {%
    \begingroup
      \leavevmode\unskip\nobreak\hfil\penalty50\hskip2em
      \hbox{}\nobreak\hfil#1%
      \parfillskip=\z@
      \finalhyphendemerits=\z@
      \endgraf
    \endgroup
  }% =<<
\makeatother

% dummy contents
\usepackage{duckuments}
\usepackage{ducksay}

% required for `\nirquote@link@forth` and the other hypertarget/hyperlink stuff
\usepackage{hyperref}

\raggedbottom

\begin{document}
\section{Ducks}
In text \nirquote[Duck,label=Duck]{\blindduck[1]} they look
\nirquote[Drake]{\blindduck[2]} like this
\nirquote[Duckling]{\blindduck[3]}

\clearpage

\section{Rabbits}
\nirquote{\ducksay[small-rabbit]{I'm a rabbit}}
\nirquote{\ducksay[rabbit]{I'm a giant hare!}}
\nirquote{\ducksay[bunny]{I'm a cute bunny.}}

Look again at \nirquoteref{Duck}.

\nirquote[Myself]{This is a strange quote that is long and longer and nonsense.}

\clearpage

\section*{Quotes}
\nirquotelist
\end{document}
```

![foo.png](/image?hash=0892cc03fd7aeb214a33661700960ce5db94333958dab423eb2bc92b9c7c6e17)

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.