latex3 / latex2e

The LaTeX2e kernel
https://www.latex-project.org/
LaTeX Project Public License v1.3c
1.84k stars 254 forks source link

\NewDocumentEnvironment: existence check without space trimming #1399

Open muzimuzhi opened 3 weeks ago

muzimuzhi commented 3 weeks ago

Brief outline of the bug

\(New|Renew|Provide)DocumentEnvironment does the existence check for envname without space trimming, while the actual name of environment to be defined (or redefined) is always space trimmed.

When the user-specified envname consists of leading and/or trailing space(s), it may lead to erroneously silent environment declaration.

Minimal example showing the bug

\RequirePackage{latexbug}       % <--should be always the first line (see CONTRIBUTING)!
\documentclass{article}

\NewDocumentEnvironment {myenv} { } {begin} {end}

\NewDocumentEnvironment {myenv} { } {begin} {end} % errors as expected
\NewDocumentEnvironment { myenv } { } {begin} {end} % !! works, which is wrong

\begin{document}
\end{document}

Log file (required) and possibly PDF file

ltcmd-env-exisistence-check.log

Relevant source lines

https://github.com/latex3/latex2e/blob/066ad1dd36a904d8b56f799bc30830416c62305f/base/ltcmd.dtx#L5030-L5047 https://github.com/latex3/latex2e/blob/066ad1dd36a904d8b56f799bc30830416c62305f/base/ltcmd.dtx#L629-L633

FrankMittelbach commented 3 weeks ago

guess that classifies as a bug even though I think it is not a high profile bug