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:
- Open any .tex document
- Use the Format Document or Build LaTex project command
- 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
- Do not use PWD entry as the cwd for fls files When using docker, the PWD entry refers to a directory inside the docker image. It is much safer to take the dirname of the .fls file as the working dire... — committed to James-Yu/LaTeX-Workshop by jlelong 5 years ago
- Use cross-spawn to run latexindent Related to #1873 — committed to James-Yu/LaTeX-Workshop by jlelong 5 years ago
- Do not echo commands in .bat scripts Related to #1873. Thanks to @MrSinamun for the tip. — committed to James-Yu/LaTeX-Workshop by jlelong 5 years ago
- Fix #1972. Use rootDir as PWD when parsing .fls file This a follow-up on 2a1cc91, related to #1873. — committed to James-Yu/LaTeX-Workshop by jlelong 4 years ago
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.batfile always outputs the command (with both modules). This is probably related to.batfiles not being executables and therefore they are executed throughcmd.exewhich hasecho onas default.I will try to implement a hack in the extension.
The current issue seems to be caused by
latexindent.batin conjunction with the%DIR%and%TMPFILE%variables.When running:
in the directory:
c:\Users\Mr Sinamun\Projects\LaTeX-Workshop\scriptsthe output is:The folder from which
latexindent.batis 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.argsas follows:and run the
Format Documentonlalala.texit works:This does not happen on Linux, because the
latexindentscript 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
.auxissue. The first line of the.flsfile saysPWD /databut the thing is that/datais actually a directory inside the docker image. We should use the dirname of the.flsfile as the working directory to interpret the file paths listed in there.