5

I am a long time user of latex and I have been searching for a good editor to use it with. I have been using TexStudio but recently I feel I need the no distractions feel of using vim. So I stumbled upon vim-latex and here is where my problems started.

I went on their site and followed the instructions but I don't think they are complete or clear enough. I copied everything as per instructions but I can't make it work. Then there is the problem of usage. How does one use vim-latex? Is there a command, a key press?

Is vim-latex the best option for using latex in vim? Or should I look elsewhere?

Cheers

Edit: The details

1) Downloaded the archive from here

2) Unpacked the archive and ended up with a dir called vim-latex-1.10.0 which I then copied to my .vim dir 3) Then I went and did the changes in the .vimrc file, but I had to stop at the tex.vim because it wasn't where the instructions said it was supposed to be.

4) I started vim regardless and issued the helptags ~/.vim/doc command which didn't work. The output was E150: Not a directory: ~/.vim/doc

5) Regarding compilation: I know about reading the manuals and I usually do, but this particular one is not very clear at least to a noob like me when it comes to vim. Here is what it says at

Setting Compilation rules:

"In order to compile LaTeX files into various formats, Latex-Suite needs to know which external programs to call and in which way they need to be called. This information is provided to Latex-Suite via a number of "rules". For each format you want to compile to, you need to specify a rule. A rule is specified by defining a variable of the form:"

Where do you put these rules?

Now what should I do?

lucian
  • 153
  • 5
  • 2
    We'll need you to help us to help you :) "I copied everything": what did you copy exactly? Where did you put it? "but I can't make it work": What have you tried to do? Why do you say it doesn't work? What were you expecting and what do you get? Finally "Is there a command, a key press": you will have to read the doc at least a little bit. – statox Nov 13 '18 at 10:40
  • Did you notice following question on tex.stackexchange.com https://tex.stackexchange.com/questions/112698/how-to-install-vim-latex ? – Hotschke Nov 13 '18 at 10:50
  • @statox see the new edits please and thank you for your help. – lucian Nov 13 '18 at 11:14
  • @Hotschke I did see that question and tried with pathogen and vundle but I couldn't get it working. – lucian Nov 13 '18 at 11:15
  • @lucian you probably should copy the contents of the vim-latex-1.10.0 folder into your .vim folder. – Christian Brabandt Nov 13 '18 at 11:25
  • Possible interesting related question: https://vi.stackexchange.com/q/2047/71 – Christian Brabandt Nov 13 '18 at 11:25
  • 1
    @Lucian: Ok. At least, I now know that you already tried to use pathogen and vundle to install plugins. Did you manage to install successfully other plugin(s)? There is the general question on how to install plugins for vim https://vi.stackexchange.com/questions/613/. Also do you know that there is a maintained github repository for vim-latex: https://github.com/vim-latex/vim-latex. I personally use vimtex another popular latex plugin for vim (according to stars on github it is more popular than vim-latex). I would recommend this instead of vim-latex. – Hotschke Nov 13 '18 at 11:34
  • @Hotschke Not sure if they installed but after issuing the PluginInstall with vundle I got the message done and that's it. I will try vimtex too. Does it have a way to insert environments like equations or stuff like that? Autocompletion for references and equations? – lucian Nov 13 '18 at 11:44
  • To answer your questions about vimtex: it provides an omnicompletion source for references and labels to equations, figures, etc. So a yes here. For inserting environments etc, you are typically referred to a snippet plugin for vim, e.g. UltiSnips and a snippet repository, e.g. https://github.com/honza/vim-snippets/blob/master/UltiSnips/tex.snippets. Also vim-surround and vim-sandwich provide support for inserting environments and more. Latex enviornments support is undocumented in the case of vim-surround: https://github.com/tpope/vim-surround/commit/ac67c1a7387a9e1c082fa98e7526b7b633f4beec – Hotschke Nov 13 '18 at 12:50
  • 1
    For more details about vimtex, you should have a look at its README.md. – Hotschke Nov 13 '18 at 12:53

1 Answers1

6

Installation into a Vim 8 packpath and an example vimrc

  1. ❯ git clone https://github.com/vim-latex/vim-latex ~/.vim/pack/my_latex_plugins/start/vim-latex

  2. Typically, you want at least following settings in your vimrc

    ❯ cat ~/.vim/vimrc
    filetype plugin on
    filetype indent on
    let g:tex_flavor='latex'
    

A minimal installation would look like visualized with tree:

~/.vim
❯ tree -L 5
.
├── pack
│   └── my_latex_plugins
│       └── start
│           └── vim-latex
│               ├── Makefile
│               ├── Makefile.in
│               ├── README.md
│               ├── compiler
│               ├── doc
│               ├── ftplugin
│               ├── indent
│               ├── latextags
│               ├── ltags
│               ├── plugin
│               └── vim-latex.metainfo.xml
└── vimrc

Mini Tutorial: Compile a Hello World in LaTeX to pdf

Create a new file with extension tex as following

❯ vim demo.tex

switch to insert mode (type i) and type

EDO

This will trigger a snippet and the buffer should now look like:

enter image description here

You can jump around with <C-j> to adjust the placeholders <++> for the documentclass options, the documentclass and begin typing the document:

I entered a Hello World equivalent for LaTeX with

<Backspace> + <C-j> + article + <C-j> + Hello World! which gives you:

enter image description here

Now press :w for saving the file and start compilation with <leader>ll. This is by default \ll. Note these are lower case L (not \11). Right now this starts latex on windows/linux which generates a dvi file (on a mac pdflatex is called by default). To get immediately a pdf on windows/linux, you have to configure vim-latex a little bit more. But first you should get acquainted with the manual of vim-latex:

In order to read the manual of vim-latex, you need to run

:helptags ALL

or

:helptags ~/.vim/pack/my_latex_plugins/start/vim-latex/doc 

to generate a so-called tags file so vim can find the manual.

You can now open the manual with :h latex-suite (not :h vim-latex).

There is a second help file, the quickstart tutorial under

:h latex-suite-quickstart

As a beginner you should take the time (30-40 min.) to go through the quickstart tutorial. It covers the basics of this feature rich plugin.

The settings for adjusting the compilation can be found under :h customizing-compiling which will tell you about

g:Tex_DefaultTargetFormat                                  *ls_11_6_1* *ls_a_dF*
                                                       *Tex_DefaultTargetFormat*


Type             String
Default Value    dvi for windows/*nix and pdf for mac

Use this setting to choose the default target format. For example, setting this
to pdf makes Latex-Suite compile a pdf file when you press \ll and fire up the
pdf viewer on pressing \lv. Make sure that a rules for compiling and viewing
have been defined for this target format as described here [|ls_a_dG|] and here
[|ls_a_dO|].

So on windows/linux you have to add following line to your vimrc to compile directly to pdf:

let g:Tex_DefaultTargetFormat = 'pdf'

I am on a mac where 'pdf' is already the default.

More questions about installation of vim-latex

If this answer does not help, consider also following questions with answers:

Hotschke
  • 4,740
  • 26
  • 37
  • Hey, that worked! Thank you for also explaining what the <leader> was! One thing was different, the result was not a pdf but a dvi. How can I get a pdf? – lucian Nov 13 '18 at 12:06
  • Please see my additions to my answer about accessing the manual of vim-latex and the setting g:Tex_DefaultTargetFormat. – Hotschke Nov 13 '18 at 12:15
  • I get this error when I run :helptags ALL: E152: Cannot open /usr/share/vim/vim81/doc/tags for writing. And where do I add the let command? In the .vimrc? – lucian Nov 13 '18 at 12:18
  • you can ignore the helptags error. /usr/share/vim/vim81/doc/tags has not been changed and you cannot write to it. You basically only want to have all tag files updated that reside inside your ~/.vim/ directory – Christian Brabandt Nov 13 '18 at 12:20
  • As said you can ignore this: The argument ALL tells vim to generate for the complete vim documentation the tag files. This is not necessary for the files under /usr/share/vim/vim81/doc/. I use ALL because it is easy to remember and short to type but actually not necessary. – Hotschke Nov 13 '18 at 12:21
  • Thank you all for your help! I can now start to familiarise myself with vim-latex! I will mark this as the answer to my question! – lucian Nov 13 '18 at 13:01
  • You are welcome. Happy latex-ing in vim! – Hotschke Nov 13 '18 at 13:06
  • @Hotschke I have one more question if you don't mind: looking here for extra settings, it says to modify the file ~/.vim/ftplugin/tex.vim but sadly there is no such file in that dir. Should I create the file or is it somewhere else? I have found one here: .vim/pack/my_latex_plugins/start/vim-latex/compiler but is this it? – lucian Nov 14 '18 at 14:28
  • The file ~/.vim/ftplugin/tex.vim does not exist by default. If there would be one, I would suspect that you have installed something else related to tex not using vim8-packpath or pathogen (i.e.manually or vimballs). Anyhow. I would recommend to put these settings in the file ~/.vim/after/ftplugin/tex.vim which you have to create as well. This file is sourced after plugins and therefore has higher priority. However, in the case of vim-latex you can also create ~/.vim/ftplugin/tex.vim. – Hotschke Nov 14 '18 at 14:41
  • ~/.vim/pack/my_latex_plugins/start/vim-latex/compiler is not the one you are looking for. In general you should not customize anything located in ~/.vim/pack/.... – Hotschke Nov 14 '18 at 14:42
  • Have also a look at this question https://vi.stackexchange.com/questions/12731/when-to-use-the-after-directory and as always at the vim help :h after-directory point 5. However, I do not agree with the note that it is rarely needed. – Hotschke Nov 14 '18 at 14:48