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 2391636
Show file tree
Hide file tree
Showing 4 changed files with 47 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_warning:nnee { cmd } { chars-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 @@ -4969,6 +4973,15 @@
with~a~command~that~was~never~defined.
\c_@@_ignore_def_tl
}
% \end{macrocode}
% \changes{v1.3a}{2025-01-08}{New message \texttt{chars-dropped-last-line}}
% \begin{macrocode}
\msg_new:nnnn { cmd } { chars-dropped-last-line }
{ Characters~'#1'~dropped~after~end~of~#2~environment. }
{
LaTeX~was~collecting~a~verbatim-like~environment,~and~the~characters~
'#1'~were~found~after~\end{#2}~on~the~last~line:~this~is~not~supported.
}
\msg_new:nnnn { cmd } { env-already-defined }
{ Environment~'#1'~already~defined. }
{
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
7 changes: 7 additions & 0 deletions base/testfiles-ltcmd/ltcmd009.tlg
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,10 @@ TEST 3: Verbatim body collection
|...|\obeyedline Content\obeyedline &\^|
|...|\obeyedline Content\obeyedline &\^|
============================================================
============================================================
TEST 4: Verbatim body collection last line handling
============================================================
| Content\obeyedline text |
LaTeX cmd Warning: Characters ' more test' dropped after end of env9 environment.
| Content|
============================================================

0 comments on commit 2391636

Please sign in to comment.