TeXpresso
I wanted to include this document in part as an example of the cool variety of LaTeX-related projects that the community has developed. The TeXpresso project is an effort to provide a full live-rendering experience while editing LaTeX documents. This was showcased on the (Neo)vim as a LaTeX editor page, and you can see another example here:
Even though I usually just use it for problem sets and other small documents, TeXpresso is perfectly happy to work with large documents (in the video below, a set of lecture notes that are about 250 pages or so). The viewer happily handles forward and reverse searching just fine, even when reverse searching requires opening up a new tex file that was included by the main one.
In addition to live rendering, TeXpresso also provides live error reporting by interacting with the quickfix window. This is a trivial example, but check this out:
Under the hood TeXpresso uses a modified version of the Tectonic typesetting system, which is itself built on XeTeX. That is to say, it’s built on something that apparently hasn’t been updated in the last few years and might not be in the future. As I said: I’m including it as an example of some of the cool stuff out there! The project has some definite limits – for instance, it struggles with citations, and needs a full (and different) LaTeX compilation pass to produce aux files. It is also a bit flaky, sometimes, and the TeXpresso command needs to sometimes be re-run, or the buffer needs to be re-sent to the viewer.
Nevertheless – it is extremely cool. Some of the limits above can be addressed by pairing it with the VimTeX plugin, and I find it useful when I want to quickly generate small documents (e.g., a problem set).
Installation
The TeXpresso project is very much a work in progress, so expect some sharp edges. I’m writing this all based on a July 2024 commit to the main TeXpresso github.
TeXpresso
TeXpresso should work on linux on MacOS machines. When installing with WSL2 running Ubuntu 24.04, the installation instructions for TeXpresso worked out of the box. That is, even though the page says it was tested with Ubuntu 22.04 and 20.04, there seem to be no issues just using the more recent version).
Neovim plugin
The above installation lets you run TeXpresso from the command line (which is not very helpful if the goal is live rendering of a file as you type), and it also provides a module that lets it integrate with emacs (which is not very helpful if you don’t know or use emacs). Fortuntantely, the author of TeXpresso has also provided a neovim plugin, which we’ll set up with (what I find to be) a useful modification.
First, just clone the TeXpresso.vim repository. In the lua
directory of it is a texpresso.lua
file – move this file into the neovim runtime path. For instance, if you have configured your setup as in this page then you can move the file to your .config/nvim/lua/
directory.
Next, we’re going to want to be able to set up TeXpresso automatically whenever we open a .tex
file. I didn’t discuss this earlier, but we can use the after and ftplugin functionality of vim to do this. From the command line, make a new directory:
$ mkdir -p ~/.config/nvim/after/ftplugin
In that new directory place a tex.lua
file – this will get loaded whenever neovim interacts with a TeX file. For now, that file can have a single line:
require('texpresso').attach()
And we with, we should be up and running. To activate the TeXpresso viewer and turn on the error reporting, open a tex file in neovim and :TeXpresso %
, where the percent sign represents the current buffer (you can also just specify the full path of the tex file instead). You can see in the screen recordings that I have mapped this command to <localleader>t
, for convenience.
A useful modification
Perhaps this is just a result of my running it under WSL, or maybe its more common, but the TeXpresso project is a little bit flaky. I find that it frequently needs to have the viewer resynchronized, especially when working with snippets. As one example, in all of the screen recordings in which I use the arbitrarily sized matrix snippet you can see that the live rendering stops after I type pMat2x2
, just as an example. One somewhat janky solution is to add a little bit of functionality, allowing us to reload the buffer into the viewer with neovim command, and then creating an autocommand to run that function when we leave insert mode. The live rendering is so fast for small documents – which is what I use TeXpresso for anyway – that I don’t even notice the update time.
To do this, let’s first set up an autocommand in our tex.lua
file in the after/ftplugin
directory. Now it should look like
require('texpresso').attach()
local autocmd = vim.api.nvim_create_autocmd
autocmd({"InsertLeave"},{
group = vim.api.nvim_create_augroup('texpressoGroup',{}),
callback = function()
vim.cmd("TeXpressoSync")
end
})
We’ve just created an autocommand that will run :TeXpressoSync
whenever we leave insert mode, so let’s write this function. Go to the texpresso.lua
file, and at the bottom is an nvim_create_user_command
that defines the :TeXpresso
command. Just below it add the following:
vim.api.nvim_create_user_command('TeXpressoSync',
function()
local buf = 0
local path = vim.api.nvim_buf_get_name(buf)
M.send("open", path, buffer_get_lines(buf, 0, -1))
end,
{
}
)
I’m not an expert, nor do I deeply understand how TeXpresso actually runs, but this seems to get the job done.