James-Yu / LaTeX-Workshop

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

Unexpected detection of `Duplicate label` in `\NewDocumentCommand` #4227

Closed NemoYuan2008 closed 3 months ago

NemoYuan2008 commented 3 months ago

Pre-checks*

Environment*

The Issue*

A warning Duplicate label #2 is reported in the following example for \NewDocumentCommand, which is unexpected. In contrast, \newcommand works well.

Similarily, \NewDocumentEnvironment has the same issue.

\documentclass{article}

\newcommand{\cmda}[2]{\section{#1}\label{#2}}   % Good
\newcommand{\cmdb}[2]{\section{#1}\label{#2}}   % Good

\NewDocumentCommand{\cmdc}{mm}{\section{#1}\label{#2}}  % Duplicate label #2
\NewDocumentCommand{\cmdd}{mm}{\section{#1}\label{#2}}  % Duplicate label #2

\begin{document}
\cmda{1}{1}
\cmdb{2}{2}
\cmdc{3}{3}
\cmdd{4}{4}
\end{document}

Logs

LaTeX Workshop Output*

[15:21:09.369][Logger] New log placeholder %WS1% registered for /home/yuan/test .
[15:21:09.369][Extension] Initializing LaTeX Workshop.
[15:21:09.457][Build][Recipe] Set $LATEXWORKSHOP_DOCKER_LATEX: ""
[15:21:09.481][Server] Creating LaTeX Workshop http and websocket server.
[15:21:09.531][Format][Bib] Bibtex format config: {"tab":"  ","case":"lowercase","left":"{","right":"}","trailingComma":false,"sort":["key"],"alignOnEqual":true,"sortFields":false,"fieldsOrder":[],"firstEntries":["string","xdata"]}
[15:21:09.563][Server] Server successfully started: {"address":"127.0.0.1","family":"IPv4","port":43047} .
[15:21:09.575][Extension] Extension root: /home/yuan/.vscode/extensions/james-yu.latex-workshop-9.19.2
[15:21:09.575][Extension] $PATH: /home/yuan/Apps/anaconda3/condabin:/home/yuan/Apps/texlive/2024/bin/x86_64-linux:/home/yuan/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin:/home/yuan/.local/share/JetBrains/Toolbox/scripts
[15:21:09.576][Extension] $SHELL: /usr/bin/zsh
[15:21:09.576][Extension] $LANG: en_US.UTF-8
[15:21:09.576][Extension] $LC_ALL: undefined
[15:21:09.576][Extension] process.platform: linux
[15:21:09.577][Extension] process.arch: x64
[15:21:09.577][Extension] vscode.env.appName: Visual Studio Code
[15:21:09.577][Extension] vscode.env.remoteName: undefined
[15:21:09.578][Extension] vscode.env.uiKind: 1
[15:21:09.580][Config] latex-workshop.latex.recipe.default: "lastUsed" .
[15:21:09.654][Extension] Trigger characters for intellisense of LaTeX documents: ["\\",",","{"]
[15:21:09.656][Root] Current workspace folders: ["file://%WS1%"]
[15:21:09.656][Extension] LaTeX Workshop initialized.
[15:21:09.657][Root] Found root file from active editor: %WS1%/test.tex
[15:21:09.657][Root] Root file changed: from %WS1%/test.tex to %WS1%/test.tex, langID latex . Refresh dependencies
[15:21:09.657][Event] ROOT_FILE_CHANGED: "%WS1%/test.tex"
[15:21:09.658][Cacher][Watcher] Reset.
[15:21:09.658][Cacher][Watcher] Reset.
[15:21:09.660][Cacher] Adding %WS1%/test.tex .
[15:21:09.661][Cacher][Watcher] Watched %WS1%/test.tex with a new .* watcher on %WS1% .
[15:21:09.661][Event] FILE_WATCHED: "%WS1%/test.tex"
[15:21:09.663][Cacher] Caching %WS1%/test.tex .
[15:21:09.664][Cacher] Updated inputs of %WS1%/test.tex .
[15:21:09.664][Cacher] Parse LaTeX AST: %WS1%/test.tex .
[15:21:09.664][Event] ROOT_FILE_SEARCHED
[15:21:09.676][Server] valdOrigin is http://127.0.0.1:43047
[15:21:09.690][Cacher] Parsed LaTeX AST: %WS1%/test.tex .
[15:21:09.691][File] Calling kpsewhich to resolve article.cls .
[15:21:09.843][File] kpsewhich returned with '/home/yuan/Apps/texlive/2024/texmf-dist/tex/latex/base/article.cls'.
[15:21:09.845][Cacher] Updated elements in 153.99 ms: %WS1%/test.tex .
[15:21:09.846][Event] FILE_PARSED: "%WS1%/test.tex"
[15:21:09.847][Structure] Structure force updated with 0 root sections for %WS1%/test.tex .
[15:21:09.847][Event] STRUCTURE_UPDATED
[15:21:11.983][Commander] BUILD command invoked.
[15:21:11.984][Build] The document of the active editor: file://%WS1%/test.tex
[15:21:11.985][Build] The languageId of the document: latex
[15:21:11.985][Root] Current workspace folders: ["file://%WS1%"]
[15:21:11.986][Root] Found root file from active editor: %WS1%/test.tex
[15:21:11.986][Root] Keep using the same root file: %WS1%/test.tex
[15:21:11.987][Event] ROOT_FILE_SEARCHED
[15:21:11.987][Event] STRUCTURE_UPDATED
[15:21:11.987][Build] Building root file: %WS1%/test.tex
[15:21:11.988][Build][Recipe] Build root file %WS1%/test.tex
[15:21:11.990][Build][Recipe] Preparing to run recipe: latexmk.
[15:21:11.990][Build][Recipe] Prepared 1 tools.
[15:21:11.998][Build][Recipe] outDir: %WS1% .
[15:21:12.000][Build] Recipe step 1 The command is latexmk:["-synctex=1","-interaction=nonstopmode","-file-line-error","-pdf","-outdir=%WS1%","%WS1%/test"].
[15:21:12.000][Build] env: {}
[15:21:12.000][Build] root: %WS1%/test.tex
[15:21:12.000][Build] cwd: %WS1%
[15:21:12.005][Build] LaTeX build process spawned with PID 17205.
[15:21:12.808][Parser][TexLog] Logged 0 messages.
[15:21:12.809][Build] Finished a step in recipe with PID 17205.
[15:21:12.809][Build] Successfully built %WS1%/test.tex .
[15:21:12.809][Event] BUILD_DONE
[15:21:12.810][Viewer] Call refreshExistingViewer: "%WS1%/test.pdf" .
[15:21:12.810][Viewer] Not found PDF viewers to refresh: %WS1%/test.pdf
[15:21:12.810][Cacher] Parsing .fls %WS1%/test.fls .
[15:21:12.812][Cacher] Found .aux %WS1%/test.tex from .fls %WS1%/test.fls , parsing.
[15:21:12.812][Cacher] Parsed .aux %WS1%/test.tex .
[15:21:12.812][Cacher] Parsed .fls %WS1%/test.fls .
[15:21:20.877][Event] STRUCTURE_UPDATED