This is a follow-up to the first post on Neovim and LaTeX.
I love LaTeX, but I don’t love LaTeX noise. If you use LazyVim’s lang.tex extra, you’ve probably seen a familiar friend pop up in your editor diagnostics: Underfull \hbox. It’s usually harmless, but it’s distracting—especially when you’re trying to focus on content. In this post, I’ll show two clean ways to silence those warnings: one for VimTeX’s quickfix and one for TexLab’s LSP diagnostics, without turning off the good stuff.
In LazyVim’s Tex extra, those Underfull \hbox … messages are coming from VimTeX’s Quickfix parsing (it’s enabled by default in the extra). VimTeX lets you hide specific warnings by regex-matching them with g:vimtex_quickfix_ignore_filters.
Create a custom plugin specification, e.g., “~/.config/nvim/lua/plugins/extend-vimtex.lua”, with these contents:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
return { { "lervag/vimtex", -- use `init` for vim.g.* so it’s set before VimTeX uses it init = function() -- These are Vim regexes. Match the log line(s) you want to hide. vim.g.vimtex_quickfix_ignore_filters = { [[Underfull \\hbox]], -- hide underfull hbox warnings -- [[Overfull \\hbox]], -- (optional) hide overfull hbox warnings too -- [[Underfull \\vbox]], -- (optional) hide underfull vbox warnings too } end, }, } |
Restart Neovim, and the quickfix list will no longer contain those warnings.
However, you’re still seeing “Underfull \hbox” as LSP diagnostics (not quickfix), that’s coming from TexLab (separate configuration):
You need to create another custom plugin specification for customizing the TexLab LSP, e.g., “~/.config/nvim/lua/plugins/extend-lspconfig.lua”:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
return { { "neovim/nvim-lspconfig", opts = { servers = { texlab = { settings = { texlab = { diagnostics = { ignoredPatterns = { -- Rust regexes. Match the diagnostic text you want to suppress. [[Underfull \\hbox]], -- If you want to be extra broad: -- [[Underfull \\hbox.*]], }, }, }, }, }, }, }, }, } |
Restart, and also the editor’s inline warnings of that space will be gone.
If you don’t like that deep specification, in LazyVim, you don’t have to restate the whole opts = { servers = { texlab = { … }}} block. You can patch the existing LSP config in a tiny opts = function(_, opts) ... end snippet (LazyVim shows this pattern for extending defaults, and also documents the opts.setup hook for server setup).
Here’s an alternative configuration:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
return { { "neovim/nvim-lspconfig", opts = function(_, opts) opts.servers = opts.servers or {} opts.servers.texlab = opts.servers.texlab or {} local s = opts.servers.texlab.settings or {} local t = s.texlab or {} local d = t.diagnostics or {} d.ignoredPatterns = d.ignoredPatterns or {} table.insert(d.ignoredPatterns, [[Underfull \\hbox]]) t.diagnostics = d s.texlab = t opts.servers.texlab.settings = s end, }, } |
Though it’s a bit longer.
The final result of this series of tutorials can be found here: https://github.com/LorenzoBettini/lazyvim-tex. Branches will denote the state of the repository for a specific blog post section.
Stay tuned for more blog posts on LaTeX and Neovim! 🙂
