Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 spaces
  • \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.

like image 530
Jeromy Anglim Avatar asked Aug 25 '11 07:08

Jeromy Anglim


1 Answers

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.

like image 58
Jeromy Anglim Avatar answered Sep 19 '22 14:09

Jeromy Anglim