3

我使用 Vim 作为我的文本编辑器,我非常喜欢 beamer 作为幻灯片演示工具。但是,编译大型投影仪演示文稿可能需要一点时间(可能 10 或 20 秒)。这个时间对于普通的 LaTeX 文档来说通常很好,因为内容通常可以正常工作。在投影仪幻灯片中,有时会出现文本在幻灯片上的适合程度的问题。当幻灯片涉及更复杂的图形、文本等布局时也是如此。

我想使用 Vim 设置一个快捷命令,它只是将活动幻灯片编译为 PDF(由光标在相关frame环境之间定义)。

我意识到文档的序言和其他几个特征会影响幻灯片的确切格式。但是,我想一个近似值就足够了。也许只需编写序言和活动幻灯片就足够了。

任何建议都是最有帮助的。

4

2 回答 2

2

这是一个小函数,可以满足您的要求(将序言和当前帧复制到单独的文件中并编译它):

function! CompileCurrentSlide()
   let tmpfile = "current-slide.tex"
   silent! exe '1,/\s*\\begin{document}/w! '.tmpfile
   silent! exe '.+1?\\begin{frame}?,.-1/\\end{frame}/w! >> '.tmpfile
   silent! exe '/\s*\\end{document}/w! >> '.tmpfile
   silent! exe '!pdflatex -halt-on-error '.tmpfile.' >/dev/null'
endfunction
" 
noremap <silent><buffer> zz :silent call <SID>CompileCurrentSlide()<CR>

按 zz 将编译光标所在的任何帧,并将输出放在“current-slide.pdf”中。您可以将 -halt-on-error 替换为您想要的任何其他选项。该脚本不会像上一个答案中的函数那样打开单独的窗口;您只需继续编辑主文件。我不是 vim 专家,所以可能有更好的方法可以做到这一点,但上述方法对我来说在创建几个 Beamer 演示文稿时效果很好。

于 2011-09-19T16:30:11.120 回答
1

以下函数应创建一个仅包含前导码和当前帧的新临时文件。它以拆分方式打开文件,从那时起,您应该能够单独编译该文件并使用您执行的任何程序来查看它。我对 tex 了解不多,对 beamer 的了解更少,因此您可能需要对其进行调整以更好地满足您的需求。

function! CompileBeamer()
  " Collect the lines for the current frame:
  let frame = []
  if searchpair('\\begin{frame}', '', '\\end{frame}', 'bW') > 0
    let frame = s:LinesUpto('\\end{frame}')
    call add(frame, getline('.')) " add the end tag as well
  endif

  " Go to the start, and collect all the lines up to the first "frame" item.
  call cursor(1, 1)
  let preamble = s:LinesUpto('\\begin{frame}')

  let body = preamble + frame

  " Open up a temporary file and put the selected lines in it.
  let filename = tempname().'.tex'
  exe "split ".filename
  call append(0, body)
  set nomodified
endfunction

function! s:LinesUpto(pattern)
  let line = getline('.')
  let lines = []

  while line !~ a:pattern && line('.') < line('$')
    call add(lines, line)
    call cursor(line('.') + 1, 1)
    let line = getline('.')
  endwhile

  return lines
endfunction
于 2011-08-06T07:08:55.213 回答