LaTeX-Workshop: Error with 'Format Document' command when path has spaces

Describe the bug

When trying to format a .tex document (Alt+Shift+F) it does not work due to there being a space (punctuation) in the paths. I’ve had a similar issue with the Maven for Java extension: See the issue here Might be related to #485, #786

When building a latex project everything works fine, but there is an error related to an .aux file appearing in the developer console. I’m not sure this is related - But I’ve included this log under it’s own section for just in case.

To Reproduce

Steps to reproduce the behavior:

  1. Open any .tex document
  2. Use the Format Document or Build LaTex project command
  3. See error

Expected behavior

When using the Format Document command, it should reformat the document.

Logs (Format Document)

LaTeX Workshop Output

[00:14:56] Formatting with command c:\Users\Mr Sinamun\.vscode\extensions\james-yu.latex-workshop-8.5.0\scripts\latexindent.bat -c,c:/Users/Mr Sinamun/Projects/web3/scratch/,c:/Users/Mr Sinamun/Projects/web3/scratch/__latexindent_temp.tex,-y=defaultIndent: '    '
[00:14:56] Formatting failed with exit code 1
[00:14:56] stderr: 'c:\Users\Mr' is not recognized as an internal or external command,
operable program or batch file.

Developer Tools Console

Formatting failed. Please refer to LaTeX Workshop Output for details.

Logs (Build LaTex project)

LaTeX Workshop Output

[00:47:25] File watcher: responding to change in c:\Users\Mr Sinamun\Projects\web3\scratch\lalala.tex
[00:47:25] Parsing c:\Users\Mr Sinamun\Projects\web3\scratch\lalala.tex
[00:47:25] c:\Users\Mr Sinamun\Projects\web3\scratch\lalala.tex changed. Auto build project.
[00:47:25] BUILD command invoked.
[00:47:25] Building root file: c:\Users\Mr Sinamun\Projects\web3\scratch\lalala.tex
[00:47:25] Build root file c:\Users\Mr Sinamun\Projects\web3\scratch\lalala.tex
[00:47:25] Recipe step 1: c:\Users\Mr Sinamun\.vscode\extensions\james-yu.latex-workshop-8.5.0\scripts\latexmk.bat, -synctex=1,-interaction=nonstopmode,-file-line-error,-pdf,-outdir=./,lalala
[00:47:25] LaTeX build process spawned. PID: 17488.
[00:47:26] Recipe of length 1 finished. PID: 17488.
[00:47:26] Successfully built c:\Users\Mr Sinamun\Projects\web3\scratch\lalala.tex.
[00:47:26] Refresh PDF viewer for c:\Users\Mr Sinamun\Projects\web3\scratch\lalala.pdf
[00:47:26] Parse fls file.
[00:47:27] Preview PDF file: c:\Users\Mr Sinamun\Projects\web3\scratch\lalala.pdf

Developer Tools Console

mainThreadExtensionService.ts:65 [[object Object]]ENOENT: no such file or directory, open 'C:\data\lalala.aux'
$onExtensionRuntimeError @ mainThreadExtensionService.ts:65
_doInvokeHandler @ rpcProtocol.ts:398
_invokeHandler @ rpcProtocol.ts:383
_receiveRequest @ rpcProtocol.ts:299
_receiveOneMessage @ rpcProtocol.ts:226
(anonymous) @ rpcProtocol.ts:101
fire @ event.ts:581
fire @ ipc.net.ts:453
_receiveMessage @ ipc.net.ts:733
(anonymous) @ ipc.net.ts:592
fire @ event.ts:581
acceptChunk @ ipc.net.ts:239
(anonymous) @ ipc.net.ts:200
t @ ipc.net.ts:28
emit @ events.js:200
addChunk @ _stream_readable.js:294
readableAddChunk @ _stream_readable.js:275
Readable.push @ _stream_readable.js:210
onStreamRead @ internal/stream_base_commons.js:166
mainThreadExtensionService.ts:66 Error: ENOENT: no such file or directory, open 'C:\data\lalala.aux'
	at Object.openSync (fs.js:447:3)
	at Object.func (electron/js2c/asar.js:138:31)
	at Object.func [as openSync] (electron/js2c/asar.js:138:31)
	at Object.readFileSync (fs.js:349:35)
	at Object.fs.readFileSync (electron/js2c/asar.js:580:40)
	at Object.fs.readFileSync (electron/js2c/asar.js:580:40)
	at c:\Users\Mr Sinamun\.vscode\extensions\james-yu.latex-workshop-8.5.0\out\src\components\manager.js:488:38
	at Array.forEach (<anonymous>)
	at Manager.parseFlsFile (c:\Users\Mr Sinamun\.vscode\extensions\james-yu.latex-workshop-8.5.0\out\src\components\manager.js:486:24)
	at Builder.buildFinished (c:\Users\Mr Sinamun\.vscode\extensions\james-yu.latex-workshop-8.5.0\out\src\components\builder.js:337:32)
	at ChildProcess.<anonymous> (c:\Users\Mr Sinamun\.vscode\extensions\james-yu.latex-workshop-8.5.0\out\src\components\builder.js:314:30)
	at ChildProcess.emit (events.js:200:13)
	at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)

Desktop

  • OS: Windows 10 1909
  • VS Code version: 1.41.0
  • Extension version: 8.5.0
  • TeX distribution version: TeX Live 2019/Debian

Additional questions

Are you using LaTeX Workshop with VS Code Remote?

Yes - With Remote Container (aergus/latex)

Non-Default settings?

    "latex-workshop.docker.image.latex": "aergus/latex",
    "latex-workshop.view.pdf.viewer": "tab"

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 23

Commits related to this issue

Most upvoted comments

Everything should be working fine now. Ask for reopening the issue if not. Thanks for your cooperation in all the tests.

Let us forget about res4. I think I have everything I need: executing a .bat file always outputs the command (with both modules). This is probably related to .bat files not being executables and therefore they are executed through cmd.exe which has echo on as default.

I will try to implement a hack in the extension.

The current issue seems to be caused by latexindent.bat in conjunction with the %DIR% and %TMPFILE% variables.

When running:

latexindent.bat -c "c:/Users/Mr Sinamun/Projects/web3/scratch/" "c:/Users/Mr Sinamun/Projects/web3/scratch/lalala.tex" -y=defaultIndent:'    '

in the directory: c:\Users\Mr Sinamun\Projects\LaTeX-Workshop\scripts the output is:

C:\Users\Mr Sinamun\Projects\LaTeX-Workshop\scripts>docker run -i --rm -w /data -v "C:\Users\Mr Sinamun\Projects\LaTeX-Workshop\scripts:/data" aergus/latex latexindent -c "c:/Users/Mr Sinamun/Projects/web3/scratch/" "c:/Users/Mr Sinamun/Projects/web3/scratch/lalala.tex" -y=defaultIndent:"    "
Could not find directory c:/Users/Mr Sinamun/Projects/web3/scratch/
Exiting, no indentation done. at /usr/share/texlive/texmf-dist/scripts/latexindent/LatexIndent/LogFile.pm line 104.

The folder from which latexindent.bat is executed (usually the project directory) is mounted as /data, therefore the arguments for the -c parameter should be -c "/data/" "/data/lalala.tex" and not the project directory path from the windows host.

When I hardcore latex-workshop.latexindent.args as follows:

    "latex-workshop.latexindent.args": [
        "-c",
        "/data/",
        "/data/lalala.tex",
        "-y=defaultIndent: '%INDENT%'"
    ],

and run the Format Document on lalala.tex it works:

[19:35:05] Formatting with command c:\Users\Mr Sinamun\Projects\LaTeX-Workshop\scripts\latexindent.bat -c,/data/,/data/lalala.tex,-y=defaultIndent: '    '
[19:35:07] Formatted c:\Users\Mr Sinamun\Projects\web3\scratch\lalala.tex

This does not happen on Linux, because the latexindent script mounts the docker volume as -v "$(pwd):$(pwd)., which makes it possible to use the %DIR% and %TMPFILE% variables without issues.

Ok I get it for the .aux issue. The first line of the .fls file says PWD /data but the thing is that /data is actually a directory inside the docker image. We should use the dirname of the .fls file as the working directory to interpret the file paths listed in there.