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

Error with 'Format Document' command when path has spaces #1873

Closed
conscribtor opened this issue Dec 18, 2019 · 23 comments
Closed

Error with 'Format Document' command when path has spaces #1873

conscribtor opened this issue Dec 18, 2019 · 23 comments
Labels
bug Issue identified by LW maintainers as bug

Comments

@conscribtor
Copy link

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"
@jlelong
Copy link
Collaborator

jlelong commented Dec 20, 2019

This is related to nodejs/node#7367. I will look into it.

@jlelong jlelong added the bug Issue identified by LW maintainers as bug label Dec 20, 2019
@jlelong
Copy link
Collaborator

jlelong commented Dec 20, 2019

The complaint about the .aux is something different. Can you post the content of the lalala.fls file?

@jlelong jlelong added the need more info More information needed to identify the issue label Dec 20, 2019
@jlelong
Copy link
Collaborator

jlelong commented Dec 21, 2019

Looking closely at the logs, I am a bit puzzled by the failure of the formatting command because of spaces in the command path. Building went fine and yet it was using latexmk.bat, which is located at the very same place as latexindent.bat and should suffer from the same issue. In both formatting and building, we simply use cp.spawn to call the appropriate command. So I do not understand what is going wrong.

I do not have access to a Windows machine. Could someone investigate what is going on in this?

@conscribtor
Copy link
Author

The complaint about the .aux is something different. Can you post the content of the lalala.fls file?

This is the content of my .fls:

PWD /data
INPUT /etc/texmf/web2c/texmf.cnf
INPUT /usr/share/texmf/web2c/texmf.cnf
INPUT /usr/share/texlive/texmf-dist/web2c/texmf.cnf
INPUT /var/lib/texmf/web2c/pdftex/pdflatex.fmt
INPUT lalala.tex
OUTPUT lalala.log
INPUT /usr/share/texlive/texmf-dist/tex/latex/base/article.cls
INPUT /usr/share/texlive/texmf-dist/tex/latex/base/article.cls
INPUT /usr/share/texlive/texmf-dist/tex/latex/base/size10.clo
INPUT /usr/share/texlive/texmf-dist/tex/latex/base/size10.clo
INPUT lalala.aux
INPUT lalala.aux
OUTPUT lalala.aux
INPUT /usr/share/texlive/texmf-dist/fonts/map/fontname/texfonts.map
INPUT /usr/share/texlive/texmf-dist/fonts/tfm/public/cm/cmr17.tfm
INPUT /usr/share/texlive/texmf-dist/fonts/tfm/public/cm/cmr12.tfm
INPUT /usr/share/texlive/texmf-dist/fonts/tfm/public/cm/cmmi12.tfm
INPUT /usr/share/texlive/texmf-dist/fonts/tfm/public/cm/cmmi12.tfm
INPUT /usr/share/texlive/texmf-dist/fonts/tfm/public/cm/cmsy10.tfm
INPUT /usr/share/texlive/texmf-dist/fonts/tfm/public/cm/cmsy10.tfm
INPUT /usr/share/texlive/texmf-dist/fonts/tfm/public/cm/cmr8.tfm
INPUT /usr/share/texlive/texmf-dist/fonts/tfm/public/cm/cmr6.tfm
INPUT /usr/share/texlive/texmf-dist/fonts/tfm/public/cm/cmmi8.tfm
INPUT /usr/share/texlive/texmf-dist/fonts/tfm/public/cm/cmmi6.tfm
INPUT /usr/share/texlive/texmf-dist/fonts/tfm/public/cm/cmsy8.tfm
INPUT /usr/share/texlive/texmf-dist/fonts/tfm/public/cm/cmsy6.tfm
INPUT /usr/share/texlive/texmf-dist/fonts/tfm/public/cm/cmr9.tfm
INPUT /usr/share/texlive/texmf-dist/fonts/tfm/public/cm/cmbx9.tfm
INPUT /usr/share/texlive/texmf-dist/fonts/tfm/public/cm/cmr12.tfm
INPUT /usr/share/texlive/texmf-dist/fonts/tfm/public/cm/cmbx12.tfm
INPUT /usr/share/texlive/texmf-dist/fonts/tfm/public/cm/cmbx12.tfm
OUTPUT lalala.pdf
INPUT /var/lib/texmf/fonts/map/pdftex/updmap/pdftex.map
INPUT lalala.aux
INPUT /usr/share/texlive/texmf-dist/fonts/type1/public/amsfonts/cm/cmbx12.pfb
INPUT /usr/share/texlive/texmf-dist/fonts/type1/public/amsfonts/cm/cmbx9.pfb
INPUT /usr/share/texlive/texmf-dist/fonts/type1/public/amsfonts/cm/cmex10.pfb
INPUT /usr/share/texlive/texmf-dist/fonts/type1/public/amsfonts/cm/cmmi10.pfb
INPUT /usr/share/texlive/texmf-dist/fonts/type1/public/amsfonts/cm/cmr10.pfb
INPUT /usr/share/texlive/texmf-dist/fonts/type1/public/amsfonts/cm/cmr12.pfb
INPUT /usr/share/texlive/texmf-dist/fonts/type1/public/amsfonts/cm/cmr17.pfb
INPUT /usr/share/texlive/texmf-dist/fonts/type1/public/amsfonts/cm/cmr9.pfb

@conscribtor
Copy link
Author

Looking closely at the logs, I am a bit puzzled by the failure of the formatting command because of spaces in the command path. Building went fine and yet it was using latexmk.bat, which is located at the very same place as latexindent.bat and should suffer from the same issue. In both formatting and building, we simply use cp.spawn to call the appropriate command. So I do not understand what is going wrong.

I do not have access to a Windows machine. Could someone investigate what is going on in this?

I have moved the project to c:\, but i get the same error:

[17:18:48] Found root file from active editor: c:\web3\scratch\lalala.tex
[17:18:48] Root file remains unchanged from: c:\web3\scratch\lalala.tex.
[17:18:50] Formatting with command c:\Users\Mr Sinamun\.vscode\extensions\james-yu.latex-workshop-8.5.0\scripts\latexindent.bat -c,c:/web3/scratch/,c:/web3/scratch/__latexindent_temp.tex,-y=defaultIndent: '    '
[17:18:50] Formatting failed with exit code 1
[17:18:50] stderr: 'c:\Users\Mr' is not recognized as an internal or external command,
operable program or batch file.

As you said it really is quite puzzling for it to work only in one case.
I am unable to investigate since I have no knowledge of ts and extension debugging, but I can provide logs from different environments with different configurations if that is helpful.

@jlelong
Copy link
Collaborator

jlelong commented Dec 22, 2019

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.

jlelong added a commit that referenced this issue Dec 22, 2019
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 directory.

Related to #1873
@jlelong
Copy link
Collaborator

jlelong commented Dec 22, 2019

Can you try to call SyncTeX from cursor from the TeX badge and post the logs?
All these commands rely on cp.spawn. Thanks for your cooperation

@conscribtor
Copy link
Author

conscribtor commented Dec 23, 2019

Can you try to call SyncTeX from cursor from the TeX badge and post the logs?
All these commands rely on cp.spawn. Thanks for your cooperation

With "latex-workshop.synctex.synctexjs.enabled": true:

[10:58:00] SYNCTEX command invoked.
[10:58:01] SyncTeX failed.
[10:58:01] no relevant entry of tex file found in the synctex file.
[10:58:01] SyncTexJsError: no relevant entry of tex file found in the synctex file.
	at Object.syncTexJsForward (c:\Users\Mr Sinamun\.vscode\extensions\james-yu.latex-workshop-8.5.0\out\src\components\synctex.js:51:15)
	at Locator.syncTeX (c:\Users\Mr Sinamun\.vscode\extensions\james-yu.latex-workshop-8.5.0\out\src\components\locator.js:126:42)
	at Commander.synctex (c:\Users\Mr Sinamun\.vscode\extensions\james-yu.latex-workshop-8.5.0\out\src\commander.js:212:32)
	at c:\Users\Mr Sinamun\.vscode\extensions\james-yu.latex-workshop-8.5.0\out\src\main.js:63:89
	at v._executeContributedCommand (c:\Users\Mr Sinamun\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:538:925)
	at v.$executeContributedCommand (c:\Users\Mr Sinamun\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:539:295)
	at p._doInvokeHandler (c:\Users\Mr Sinamun\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:663:275)
	at p._invokeHandler (c:\Users\Mr Sinamun\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:662:971)
	at p._receiveRequest (c:\Users\Mr Sinamun\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:661:639)
	at p._receiveOneMessage (c:\Users\Mr Sinamun\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:660:468)
	at c:\Users\Mr Sinamun\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:658:691
	at l.fire (c:\Users\Mr Sinamun\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:46:893)
	at _.fire (c:\Users\Mr Sinamun\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:189:274)
	at c:\Users\Mr Sinamun\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:820:285
	at l.fire (c:\Users\Mr Sinamun\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:46:893)
	at _.fire (c:\Users\Mr Sinamun\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:189:274)
	at t.PersistentProtocol._receiveMessage (c:\Users\Mr Sinamun\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:193:629)
	at c:\Users\Mr Sinamun\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:190:824
	at l.fire (c:\Users\Mr Sinamun\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:46:893)
	at p.acceptChunk (c:\Users\Mr Sinamun\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:186:737)
	at c:\Users\Mr Sinamun\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:186:89
	at Socket.t (c:\Users\Mr Sinamun\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:195:68)
	at Socket.emit (events.js:200:13)
	at addChunk (_stream_readable.js:294:12)
	at readableAddChunk (_stream_readable.js:275:11)
	at Socket.Readable.push (_stream_readable.js:210:10)
	at Pipe.onStreamRead (internal/stream_base_commons.js:166:17)

With "latex-workshop.synctex.synctexjs.enabled": false:

[11:22:46] SYNCTEX command invoked.
[11:22:46] Executing synctex with args view,-i,24:16:lalala.tex,-o,lalala.pdf
[11:22:48] Try to synctex c:\Users\Mr Sinamun\Projects\web3\scratch\lalala.pdf

@jlelong
Copy link
Collaborator

jlelong commented Dec 24, 2019

Thanks. The test with "latex-workshop.synctex.synctexjs.enabled": true works fine, which means that cp.spawn is able to run the c:\Users\Mr Sinamun\.vscode\extensions\james-yu.latex-workshop-8.5.0\scripts\synctex.bat and is not bothered by the space.

It took me a while googling around but I hope I get it. This seems related to nodejs/node/issues/7367 stating that the failure only occurs when there is a space both in the command and an argument. Synctex and build take the relative path to the file lalala.tex

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
Executing synctex with args view,-i,24:16:lalala.tex,-o,lalala.pdf

whereas

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: '    '

Yet, I am bit puzzled by this one. Maybe the -y=defaultIndent: ' '

Formatting with command c:\Users\Mr Sinamun\.vscode\extensions\james-yu.latex-workshop-8.5.0\scripts\latexindent.bat -c,c:/web3/scratch/,c:/web3/scratch/__latexindent_temp.tex,-y=defaultIndent: '    '

There is no easy fix mentioned in nodejs/node/issues/7367. The solution might be to use cross-spawn. I can make a PR but unfortunately I won't be able to test because I have no access to a Windows machine. Will you be able to test it, see here for how to?

jlelong added a commit that referenced this issue Dec 24, 2019
@jlelong jlelong removed the need more info More information needed to identify the issue label Dec 24, 2019
@conscribtor
Copy link
Author

I've followed your guide and was able to test #1883.

The format command has slightly different output depending on which docker image was used:

aergus/latex

[15:15:46] Formatting with command c:\Users\Mr Sinamun\Projects\LaTeX-Workshop\scripts\latexindent.bat -c,c:/Users/Mr Sinamun/Projects/web3/scratch/,c:/Users/Mr Sinamun/Projects/web3/scratch/__latexindent_temp.tex,-y=defaultIndent: '    '
[15:15:48] Formatting failed with exit code 2
[15:15:48] stderr: 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.

default: (tianon/latex)

[15:23:16] Formatting with command c:\Users\Mr Sinamun\Projects\LaTeX-Workshop\scripts\latexindent.bat -c,c:/Users/Mr Sinamun/Projects/web3/scratch/,c:/Users/Mr Sinamun/Projects/web3/scratch/__latexindent_temp.tex,-y=defaultIndent: '    '
[15:23:18] Formatting failed with exit code 2
[15:23:18] stderr: Unknown option: y
Could not find directory c:/Users/Mr Sinamun/Projects/web3/scratch/
Exiting, no indentation done. at /usr/bin/latexindent line 141.

The tianon/latex docker image does not support the y option, since it is using latexindent.pl version 2.2. Is this worth it's own issue?

Other commands such as SyncTeX and Build still work.

@jlelong
Copy link
Collaborator

jlelong commented Dec 24, 2019

This is good news! With aergus/latex, the latexindent.bat was indeed launched, which means we have fixed the original issue. The complaint about the missing directory c:/Users/Mr Sinamun/Projects/web3/scratch/ is raised by the Perl code itself. Have you checked that this directory does exist? It looks odd to have c: followed by a path with / instead of \, however Perl has been understanding forward slashes for long.

Can you try to run the formatting command from the command line (directly from directory c:\Users\Mr Sinamun\Projects\LaTeX-Workshop\scripts`)? You need set the environment variable LATEXWORKSHOP_DOCKER_LATEX with the value of latex-workshop.docker.image.latex.

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

If it fails, can you play a bit with the quotes and / ?

To solve the issue with tianon/latex, you have to edit the configuration variable latex-workshop.latexindent.args.

@conscribtor
Copy link
Author

conscribtor commented Dec 25, 2019

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.

@jlelong
Copy link
Collaborator

jlelong commented Dec 26, 2019

I think you have found the second problem. Looking closely at your first post

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

The build spawn uses the basename of the rootFile lalala and ./ as output although in the definition of the recipe we use %DOC% and %DIR%. This change is handled by the extension

replaceArgumentPlaceholders(rootFile: string, tmpDir: string): (arg: string) => string {
return (arg: string) => {
const docker = vscode.workspace.getConfiguration('latex-workshop').get('docker.enabled')
const doc = rootFile.replace(/\.tex$/, '').split(path.sep).join('/')
const docfile = path.basename(rootFile, '.tex').split(path.sep).join('/')
const outDir = this.extension.manager.getOutDir(rootFile)
return arg.replace(/%DOC%/g, docker ? docfile : doc)
.replace(/%DOCFILE%/g, docfile)
.replace(/%DIR%/g, path.dirname(rootFile).split(path.sep).join('/'))
.replace(/%TMPDIR%/g, tmpDir)
.replace(/%OUTDIR%/g, outDir)
}
}
}

This is supposed to work similarly for formatting but it does not. I will look into it

@jlelong
Copy link
Collaborator

jlelong commented Dec 26, 2019

I have updated #1883. Can you test it again? The stock configuration should be working fine.
I am waiting for your before merging #1883.

@conscribtor
Copy link
Author

conscribtor commented Dec 26, 2019

Using #1883, the stock configuration works for formatting!:

[13:08:28] Formatting with command c:\Users\Mr Sinamun\Projects\LaTeX-Workshop\scripts\latexindent.bat -c,.//,__latexindent_temp.tex,-y=defaultIndent: '    '
[13:08:29] Formatted c:\Users\Mr Sinamun\Projects\web3\scratch\lalala.tex

There are two small oddities that I noticed:

  1. The double slashes for the -c of the command. I think you tried to address this with e15db2d, but the commit logs show no changes. It however does not affect the functionality.
  2. Some stdout is appended to the top of the document with each format command:

c:\Users\Mr Sinamun\Projects\web3\scratch>docker run -i --rm -w /data -v "c:\Users\Mr Sinamun\Projects\web3\scratch:/data" aergus/latex latexindent "-c" ".//" "__latexindent_temp.tex" "-y=defaultIndent: '    '" 
\documentclass{article}
\usepackage{graphicx}  

\begin{document}
[...]

After running it twice:


c:\Users\Mr Sinamun\Projects\web3\scratch>docker run -i --rm -w /data -v "c:\Users\Mr Sinamun\Projects\web3\scratch:/data" aergus/latex latexindent "-c" ".//" "__latexindent_temp.tex" "-y=defaultIndent: '    '" 

c:\Users\Mr Sinamun\Projects\web3\scratch>docker run -i --rm -w /data -v "c:\Users\Mr Sinamun\Projects\web3\scratch:/data" aergus/latex latexindent "-c" ".//" "__latexindent_temp.tex" "-y=defaultIndent: '    '" 
\documentclass{article}
\usepackage{graphicx}  

\begin{document}
[...]

I realize this is quite the edge-case 😅 .
Thank you very much for your work and your time!

@jlelong
Copy link
Collaborator

jlelong commented Dec 26, 2019

Great!!

  1. is now fixed by 17b55ba
  2. is related to cmd.exe, see Use the /q flag with cmd.exe in child_process.spawn() nodejs/node#27120
    To deal with spaces and other oddities in paths, cross-spawn escapes the whole command and its args and uses the shell option of child_process to execute it. There are several "fixes" for this:
    1. Open an issue against https://github.com/moxystudio/, which already adds some extra flags to cms.exe(see here
    2. Go back to child_process instead of cross-spawn now that we have fixed placeholders expansion with docker but the problem will undoubtedly reappear.
    3. Add a dirty hack directly in the extension.

@jlelong
Copy link
Collaborator

jlelong commented Dec 26, 2019

Can you run the following test?

  • At the root of the cloned extension, create a file spawn.jscontaining
const cs = require("cross-spawn");
const cp = require("child_process");

const res1 = cs.spawn.sync('t.bat', [], {stdio: 'pipe', cwd: process.cwd()});
console.log(res1.stdout.toString());
const res2 = cs.spawn.sync('echo', ['Hello'], {stdio: 'pipe', cwd: process.cwd()});
console.log(res2.stdout.toString());

const res3 = cp.spawnSync('t.bat', [], {stdio: 'pipe', cwd: process.cwd()});
console.log(res3.stdout.toString());
const res4 = cp.spawnSync('echo', ['Hello'], {stdio: 'pipe', cwd: process.cwd()});
console.log(res4.stdout.toString());
  • Create a file t.bat containing echo hello

  • run node spawn.js and post the output

@conscribtor
Copy link
Author

conscribtor commented Dec 26, 2019

The output is:

C:\Users\Mr Sinamun\Projects\LaTeX-Workshop>echo hello 
hello

"Hello"


C:\Users\Mr Sinamun\Projects\LaTeX-Workshop>echo hello 
hello

C:\Users\Mr Sinamun\Projects\LaTeX-Workshop\spawn.js:12
console.log(res4.stdout.toString());
                        ^

TypeError: Cannot read property 'toString' of null
    at Object.<anonymous> (C:\Users\Mr Sinamun\Projects\LaTeX-Workshop\spawn.js:12:25)
    at Module._compile (internal/modules/cjs/loader.js:959:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
    at Module.load (internal/modules/cjs/loader.js:815:32)
    at Function.Module._load (internal/modules/cjs/loader.js:727:14)
    at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10)
    at internal/main/run_main_module.js:17:11

The error stack for res4:

Error: spawnSync echo ENOENT
    at Object.spawnSync (internal/child_process.js:1041:20)
    at Object.spawnSync (child_process.js:607:24)
    at Object.<anonymous> (c:\Users\Mr Sinamun\Projects\LaTeX-Workshop\spawn.js:11:17)
    at Module._compile (internal/modules/cjs/loader.js:956:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
    at Module.load (internal/modules/cjs/loader.js:815:32)
    at Function.Module._load (internal/modules/cjs/loader.js:727:14)
    at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10)
    at internal/main/run_main_module.js:17:11

@jlelong
Copy link
Collaborator

jlelong commented Dec 26, 2019

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.

@jlelong
Copy link
Collaborator

jlelong commented Dec 26, 2019

To avoid mixing up things. I will merge #1883 and open a new one to fix the echo mode of `cmd.exe.
I will let you know so that you can test it (thanks in advance).

@conscribtor
Copy link
Author

conscribtor commented Dec 26, 2019

Yes you are right!

By prepending the content of latexindent.bat with an @ the issue with the echoed line is solved:

@docker run -i --rm -w /data -v "%cd%:/data" %LATEXWORKSHOP_DOCKER_LATEX% latexindent %*

I've tested it with aergus/latex and also with a classic TeX Live installation.

jlelong added a commit that referenced this issue Dec 28, 2019
Related to #1873. Thanks to @MrSinamun for the tip.
@jlelong
Copy link
Collaborator

jlelong commented Dec 28, 2019

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

@conscribtor
Copy link
Author

Thank you for your time. Everything is good now.

jlelong added a commit that referenced this issue Mar 1, 2020
Repository owner locked as resolved and limited conversation to collaborators Jul 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by LW maintainers as bug
Projects
None yet
Development

No branches or pull requests

2 participants