# Macro for handling placement of last quotation mark when setting quotes in text?

When including quotes in a text, there are some styles that need to be adhered to. One style is to always place the last quote where the actual quote ends, no matter the next character (e.g. ... and then he said, "This is a disgrace", which is uncommon even for him.. Another style is to include punctuation marks inside the quote if such characters follow the quote (e.g. ... and then he said, "This is a disgrace," which is uncommon even for him.).

Once selected, a style should be consistent throughout the document. Thus, I figured it would be nice to use a macro which took care of this, like so:

... and then he said, \quote{This is a disgrace}, which is uncommon even for him.


The macro should then be able to wrap the argument in quotation marks scan the next character and place the last quotation mark where appropriate, depending on the desired style. (I know that \ifnextchar can be used to scan the following character, but not how to move it inside the quote if necessary.)

-
I believe that the csquotes package does it. –  egreg Mar 2 '12 at 10:16
@egreg: Indeed it does. But for sake of interest, how would one go about doing it if csquotes wasn't available? =) –  gablin Mar 4 '12 at 9:50

The package csquotes does this job and there's no much point in reinventing the wheel. :)

Just to play with \futurelet here's a way to put commas, periods, colons and semicolons before the closing quotes:

\documentclass{article}
\makeatletter
\DeclareRobustCommand{\squote}[1]{#1\futurelet\@squotenext\@squotedecide}
\def\@squotedecide{%
\if\noexpand\@squotenext,\let\next\@squotecorrect\else
\if\noexpand\@squotenext.\let\next\@squotecorrect\else
\if\noexpand\@squotenext:\let\next\@squotecorrect\else
\if\noexpand\@squotenext;\let\next\@squotecorrect\else
''\let\next\relax
\fi
\fi
\fi
\fi\next}
\def\@squotecorrect#1{\@squotenext''}
\makeatother

\begin{document}
and then he said, \squote{This is a disgrace}, which is uncommon even for him.

and then he said, \squote{This is a disgrace,} which is uncommon even for him.
\end{document}

-
It might be worth noting that (despite the original request), colons and semi-colons are always put outside of the closing quotation mark. –  jon Mar 4 '12 at 20:55
@jon Just remove the relevant lines from the code (and the corresponding \fi). –  egreg Mar 4 '12 at 21:10
Yes. My comment was less about correcting your answer and more as a caveat for people who adopt the solution blindly. –  jon Mar 4 '12 at 21:31