skip to Main Content

I’m having trouble getting the LTeX extension to work properly in my Visual Studio Code LaTeX profile. When I open a folder containing LaTeX documents with this profile, I get the following error messages:

enter image description here

Could not run ltex-ls with Java, please see the output panel ‘LTeX Language Client’ for details. You might want to try offline installation.

and then

enter image description here

which points me to this page.

Here’s the output from the LTeX Language Client:

Info: Setting LTeX UI language to 'en'.
Info: Loading i18n messages...
Info: Loading default i18n messages...
Info: 
Info: ltex.ltex-ls.path not set.
Info: Searching for ltex-ls in 'c:Usersfoobar.vscodeextensionsvalentjn.vscode-ltex-13.1.0lib'...
Info: ltex-ls found in 'c:Usersfoobar.vscodeextensionsvalentjn.vscode-ltex-13.1.0libltex-ls-15.2.0'.
Info: 
Info: Using ltex-ls from 'c:Usersfoobar.vscodeextensionsvalentjn.vscode-ltex-13.1.0libltex-ls-15.2.0'.
Info: Using Java from 'C:Program FilesMicrosoftjdk-11.0.16.101-hotspotbinjava.exe' (set in ltex.java.path).
Info: Testing ltex-ls...
Info:   Command: "c:\Users\foobar\.vscode\extensions\valentjn.vscode-ltex-13.1.0\lib\ltex-ls-15.2.0\bin\ltex-ls.bat"
Info:   Arguments: ["--version"]
Info:   env['JAVA_HOME']: "C:\Program Files\Microsoft\jdk-11.0.16.101-hotspot\bin\java.exe"
Info:   env['JAVA_OPTS']: "-Xms64m -Xmx512m"
Error: Test failed.
Error: Error details:
Error: Error: spawnSync c:Usersfoobar.vscodeextensionsvalentjn.vscode-ltex-13.1.0libltex-ls-15.2.0binltex-ls.bat EINVAL
Error:  at Object.spawnSync (node:internal/child_process:1124:20)
Error:  at Object.spawnSync (node:child_process:914:24)
Error:  at DependencyManager.<anonymous> (c:Usersfoobar.vscodeextensionsvalentjn.vscode-ltex-13.1.0distextension.js:13528:45)
Error:  at Generator.next (<anonymous>)
Error:  at fulfilled (c:Usersfoobar.vscodeextensionsvalentjn.vscode-ltex-13.1.0distextension.js:13159:58)
Info: ltex-ls did not print expected version information to stdout.
Info: stdout of ltex-ls:
Info: 
Info: stderr of ltex-ls:
Info: 
Info: You might want to try offline installation, see https://valentjn.github.io/vscode-ltex/docs/installation-and-usage.html#offline-installation.

I have multiple Java versions installed on my system via Chocolatey and winget. When I run where java in cmd, I get:

C:Program FilesEclipse Adoptiumjre-8.0.422.5-hotspotbinjava.exe
C:Program Files (x86)Common FilesOracleJavajava8pathjava.exe
C:Program Files (x86)Common FilesOracleJavajavapathjava.exe
C:Program FilesAdoptOpenJDKjdk-15.0.2.7-hotspotbinjava.exe
C:ProgramDataOracleJavajavapathjava.exe
C:Program FilesMicrosoftjdk-11.0.16.101-hotspotbinjava.exe
C:Program FilesOpenJDKjdk-22.0.2binjava.exe

Here’s my settings.json for the LaTeX profile:

{
    "editor.formatOnSave": true,
    "ltex.java.path": "C:\Program Files\Microsoft\jdk-11.0.16.101-hotspot\bin\java.exe"
}

I’ve tried various combinations of settings and Java versions, but I can’t get LTeX to work properly. When I run the ltex-ls.bat file manually with the --version flag, it seems to work and reports using Java 22.0.2.

Any ideas on how to resolve this issue and get LTeX working with my LaTeX profile in VS Code?

2

Answers


  1. I have fixed this problem using the code solution given by tobiscode in this post:

    https://github.com/valentjn/vscode-ltex/issues/884#issuecomment-2263630384

    You will have to change the extensions.js file that can be found in

    %USERPROFILE%.vscodeextensionsvalentjn.vscode-ltex-13.1.0dist
    

    After that I just restarted my computer, open VSCode and the error was still there, but now clicking on Try Again when the error appears fix the issue.

    Edit
    As Abra suggested, I’m including the changes mentioned in the link above, in case the link becomes unavailable or any similar issue occurs.

    You will have to include the following changes in the file extensions.js mentioned above.

    • Change line 13516:

            const executableOptions = {
                encoding: 'utf-8',
                timeout: 15000,
            };
      

      to:

            const executableOptions = {
                encoding: 'utf-8',
                timeout: 15000,
                shell: true,
            };
      
    • Change line 13616:

            const executableOptions = {
                encoding: 'utf-8',
                timeout: 15000,
            };
      

      to:

            const executableOptions = {
                encoding: 'utf-8',
                timeout: 15000,
                shell: true,
            };
      
    • Change line 24689:

            const execOptions = Object.create(null);
      

      to:

            const execOptions = {
                        shell: true
                    }
      
    • Change line 24823:

            options.cwd = options.cwd || serverWorkingDir;
      

      to:

            options.cwd = options.cwd || serverWorkingDir;
            options.shell = true;
      
    Login or Signup to reply.
  2. In case you are still encountering issues with this and/or don’t want to have to adjust those lines in extensions.js, the LTeX grammar tool extension was recently forked by spitzerd and it resolved the ltex-ls failure to run with Java error for me.

    Search for LTeX+ in the vscode extensions marketplace and install. I hope this helps.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search