|
| 1 | +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" |
| 2 | +"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
| 3 | + |
| 4 | +<html xmlns="http://www.w3.org/1999/xhtml" lang="zh" xml:lang="zh"> |
| 5 | +<head> |
| 6 | + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
| 7 | + <link rel="stylesheet" type="text/css" href="learn-vi.css" /> |
| 8 | + <title>VIM学习笔记 编译文档(Compiling Latex)</title> |
| 9 | +</head> |
| 10 | +<body> |
| 11 | + <h1>VIM学习笔记 编译文档(Compiling Latex)</h1> |
| 12 | + <p>LaTeX是一种用于生成高印刷质量的科技和数学类文档的排版系统,可以生成包含复杂表格和数学公式的复杂文档。</p> |
| 13 | + <p>LaTeX文档是一个以<kbd>.tex</kbd>扩展名的文本文件,可以使用任意文本编辑器(比如Vim)编辑;在编辑完成后,可以编译为更容易阅读的文档格式(比如PDF)。</p> |
| 14 | + |
| 15 | + <h2 class="article"><a id="TeX-Live">TeX Live</a></h2> |
| 16 | + <p><a href="https://tug.org/texlive/" title="TeX Live">TeX Live</a>是一种免费的跨平台TeX文档制作系统。它包括所有与TeX相关的主要程序、宏包和字体,支持全球多种语言。许多Unix/GNU/Linux操作系统通过自己的包管理器提供TeX Live,但<strong>强烈推荐严格按照<a href="https://tug.org/texlive/quickinstall.html" title="Quick install for Unix">官方文档</a>进行手动安装</strong>。(另:<a href="https://tex.stackexchange.com/questions/1092/how-to-install-vanilla-texlive-on-debian-or-ubuntu" title="How to install TeXLive on Debian or Ubuntu?">参考</a>)</p> |
| 17 | + <p>在安装之后,增加以下PATH路径:</p> |
| 18 | + <pre class="block"><code class="inset">export PATH=$PATH:/usr/local/texlive/2025/bin/i386-linux |
| 19 | +export INFOPATH=$INFOPATH:/usr/local/texlive/2025/texmf-dist/doc/info |
| 20 | +export MANPATH=$MANPATH:/usr/local/texlive/2025/texmf-dist/doc/man</code></pre> |
| 21 | + <p>同理,使用以下命令为sudo增加安全路径:</p> |
| 22 | + <p style="text-indent:2em"><code class="inset">$ sudo visudo</code></p> |
| 23 | + <pre class="block"><code class="inset">Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/texlive/2025/bin/i386-linux"</code></pre> |
| 24 | + <p>使用<a href="https://tug.org/texlive/doc/tlmgr.html" title="tlmgr">tlmgr</a>更新Tex Live系统以及安装的Packages:</p> |
| 25 | + <p style="text-indent:2em"><code class="inset">$ sudo tlmgr update --self</code></p> |
| 26 | + <p style="text-indent:2em"><code class="inset">$ sudo tlmgr update --all</code></p> |
| 27 | + <p>如果在使用过程中,仍然出现类似以下缺失包的报错信息:</p> |
| 28 | + <p><code class="error">! LaTeX Error: File `gb4e.sty' not found.</code></p> |
| 29 | + <p>那么可以使用以下命令,手动安装缺失的包:</p> |
| 30 | + <p style="text-indent:2em"><code class="inset">$ sudo tlmgr install gb4e</code></p> |
| 31 | + |
| 32 | + <h2 class="article"><a id="Latex-Edit">编辑Latex文档</a></h2> |
| 33 | + <p>Vim内置了<a href="https://vimhelp.org/syntax.txt.html#latex-syntax" title="latex-syntax">Latex</a>语法高亮度,可以很方便地编辑文档。</p> |
| 34 | + <p><a href="https://yyq123.github.io/learn-vim/images/Latex-Syntax.png" title="Latex-Syntax"><img src="https://yyq123.github.io/learn-vim/images/Latex-Syntax.png" alt="Latex-Syntax" width="500" height="269" /></a></p> |
| 35 | + |
| 36 | + <h2 class="article"><a id="Latex-Compile">编译Latex文档</a></h2> |
| 37 | + <p>在Vim命令行中执行<a href="https://tug.org/applications/pdftex/" title="pdfTeX">pdfTeX</a>命令,可以将Latex源文件编译为更容易阅读的PDF文件:</p> |
| 38 | + <p style="text-indent:2em"><code class="inset">:!pdflatex sample.tex |
| 39 | +</code></p> |
| 40 | + <p>默认情况下,将显示类似以下输出信息,并等待用户按回车键以返回到Vim:</p> |
| 41 | + <p><code class="msg">Output written on sample.pdf (1 page, 66919 bytes).<br /> |
| 42 | +Transcript written on sample.log.<br /> |
| 43 | +Press ENTER or type command to continue</code></p> |
| 44 | + |
| 45 | + <h2 class="article"><a id="Latex-View-PDF">查看Latex输出文档</a></h2> |
| 46 | + <p>命令执行成功后,将在同一目录下,生成一个同名的PDF文件。同时还会生成一些辅助文件,如sample.log,其中包含有关编译过程的详细信息。</p> |
| 47 | + <p>使用以下命令,启动PDF查看器验证生成的输出结果:</p> |
| 48 | + <p style="text-indent:2em"><code class="inset">:zathura sample.pdf</code></p> |
| 49 | + <p><a href="https://yyq123.github.io/learn-vim/images/Latex-View-PDF.png" title="Latex-View-PDF"><img src="https://yyq123.github.io/learn-vim/images/Latex-View-PDF.png" alt="Latex-View-PDF" width="500" height="295" /></a></p> |
| 50 | + <h2 class="article"><a id="Latex-UDC">自动化Latex编译和输出</a></h2> |
| 51 | + <p>在vimrc启动文件中自定义以下命令:</p> |
| 52 | + <p style="text-indent:2em"><code class="inset">:command Latex execute "silent !pdflatex % > /dev/null && zathura %:r.pdf > /dev/null 2>&1 &" | redraw!</code></p> |
| 53 | + <ul> |
| 54 | + <li><code>silent</code>,将避免显示诸如 “Press ENTER to continue” 等命令执行过程中的提示信息;</li> |
| 55 | + <li><code>pdlatex</code>,将编译当前文件, <code> % > </code>将标准输出重定向到<code>/dev/null</code>而不是显示在屏幕上;</li> |
| 56 | + <li><code>zathura</code>,用于查看生成的PDF文件,即以<code>%:r</code>指定的当前文件名,以<code>.pdf</code>指定的后缀扩展名;</li> |
| 57 | + <li><code>redraw</code>,重画屏幕,以保证正常显示;</li> |
| 58 | + </ul> |
| 59 | + <p>在命令行中执行以下自定义命令,将自动化使用pdflatex来编译文档,并使用Zathura来显示生成的PDF文件:</p> |
| 60 | + <p style="text-indent:2em"><code class="inset">:Latex</code></p> |
| 61 | + <p>您也可以在vimrc启动文件中自定义以下快捷键:</p> |
| 62 | + <p style="text-indent:2em"><code class="inset">:map <F2> :Latex <CR></code></p> |
| 63 | + |
| 64 | + <p style="border-top:1px solid lightgray"><span style="float:right">Ver: 25.06.07 | <a href="mailto:yyq123@gmail.com">YYQ</a></span><span><<a title="编译源码(Compile Code)-C" href="http://yyq123.github.io/learn-vim/learn-vim-CompileCode-C.html">上一篇</a> |<a title="笔记列表" href="http://yyq123.github.com/learn-vim/learn-vi-00-00-TOC.html"> 目录 </a>| <a title="编译源码(Compile Code)-Java" href="http://yyq123.github.io/learn-vim/learn-vim-CompileCode-Java.html">下一篇</a>></span></p> |
| 65 | + |
| 66 | +</body> |
| 67 | +</html> |
0 commit comments