- LaTeX
- Adds support for LaTeX.
- 1602 Installs
-
This extension is allowed to:
- Launch Subprocesses
Readme
This extension provides basic support for LaTeX:
- Syntax highlighting, document outlining, and code folding.
- Building and previewing PDF files, with LaTeX ⇌ PDF synchronization.
- Smart code completion, contextual hover information, and issue reports.
Requirements
-
Syntax highlighting, document outlining, and code folding work out of the box, for LaTeX (
.tex
) and BibTeX (.bib
) files. -
To build PDF files from LaTeX sources, MacTeX (or any other TeX distribution with
latexmk
) is required. -
To preview PDF files with LaTeX ⇌ PDF synchronization, the PDF reader Skim is required. To enable jumping back to the LaTeX source line in Nova corresponding to a point in a PDF in Skim, open Skim’s Preferences → Sync and then choose Nova from the PDF–TeX Sync Preset dropdown menu. This requires Nova ≥ 8.0 & Skim ≥ 1.6.9.
-
Smart code completion, contextual hover information, and issue reports require the TexLab Language Server. The easiest way to install TexLab is to first install Homebrew and then run
brew install texlab
in a terminal. If no language server is installed or the path provided in this extension’s Preferences tab is incorrect, then smart code completion, contextual hover information, and issue reports are just not available, but everything else works. Other LaTeX language servers may also be used. Make sure that the Language Server features are enabled in Nova’s Preferences → Editor → Extensions (they are enabled by default).N.B. This extension and its developer are not affiliated with TexLab.
Usage
To build and preview PDF files, this extension provides Build (⌘B) and Run (⌘R) tasks, available in the project toolbar, under the Project menu item, and in the command palette (⇧⌘P). There is also a Clean (⇧⌘K) task to remove TeX auxiliary files.
These tasks become automatically available in any project containing .tex
files.
The default engine used to build PDF files (pdfLaTeX or XeLaTex or LuaLaTeX) can be chosen in this extension’s Preferences tab, and it can also be configured on a per-project basis in Project → Project Settings.
By default the tasks use whichever file is active, but there is also an option to choose a main (root) .tex
file in the Project Settings.
Custom LaTeX tasks can also be added — and used, for example, in Task Pipelines.
The Run (⌘R) task opens in Skim the PDF corresponding to the LaTeX source in Nova’s active editor, and highlights the line under the cursor’s position in Nova. By default, Skim is kept in the background, but this can be changed in this extension’s Preferences tab.
To jump back to the LaTeX source line corresponding to a point in a PDF file, just ⇧⌘-click on a point in the PDF in Skim. Make sure that Nova is selected in Skim’s PDF–TeX Sync preferences, as explained above in the third bullet point under Requirements.
The log files produced during the Build (⌘B) task are available in Nova’s Reports Sidebar. Compilation errors and warnings are displayed in the Issues Sidebar and in the editor gutter (this requires the TexLab Language Server). Finally, the Symbols Sidebar shows an outline of the LaTeX document structure.
Technical Implementation Details
This extension is very elementary.
As the name suggests, it only supports LaTeX (no ConTeXt, no plain TeX, …).
It uses latexmk
for its Build and Clean tasks:
- Build calls
latexmk 🔨 -interaction=nonstopmode -synctex=1 -cd 📜
, where🔨
is either-pdflatex
or-xelatex
or-lualatex
or empty, according to the choice in Preferences, and📜
is the active file or the one chosen in Project Settings. - Clean simply calls
latexmk -c -cd 📜
.
This should cover most use cases.
Instead of providing an interface to some of latexmk
’s many, many configuration options in the extension Preferences, I recommend using latexmkrc
files.
These can be tracked in revision control systems, shared with collaborators, and used in other apps and operating systems.
The Build, Run, and Clean tasks are automatically available.
Technically, they are implemented as Task Assistants, and not only as Task Templates, because for most use cases “requiring a user to add an instance of a task via a Task Template may be too much overhead.”
This way it’s also possible to open a single .tex
file in Nova and just build it, with no need to first choose a project for the corresponding window.
The cool stuff (smart code completion, contextual hover information, issue reports) is provided by the TexLab Language Server. Nova’s implementation of the Language Server Protocol (LSP) is great, and TexLab’s implementation of the LSP for LaTeX is great — why reinvent the wheel? In fact, this extension uses nothing more than Nova’s Language Server Extension template (and so it can be run with other language servers; for example, Digestif).
Syntax highlighting and symbolication are also rudimentary, but seem to get the job done fast. LaTeX ⇌ PDF synchronization just works thanks to Skim’s implementation of the magic of SyncTeX.
I cobbled together this extension around my (perhaps idiosyncratic) LaTeX workflow, and I’ve been happily doing all my TeXing in Nova ever since. Hopefully other LaTeX users may find this extension useful, too!
Changelog
Version 0.7
- New: Added an option in Preferences to use Skim’s reading bar to indicate position
Version 0.6
- New:
.bib
files now also have smart code completion, contextual hover information, and issue reports (provided by the language server)
Version 0.5
- New: Added custom task templates (which, for example, can be used in Nova 9’s new Task Pipelines)
- Improved: Tasks now fail gracefully if unavailable (e.g., when the active tab is a terminal and no main
.tex
file has been chosen)
Version 0.4
- New: Added BibTeX (
.bib
) syntax highlighting, outlining, and folding
Version 0.3
- New: Added an option in Project Settings to choose a main
.tex
file - Improved: Paths are no longer needed in the Extension Preferences if the executables are in
$PATH
Version 0.2
- Fixed: Fixed the Run task, which was broken by a bug introduced in Nova 9
Version 0.1
- First alpha release
Version 0.0
- Initial commit on GitHub
License
MIT License
Copyright (c) 2021 Marco Varisco
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.