附加文本块的副本

appending a copy of a text block

我正在做一个 LaTeX beamer 演示文稿,我想在每个 \item 标题下面添加一个注释部分,它只是复制其文本。例如我有

\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}

我想要

\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}

如何在 vim 或使用 awksed 等命令行工具执行此操作?

通过 vim 我可以通过

copy-and-append 以模式 \item 开头的隔离行
:g/^\item/ copy . | s//\note\{item\}<.>\{/g

但我无法捕获属于每个 top-level \item.

的整个块

这可能对你有用 (GNU sed):

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

关注 \begin{itemize}\end{itemize}

之间的行

复制每个 \item 并将副本附加到每个 \item 节,用所需的 \note 命令替换 \item 命令。

N.B。解决方案取决于缩进 \item 命令的空格,目前缩进设置为 4 个空格,但可以使用制表符(请参阅第二行开头的正则表达式)。