I am trying to adapt this answer to produce the same result with a verse environment: I want to be able to copy a poem out of a PDF maintaining its indentation (numbering included) as typeset in the PDF.
Although the following MWE produces the desired result with the text in the verbatim environment, I can't get it working also with the verse environment that is additionally complicated by the verse numbering (which I also what to copy out from the PDF).
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{verse}
\usepackage{color}
\input{glyphtounicode}
\pdfglyphtounicode{visiblespace}{A0}
\pdfglyphtounicode{blank}{A0}
\pdfglyphtounicode{visualspace}{A0}
\pdfglyphtounicode{uni2423}{A0}
\pdfgentounicode=1
\begin{document}\showoutput
\makeatletter
\def\@xobeysp{\textcolor{white}{\char32}}
\makeatother
% Set style for poem typesetting
\verselinenumbersleft
\setlength{\vrightskip}{-2em}
\poemlines{5}
\begin{verbatim}
S'i' fosse foco
S'i' fosse foco, arderei 'l mondo;
s'i' fosse vento, lo tempesterei;
s'i' fosse acqua, i' l'annegherei;
s'i' fosse Dio, mandereil' en profondo;
s'i' fosse Papa, allor sarei giocondo,
che` tutti cristiani 'mbrigarei;
s'i' fosse 'mperator, ben lo farei:
a tutti taglierei lo capo a tondo.
S'i' fosse morte, andarei a mi' padre;
s'i' fosse vita, non starei con lui:
similmente faria con mi' madre.
S'i' fosse Cecco, com'i' sono e fui,
torrei le donne giovani e leggiadre:
le zoppe e vecchie lasserei altrui.
\end{verbatim}
\begin{verse}
\poemtitle{S'i' fosse foco}
S'i' fosse foco, arderei 'l mondo;\\
\hspace{2em}s'i' fosse vento, lo tempesterei;\\
\hspace{2em}s'i' fosse acqua, i' l'annegherei;\\
\hspace{2em}s'i' fosse Dio, mandereil' en profondo;\\!
s'i' fosse Papa, allor sarei giocondo,\\
\hspace{2em}che` tutti cristiani 'mbrigarei;\\
\hspace{2em}s'i' fosse 'mperator, ben lo farei:\\
\hspace{2em}a tutti taglierei lo capo a tondo.\\!
S'i' fosse morte, andarei a mi' padre;\\
\hspace{2em}s'i' fosse vita, non starei con lui:\\
\hspace{2em}similmente faria con mi' madre.\\!
S'i' fosse Cecco, com'i' sono e fui,\\
\hspace{2em}torrei le donne giovani e leggiadre:\\
\hspace{2em}le zoppe e vecchie lasserei altrui.\\!
\end{verse}
\end{document}
Indeed I have no idea what the code
\input{glyphtounicode}
\pdfglyphtounicode{visiblespace}{A0}
\pdfglyphtounicode{blank}{A0}
\pdfglyphtounicode{visualspace}{A0}
\pdfglyphtounicode{uni2423}{A0}
\pdfgentounicode=1
\begin{document}\showoutput
\makeatletter
\def\@xobeysp{\textcolor{white}{\char32}}
\makeatother
produces, so I can't really tweak it for the verse environment.

versedo you need? because as it stands I am afraid rather extensive re-write of verse innards are needed; things like\hspacewill need to be redefined inside the environment. If mainly you need the numbering, I would go for an environment simply obeying spaces and line breaks and adding the automatic numbering. – May 15 '14 at 06:35\pdfglyphtounicodelines. On the other hand the code as is works well with acroread, but ceases to work with it if the\pdfglyphtounicodelines are used. – May 15 '14 at 16:23