【问题标题】:Compile and display PDF of individual slide in beamer presentation using Vim使用 Vim 在 beamer 演示文稿中编译和显示单个幻灯片的 PDF
【发布时间】:2011-08-05 11:41:40
【问题描述】:

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

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

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

任何建议都会很有帮助。

【问题讨论】:

  • 如果您投票支持其中一个或另一个作为提供可行的解决方案,这将对我们其他用户提供信息。

标签: vim latex beamer


【解决方案1】:

这是一个小函数,可以做你想做的事(将序言和当前帧复制到一个单独的文件中并编译它):

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 演示文稿时效果很好。

【讨论】:

    【解决方案2】:

    以下函数应创建一个仅包含前导码和当前帧的新临时文件。它以拆分方式打开文件,从那时起,您应该能够单独编译该文件并使用您执行的任何程序来查看它。我对 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
    

    【讨论】:

      猜你喜欢
      • 2023-02-23
      • 2021-06-02
      • 2017-10-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-17
      • 1970-01-01
      相关资源
      最近更新 更多