2

In the following MWE, the environment "quoter" is used let's say a little bit as a "pseudo"-caption: it is not a real \caption or \captionof, but still it generates a counter and displays a word such as "Quote" or "Figure" (or anything else to your liking) and a counted number after it.

I am just wondering how I could easily reference to a certain instance of such a "quoter"-environment, with the number and additionally a title/description of the "Quote" (in casu, or in other cases: "Figure", or anything else).

With a real \caption or \captionof, this is not all too hard. But, how do we do it for this "pseudo"-caption? A vital step is to know how to recuperate the number of a certain labeled Quote, but not reference to it according to its number (because that might change because the whole document might change). It might be good to somehow automatically \label a quote's title/description, and then through that: automatically recuperate the Quote's number.

The MWE shows how a desired end-result could look like.

MWE

\documentclass{article}

\usepackage[framemethod=tikz]{mdframed}
\usetikzlibrary{calc}

%%%%% quoter environment

\newcounter{quote}

\newmdenv[
hidealllines=true,
innertopmargin=16pt,
innerbottommargin=10pt,
leftmargin=0cm,
rightmargin=0cm,
skipabove=10pt,
skipbelow=10pt,
singleextra={
  \coordinate (aux) at ( $ (O)!0.5!(P) $ );
  \fill[rounded corners=6pt,line width=1pt,blue!30]
    (O|-P) -- 
    (aux|-P) --
    ([yshift=12pt]aux|-P) --
    ([yshift=12pt,xshift=4cm]aux|-P) --
    ([xshift=4cm]aux|-P) -- 
    (P) {[sharp corners] --
    ([yshift=-6pt]P) -- 
    ([yshift=-6pt]O|-P) } -- cycle;
  \draw[rounded corners=6pt,line width=1pt,blue]
    (O|-P) -- 
    (aux|-P) --
    ([yshift=12pt]aux|-P) --
    ([yshift=12pt,xshift=4cm]aux|-P) --
    ([xshift=4cm]aux|-P) -- 
    (P) --
    (P|-O) --
    (O) -- cycle;
  \node at ([xshift=2cm,yshift=3pt]aux|-P)
    {\refstepcounter{quote}\large Quote~\thequote} ; 
  },
firstextra={
  \coordinate (aux) at ( $ (O)!0.5!(P|-O) $ );
  \fill[rounded corners=6pt,line width=1pt,blue!30,overlay]
    (O|-P) -- 
    (aux|-P) --
    ([yshift=12pt]aux|-P) --
    ([yshift=12pt,xshift=4cm]aux|-P) --
    ([xshift=4cm]aux|-P) -- 
    (P) {[sharp corners] --
    ([yshift=-6pt]P) -- 
    ([yshift=-6pt]O|-P) } -- cycle;
  \draw[rounded corners=6pt,line width=1pt,blue,overlay]
    (O) --
    (O|-P) -- 
    (aux|-P) --
    ([yshift=12pt]aux|-P) --
    ([yshift=12pt,xshift=4cm]aux|-P) --
    ([xshift=4cm]aux|-P) -- 
    (P) --
    (P|-O);
  \node[overlay] at ([xshift=2cm,yshift=3pt]aux|-P)
    {\refstepcounter{quote}\large Quote~\thequote} ; 
  },
middleextra={
  \draw[rounded corners=6pt,line width=1pt,blue,overlay]
    (O|-P) -- 
    (O);
  \draw[rounded corners=6pt,line width=1pt,blue,overlay]
    (P) -- 
    (P|-O);
  },
secondextra={
  \coordinate (aux) at ( $ (O)!0.5!(P|-O) $ );
  \draw[rounded corners=6pt,line width=1pt,blue,overlay]
    (O|-P) -- 
    (O) --
    (P|-O) --
    (P);
  },
]{quoter}

%%%%% begin the beguine

\begin{document}

If you are interested in this, please see \textbf{Quote 1: Kierkegaard's quote, reproduced blindly from the internet}.

\begin{quoter}

\begin{center}

\textbf{Kierkegaard's quote, reproduced blindly from the internet}
\vspace{0.5em}
\hrule
\vspace{1em}

\end{center}

The function of prayer is not to influence God, but rather to change the nature of the one who prays.\footnote{Kierkegaard.}

\end{quoter}

\end{document}

P.S.: It would be handy, of course, to have the \nameref, or the "pseudo"-nameref automatically (or optionally) clickable hyperlink to the actual Quote.

  • \nameref is not standard LaTeX, but is provided by hyperref (and possibly other packages). Hyperref modifies \label to pass more information than a standard \label. – John Kormylo Apr 21 '16 at 4:24
  • @John Kormylo Thanks for that, I'll change all mentions of the word \nameref into \label then, in the OP? – Vincent Mia Edie Verheyen Apr 21 '16 at 8:32
3

It is possible to write text content to the .aux file

I've done this using an \labelText command that is setting the title and sets the label (according to user specifcations.)

Use \nameref then to refer to this label.

The formatting should be done outside of the textlabel, not inside.

(Since I am writing on a Tablet, I can't provide a better solution right now)

\documentclass{article}

\usepackage[framemethod=tikz]{mdframed}
\usepackage{nameref}
\usetikzlibrary{calc}

%%%%% quoter environment

\newcounter{quote}

\newmdenv[
hidealllines=true,
innertopmargin=16pt,
innerbottommargin=10pt,
leftmargin=0cm,
rightmargin=0cm,
skipabove=10pt,
skipbelow=10pt,
settings={\refstepcounter{quote}},
singleextra={
  \coordinate (aux) at ( $ (O)!0.5!(P) $ );
  \fill[rounded corners=6pt,line width=1pt,blue!30]
    (O|-P) -- 
    (aux|-P) --
    ([yshift=12pt]aux|-P) --
    ([yshift=12pt,xshift=4cm]aux|-P) --
    ([xshift=4cm]aux|-P) -- 
    (P) {[sharp corners] --
    ([yshift=-6pt]P) -- 
    ([yshift=-6pt]O|-P) } -- cycle;
  \draw[rounded corners=6pt,line width=1pt,blue]
    (O|-P) -- 
    (aux|-P) --
    ([yshift=12pt]aux|-P) --
    ([yshift=12pt,xshift=4cm]aux|-P) --
    ([xshift=4cm]aux|-P) -- 
    (P) --
    (P|-O) --
    (O) -- cycle;
  \node at ([xshift=2cm,yshift=3pt]aux|-P)
    {\large Quote~\thequote} ; 
  },
firstextra={
  \coordinate (aux) at ( $ (O)!0.5!(P|-O) $ );
  \fill[rounded corners=6pt,line width=1pt,blue!30,overlay]
    (O|-P) -- 
    (aux|-P) --
    ([yshift=12pt]aux|-P) --
    ([yshift=12pt,xshift=4cm]aux|-P) --
    ([xshift=4cm]aux|-P) -- 
    (P) {[sharp corners] --
    ([yshift=-6pt]P) -- 
    ([yshift=-6pt]O|-P) } -- cycle;
  \draw[rounded corners=6pt,line width=1pt,blue,overlay]
    (O) --
    (O|-P) -- 
    (aux|-P) --
    ([yshift=12pt]aux|-P) --
    ([yshift=12pt,xshift=4cm]aux|-P) --
    ([xshift=4cm]aux|-P) -- 
    (P) --
    (P|-O);
  \node[overlay] at ([xshift=2cm,yshift=3pt]aux|-P)
    {\large Quote~\thequote} ; 
  },
middleextra={
  \draw[rounded corners=6pt,line width=1pt,blue,overlay]
    (O|-P) -- 
    (O);
  \draw[rounded corners=6pt,line width=1pt,blue,overlay]
    (P) -- 
    (P|-O);
  },
secondextra={
  \coordinate (aux) at ( $ (O)!0.5!(P|-O) $ );
  \draw[rounded corners=6pt,line width=1pt,blue,overlay]
    (O|-P) -- 
    (O) --
    (P|-O) --
    (P);
  },
]{quoter}




\makeatletter
\newcommand{\labelText}[2]{%
#1%
\immediate\write\@auxout{%
  \string\newlabel{#2}{{1}{\thepage}{{Quote \thequote: #1}}{quoter.\number\value{quote}}{}}%
}%
}
%%%%% begin the beguine

\begin{document}

%\textbf{Quote 1: Kierkegaard's quote, reproduced blindly from the internet}.

If you are interested in this, please see \textbf{\nameref{kierkegaard}}

\begin{quoter}

\begin{center}
\textbf{\labelText{Kierkegaard's quote, reproduced blindly from the internet}{kierkegaard}}
%\textbf{Kierkegaard's quote, reproduced blindly from the internet}
\vspace{0.5em}
\hrule
\vspace{1em}

\end{center}

The function of prayer is not to influence God, but rather to change the nature of the one who prays.\footnote{Kierkegaard.}

\end{quoter}

\end{document}

Update with links

 \documentclass{article}

    \usepackage[framemethod=tikz]{mdframed}
    \usepackage{hyperref}
    \usetikzlibrary{calc}

    %%%%% quoter environment

    \newcounter{quote}

    \renewcommand{\theHquote}{quote.\thequote}

    \makeatletter
    \newcommand{\labelText}[2]{%
      #1%
      \immediate\write\@auxout{%
        \string\newlabel{#2}{{1}{\thepage}{{Quote \thequote: #1}}{quote.\theHquote}{}}%
      }%
    }
    \makeatother


    \newmdenv[
    hidealllines=true,
    innertopmargin=16pt,
    innerbottommargin=10pt,
    leftmargin=0cm,
    rightmargin=0cm,
    skipabove=10pt,
    skipbelow=10pt,
    settings={\refstepcounter{quote}},
    singleextra={
      \coordinate (aux) at ( $ (O)!0.5!(P) $ );
      \fill[rounded corners=6pt,line width=1pt,blue!30]
        (O|-P) -- 
        (aux|-P) --
        ([yshift=12pt]aux|-P) --
        ([yshift=12pt,xshift=4cm]aux|-P) --
        ([xshift=4cm]aux|-P) -- 
        (P) {[sharp corners] --
        ([yshift=-6pt]P) -- 
        ([yshift=-6pt]O|-P) } -- cycle;
      \draw[rounded corners=6pt,line width=1pt,blue]
        (O|-P) -- 
        (aux|-P) --
        ([yshift=12pt]aux|-P) --
        ([yshift=12pt,xshift=4cm]aux|-P) --
        ([xshift=4cm]aux|-P) -- 
        (P) --
        (P|-O) --
        (O) -- cycle;
      \node at ([xshift=2cm,yshift=3pt]aux|-P)
        {\large Quote~\thequote} ; 
      },
    firstextra={
      \coordinate (aux) at ( $ (O)!0.5!(P|-O) $ );
      \fill[rounded corners=6pt,line width=1pt,blue!30,overlay]
        (O|-P) -- 
        (aux|-P) --
        ([yshift=12pt]aux|-P) --
        ([yshift=12pt,xshift=4cm]aux|-P) --
        ([xshift=4cm]aux|-P) -- 
        (P) {[sharp corners] --
        ([yshift=-6pt]P) -- 
        ([yshift=-6pt]O|-P) } -- cycle;
      \draw[rounded corners=6pt,line width=1pt,blue,overlay]
        (O) --
        (O|-P) -- 
        (aux|-P) --
        ([yshift=12pt]aux|-P) --
        ([yshift=12pt,xshift=4cm]aux|-P) --
        ([xshift=4cm]aux|-P) -- 
        (P) --
        (P|-O);
      \node[overlay] at ([xshift=2cm,yshift=3pt]aux|-P)
        {\large Quote~\thequote} ; 
      },
    middleextra={
      \draw[rounded corners=6pt,line width=1pt,blue,overlay]
        (O|-P) -- 
        (O);
      \draw[rounded corners=6pt,line width=1pt,blue,overlay]
        (P) -- 
        (P|-O);
      },
    secondextra={
      \coordinate (aux) at ( $ (O)!0.5!(P|-O) $ );
      \draw[rounded corners=6pt,line width=1pt,blue,overlay]
        (O|-P) -- 
        (O) --
        (P|-O) --
        (P);
      },
    ]{quoter}


      %\string\newlabel{#2}{{1}{\thepage}{{#1}}{mylabelcounter.\number\value{mylabelcounter}}{}}


    %%%%% begin the beguine

    \begin{document}


    If you are interested in this, please see \textbf{\nameref{kierkegaard}}

    \clearpage

    \begin{quoter} %\label{quoter}

    \begin{center}
      \textbf{\labelText{Kierkegaard's quote, reproduced blindly from the internet}{kierkegaard}}
    \vspace{0.5em}
    \hrule
    \vspace{1em}

    \end{center}

    The function of prayer is not to influence God, but rather to change the nature of the one who prays.\footnote{Kierkegaard.}

    \end{quoter}

    \end{document}
  • Beautiful! And adding the possibility of a clickable hyperlink from the \nameref to the \labelText is easy and elegant as well? – Vincent Mia Edie Verheyen Apr 21 '16 at 11:17
  • 1
    @VincentVerheyen: See the update please. It required the correct link anchors provided, but this done now – user31729 Apr 21 '16 at 12:50
  • I have now asked a new question, since I would like to make your perfect answer compatible with another code; at the new question Macro: compatibility of 1) Auto-colorization & 2) Auto-counter-and-title-to-label. – Vincent Mia Edie Verheyen Apr 22 '16 at 23:58
  • @VincentVerheyen: Yes, but I won't address that -- luatex is not my favorite, actually. – user31729 Apr 23 '16 at 5:30
  • @ChristianHupfer - The OP's combined code suffered from the fact that the code of the \labelText macro wasn't sufficiently robust (paranoid?!) to deal with the possibility that the contents of the macro's first argument might get modified "on the fly" by a Lua function. I've provided an answer to the OP's follow-up query, in which I use the \hypertarget and \hyperlink macros in lieu of \labelText. If you feel like writing an alternate answer, it might be instructive to have a solution that works with a modified (more-robust?) version of \labelText. – Mico Apr 23 '16 at 16:53

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.