开发者

Custom formatting of LaTeX (beamer) frames in Vim using the gq command

I want to be able to use the gq key combination in Vim to format the text in my Beamer LaTeX slides.

For example, I'd like gqap to transform this:

\begin{frame}{Some title}
\begin{itemize}\item first point
\item second point
\item etc. point \end{itemize} \end{frame}

into this:

\begin{frame}{Some title}
  \begin{itemize}
    \item first point
    \item second point
    \item etc. point  
   \end{itemize} 
\end{frame}

Specifically, I'd like to observe the following rules:

  • \item always begins on a new line
  • \begin and \end always begin on a new line
  • \begin{frame} and \end{frame} always start in column 1
  • environments within environments are indented 2 spa开发者_运维问答ces
  • \item is indented 2 spaces within its environment

Thus, my core question relates to how the above could be achieved.

Alternatively, any suggestions on starting points or useful tutorials would be most helpful. I'd also be interested in any comments about the relative merits of formatexpr, formatprg, or internal formatting for performing such formatting.


After a little searching I found this useful answer on Tex.SE to a similar question. It provides a dedicated function for formatting Context source, which could be adapted to LaTeX.

I think I'd prefer something integrated with the built-in gq functionality in Vim. And the answer still requires a little bit of work to get configured with LaTeX, and I'm not sure what indenting it provides. Anyway, I thought I'd share it in case it was useful to others.


why don't try snipmate plugin

begin<tab>

to

begin{<cursor>env}                                                                                                                                                                         
    %text                                                                                                                                                                 
\end{env}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜