rzukic / zed-latex

31 stars 4 forks source link

On-save build and preview working normally until suddenly it stopped #33

Open ivansigmund opened 1 week ago

ivansigmund commented 1 week ago

I was just working on my latex file, and it was working as expected, until there were no more latexmk builds going on automatically on save. now i need to do it manually from terminal. There are no latex errors. here is my setup:


    "texlab": {
      "settings": {
        "texlab": {
          "latexindent": { "modifyLineBreaks": true },
          "build": {
            "onSave": true,
            "forwardSearchAfter": true,
            "executable": "latexmk",
            "args": ["-pdf", "-synctex=1", "-interaction=nonstopmode"]
          },
          "forwardSearch": {
            "executable": "/Applications/Skim.app/Contents/SharedSupport/displayline",
            "args": ["-r", "%l", "%p", "%f"]
          }
        }
      }
    }
  }```
ivansigmund commented 1 week ago

i found it has to do with the same bug as here: https://github.com/zed-industries/zed/issues/18456

ivansigmund commented 1 week ago

i downgraded my zed to 0.155.2 in order to make the build on save working

lnay commented 1 day ago

Probably worth keep this open for visibility if when others try to look up this issue. The underlying issue is a change in expectation from Zed about how certain things are communicated with texlab (resulting in texlab no longer being notified on files being saved).

Fix option 1 (keep on-save build via Zed and texlab):

Revert to some version of Zed before 0.156.0 (released 9th Oct).

Fix option 2 (terminal/tasks.json)

Alternatively, you can completely bypass texlab for build and forward/inverse search. This could be done in the terminal (in Zed or external), or via Zed tasks. The benefit of tasks is that they can be given keybinds in Zed.

Building

You could run the build program in the terminal (inside Zed or external). For example running latexmk -pvc will be suitable for most people, which will build the PDF and rebuild it whenever any relevant files change.

Forward/inverse search

Add a task in .config/zed/tasks.json (or .zed/tasks.json in your workspace), to open the PDF with the appropriate arguments to have forward/inverse search working correctly. A benefit of this is that the forward-search is more accurate this way compared to on-save (see this issue). Here is an example for zathura:

// .zed/tasks.json
[
  {
    "label": "Forward Search",
    "command": "zathura --synctex-forward \"$ZED_ROW:$ZED_COLUMN:$ZED_FILE\" -x 'zed %{input}:%{line}' main.pdf",
    "allow_concurrent_runs": true,
    "reveal": "never"
  }
]

Have a look at this issue for other examples. The Zed task will be invoked with environment variables $ZED_ROW, $ZED_COLUMN, $ZED_FILE (among others, see docs). These must be used to have the PDF viewer highlight the correct location. Note also that the example assumes that the PDF is called main.pdf and at the root of the workspace. Adjust this to your situation, a robust solution working out the location of the PDF in general would inevitably be complicated.

Afterwards, this task can be run from the command pallet > spawn task > Forward Search. Or can be given a keybind, for example:

// ~/.config/zed/keymap.json
// ...
  {
    "context": "Workspace",
    "bindings": {
      "shift shift": ["task::Spawn", { "task_name": "Forward Search" }]
    }
  }
]

Future plans to address this issue:

I am personally unlikely be working much on these over the next two weeks. However for point 2, people could raise issues with suggestions for content to put in the wiki if they have created their own tasks.json which works well with a their PDF viewer. Bonus points for typing/formatting accompanying text so that it can just be copy-pasted as is into the wiki.

ivansigmund commented 1 day ago

my forward search task in tasks.json with Skim:

[
  {
    "label": "Forward Search",
    "command": "/Applications/Skim.app/Contents/SharedSupport/displayline -r \"$ZED_ROW\" main.pdf \"$ZED_FILE\"",
    "allow_concurrent_runs": true,
    "reveal": "never"
  }
]