Preview ‐ MacOS - rzukic/zed-latex GitHub Wiki
On MacOS, the recommended PDF viewer to use is Skim which gives the best forwards+inverse search experience.
[!IMPORTANT] If having issues with next section, see issue guidance here.
Build and Preview on Save (forwards+inverse search incl.)
With Skim installed in its default location, Zed will automatically build (with latexmk
) and forward-search (including opening the Skim window the first time) on save unless any user texlab
workspace settings specify otherwise.
Skim will then highlight the location in the PDF corresponding to the current editing location.
[!WARNING] On save, the position of the cursor is not communicated, so the forward-search (on save) location is only an estimate based on LSP communications. See below for more accurate forward-search using keybinds.
[!NOTE] The texlab wiki mentions the
-g
flag to stop refocusing the window. And another setting (Skim -> Preferences -> Sync -> Check for file changes) to stop reloads... revisit this.
Inverse search
After being set up, this will allow you to Shift+⌘+Click
in the Skim window to jump to the corresponding location in Zed.
Go to Skim -> Preferences -> Sync -> PDF-TeX Sync support, then specify the custom command open
with argument zed://file"%urlfile":%line
(this should match the VSCode preset with vscode -> zed). Or alternatively, provided you can start zed
from the terminal, you can set the command to zed
with arguments '%file':%line
.
[!CAUTION] If specifying a custom build command, synctex must be enabled in some way for forwards+inverse search to work. Furthermore these instructions assume that the LaTeX compiler is run on the same computer and not in a container.
Manual Build and Preview
As with other PDF viewers, you can disable build+preview on save.
One can then use Zed tasks for building and forward search, and also give them keybindings. As a by-product, the forward search will be more accurate by using the actual position of the cursor in Zed.
Example configuration
The following should be a good fit for most users provided that they do not have anything affecting the name and location of the output PDF such as the output directory or jobname being specified in a latexmkrc
file.
// tasks.json
[
{
"label": "forward_search",
"command": "/Applications/Skim.app/Contents/SharedSupport/displayline -r -z -b $ZED_ROW $ZED_DIRNAME/$ZED_STEM.pdf",
"allow_concurrent_runs": false,
"reveal": "never",
"hide": "always"
},
{
"label": "pdflatex_view",
"command": "cd \"$ZED_DIRNAME\" && pdflatex -shell-escape -synctex=-1 \"$ZED_STEM\" && /Applications/Skim.app/Contents/SharedSupport/displayline -r -z -b $ZED_ROW \"$ZED_STEM\".pdf",
"allow_concurrent_runs": false,
"reveal": "no_focus",
"hide": "on_success"
},
{
"label": "latexmk_view",
"command": "cd \"$ZED_DIRNAME\" && latexmk -pdf \"$ZED_STEM\" && /Applications/Skim.app/Contents/SharedSupport/displayline -r -z -b $ZED_ROW \"$ZED_STEM\".pdf",
"allow_concurrent_runs": false,
"reveal": "no_focus",
"hide": "on_success"
},
]
And for keybindings:
[
{
"context": "Workspace",
//"context": "Editor && extension==tex", // This restricts the keybindings to tex files however does not work when in terminal
"bindings": {
"shift shift": ["task::Spawn", { "task_name": "forward_search" }],
"f5": ["task::Spawn", { "task_name": "pdflatex_view" }],
"shift-f5": ["task::Spawn", { "task_name": "latexmk_view" }],
}
},
]