James-Yu / LaTeX-Workshop

Boost LaTeX typesetting efficiency with preview, compile, autocomplete, colorize, and more.
MIT License
10.42k stars 519 forks source link

[Bug] Failed to format tex file via LatexWorkshop when use self-make _latexindent_ yaml settings #4265

Closed Mikachu2333 closed 1 month ago

Mikachu2333 commented 1 month ago

Pre-checks*

Environment*

The Issue*

When I tried to indent the file with latexWorkshop, it output successed! but didn't change the file indeed. And I tried to run the commands in terminal and get correct results.

Reproduction Steps

Please list out the steps to reproduce your bug. Include relevant environmental variables or any other configuration.

  1. Open a folder for test with VSCode (e.g. test_tex)
  2. Create a main.tex file (Context is on the following)
  3. Create a file named school_life_fuyanshan.tex with dir structs /in_school/life/ (Context is on the following)
  4. Add a latexindent.yaml file. (Context is on the following)
  5. Modify the LatexWorkshop settings as the following shows.
  6. Format the school_life_fuyanshan.tex

File (dir) Struct:

.
├── in_school
│   └── life
│       └── school_life_fuyanshan.tex
├── latexindent.yaml
└── main.tex

2 directories, 3 files

Context main.tex

% !TeX encoding = UTF-8
% !TEX TS-program = xelatex
\documentclass{ctexrep}%Chinese report
\usepackage{tabularray}%tabular
\begin{document}
\input{in_school/life/school_life_fuyanshan.tex}
\end{document}

Context latexindent.yaml

fineTuning:
  keyEqualsValuesBracesBrackets:
    name: |-
      (?x)
      [a-zA-Z@\*0-9_\/.:\#-]+
      (?:
        [a-zA-Z@\*0-9_\/.\h:\#-]
        \{
          [a-zA-Z@\*0-9_\/.\h:\#-,]+?
        \}
      )*?
defaultIndent: "    "

Context _school_lifefuyanshan.tex

\begin{tblr}[long,
    note{1} = {除餐厅东南侧楼梯外均可到达。},
    ]
    {
    cells = {c,m},
    cell{1}{1} = {r=3}{},
    cell{4}{1} = {r=3}{},
    cell{7}{2} = {c=4}{},
    vlines,
    hline{1,4,7-8} = {-}{1pt},
    hline{2-3,5-6} = {2-5}{},
            column{1} = {cmd=\bfseries},
        }
    1层             & 麦西麦乐              & 包子水饺$^㊐$        & 牛肉板面 & 兰州拉面         \\
                    & 大米粒儿$^㊐$(油条) & 自选菜(稍贵)       & 豆腐脑   & 盒饭(便宜量大) \\
                    & 粥$^㊐$(种类多)     & 馄饨$^㊐$            & 麻辣烫   & 烤夫王           \\
    2层             & 大骨饭                & 麻汁馄饨             & 水饺     & 东北玉米面       \\
                    & 烤鸭饭(瓦罐汤)      & 铁板炒饭(量大管饱) & 米线     & 清真窗口         \\
                    & 馋嘴鱼                & 自选水饺             & 茶拌饭   & 略               \\
    3层\TblrNote{1} & 略(较贵;有包间)
\end{tblr}

Latexindnet part of VSCode Settings

    "latex-workshop.latexindent.args": [
        "-c=%DIR%/",
        "%TMPFILE%",
        "-m",
        "--GCString",
        "-l=latexindent.yaml"
    ],

Expected Behavior

The file school_life_fuyanshan.tex should be formatted as the following show.

(not 3 tabs but 8 spaces in line 12 column{1} = {cmd=\bfseries},)

\begin{tblr}[long,
        note{1} = {除餐厅东南侧楼梯外均可到达。},
    ]
    {
        cells = {c,m},
        cell{1}{1} = {r=3}{},
        cell{4}{1} = {r=3}{},
        cell{7}{2} = {c=4}{},
        vlines,
        hline{1,4,7-8} = {-}{1pt},
        hline{2-3,5-6} = {2-5}{},
        column{1} = {cmd=\bfseries},
    }
    1层             & 麦西麦乐              & 包子水饺$^㊐$        & 牛肉板面 & 兰州拉面         \\
                    & 大米粒儿$^㊐$(油条) & 自选菜(稍贵)       & 豆腐脑   & 盒饭(便宜量大) \\
                    & 粥$^㊐$(种类多)     & 馄饨$^㊐$            & 麻辣烫   & 烤夫王           \\
    2层             & 大骨饭                & 麻汁馄饨             & 水饺     & 东北玉米面       \\
                    & 烤鸭饭(瓦罐汤)      & 铁板炒饭(量大管饱) & 米线     & 清真窗口         \\
                    & 馋嘴鱼                & 自选水饺             & 茶拌饭   & 略               \\
    3层\TblrNote{1} & 略(较贵;有包间)

Logs

LaTeX Workshop Output*

[20:25:56.968][Logger] New log placeholder %WS1% registered for /home/linkchou/文档/tex_test .
[20:25:56.968][Extension] Initializing LaTeX Workshop.
[20:25:57.045][Build][Recipe] Set $LATEXWORKSHOP_DOCKER_LATEX: ""
[20:25:57.068][Server] Creating LaTeX Workshop http and websocket server.
[20:25:57.124][Format][Bib] Bibtex format config: {"tab":"    ","case":"lowercase","left":"{","right":"}","trailingComma":false,"sort":["key"],"alignOnEqual":true,"sortFields":false,"fieldsOrder":[],"firstEntries":["string","xdata"]}
[20:25:57.161][Server] Server successfully started: {"address":"127.0.0.1","family":"IPv4","port":40741} .
[20:25:57.164][Extension] Extension root: /home/linkchou/.vscode/extensions/james-yu.latex-workshop-9.20.1
[20:25:57.164][Extension] $PATH: /usr/local/texlive/2024/bin/x86_64-linux:/usr/local/texlive/2024/bin/x86_64-linux:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin
[20:25:57.164][Extension] $SHELL: /bin/bash
[20:25:57.164][Extension] $LANG: zh_CN.UTF-8
[20:25:57.164][Extension] $LC_ALL: undefined
[20:25:57.164][Extension] process.platform: linux
[20:25:57.165][Extension] process.arch: x64
[20:25:57.165][Extension] vscode.env.appName: Visual Studio Code
[20:25:57.165][Extension] vscode.env.remoteName: undefined
[20:25:57.165][Extension] vscode.env.uiKind: 1
[20:25:57.190][Config] latex-workshop.latexindent.args: ["-c=%DIR%/","%TMPFILE%","-m","--GCString","-l=latexindent.yaml"] .
[20:25:57.198][Config] latex-workshop.bibtex-format.tab: "4 spaces" .
[20:25:57.203][Extension] Trigger characters for intellisense of LaTeX documents: ["\\",",","{"]
[20:25:57.205][Root] Current workspace folders: ["file://%WS1%"]
[20:25:57.205][Extension] LaTeX Workshop initialized.
[20:25:57.206][Root] Current workspaceRootDir: file://%WS1% .
[20:25:57.297][Server] valdOrigin is http://127.0.0.1:40741
[20:25:57.394][Root] Found files that might be root, choose the first one: %WS1%/main.tex .
[20:25:57.394][Root] Root file changed: from %WS1%/main.tex to %WS1%/main.tex, langID latex . Refresh dependencies
[20:25:57.395][Event] ROOT_FILE_CHANGED: "%WS1%/main.tex"
[20:25:57.395][Cacher][Watcher] Reset.
[20:25:57.395][Cacher][Watcher] Reset.
[20:25:57.397][Cacher] Adding %WS1%/main.tex .
[20:25:57.398][Cacher][Watcher] Watched %WS1%/main.tex with a new .* watcher on %WS1% .
[20:25:57.398][Event] FILE_WATCHED: "%WS1%/main.tex"
[20:25:57.399][Cacher] Caching %WS1%/main.tex .
[20:25:57.400][Cacher] Input %WS1%/in_school/life/school_life_fuyanshan.tex from %WS1%/main.tex .
[20:25:57.400][Cacher] Adding %WS1%/in_school/life/school_life_fuyanshan.tex .
[20:25:57.400][Cacher][Watcher] Watched %WS1%/in_school/life/school_life_fuyanshan.tex with a new .* watcher on %WS1%/in_school/life .
[20:25:57.400][Event] FILE_WATCHED: "%WS1%/in_school/life/school_life_fuyanshan.tex"
[20:25:57.401][Cacher] Caching %WS1%/in_school/life/school_life_fuyanshan.tex .
[20:25:57.401][Cacher] Updated inputs of %WS1%/in_school/life/school_life_fuyanshan.tex .
[20:25:57.401][Cacher] Parse LaTeX AST: %WS1%/in_school/life/school_life_fuyanshan.tex .
[20:25:57.402][Cacher] Updated inputs of %WS1%/main.tex .
[20:25:57.402][Cacher] Parse LaTeX AST: %WS1%/main.tex .
[20:25:57.402][Event] ROOT_FILE_SEARCHED
[20:25:57.419][Cacher] Parsed LaTeX AST: %WS1%/in_school/life/school_life_fuyanshan.tex .
[20:25:57.420][Cacher] Updated elements in 0.87 ms: %WS1%/in_school/life/school_life_fuyanshan.tex .
[20:25:57.420][Event] FILE_PARSED: "%WS1%/in_school/life/school_life_fuyanshan.tex"
[20:25:57.421][Cacher] Parsed LaTeX AST: %WS1%/main.tex .
[20:25:57.421][File] Calling kpsewhich to resolve ctexrep.cls .
[20:25:57.447][File] kpsewhich returned with '/usr/local/texlive/2024/texmf-dist/tex/latex/ctex/ctexrep.cls'.
[20:25:57.448][Cacher] Updated elements in 26.59 ms: %WS1%/main.tex .
[20:25:57.448][Event] FILE_PARSED: "%WS1%/main.tex"
[20:25:57.449][Structure] Structure force updated with 0 root sections for %WS1%/main.tex .
[20:25:57.449][Event] STRUCTURE_UPDATED
[20:26:04.050][Format][TeX] Start formatting with latexindent.
[20:26:04.050][Format][TeX] Checking latexindent: which latexindent
[20:26:04.057][Format][TeX] Checking latexindent is ok: /usr/local/texlive/2024/bin/x86_64-linux/latexindent

[20:26:04.059][Format][TeX] Formatting LaTeX. The command is latexindent:["-c=%WS1%/","%WS1%/in_school/life/__latexindent_temp_school_life_fuyanshan.tex","-m","--GCString","-l=latexindent.yaml"].
[20:26:04.161][Format][TeX] Formatted %WS1%/in_school/life/school_life_fuyanshan.tex

Developer Tools Console

workbench.desktop.main.js:sourcemap:656  INFO Started local extension host with pid 61424.
workbench.desktop.main.js:sourcemap:656   ERR Ignoring latex-workshop.synctex.indicator.enabled as latex-workshop.synctex.indicator is "rectangle"
workbench.desktop.main.js:sourcemap:1723 Overwriting grammar scope name to file mapping for scope text.tex.
Old grammar file: file:///snap/code/159/usr/share/code/resources/app/extensions/latex/syntaxes/TeX.tmLanguage.json.
New grammar file: file:///home/linkchou/.vscode/extensions/james-yu.latex-workshop-9.20.1/syntax/TeX.tmLanguage.json
register @ workbench.desktop.main.js:sourcemap:1723
workbench.desktop.main.js:sourcemap:1723 Overwriting grammar scope name to file mapping for scope text.tex.latex.
Old grammar file: file:///snap/code/159/usr/share/code/resources/app/extensions/latex/syntaxes/LaTeX.tmLanguage.json.
New grammar file: file:///home/linkchou/.vscode/extensions/james-yu.latex-workshop-9.20.1/syntax/LaTeX.tmLanguage.json
register @ workbench.desktop.main.js:sourcemap:1723
workbench.desktop.main.js:sourcemap:1723 Overwriting grammar scope name to file mapping for scope text.bibtex.
Old grammar file: file:///snap/code/159/usr/share/code/resources/app/extensions/latex/syntaxes/Bibtex.tmLanguage.json.
New grammar file: file:///home/linkchou/.vscode/extensions/james-yu.latex-workshop-9.20.1/syntax/Bibtex.tmLanguage.json
register @ workbench.desktop.main.js:sourcemap:1723
workbench.desktop.main.js:sourcemap:1723 Overwriting grammar scope name to file mapping for scope text.tex.markdown_latex_combined.
Old grammar file: file:///snap/code/159/usr/share/code/resources/app/extensions/latex/syntaxes/markdown-latex-combined.tmLanguage.json.
New grammar file: file:///home/linkchou/.vscode/extensions/james-yu.latex-workshop-9.20.1/syntax/markdown-latex-combined.tmLanguage.json
register @ workbench.desktop.main.js:sourcemap:1723
workbench.desktop.main.js:sourcemap:1723 Overwriting grammar scope name to file mapping for scope source.cpp.embedded.latex.
Old grammar file: file:///snap/code/159/usr/share/code/resources/app/extensions/latex/syntaxes/cpp-grammar-bailout.tmLanguage.json.
New grammar file: file:///home/linkchou/.vscode/extensions/james-yu.latex-workshop-9.20.1/syntax/cpp-grammar-bailout.tmLanguage.json
register @ workbench.desktop.main.js:sourcemap:1723
TMScopeRegistry.ts:46 Overwriting grammar scope name to file mapping for scope text.tex.
Old grammar file: file:///snap/code/159/usr/share/code/resources/app/extensions/latex/syntaxes/TeX.tmLanguage.json.
New grammar file: file:///home/linkchou/.vscode/extensions/james-yu.latex-workshop-9.20.1/syntax/TeX.tmLanguage.json
register @ TMScopeRegistry.ts:46
TMScopeRegistry.ts:46 Overwriting grammar scope name to file mapping for scope text.tex.latex.
Old grammar file: file:///snap/code/159/usr/share/code/resources/app/extensions/latex/syntaxes/LaTeX.tmLanguage.json.
New grammar file: file:///home/linkchou/.vscode/extensions/james-yu.latex-workshop-9.20.1/syntax/LaTeX.tmLanguage.json
register @ TMScopeRegistry.ts:46
TMScopeRegistry.ts:46 Overwriting grammar scope name to file mapping for scope text.bibtex.
Old grammar file: file:///snap/code/159/usr/share/code/resources/app/extensions/latex/syntaxes/Bibtex.tmLanguage.json.
New grammar file: file:///home/linkchou/.vscode/extensions/james-yu.latex-workshop-9.20.1/syntax/Bibtex.tmLanguage.json
register @ TMScopeRegistry.ts:46
TMScopeRegistry.ts:46 Overwriting grammar scope name to file mapping for scope text.tex.markdown_latex_combined.
Old grammar file: file:///snap/code/159/usr/share/code/resources/app/extensions/latex/syntaxes/markdown-latex-combined.tmLanguage.json.
New grammar file: file:///home/linkchou/.vscode/extensions/james-yu.latex-workshop-9.20.1/syntax/markdown-latex-combined.tmLanguage.json
register @ TMScopeRegistry.ts:46
TMScopeRegistry.ts:46 Overwriting grammar scope name to file mapping for scope source.cpp.embedded.latex.
Old grammar file: file:///snap/code/159/usr/share/code/resources/app/extensions/latex/syntaxes/cpp-grammar-bailout.tmLanguage.json.
New grammar file: file:///home/linkchou/.vscode/extensions/james-yu.latex-workshop-9.20.1/syntax/cpp-grammar-bailout.tmLanguage.json
register @ TMScopeRegistry.ts:46
workbench.desktop.main.js:sourcemap:152 [Extension Host] [vscode-icons] v12.7.0 activated!
workbench.desktop.main.js:sourcemap:656   ERR Ignoring latex-workshop.synctex.indicator.enabled as latex-workshop.synctex.indicator is "rectangle"
workbench.desktop.main.js:sourcemap:656  INFO [perf] Render performance baseline is 25ms
12workbench.desktop.main.js:sourcemap:656  WARN [cmake-tools]: 无法找到键 cmake-tools.configuration.cmake.options.advanced.statusBarLength.description 的消息。
workbench.desktop.main.js:sourcemap:152 [Extension Host] rejected promise not handled within 1 second: Error: command 'workbench.view.lw.latex-workshop-activitybar' not found
w @ workbench.desktop.main.js:sourcemap:152
workbench.desktop.main.js:sourcemap:152 [Extension Host] stack trace: Error: command 'workbench.view.lw.latex-workshop-activitybar' not found
    at y.n (vscode-file://vscode-app/snap/code/159/usr/share/code/resources/app/out/vs/workbench/workbench.desktop.main.js:1609:23057)
    at y.executeCommand (vscode-file://vscode-app/snap/code/159/usr/share/code/resources/app/out/vs/workbench/workbench.desktop.main.js:1609:22986)
w @ workbench.desktop.main.js:sourcemap:152
workbench.desktop.main.js:sourcemap:656   ERR command 'workbench.view.lw.latex-workshop-activitybar' not found: Error: command 'workbench.view.lw.latex-workshop-activitybar' not found
    at y.n (vscode-file://vscode-app/snap/code/159/usr/share/code/resources/app/out/vs/workbench/workbench.desktop.main.js:1609:23057)
    at y.executeCommand (vscode-file://vscode-app/snap/code/159/usr/share/code/resources/app/out/vs/workbench/workbench.desktop.main.js:1609:22986)

Anything Else?

I tried the command and it gave correct result.

latexindent in_school/life/school_life_fuyanshan.tex -m --GCString -l=latexindent.yaml
James-Yu commented 1 month ago

You can add "-y=defaultIndent: '%INDENT%'" to your arguments. latexindent sometimes ignores that setting in yaml.

Mikachu2333 commented 1 month ago

You can add "-y=defaultIndent: '%INDENT%'" to your arguments. latexindent sometimes ignores that setting in yaml.

Sorry for bother, but I mean that whether I set -y=defaultIndent: '%INDENT%' or not, LaTeX Workshop did not respond and made no change to my tex file. Although it displayed success, it did not actually modify any of the lines as what I want it to do.

latexindent sometimes ignores that setting in yaml.

If it ignores the setting of default indent spaces, at least it should have corrected lines 9 to 10 in my tex file which were indented incorrectly, but it did not complete the task.

James-Yu commented 1 month ago

I tried your example and it works well on my side, except for the tab indentation. So I figure it should be a local problem. The log message also did not indicate anything wrong.

Mikachu2333 commented 1 month ago

I tried your example and it works well on my side, except for the tab indentation. So I figure it should be a local problem. The log message also did not indicate anything wrong.

Thanks for timely anster, I'd re-try it with my friends to check it out if it is a local problem.

Mikachu2333 commented 1 month ago

latexindent sometimes ignores that setting in yaml.

Thank you for your tip!

At your prompt, I found that although the yaml file was specified and LaTeX Workshop did not report any error, indeed, the yaml file was not used for not found error, this issue is reffering to the error file locate (It seems that Latex Workshop did not check the file in workfolder path and just ignore the arg.).

The correct setting in the json file should be -l=%DIR%/latexindent.yaml ...