appending a copy of a text block

Viewed 76

I'm working on a LaTeX beamer presentation where I'd like to add a notes section below each \item heading which simply copies its text. For example I have

\begin{frame}{Frame Title}
\begin{itemize}[<+->]
    \item Einstein was a clever man.
    \item My favorite equation is,
    \begin{equation}
        E = m c^2.
    \end{equation} where
    \begin{enumerate}
        \item $m$ is the mass,
        \item $c$ the velocity of light and,
        \item $E$ is the energy.
    \end{enumerate}
\end{itemize}
\end{frame}

and I would like to have

\begin{frame}{Frame Title}
\begin{itemize}[<+->]
    \item Einstein was a clever man.
    \note<.>[item]{
          Einstein was a clever man.
    }
    \item My favorite equation is,
    \begin{equation}
        E = m c^2.
    \end{equation} where
    \begin{enumerate}
        \item $m$ is the mass,
        \item $c$ the velocity of light and,
        \item $E$ is the energy.
    \end{enumerate}

    \note<.>[item] { 
          My favorite equation is,
    \begin{equation}
        E = m c^2.
    \end{equation where
    \begin{enumerate}
        \item $m$ is the mass,
        \item $c$ the velocity of light and,
        \item $E$ is the energy.
    \end{enumerate}
    }
\end{itemize}
\end{frame}

How can I do this in vim, or using command line tools like awk or sed?

Via vim I'm able to copy-and-append isolated lines starting with the pattern \item via

:g/^\\item/ copy . | s//\\note\{item\}<.>\{/g

but I'm unable to capture the whole block belonging to each top-level \item.

1 Answers

This might work for you (GNU sed):

sed -E '/^\\begin\{itemize\}/{:a;n;/^\\end\{itemize\}/bb
        /^( {4}|\t)\\item/{
          :b;x;s/^(\s*)\\item(.*)/\1\\note<.*>[item]{\n\1\1\2\n\1}/p;x;h;ba}
        H;ba}' file 

Focus on lines between \begin{itemize} and \end{itemize}

Make a copy of each \item and append the copy to each \item stanza, replacing the \item command by the desired \note command.

N.B. The solution depends on the whitespace indenting the \item command, currently the indent is set at 4 spaces but tabs may be used (see regexp at the beginning of the second line).

Related