Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A new perl script is spawned each time latexmk is called #440

Closed
pvonmoradi opened this issue Jun 3, 2021 · 8 comments
Closed

A new perl script is spawned each time latexmk is called #440

pvonmoradi opened this issue Jun 3, 2021 · 8 comments

Comments

@pvonmoradi
Copy link

I'm using texlab v3.1.0 alongside coc-texlab with these options:

    // coc-texlab
    "texlab.build.args": [
        "-pdf",
        "-interaction=nonstopmode",
        "-synctex=1",
        "-pvc",
        "%f"
    ],
    "texlab.build.isContinuous": true,
    "texlab.build.onSave": true,
    "texlab.chktex.onOpenAndSave": true,
    "texlab.chktex.onEdit": true,
    "texlab.forwardSearch.executable": "zathura",
    "texlab.forwardSearch.args": [
        "--synctex-forward",
        "%l:1:%f",
        "%p"
    ],

Each time a build command is initiated (manually or by saving the file), a perl script related to latexmk is invoked. Now, since I'm using -pvc switch for a continuous build I also used "texlab.build.isContinuous": true which I thought would prevent these excessive perl scripts which would eventually result in a memory leak.

Here is a screen-cast of the situation:
(Note the htop window with the \tex filter)

Peek.2021-06-03.19-25.mp4
@pvonmoradi pvonmoradi changed the title A new perl script is spawned each time a latexmk is called A new perl script is spawned each time latexmk is called Jun 3, 2021
@pfoerster
Copy link
Member

Thanks for the very detailed report. The problem is that you should not combine texlab.build.onSave and the -pvc flag at the moment. They basically do the same. -pvc causes latexmk to never stop and run a build each time a document is saved. texlab.build.onSave triggers the build command specified by texlab.build.args, which causes a new instance of latexmk each time. For now, you can set the continous build to false and replace -pvc with -pv. Perhaps, I should include a "fail-safe" to prevent this issue from happening.

@pvonmoradi
Copy link
Author

pvonmoradi commented Jun 3, 2021

@pfoerster Thanks for your quick reply.
If I use -pv and isContinuous": false, on each build, a new previewer window (Zathura in my case) is spawned instead of it getting updated.
If I use this setting instead:

// coc-texlab
    "texlab.build.args": [
        "-pdf",
        "-interaction=nonstopmode",
        "-synctex=1",
        "-pvc",
        "%f"
    ],
    "texlab.build.isContinuous": false,
    "texlab.build.onSave": false,

It works fine (without re-spawning perl) but I have to issue latex.Build one time to create the previewer window.
Also, It seems "texlab.build.onSave": true, checks the file for diffs faster than the polling mechanism latexmk has implemented. So the above solution causes a ~1 sec delay.

@pfoerster
Copy link
Member

It works fine (without re-spawning perl) but I have to issue latex.Build one time to create the previewer window.

From the documentation, I can see that Zathura reloads the file automatically so we do not need to issue another call to the executable when the PDF changes. It looks like #436 needs to be implemented and we need to move away from configuring the PDF viewer in latexmkrc files.

Also, It seems "texlab.build.onSave": true, checks the file for diffs faster than whatever polling mechanism latexmk has implemented. So the above solution causes a ~1 sec delay.

That's because texlab is notified by the editor when a file is saved (textDocument/didSave). latexmk does not have that information. So I think there is definitely a benefit in replacing -pvc.

Thinking about it, I think there is a way to reliably re-implement texlab.build.forwardSearchAfter while we are at it.
I will take a look at it this weekend.

@pfoerster
Copy link
Member

texlab 3.2.0 and coc-texlab 3.2.0 have been released in the meantime.
Can you try the latest version with the following settings?

"texlab.build.args": [
    "-pdf",
    "-interaction=nonstopmode",
    "-synctex=1",
    "%f"
],
"texlab.build.forwardSearchAfter": true,
"texlab.build.onSave": true,
"texlab.forwardSearch.executable": "zathura",
"texlab.forwardSearch.args": [
    "--synctex-forward",
    "%l:1:%f",
    "%p"
]    ​

​With this configuration, texlab will recompile your document after saving and keep the viewer synchronized with the cursor.
Note that you do not need a latexmkrc file and the -pv(c) flags anymore.

@pvonmoradi
Copy link
Author

@pfoerster Thanks for the new release 😉
Used your config and updated the plugin and binary. Now the output pdf is updated on every save. Moreover, that perl script is not even run once.

A minor problem persists though. Zathura is not executed by the plugin on any of the commands latex.Build or latex.ForwardSearch or saving the file. I have to manually open the output pdf once. Actually, I don't think latex.ForwardSearch is functioning. I've tested this with and without the .latexmkrc file in the project dir.

λ cat .latexmkrc
$pdf_previewer = 'start zathura';

@pfoerster
Copy link
Member

@pvonmoradi Can you try running the forward search command

zathura --synctex-forward 42:1:somefile.tex somefile.pdf

manually and see if it works? Did you configure your zathurarc file?

@pvonmoradi
Copy link
Author

@pfoerster
I think my zathura is not built with synctex support:
error: Built without synctex support, but synctex specific option was specified.
So the forwardSearch problem is unrelated to texlab.

@pfoerster
Copy link
Member

@pvonmoradi Is there anything else that needs to be done from the side of texlab or can we close this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants