latex-lsp / texlab

An implementation of the Language Server Protocol for LaTeX
GNU General Public License v3.0
1.51k stars 52 forks source link

Forward search broken with empty latexmkrc #1095

Closed HarryHeres closed 4 months ago

HarryHeres commented 4 months ago

Hi!

I have just finished debugging an issue where Texlab was, on forward seach, still looking into the root directory, even though I have set the directories in Neovim config as following:

['texlab'] = function()
    local forward_search_args = {
        '--reuse-window',
        -- '--execute-command', 'toggle_synctex', -- Open Sioyek in synctex mode.
        -- '--inverse-search',
        -- [[nvim-texlabconfig -file %%%1 -line %%%2 -server ]] .. vim.v.servername,
        '--forward-search-file', '%f',
        '--forward-search-line', '%l',
        '%p'
    }

    local pdf_executable = 'sioyek'

    require('lspconfig').texlab.setup({
        capabilities = capabilities,
        filetypes = { "tex", "bib" },

        settings = {
            texlab = {
                build = {
                    auxDirectory = "build",
                    pdfDirectory = "build",
                    logDirectory = "build",
                    args = { "-pdf", "-auxdir=build", "-outdir=build", "-interaction=nonstopmode", "-synctex=1", "%f" },
                    executable = "latexmk",
                    forwardSearchAfter = false,
                    onSave = true
                },

                forwardSearch = {
                    executable = pdf_executable,
                    args = forward_search_args
                }
            }
        }

    })
end

When there's not a latexmkrc file present in the root directory, the process finishes sucessfuly.

However, when there's a latexmkrc file present in the root directory without out_dir=<path> set, the server does not fall back to the settings it has in its configuration, therefore searches for the PDF file in the root directory.

Also, based on the documentation of latexmkrc, the variables must be set with $ pre-pended to the string, i.e. $out_dir=<path>, however when done so, Texlab does not recognize this setting. When variable is introduced without the $, the latexmk process fails due to invalid latexmkrc format.

Tested on Texlab 5.15.0