10

This looks like a very simple problem, but I can't find any obvious solution. I am dealing with long lists of quotes, and currently I'm doing it manually:

 \begin{itemize}
  \item "1st quote here."
  \item "2nd quote here."
\end{itemize}

Manually typing in quotation marks '00s of times gets old fast. Is there a switch I could use for quoting each item of a list in one go?

10

You could create a command that redefines \item.

\documentclass{article}
\let\olditem\item
\newcommand{\StartQuotation}{%
\def\item{\unskip''\olditem``}``%
}
\begin{document}
\begin{itemize}
  \item\StartQuotation 1st quote here.
  \item 2nd quote here.
  \item 3nd quote here.
  \item 4th quote here.''
\end{itemize}
\end{document}

enter image description here

You still have add \StartQuotation and one '' per list, but not more than that.

  • 3
    Absolutely perfect! This is exactly what I wanted. Thanks, @Schrödinger'scat! – user3671 Jan 18 at 6:41
  • 1
    @user3671 You're welcome! – Schrödinger's cat Jan 18 at 6:55
7

An elegant way do this is to use regular expressions from LaTeX3. The idea is to use the \item commands to split the contents of the environment after which you can recreate the itemize environment with quotation marks around each entry. This way the code:

  \begin{qitemize}
    \item 1st quote here.
    \item 2nd quote here.
  \end{qitemize}

produces the requested output of:

enter image description here

The code itself is not that long but if you are not familiar with LaTeX3 and regular expressions then it may look a little cryptic.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{xparse}

\ExplSyntaxOn
\seq_new:N \l_items_seq
\NewDocumentEnvironment{qitemize}{ +b }{
  % split the environment contents around the \item commands
  \regex_split:nnN { \s*\c{item}\s* } { #1 } \l_items_seq
  \seq_pop_left:NN \l_items_seq \l_items_tl % pop empty first item
  \seq_if_empty:NF \l_items_seq { % check for no items
    \begin{itemize}% create the quoted itemize environment
      \seq_map_inline:Nn \l_items_seq { \item ``##1'' }
    \end{itemize}
  }
}{}
\ExplSyntaxOff

\begin{document}

  \begin{qitemize}
    \item 1st quote here.
    \item 2nd quote here.
  \end{qitemize}

\end{document}

Above I said that I split the contents of the environment around the \item commands but this was a slight lie because the code actually splits around the \item command together with the spaces on either side of it, which is why the two \s* appear inside the regular expression. This is so that you do not end up quoting the spaces before and after each item.

Finally, note that the \item command in the qitemize environment does not correctly cater for an optional argument, such as \item[*] quoted item. With a little extra work this would be possible.

  • Thanks, @Andrew - I was not aware of LaTeX3. Will definitely look into this. – user3671 Jan 18 at 9:57

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.