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

2

9

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.

Foxglove answered 25/8, 2011 at 7:3 Comment(1)
@ Whoever voted to close: it’s been long established that questions about programming tools, notably Emacs and Vim, are on topic here.Abscissa
F
1

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.

Foxglove answered 26/8, 2011 at 3:19 Comment(0)
C
0

why don't try snipmate plugin

begin<tab>

to

begin{<cursor>env}                                                                                                                                                                         
    %text                                                                                                                                                                 
\end{env}
Caroylncarp answered 27/4, 2012 at 14:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.