Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

\NewDocumentEnvironment: existence check without space trimming #1399

Open
muzimuzhi opened this issue Jul 5, 2024 · 1 comment
Open

\NewDocumentEnvironment: existence check without space trimming #1399

muzimuzhi opened this issue Jul 5, 2024 · 1 comment
Labels
bug category base (latex) fixed in dev Fixed in development branch, not in stable release

Comments

@muzimuzhi
Copy link
Contributor

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

latex2e/base/ltcmd.dtx

Lines 5030 to 5047 in 066ad1d

\cs_new_protected:Npn \NewDocumentEnvironment #1#2#3#4
{
\cs_if_exist:cTF {#1}
{ \msg_error:nnx { cmd } { env-already-defined } {#1} }
{
\cs_if_exist:cTF { end #1 }
{ \msg_error:nnx { cmd } { env-end-already-defined } {#1} }
{ \@@_declare_env:nnnn {#1} {#2} {#3} {#4} }
}
}
\cs_new_protected:Npn \RenewDocumentEnvironment #1#2#3#4
{
\cs_if_exist:cTF {#1}
{ \@@_declare_env:nnnn {#1} {#2} {#3} {#4} }
{ \msg_error:nnx { cmd } { env-undefined } {#1} }
}
\cs_new_protected:Npn \ProvideDocumentEnvironment #1#2#3#4
{ \cs_if_exist:cF {#1} { \@@_declare_env:nnnn {#1} {#2} {#3} {#4} } }

latex2e/base/ltcmd.dtx

Lines 629 to 633 in 066ad1d

\cs_new_protected:Npn \@@_declare_env:nnnn #1#2
{
\str_set:Nx \l_@@_environment_str {#1}
\str_set:Nx \l_@@_environment_str
{ \tl_trim_spaces:o { \l_@@_environment_str } }

@FrankMittelbach
Copy link
Member

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

muzimuzhi added a commit to muzimuzhi/latex2e that referenced this issue Jul 6, 2024
FrankMittelbach pushed a commit that referenced this issue Jul 6, 2024
* Trim spaces from envname first (#1399)

* Extend ltcmd001 tests

* Add rollback

* Add ltnews entry

* Correct fun. names in {macro} markup
@FrankMittelbach FrankMittelbach added the fixed in dev Fixed in development branch, not in stable release label Jul 6, 2024
@FrankMittelbach FrankMittelbach added this to the Release 2024 Fall milestone Jul 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug category base (latex) fixed in dev Fixed in development branch, not in stable release
Projects
Status: Done in dev
Development

No branches or pull requests

2 participants