Math & ScienceCustom Environment for dealing with Quotations

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
EggMeister
Posts: 1
Joined: Mon Aug 08, 2011 3:18 pm

Custom Environment for dealing with Quotations

Post by EggMeister »

Hi all,

In qualitative research and the social sciences you often have a lot of quotes from various interviewees and / or other research participants to use and keep track of in your text. Ideally, I wanted to be able to treat quotations in a way similar to equations; set apart from the body of the text, automatic numbering, being able to refer to them from the text, etc. After a lot of searching around and piecing together separate how-tos and pieces of advice, I've created my own environment for easily dealing with quotations. It has automatic numbering, can be cross-referenced to, and allows for the attribution to be passed as a parameter. It took me quite some time to figure all this out so I wanted to share it here so the next person who needs something like this won't have to go through the same effort.

First I'll give an example of what it does;

Code: Select all

Quote \ref{ExampleQuote} contains an example.

\begin{QuoteEnv}{Person who said it}
\label{ExampleQuote}
	``An example of a quotation''
\end{QuoteEnv}
This results in the following:
ExampleQuotation.png
ExampleQuotation.png (8.92 KiB) Viewed 1311 times
The environment that makes this possible is defined as follows:

Code: Select all

\usepackage{fmtcount}

% set background color for quotation box
\definecolor{QuoteEnvshade}{HTML}{F0F0F0} 
\newcommand{\tmpQuote}{}%temporary storage for supplied quote
\newcommand{\tmpNumber}{}%temporary storage for current quote number
\newcounter{quotationsCounter} \setcounter{quotationsCounter}{0}
\newenvironment{QuoteEnv}[1]
%before
{%
	\refstepcounter{quotationsCounter}
	
	%%have to store the parameter and counter value temporarily to use it in 'after' section of command
	\renewcommand{\tmpQuote}{#1}
	\renewcommand{\tmpNumber}{\decimal{quotationsCounter}}
	
	\def\FrameCommand{%
		\hspace{1pt}%
		{\color{Blue}\vrule width 2pt}%
		{\color{QuoteEnvshade}\vrule width 4pt}%
		\colorbox{QuoteEnvshade}%
	}%
	\MakeFramed{\advance\hsize-\width\FrameRestore}%
	\noindent\hspace{-4.55pt}% disable indenting first paragraph
	\begin{adjustwidth}{}{7pt}%
	\vspace{2pt}\vspace{2pt}%
}
%after
{%
	\begin{center}
		\footnotesize Quotation \tmpNumber, \emph{\textbf{\tmpQuote}}
	\end{center}
	\vspace{2pt}
	\end{adjustwidth}
	\endMakeFramed
}
Storing the attribution and the current table count was necessary because newenvironment doesn't have access to these directly in the 'after' section.

Disclaimer; I am not a LaTeX expert by any means. Quite to the contrary. While this function may seem trivial to some of the more die-hard LaTeX experts, I hope it'll be of use to other non-experts like me.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Post Reply