Closed t4rf9 closed 1 year ago
This might be a bigger issue than it looks. I will check the details.
Using cross-spawn-async
instead is not an option as it was deprecated and superceded by cross-spawn
, according to https://www.npmjs.com/package/cross-spawn-async .
I suspect it to be a local problem or the naming of .aux
on win. You may take a look into https://github.com/James-Yu/LaTeX-Workshop/actions/runs/4060600101/jobs/6989848291 on test [104] and
https://github.com/James-Yu/LaTeX-Workshop/blob/ab357e31ac2f2b3ada99e3461d2cc9c893cc7677/test/suites/10_cleaner.test.ts#L79-L90
It just tests your use case.
In further attempts, I find that it has nothing to do with -auxdir
...
Even if I configure to run latexmk -c %TEX%
, the same error is produced with no file removed.
I'll try to explore this in depth.
On my device, child_process.spawn
just fails when trying to run latexmk
which is from MiKTeX and returns an exit-code of 3221226505, but works fine for other commands like node main.js
.
latexmk
works fine from PowerShell or CMD manually.
That might be a node.js problem or MiKTeX problem.
Adding shell: true
to the options
paramater in https://github.com/James-Yu/LaTeX-Workshop/blob/master/src/components/cleaner.ts#L160 can be a solution, but a shell window may pop out.
Using
command = 'perl';
args = [
'C:\\Users\\t4rf9\\AppData\\Local\\Programs\\MiKTeX\\scripts\\latexmk\\latexmk.pl',
'-c',
'-bibtex',
'-auxdir=c:/Users/t4rf9/Programs/test/.aux',
'c:/Users/t4rf9/Programs/test/main.tex'
];
options = { cwd: 'c:\\Users\\t4rf9\\Programs\\test', detached: true };
works fine.
So I think the problem comes from latexmk.exe, which is installed by MiKTeX from CTAN.
spawning a new process with subprocess.run
in python executes latexmk
successfully, so the problem seems to lie in nodejs
Using
command = 'latexmk';
args = [
'-c',
'-bibtex',
'-auxdir=c:/Users/t4rf9/Programs/test/.aux',
'c:/Users/t4rf9/Programs/test/main.tex'
];
options = { cwd: 'c:\\Users\\t4rf9\\Programs\\test', detached: false };
also works.
I am not sure whether it's necessary to set detached
as true
.
The following python script fails with the same return code,
which proves that it's spawning a detached latexmk
process that causes the issue.
import subprocess
p = subprocess.Popen(["latexmk", "-v"], creationflags=subprocess.DETACHED_PROCESS)
p.wait()
print(p.returncode)
@James-Yu
I find out that settting detached: true
in the spawning options may be the cause of the problem
and setting detached: false
avoids the problem
by using cross-spawn
to spawn latexmk -c -bibtex -auxdir=c:/Users/t4rf9/Programs/test/.aux c:/Users/t4rf9/Programs/test/main.tex
in a nodejs terminal.
If there is no other problems that may be caused, I think it's ok to try detached: false
.
BTW, your tests are run with TeXLive, while in my case I used MiKTeX.
This is my code for the mentioned attempt of detached: false
, which works well for me.
var cs = require('cross-spawn');
let command = 'latexmk';
let args = [
'-c',
'-bibtex',
'-auxdir=c:/Users/t4rf9/Programs/test/.aux',
'c:/Users/t4rf9/Programs/test/main.tex'
];
let options = { cwd: 'c:\\Users\\t4rf9\\Programs\\test', detached: false };
let proc = cs.spawn(command, args, options);
let output = '';
proc.stdout.setEncoding('utf8')
proc.stdout.on('data', function (data) {
output += data.toString();
});
proc.stderr.setEncoding('utf8')
proc.stderr.on('data', function (data) {
output += data.toString();
});
proc.on('close', function (code) {
console.log('exit code: ' + code);
console.log();
console.log(output);
});
@James-Yu
Besides, when using options = { cwd: 'c:\\Users\\t4rf9\\Programs\\test', detached: true, shell: true }
,
everything works as well.
This can be a better choice than detached: false
in case the parent process exits, although I think the case is quite unlikely to happen.
I installed TeXLive on my device and find out that the latexmk.exe
generated by TeXLive always runs in a new shell, so it works with the original options = { cwd: 'c:\\Users\\t4rf9\\Programs\\test', detached: true }
.
Preliminary questions [Required]
Disable all the other extensions except for LaTeX Workshop, restart VS Code, and check that you still see this issue. [Required]
You still see this issue?: Yes
Make sure to visit the wiki FAQ before filling an issue.
You visited the wiki?: Yes
If your issue is with compiling a document (not having to do with finding the root file of a project), check first that you can compile manually.
You can compile a TeX document manually?: Yes
Describe the bug [Required]
When I try to configure latex-workshop to clean with
latexmk -c -auxdir=%OUTDIR%/.aux %TEX%
(compiled withlatexmk -auxdir=%OUTDIR%/.aux
), I added "-c", "-auxdir=%OUTDIR%/.aux" and "%TEX%" to latex-workshop.latex.clean.args.Then, it works well on macOS 13, but fails on Windows 11.
After investigating the source code, I found the problem comes from https://github.com/James-Yu/LaTeX-Workshop/blob/master/src/components/cleaner.ts#L160, where
cross-spawn.spawn
is used. Usingcross-spawn-async.spawn
would work well. That's because after parsing,cross-spawn.spawn
directly returns the cleaning commandlatexmk
, namelywhilst
cross-spawn-async.spawn
returnscmd.exe
as the command, namelyThe latter wraps the cleaning command in a separated CMD, I think that's what makes it a success. However, I have no time to dig deeper. Hope this helps solving the bug.
To Reproduce
Steps to reproduce the behavior:
latexmk -auxdir=%OUTDIR%/.aux
Expected behavior
The cleaning should be successful.
Logs [Required]
Please paste the whole log messages here, not parts of ones. The log should start with
Initializing LaTeX Workshop
. It is very important to identify problems.LaTeX Workshop Output [Required]
Developer Tools Console [Required]
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop [Required]
Please write exact version numbers. Please don't write
latest
instead of exact numbers.Additional questions
Are you using VSCodium?
No
Are you using the Snap or Flatpack versions of VS Code?
No
Are you using LaTeX Workshop with VS Code Remote?
No