This is a follow-up to thefirst post on Neovim and LaTeX.
I love LaTeX, but I don’t love LaTeXnoise. If you use LazyVim’slang.texextra, 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 withg: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” asLSP diagnostics(not quickfix), that’s coming fromTexLab (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 wholeopts = { servers = { texlab = { … }}}block. You canpatchthe existing LSP config in a tinyopts = function(_, opts) ... endsnippet (LazyVim shows this pattern for extending defaults, and also documents theopts.setuphook 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.serversor{} opts.servers.texlab=opts.servers.texlabor{} locals=opts.servers.texlab.settingsor{} localt=s.texlabor{} locald=t.diagnosticsor{} d.ignoredPatterns=d.ignoredPatternsor{} 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! 🙂
