Skip to content

Commit

Permalink
Allow text before but not after \end{foo} for f-type env
Browse files Browse the repository at this point in the history
  • Loading branch information
josephwright committed Jan 8, 2025
1 parent 28d8936 commit 2d6ab59
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 2 deletions.
7 changes: 7 additions & 0 deletions base/doc/usrguide.tex
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,13 @@ \subsection{Verbatim environments}
at both ends of the body. Putting the prefix |!| before \texttt{f} suppresses
space-trimming.

Collection of the body takes place on a line-by-line basis: content is
collected up to the end-of-line in the source, then examined before storage.
This means that the line ending the environment (containing in the example
above |\end{MyVerbatim}|) cannot have any text \emph{after} the end of the
environment. Text \emph{before} the end of environment is treated normally,
but note that there is no trailing \cs{obeyedline} added if there is text here.

Notice that for technical reasons, we recommend that an optional argument
coming immediately before an \texttt{f} specification should not allow any
spaces, achieved by adding the \texttt{!} as showing in the example. However,
Expand Down
17 changes: 15 additions & 2 deletions base/ltcmd.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -3483,8 +3483,12 @@
\cs_new_protected:Npn \@@_grab_f_loop:w { }
\cs_new_protected:Npn \@@_grab_f_end:nn #1#2
{
\tl_if_blank:nF {#1#2}
\ERROR
\tl_put_right:Nn \l_@@_v_arg_tl {#1}
\tl_if_blank:nF {#2}
{
\msg_error:nnee { cmd } { text-dropped-last-line } { \exp_not:n {#2} }
{ \exp_not:V \@currenvir }
}
\exp_args:NNNo \group_end:
\tl_set:Nn \l_@@_v_arg_tl { \l_@@_v_arg_tl }
\@@_add_arg:x
Expand Down Expand Up @@ -5079,6 +5083,15 @@
This~is~only~supported~for~robust~commands,~but~not~for~expandable~ones.
\c_@@_ignore_def_tl
}
% \end{macrocode}
% \changes{v1.3a}{2025-01-08}{New message \texttt{text-dropped-last-line}}
% \begin{macrocode}
\msg_new:nnnn { cmd } { text-dropped-last-line }
{ Text~'#1'~dropped~after~end~of~#2~environment. }
{
LaTeX~was~collecting~a~verbatim-like~environment,~and~the~text~
'#1'~was~found~after~\end{#2}~on~the~last~line:~this~is~not~supported.
}
\msg_new:nnnn { cmd } { too-many-args }
{ Too~many~arguments~for~#1. }
{
Expand Down
18 changes: 18 additions & 0 deletions base/testfiles-ltcmd/ltcmd009.lvt
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,22 @@
\ENDTEST
\BEGINTEST { Verbatim~body~collection~last~line~handling }
\ExplSyntaxOn
\NewDocumentEnvironment { env9 } { f }
{ \TYPE { \tl_to_str:n {|#1|} } }
{ }
\ExplSyntaxOff
\begin{env9}
Content
text \end{env9}
\begin{env9}
Content
\end{env9} more test
\ENDTEST
\END
11 changes: 11 additions & 0 deletions base/testfiles-ltcmd/ltcmd009.tlg
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,14 @@ TEST 3: Verbatim body collection
|...|\obeyedline Content\obeyedline &\^|
|...|\obeyedline Content\obeyedline &\^|
============================================================
============================================================
TEST 4: Verbatim body collection last line handling
============================================================
| Content\obeyedline text |
! LaTeX cmd Error: Text ' more test' dropped after end of env9 environment.
For immediate help type H <return>.
...
l. ...\end{env9} more test
LaTeX was collecting a verbatim-like environment, and the text ' more test' was found after \end {env9} on the last line: this is not supported.
| Content|
============================================================

0 comments on commit 2d6ab59

Please sign in to comment.