[BUG] Latex with poppler fails to create SVG file.
Describe the bug
With Run subprocesses in shell: False, pdftocairo fails to write the file.
I opened the debugger and marked a breakpoint at this snippet:
const child = (0, import_child_process3.spawn)(cmd, args, {
env: process.env,
windowsVerbatimArguments: true,
cwd: cwdDir,
shell: Boolean(this.settings.latexSubprocessesUseShell)
});
Ignoring the first break event (for lualatex), the second one is the call to pdftocairo, when inspecting args, it shows that it has this value:
['-svg', 'o.pdf', '"/.../vault/Media 💿/figure testlatex.svg"']
Note: ... is a placeholder.
The issue seems to be those extra double quotation marks ("). I then tried to run this in the debugging console after copying the contents of cwdDir:
(0, import_child_process3.spawnSync)(cmd, ['-svg', 'o.pdf', '"test.svg"'], {
env: process.env,
windowsVerbatimArguments: true,
cwd: cwdDir,
shell: Boolean(this.settings.latexSubprocessesUseShell)
});
fs.readdirSync(cwdDir);
['"test.svg"', 'o.aux', 'o.log', 'o.pdf', 'o.tex']
The file is getting saved as "test.svg", not test.svg, so I believe the issue is that it can't find the directory to put the file in due to this reason.
Perhaps the double quotations here have to be removed? Or escaped some other way that works across platforms...
https://github.com/twibiral/obsidian-execute-code/blob/3331392f006d2fc1f65e0e68e74b771f78481295/src/executors/LatexExecutor.ts#L137
@Yetenol
Software Version OS: Linux 6.12.26, NixOS, 25.05 (Warbler) Plugin Version: 2.1.2 Obsidian Version: 1.8.10
To Reproduce
- Compiler path:
.../lualatex - Convert to SVG:
Poppler - SVG converter path:
.../pdftocairo - SVG converter arguments:
-svg - Run subprocesses in shell:
FALSE
\title{testlatex}
\begin{document}
Hello World! Test?
\end{document}
Error opening output file "/.../vault/Media 💿/figure testlatex.svg"
Subprocess /.../pdftocairo -svg o.pdf "/.../vault/Media 💿/figure testlatex.svg" failed with code 2.
Does the run subprocesses in shell options change anything?
Hi, I'm the contributor who added the latex support, and will take a look at it. I only ever tested the latex compilation in Window, not on Linux, but I will use WSL to try to recreate it.
Yes, if the option Run subprocesses in shell is turned on, then the issue disappears. I am not familiar with the Node system utilities, but after some tests, it seems that, at least on my machine:
- If
Run subprocesses in shell: TRUE, thenargs.push(`${outFileArg}`);leads to errors - If
Run subprocesses in shell: TRUE, thenargs.push(`"${outFileArg}"`);works as expected - If
Run subprocesses in shell: FALSE, thenargs.push(`"${outFileArg}"`);leads to errors - If
Run subprocesses in shell: FALSE, thenargs.push(`${outFileArg}`);works as expected
So perhaps something like this would be enough?
diff --git a/src/executors/LatexExecutor.ts b/src/executors/LatexExecutor.ts
index 18da652..91512fb 100644
--- a/src/executors/LatexExecutor.ts
+++ b/src/executors/LatexExecutor.ts
@@ -127,6 +127,7 @@ export default class LaTeXExecutor extends NonInteractiveCodeExecutor {
private async runChildProcess(cmd: string, args: string[], outName: string, exec: ExecutionContext, options?: { outFileArg?: string, skipWriteFileLink?: boolean, doDetectRerun?: boolean }): Promise<string | undefined> {
const outDir = exec.outputDir;
const cwdDir = exec.workingDir;
+ const shell = Boolean(this.settings.latexSubprocessesUseShell);
const outputter = exec.outputter;
let outFileArg: string = options?.outFileArg || outName;
const outFile = path.join(outDir, outFileArg);
@@ -134,14 +135,18 @@ export default class LaTeXExecutor extends NonInteractiveCodeExecutor {
if (outDir !== cwdDir) {
outFileArg = outFile;
}
- args.push(`"${outFileArg}"`);
+ if (shell) {
+ args.push(`"${outFileArg}"`);
+ } else {
+ args.push(`${outFileArg}`);
+ }
}
const child = spawn(cmd, args, {
env: process.env,
windowsVerbatimArguments: true,
cwd: cwdDir,
- shell: Boolean(this.settings.latexSubprocessesUseShell)
+ shell: shell
});
outputter.runningSubprocesses.add(child);
const description = `Subprocess ${cmd} ${args.join(" ")}`;
Hi @MathiasSven thanks for reporting the problem, and thanks to you and @Yetenol for the quick fix! I will include this in the next release.
If I remember correctly, we added the quoations marks (") a whole while ago because some arguments or path were making problems. I did not expect this change to also make its own problems.