[SOLVED] Help needed setting texlab up - Latex Language Server Protocol

Hello,

I’m trying to set up kakoune to take notes in latex. Similar to this post in vim: https://castel.dev/post/lecture-notes-1/.

Right now, I’m focused on setting up the language server protocol and some snippets.

To this purpose, I installed kak-lsp plugin and copied texlab binary to my path. After that I added the following lines to my kakrc:

plug "ul/kak-lsp" do %{
    cargo install --locked --force --path .
} config %{
    eval %sh{kak-lsp --kakoune -s $kak_session}
}

and

# Latex Specific
hook global WinCreate .*(\.tex|\.latex) %{
    # Line Wrapping
    add-highlighter window/ wrap -indent -width 120
    # Compile on save
    hook window BufWritePost .* %{ %sh{ pdflatex header.tex } }
    # Language Server Protocol
    lsp-enable-window
}

I also added these lines to my kak-lsp.toml file located in ~/.config/kak/kak-lsp/

[language.latex]
filetypes = ["latex"]
roots = ["header.tex"]
command = "texlab"

I don’t know if I have to do something else, but I can’t make the lsp work. I would expect that now if I start typing \beg suggestions should appear.

Thanks in advance,

first of, you should start kak-lsp by using lsp-enable-window and not by calling eval %sh{...}. Plug already loads lsp for you, so you only need the hook that will call it for needed filetype:

plug "ul/kak-lsp" do %{
    cargo install --locked --force --path .
} config %{
    hook global WinSetOption filetype=latex lsp-enable-window
}

Though Kakoune doesn’t set latex filetype for .latex buffers, so we can fix this:

hook global BufCreate .*\.latex %{
    set-option buffer filetype latex
}

Latex specific settings then should go under hook for filetype:

hook global WinSetOption filetype=latex %{
    # Line Wrapping
    add-highlighter window/ wrap -indent -width 120
    # Compile on save
    hook window BufWritePost .* %{ %sh{ pdflatex header.tex } }
}

Try this and see if it works

1 Like

Hi, thanks for your help.

I changed my settings but again it doesn’t work. It is recognizing the file type because compile on save and wrap do work, but when I run kak-capabilities nothing appears.

Is there an easy way of testing components separately? I mean kak-lsp and texlab.

Thanks

perhaps you should run lsp-capabilities instead.

@ulis have you tried LSP for LATEX for a chance?


I’ve downloaded texlab source, compiled it with cargo build --release installed it with cargo install --path . --locked and it works for me with the config I’ve mentioned in my previous reply. @useredsa are you sure that you have texlab installed correctly?

Of course :), I was running lsp-capabilities but wrote it by heart.

Well, actually, I didn’t download texlab from source, I just downloaded the binary. I will compile from source and see.

The usual kak-lsp troubleshooting procedure might offer some clues:

  • instead of letting Kakoune automatically launch kak-lsp, launch it manually yourself with a specific session name:

      kak-lsp --session foobarbaz
    
  • In a separate terminal, run Kakoune with the same session name, so it will connect to the kak-lsp you’ve already started:

      kak -s foobarbaz path/to/my/document.latex
    
  • Run lsp-capabilities in Kakoune, and check the terminal containing kak-lsp for error messages.

If that doesn’t provide enough clues, try it again but this time add -v to the kak-lsp command line… or -vv or -vvv or however much additional verbosity you want.

2 Likes

Thanks for the info on debugging kak-lsp. Doing it I managed to find the mistake. Basically, when I told plug to install the plugin, it didn’t work because cargo wasn’t in my path at the moment. I didn’t notice that because although it said error, after hitting enter to retry it said done. Also, I had some other problems.

Anyway, everything works great now. Thank both!

In case of error you can run post installation hooks again with R in plug menu. Log is also available with L

1 Like

Thank you for your post @useredsa I had no idea this was possible with kak-lsp must set it up.

I have found this helpful with my Uni maths assignments for *.png LaTeXiT.

As well, compatible with all IntelliJ-based IDEs including community additions.
TeXiFy IDEA
TeXiFy-IDEA

Enjoy and the struggle of learning is definitely worth the reward.