No edit summary |
(LaTeX-Box, not Vim-Box) Tag: Visual edit |
||
(14 intermediate revisions by 7 users not shown) | |||
Line 1: | Line 1: | ||
+ | {{TipNew |
||
⚫ | When editing LaTeX files from Vim, you want to be able to compile latex, retrieve a list of errors, step through errors, etc. |
||
+ | |id=1678 |
||
+ | |previous=1677 |
||
+ | |next=1679 |
||
+ | |created=November 28, 2011 |
||
+ | |complexity=basic |
||
+ | |author=Wuzzeb |
||
+ | |version=7.0 |
||
+ | |subpage=/201111 |
||
+ | |category1=LaTeX |
||
+ | |category2= |
||
+ | }} |
||
⚫ | When editing LaTeX files from Vim, you want to be able to compile latex, retrieve a list of errors, step through errors, etc. This tip explains the different options. They all work with the quickfix feature of Vim ({{help|quickfix}}), so before using this tip you need to be familiar with the basics of quickfix operation. |
||
− | == |
+ | ==Vim-Latex plugin== |
⚫ | The ''Vim-LaTeX'' plugin sets up make, makeprog, and errorformat for compiling single latex files on any system. See the [http://vim-latex.sourceforge.net/documentation/latex-suite/latex-compiling.html vim-latex documentation] for more details about compiling. The vim-latex compilation has several limitations on large multi-document projects which include figures, plots, etc where there are more steps to building than just running pdflatex. This makes building using the vim-latex provided features somewhat awkward. |
||
+ | If you want to automatically compile and refresh xdvi whenever you write the current buffer, you can add the following code into your tex.vim ftplugin. |
||
⚫ | The |
||
+ | <pre> |
||
+ | au BufWritePost *.tex silent call Tex_RunLaTeX() |
||
+ | au BufWritePost *.tex silent !pkill -USR1 xdvi.bin |
||
+ | </pre> |
||
+ | |||
+ | Note that ''Vim-LaTeX'' should be downloaded from its [http://vim-latex.sf.net web page]. The version at {{script|id=475}} is outdated and will not be updated. |
||
+ | |||
+ | ==Automatic LaTeX plugin== |
||
+ | The [http://atp-vim.sf.net AutomaticLaTeX Plugin] has a build-in solution for compiling LaTeX files when they got changed (using CursorHold and CursorHoldI autcommand groups). Compiles documents in the '''background''', and shows a '''progress bar''' in the vim status line. It also rewrites the log file into a vim readable form and has options to filter errors, warnings and info messages in the QuickFix window. It also has ''':MakeLatex''' command which builds the document and runs TeX's friends when necessary. Additionally, it includes {{script|id=3109}} to provide interface to [http://www.phys.psu.edu/~collins/software/latexmk-jcc/ Latexmk]. |
||
+ | This plugin works under ''Linux'' and ''MacOs'' and for best performance requires a recent version of Vim (7.3.468) with ''Python'' interface. The plugin has a very rich '''completion''', which makes writing LaTeX files much faster and easier. For a long '''list of features''' see the web page [http://atp-vim.sourceforge.net/features.shtml], [http://atp-vim.sourceforge.net/automatic-tex-plugin.html online documentation] there are also some [http://atp-vim.sourceforge.net/videos.shtml videos] which advertise some nice features. |
||
⚫ | |||
+ | ==Other plugins== |
||
⚫ | [https://launchpad.net/rubber Rubber] (sudo apt-get install rubber) is a wonderful tool for compiling latex files. |
||
+ | [http://atp-vim.sf.net Automatic LaTeX Plugin] and [http://vim-latex.sf.net Vim-LaTeX] are fully flagged plugins, if you prefer a smaller solutions there are also these plugins available: |
||
+ | * LaTeX''-Box'' {{script|id=3109}} which is using [http://atp-vim.sourceforge.net/features.shtml Latexmk] |
||
+ | * ''TeX-9'' {{script|id=3508}} a nice small plugin written in ''Python'' |
||
+ | * ''TeX-PDF'' {{script|id=3230}} which uses Makefile if present, otherwise invokes [https://launchpad.net/rubber Rubber] |
||
+ | * ''TeX Mini'' {{script|id=3058}} |
||
+ | There are also other LaTeX plugins which do not provide interface for compilation" |
||
+ | * ''AucTex'' {{script||id=162}} |
||
+ | * ''Tex Autoclose'' {{script|id=920}} |
||
⚫ | |||
⚫ | |||
⚫ | [https://launchpad.net/rubber Rubber] (<code>sudo apt-get install rubber</code>) is a wonderful tool for compiling latex files. It knows how many times to compile, knows to run bibtex, filters error messages and warnings (so you can ignore overfull hboxes until you want to see them), and so on. Rubber combined with make is a great fit for Vim's quickfix. |
||
⚫ | |||
<pre> |
<pre> |
||
.PHONY: clean |
.PHONY: clean |
||
Line 22: | Line 54: | ||
</pre> |
</pre> |
||
− | Edit to your taste. |
+ | Edit to your taste. In particular, you might consider updating the clean to not remove all pdfs (if you have figures in pdfs) perhaps using rubber <code>--clean</code> (see rubber's man page). Other changes include ignoring certain warnings or passing other options to rubber (see the man page). Also, you might add a tags target which runs ctags with the correct options (see [http://vim-taglist.sourceforge.net/extend.html tag-list documentation] for ctags arguments). |
− | |||
⚫ | |||
⚫ | |||
<pre> |
<pre> |
||
setlocal errorformat=%f:%l:\ %m,%f:%l-%\\d%\\+:\ %m |
setlocal errorformat=%f:%l:\ %m,%f:%l-%\\d%\\+:\ %m |
||
if filereadable('Makefile') |
if filereadable('Makefile') |
||
− | + | setlocal makeprg=make |
|
else |
else |
||
− | + | exec "setlocal makeprg=make\\ -f\\ ~/academic/tools/latex.mk\\ " . substitute(bufname("%"),"tex$","pdf", "") |
|
endif |
endif |
||
</pre> |
</pre> |
||
− | If the current directory does not have a Makefile, it sets makeprog to compile using the generic makefile. |
+ | If the current directory does not have a Makefile, it sets makeprog to compile using the generic makefile. This works great on single-file latex files where a makefile is overkill. |
− | |||
⚫ | |||
⚫ | |||
<pre> |
<pre> |
||
DEPENDS=intro.tex somesection.tex somethingelse.tex appendix.tex refs.bib |
DEPENDS=intro.tex somesection.tex somethingelse.tex appendix.tex refs.bib |
||
Line 48: | Line 78: | ||
</pre> |
</pre> |
||
− | and from here you can add more targets, creating figures, etc. |
+ | and from here you can add more targets, creating figures, etc. Anything make can do, you can insert it here. |
− | |||
⚫ | |||
− | |||
⚫ | |||
⚫ | |||
⚫ | |||
<pre> |
<pre> |
||
let b:tex_flavor = 'pdflatex' |
let b:tex_flavor = 'pdflatex' |
||
Line 62: | Line 90: | ||
While it is possible to grep the output to filter the output from pdflatex, using rubber is a much better option since it knows all about filtering and compiling more than once. |
While it is possible to grep the output to filter the output from pdflatex, using rubber is a much better option since it knows all about filtering and compiling more than once. |
||
+ | |||
+ | ==Comments== |
||
+ | In the [[#Manual setup]] section, what's wrong with the default makeprg and errorformat set up by the "compiler tex" command? This section should probably go first to show what Vim offers out-of-the-box, then explain what is wrong with it, THEN present the alternatives. --[[User:Fritzophrenic|Fritzophrenic]] 21:02, June 15, 2012 (UTC) |
Revision as of 15:28, 9 August 2014
created November 28, 2011 · complexity basic · author Wuzzeb · version 7.0
When editing LaTeX files from Vim, you want to be able to compile latex, retrieve a list of errors, step through errors, etc. This tip explains the different options. They all work with the quickfix feature of Vim (:help quickfix), so before using this tip you need to be familiar with the basics of quickfix operation.
Vim-Latex plugin
The Vim-LaTeX plugin sets up make, makeprog, and errorformat for compiling single latex files on any system. See the vim-latex documentation for more details about compiling. The vim-latex compilation has several limitations on large multi-document projects which include figures, plots, etc where there are more steps to building than just running pdflatex. This makes building using the vim-latex provided features somewhat awkward.
If you want to automatically compile and refresh xdvi whenever you write the current buffer, you can add the following code into your tex.vim ftplugin.
au BufWritePost *.tex silent call Tex_RunLaTeX() au BufWritePost *.tex silent !pkill -USR1 xdvi.bin
Note that Vim-LaTeX should be downloaded from its web page. The version at script#475 is outdated and will not be updated.
Automatic LaTeX plugin
The AutomaticLaTeX Plugin has a build-in solution for compiling LaTeX files when they got changed (using CursorHold and CursorHoldI autcommand groups). Compiles documents in the background, and shows a progress bar in the vim status line. It also rewrites the log file into a vim readable form and has options to filter errors, warnings and info messages in the QuickFix window. It also has :MakeLatex command which builds the document and runs TeX's friends when necessary. Additionally, it includes script#3109 to provide interface to Latexmk.
This plugin works under Linux and MacOs and for best performance requires a recent version of Vim (7.3.468) with Python interface. The plugin has a very rich completion, which makes writing LaTeX files much faster and easier. For a long list of features see the web page [1], online documentation there are also some videos which advertise some nice features.
Other plugins
Automatic LaTeX Plugin and Vim-LaTeX are fully flagged plugins, if you prefer a smaller solutions there are also these plugins available:
- LaTeX-Box script#3109 which is using Latexmk
- TeX-9 script#3508 a nice small plugin written in Python
- TeX-PDF script#3230 which uses Makefile if present, otherwise invokes Rubber
- TeX Mini script#3058
There are also other LaTeX plugins which do not provide interface for compilation"
- AucTex script#162
- Tex Autoclose script#920
Rubber plus Make
Rubber (sudo apt-get install rubber
) is a wonderful tool for compiling latex files. It knows how many times to compile, knows to run bibtex, filters error messages and warnings (so you can ignore overfull hboxes until you want to see them), and so on. Rubber combined with make is a great fit for Vim's quickfix.
First, create a generic makefile for compiling latex using rubber and place it in some global location (I use ~/academic/tools/latex.mk
).
.PHONY: clean %.pdf: %.tex $(DEPENDS) rubber -f --pdf -s $< rubber-info --check $< clean: rm -rf *.aux *.bbl *.blg *.log *.pdf *.toc *.snm *.out *.nav tags
Edit to your taste. In particular, you might consider updating the clean to not remove all pdfs (if you have figures in pdfs) perhaps using rubber --clean
(see rubber's man page). Other changes include ignoring certain warnings or passing other options to rubber (see the man page). Also, you might add a tags target which runs ctags with the correct options (see tag-list documentation for ctags arguments).
Now in your tex.vim
ftplugin add the following lines:
setlocal errorformat=%f:%l:\ %m,%f:%l-%\\d%\\+:\ %m if filereadable('Makefile') setlocal makeprg=make else exec "setlocal makeprg=make\\ -f\\ ~/academic/tools/latex.mk\\ " . substitute(bufname("%"),"tex$","pdf", "") endif
If the current directory does not have a Makefile, it sets makeprog to compile using the generic makefile. This works great on single-file latex files where a makefile is overkill.
If you have a multi-file, complicated build project, you can create a custom makefile for the project. Mine normally start out like:
DEPENDS=intro.tex somesection.tex somethingelse.tex appendix.tex refs.bib .PHONY: all all: mypaper.pdf include ~/academic/tools/latex.mk
and from here you can add more targets, creating figures, etc. Anything make can do, you can insert it here.
Manual setup
I strongly suggest you use one of the above options, but it is possible to set makeprg and errorformat directly and use the built in tex compiler.
let b:tex_flavor = 'pdflatex' compiler tex set makeprg=pdflatex\ \-file\-line\-error\ \-interaction=nonstopmode set errorformat=%f:%l:\ %m
While it is possible to grep the output to filter the output from pdflatex, using rubber is a much better option since it knows all about filtering and compiling more than once.
Comments
In the #Manual setup section, what's wrong with the default makeprg and errorformat set up by the "compiler tex" command? This section should probably go first to show what Vim offers out-of-the-box, then explain what is wrong with it, THEN present the alternatives. --Fritzophrenic 21:02, June 15, 2012 (UTC)