James-Yu / LaTeX-Workshop

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

In math preview, \newcommand wrongly parsed when line break before the body of the macro presents #4428

Closed MajoranaOedipus closed 1 week ago

MajoranaOedipus commented 1 week ago

Please fill the following fields with a star (*) and provide as much related information as possible.

Pre-checks*

Please change the following [ ] to [x] for confirmation.

  • [x] The issue has not been reported in this repository.
  • [x] The issue remains after disabling all other extensions and restarting Visual Studio Code.
  • [x] The FAQ cannot address the issue.
  • [x] The issue is not related to compiling a document, or the document can be successfully compiled in the OS terminal but not in Visual Studio Code with this extension.

Environment*

The Issue*

When defining macros with \newcommand like:

\newcommand{\foo}%  <-- line break here
{%
    body%
}

The math preview breaks in several ways. And it behaves differently in panel and in hover preview.

Detailed exampled listed in Reproduction Steps.

Reproduction Steps

Example 1:

\documentclass{article}
\newcommand{\hello}%
{%
    Not hello%
}
\newcommand{\hi}{%
    Not hi%
}
\begin{document}
$\frac a b$
\end{document}

When hovering over the formula $\frac a b$, the preview is correct.

While, if the math preview panel is enabled via Shift + Ctrl + P -> LaTeX Workshop: Open math preview panel, the preview panel is blank, leaving an output message saying:

[21:52:07.415][Preview][Math] Failed rendering MathJax \newcommand{\hello}
\newcommand{\hi}{%
Not hi%
}
\frac a b{\color{orange}\!\Big\vert\!} . Try removing macro definitions.

Example 2:

\documentclass{article}
\newcommand{\hello}%
{%
    Not hello%
}
\newcommand{\hi}{%
    Not hi%
}
\begin{document}
$a$ 
\end{document}

The preview becomes: Preview in case 2

Logs

LaTeX Workshop Output*

[21:56:51.893][Logger] New log placeholder %WS1% registered for /root/Worktable/texpreviewproblem .
[21:56:51.893][Extension] Initializing LaTeX Workshop.
[21:56:52.202][Build][Recipe] Set $LATEXWORKSHOP_DOCKER_LATEX: ""
[21:56:52.204][Build][Recipe] Set $LATEXWORKSHOP_DOCKER_PATH: "docker"
[21:56:52.325][Server] Creating LaTeX Workshop http and websocket server.
[21:56:52.531][Format][Bib] Bibtex format config: {"tab":"  ","case":"lowercase","left":"{","right":"}","trailingComma":false,"sort":["key"],"alignOnEqual":true,"sortFields":false,"fieldsOrder":[],"firstEntries":["string","xdata"]}
[21:56:52.684][Server] Server successfully started: {"address":"127.0.0.1","family":"IPv4","port":38497} .
[21:56:52.741][Extension] Extension root: /root/.vscode-server/extensions/james-yu.latex-workshop-10.5.0
[21:56:52.742][Extension] $PATH: /root/.vscode-server/bin/fee1edb8d6d72a0ddff41e5f71a671c23ed924b9/bin/remote-cli:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib:/mnt/c/Windows/system32:/mnt/c/Windows:/mnt/c/Windows/System32/Wbem:/mnt/c/Windows/System32/WindowsPowerShell/v1.0/:/mnt/c/Windows/System32/OpenSSH/:/mnt/c/Program Files/Wolfram Research/WolframScript/:/mnt/c/Program Files/Git/cmd:/mnt/c/Users/Lenovo/AppData/Local/Microsoft/WindowsApps:/mnt/c/Users/Lenovo/AppData/Local/Programs/Microsoft VS Code/bin:/mnt/c/Program Files/Git/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl
[21:56:52.743][Extension] $SHELL: /bin/bash
[21:56:52.743][Extension] $LANG: en_US.UTF-8
[21:56:52.743][Extension] $LC_ALL: undefined
[21:56:52.744][Extension] process.platform: linux
[21:56:52.744][Extension] process.arch: x64
[21:56:52.744][Extension] vscode.env.appName: Visual Studio Code
[21:56:52.745][Extension] vscode.env.remoteName: wsl
[21:56:52.745][Extension] vscode.env.uiKind: 1
[21:56:52.754][Config] latex-workshop.latex.recipes: [{"name":"Draft","tools":["xelatex"]},{"name":"Full article","tools":["xelatex","biblatex","xelatex","xelatex"]},{"name":"Full book","tools":["xelatex","biblatex","makeindex","xelatex","xelatex"]}] .
[21:56:52.756][Config] latex-workshop.latex.tools: [{"name":"latexmk","command":"latexmk","args":["-synctex=1","-interaction=nonstopmode","-file-line-error","-pdf","-outdir=%OUTDIR%","%DOC%"],"env":{}},{"name":"lualatexmk","command":"latexmk","args":["-synctex=1","-interaction=nonstopmode","-file-line-error","-lualatex","-outdir=%OUTDIR%","%DOC%"],"env":{}},{"name":"latexmk_rconly","command":"latexmk","args":["%DOC%"],"env":{}},{"name":"pdflatex","command":"pdflatex","args":["-synctex=1","-interaction=nonstopmode","-file-line-error","%DOC%"],"env":{}},{"name":"xelatex","command":"xelatex","args":["-synctex=1","-interaction=nonstopmode","-file-line-error","%DOCFILE%"],"env":{}},{"name":"bibtex","command":"bibtex","args":["%DOCFILE%"],"env":{}},{"name":"biblatex","command":"biber","args":["%DOCFILE%"],"env":{}},{"name":"makeindex","command":"makeindex","args":["%DOCFILE%"],"env":{}},{"name":"rnw2tex","command":"Rscript","args":["-e","knitr::opts_knit$set(concordance = TRUE); knitr::knit('%DOCFILE_EXT%')"],"env":{}},{"name":"jnw2tex","command":"julia","args":["-e","using Weave; weave(\"%DOC_EXT%\", doctype=\"tex\")"],"env":{}},{"name":"jnw2texmintex","command":"julia","args":["-e","using Weave; weave(\"%DOC_EXT%\", doctype=\"texminted\")"],"env":{}}] .
[21:56:52.793][Config] latex-workshop.latex.autoBuild.run: "never" .
[21:56:52.797][Config] latex-workshop.latex.autoClean.run: "onFailed" .
[21:56:52.798][Config] latex-workshop.latex.clean.fileTypes: ["%DOCFILE%.aux","%DOCFILE%.bbl","%DOCFILE%.blg","%DOCFILE%.idx","%DOCFILE%.ind","%DOCFILE%.lof","%DOCFILE%.lot","%DOCFILE%.out","%DOCFILE%.toc","%DOCFILE%.acn","%DOCFILE%.acr","%DOCFILE%.alg","%DOCFILE%.glg","%DOCFILE%.glo","%DOCFILE%.gls","%DOCFILE%.fls","%DOCFILE%.fdb_latexmk","%DOCFILE%.snm","%DOCFILE%.synctex(busy)","%DOCFILE%.synctex.gz(busy)","%DOCFILE%.nav","%DOCFILE%.vrb"] .
[21:56:52.800][Config] latex-workshop.view.outline.sections: ["part","chapter","section","subsection","subsubsection","paragraph","term"] .
[21:56:52.802][Config] latex-workshop.view.pdf.viewer: "external" .
[21:56:52.802][Config] latex-workshop.view.pdf.ref.viewer: "external" .
[21:56:52.803][Config] latex-workshop.view.pdf.external.viewer.command: "/usr/bin/okular" .
[21:56:52.804][Config] latex-workshop.view.pdf.external.viewer.args: ["--unique","%PDF%"] .
[21:56:52.804][Config] latex-workshop.view.pdf.external.synctex.command: "/usr/bin/okular" .
[21:56:52.805][Config] latex-workshop.view.pdf.external.synctex.args: ["--unique","%PDF%#scr:%LINE%%TEX%"] .
[21:56:52.812][Config] latex-workshop.linting.chktex.enabled: true .
[21:56:52.814][Config] latex-workshop.linting.chktex.exec.args: ["-wall","-n22","-n30","-e16","-q","-n46","-n19","-n21","-n3","-n1"] .
[21:56:52.830][Config] latex-workshop.intellisense.unimathsymbols.enabled: true .
[21:56:52.830][Config] latex-workshop.intellisense.subsuperscript.enabled: true .
[21:56:52.841][Config] latex-workshop.hover.preview.newcommand.newcommandFile: " " .
[21:56:52.850][Config] latex-workshop.hover.preview.cursor.symbol: "\\!\\Big\\vert\\!" .
[21:56:52.851][Config] latex-workshop.hover.preview.cursor.color: "orange" .
[21:56:52.853][Config] latex-workshop.hover.preview.mathjax.extensions: ["boldsymbol","mathtools","cases","bbox","textmacros","cancel"] .
[21:56:52.854][Config] latex-workshop.intellisense.citation.backend: "biblatex" .
[21:56:52.883][Config] latex-workshop.mathpreviewpanel.cursor.enabled: true .
[21:56:52.893][Extension] Trigger characters for intellisense of LaTeX documents: ["\\",",","{","}"]
[21:56:52.895][Root] Current workspace folders: ["file://%WS1%"]
[21:56:52.896][Root] Try finding root from magic comment.
[21:56:52.897][Extension] LaTeX Workshop initialized.
[21:56:52.898][Root] Try finding root from active editor.
[21:56:52.900][Root] Found root file from active editor: %WS1%/test.tex
[21:56:52.902][Root] Root file changed: from %WS1%/test.tex to %WS1%/test.tex, langID latex . Refresh dependencies
[21:56:52.903][Event] ROOT_FILE_CHANGED: "%WS1%/test.tex"
[21:56:52.905][Cacher][Watcher] Reset.
[21:56:52.905][Cacher][Watcher] Reset.
[21:56:52.916][Cacher] Adding %WS1%/test.tex .
[21:56:52.918][Cacher][Watcher] Watched file://%WS1%/test.tex with a new .* watcher on %WS1% .
[21:56:52.918][Event] FILE_WATCHED: "file://%WS1%/test.tex"
[21:56:52.929][Cacher] Caching %WS1%/test.tex .
[21:56:52.932][Event] ROOT_FILE_SEARCHED
[21:56:52.935][Linter] ChkTeX lints root %WS1%/test.tex .
[21:56:52.946][Linter][ChkTeX] Linter for ChkTeX command The command is chktex:["-wall","-n22","-n30","-e16","-q","-n46","-n19","-n21","-n3","-n1","-f%f:%l:%c:%d:%k:%n:%m\n","%WS1%/test.tex"].
[21:56:52.960][Cacher] Updated inputs of %WS1%/test.tex .
[21:56:52.962][Cacher] Parse LaTeX AST: %WS1%/test.tex .
[21:56:52.999][Server] validOrigin is http://127.0.0.1:38497
[21:56:53.010][Cacher] Parsed LaTeX AST in 39.26 ms: %WS1%/test.tex .
[21:56:53.014][File] Calling kpsewhich to resolve article.cls .
[21:56:53.237][File] kpsewhich returned with '/usr/share/texmf-dist/tex/latex/base/article.cls'.
[21:56:53.248][Cacher] Updated elements in 237.14 ms: %WS1%/test.tex .
[21:56:53.249][Event] FILE_PARSED: "%WS1%/test.tex"
[21:56:53.252][Structure] Structure force updated with 0 root sections for %WS1%/test.tex .
[21:56:53.253][Event] STRUCTURE_UPDATED
[21:56:53.255][Linter] Linter for root successfully finished in 0s 299ms
[21:56:53.256][Linter][ChkTeX] No .chktexrc file is found to determine TabSize.
[21:56:53.256][Linter][ChkTeX] Logged 0 messages.
[21:56:53.410][Preview][Math] Math preview panel: restored
[21:56:53.514][Preview][Math][Cursor] Parse LaTeX AST from $a$ .
[21:56:53.766][Preview][Math] Math preview panel: initialized
[21:56:53.768][Preview][Math][Cursor] Use previous AST of $a$ .

Developer Tools Console

Please paste the whole log messages below, not parts of ones. This console logs can sometimes be very important in many cases. To access the log, click Help -> Toggle Developer Tools -> Console.

INFO Started local extension host with pid 14792.
log.ts:439   ERR Extension 'ms-vscode.cpptools' appears in product.json but enables LESS API proposals than the extension wants.
package.json (LOSES): terminalDataWriteEvent, lmTools
product.json (WINS): terminalDataWriteEvent
log.ts:419  INFO Invoking resolveAuthority(wsl)...
log.ts:419  INFO [LocalProcess0][resolveAuthority(wsl,1)][0ms] obtaining proxy...
log.ts:419  INFO [LocalProcess0][resolveAuthority(wsl,1)][0ms] invoking...
log.ts:419  INFO [LocalProcess0][resolveAuthority(wsl,1)][476ms] returned WebSocket(127.0.0.1:7233)
log.ts:419  INFO resolveAuthority(wsl) returned 'WebSocket(127.0.0.1:7233)' after 476 ms
log.ts:419  INFO Creating a socket (renderer-Management-af83b59e-028b-4344-9e9b-0736a96bcde3)...
log.ts:419  INFO Creating a socket (renderer-ExtensionHost-9fdf91a2-0941-4329-b13d-a99e2ed342b7)...
log.ts:419  INFO Creating a socket (renderer-Management-af83b59e-028b-4344-9e9b-0736a96bcde3) was successful after 170 ms.
log.ts:419  INFO Creating a socket (renderer-ExtensionHost-9fdf91a2-0941-4329-b13d-a99e2ed342b7) was successful after 434 ms.
TMScopeRegistry.ts:46 Overwriting grammar scope name to file mapping for scope text.tex.
Old grammar file: file:///c%3A/Users/Lenovo/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/extensions/latex/syntaxes/TeX.tmLanguage.json.
New grammar file: vscode-remote://wsl%2Barch/root/.vscode-server/extensions/james-yu.latex-workshop-10.5.0/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:///c%3A/Users/Lenovo/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/extensions/latex/syntaxes/LaTeX.tmLanguage.json.
New grammar file: vscode-remote://wsl%2Barch/root/.vscode-server/extensions/james-yu.latex-workshop-10.5.0/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:///c%3A/Users/Lenovo/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/extensions/latex/syntaxes/Bibtex.tmLanguage.json.
New grammar file: vscode-remote://wsl%2Barch/root/.vscode-server/extensions/james-yu.latex-workshop-10.5.0/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:///c%3A/Users/Lenovo/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/extensions/latex/syntaxes/markdown-latex-combined.tmLanguage.json.
New grammar file: vscode-remote://wsl%2Barch/root/.vscode-server/extensions/james-yu.latex-workshop-10.5.0/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:///c%3A/Users/Lenovo/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/extensions/latex/syntaxes/cpp-grammar-bailout.tmLanguage.json.
New grammar file: vscode-remote://wsl%2Barch/root/.vscode-server/extensions/james-yu.latex-workshop-10.5.0/syntax/cpp-grammar-bailout.tmLanguage.json
register @ TMScopeRegistry.ts:46
log.ts:429  WARN No search provider registered for scheme: vscode-remote, waiting
TMScopeRegistry.ts:46 Overwriting grammar scope name to file mapping for scope text.tex.
Old grammar file: file:///c%3A/Users/Lenovo/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/extensions/latex/syntaxes/TeX.tmLanguage.json.
New grammar file: vscode-remote://wsl%2Barch/root/.vscode-server/extensions/james-yu.latex-workshop-10.5.0/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:///c%3A/Users/Lenovo/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/extensions/latex/syntaxes/LaTeX.tmLanguage.json.
New grammar file: vscode-remote://wsl%2Barch/root/.vscode-server/extensions/james-yu.latex-workshop-10.5.0/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:///c%3A/Users/Lenovo/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/extensions/latex/syntaxes/Bibtex.tmLanguage.json.
New grammar file: vscode-remote://wsl%2Barch/root/.vscode-server/extensions/james-yu.latex-workshop-10.5.0/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:///c%3A/Users/Lenovo/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/extensions/latex/syntaxes/markdown-latex-combined.tmLanguage.json.
New grammar file: vscode-remote://wsl%2Barch/root/.vscode-server/extensions/james-yu.latex-workshop-10.5.0/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:///c%3A/Users/Lenovo/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/extensions/latex/syntaxes/cpp-grammar-bailout.tmLanguage.json.
New grammar file: vscode-remote://wsl%2Barch/root/.vscode-server/extensions/james-yu.latex-workshop-10.5.0/syntax/cpp-grammar-bailout.tmLanguage.json
register @ TMScopeRegistry.ts:46
webviewElement.ts:482 An iframe which has both allow-scripts and allow-same-origin for its sandbox attribute can escape its sandboxing.
mountTo @ webviewElement.ts:482
log.ts:419  INFO [perf] Render performance baseline is 33ms
2console.ts:137 [Extension Host] [certificates] Failed to parse certificate # ACCVRAIZ1
Error: error:0480006C:PEM routines::no start line
at new X509Certificate (node:internal/crypto/x509:119:21)
at /root/.vscode-server/extensions/github.copilot-1.236.0/lib/src/network/certificateReaders.ts:79:36
at Array.filter (<anonymous>)
at XV.removeExpiredCertificates (/root/.vscode-server/extensions/github.copilot-1.236.0/lib/src/network/certificateReaders.ts:77:32)
at XV.getAllRootCAs (/root/.vscode-server/extensions/github.copilot-1.236.0/lib/src/network/certificateReaders.ts:68:38)
at iae.createSecureContext (/root/.vscode-server/extensions/github.copilot-1.236.0/lib/src/network/certificates.ts:46:23) {
opensslErrorStack: [
'error:0688010A:asn1 encoding routines::nested asn1 error',
'error:06800066:asn1 encoding routines::bad object header',
'error:0680009B:asn1 encoding routines::too long'
],
library: 'PEM routines',
reason: 'no start line',
code: 'ERR_OSSL_PEM_NO_START_LINE'
}
y @ console.ts:137
console.ts:137 [Extension Host] ApplicationInsights:Sender Array(2)
y @ console.ts:137
console.ts:137 [Extension Host] ApplicationInsights:Sender Array(2)
James-Yu commented 1 week ago

Sorry, but I cannot reproduce the issue.

image
dominikue commented 4 days ago

Hey @James-Yu ,

I have exactly the same issue. on MacOS and the Extension version v10.5.4. I really love this preview feature but I would need to define new commands. Let me know if I can help debug this.

br