diff --git a/sources/scontents.dtx b/sources/scontents.dtx index 46105f1..d58b92a 100644 --- a/sources/scontents.dtx +++ b/sources/scontents.dtx @@ -1334,6 +1334,22 @@ conditions of the [LaTeX Project Public License](https://www.latex-project.org/l % \end{macrocode} % \end{macro} % +% \begin{macro}{\g_@@_end_verbatimsc_tl} +% A token list to match when ending verbatim environments. +% \begin{macrocode} +\tl_new:N \g_@@_end_verbatimsc_tl +\tl_gset_rescan:Nnn + \g_@@_end_verbatimsc_tl + { + \char_set_catcode_escape:N \| + \char_set_catcode_other:N \\ + \char_set_catcode_other:N \{ + \char_set_catcode_other:N \} + } + { \end{verbatimsc} } +% \end{macrocode} +% \end{macro} +% % \subsection{Add keys for environment} % % We define a set of keys for environment \env{scontents}. @@ -1597,7 +1613,7 @@ conditions of the [LaTeX Project Public License](https://www.latex-project.org/l % This implementation is an adaptation taken from answer by Phelype Oleinik % in (\url{https://tex.stackexchange.com/a/497651/7832}). % -% \begin{macro}{\typestored,@@_fcdef_print:N,verbatimsc} +% \begin{macro}{\typestored,\@@_fcdef_print:N,\@@_xverb:w,verbatimsc} % The \cs{typestored} commands fetches a buffer from memory, prints it % to the log file, %^^A NOTE: Perhaps this logging should be optional, with a key to switch @@ -1639,8 +1655,7 @@ conditions of the [LaTeX Project Public License](https://www.latex-project.org/l \exp_not:N \begin{verbatimsc} ^^M \@@_strip_scantokens:N #1 \bool_if:NF \l_@@_typeverb_env_bool { ^^M } - \c_backslash_str end - \c_left_brace_str verbatimsc \c_right_brace_str + \g_@@_end_verbatimsc_tl } } \cs_set_eq:NN ^^M \@@_fcdef_saved_EOL: @@ -1648,24 +1663,17 @@ conditions of the [LaTeX Project Public License](https://www.latex-project.org/l \group_end: % \end{macrocode} % Finally, the \env{verbatimsc} environment is defined. -%^^A An idea take from spverbatim +%^^A An idea taken from spverbatim % \begin{macrocode} -\group_begin: - \catcode`|=0 - \catcode`[=1 - \catcode`]=2 - \catcode`\{=12 - \catcode`\}=12 - \catcode`\\=12 - |gdef|scxverbatim#1\end{verbatimsc}[#1|end[verbatimsc]] -|group_end: -% \end{macrocode} -% \begin{macrocode} -\ProvideDocumentEnvironment {verbatimsc} { } +\use:x + { \cs_gset_protected:Npn \exp_not:N \@@_xverb:w ##1 \g_@@_end_verbatimsc_tl } + { #1 \end{verbatimsc} } +\ProvideDocumentEnvironment { verbatimsc } { } { - \let\@xverbatim=\scxverbatim + \cs_set_eq:cN { @xverbatim } \@@_xverb:w \verbatim - }{} + } + { } % \end{macrocode} % \end{macro} % @@ -1787,4 +1795,4 @@ conditions of the [LaTeX Project Public License](https://www.latex-project.org/l % \iffalse % % \fi -% \Finale +% \Finale \ No newline at end of file diff --git a/sources/scontents.sty b/sources/scontents.sty index 6bbf90f..2f3dca7 100644 --- a/sources/scontents.sty +++ b/sources/scontents.sty @@ -47,6 +47,16 @@ %%^^A Internal quarks \quark_new:N \q__scontents_stop \quark_new:N \q__scontents_mark +\tl_new:N \g__scontents_end_verbatimsc_tl +\tl_gset_rescan:Nnn + \g__scontents_end_verbatimsc_tl + { + \char_set_catcode_escape:N \| + \char_set_catcode_other:N \\ + \char_set_catcode_other:N \{ + \char_set_catcode_other:N \} + } + { \end{verbatimsc} } %%^^A Add keys to scontents environnment \keys_define:nn { scontents } { @@ -207,27 +217,21 @@ \exp_not:N \begin{verbatimsc} ^^M \__scontents_strip_scantokens:N #1 \bool_if:NF \l__scontents_typeverb_env_bool { ^^M } - \c_backslash_str end - \c_left_brace_str verbatimsc \c_right_brace_str + \g__scontents_end_verbatimsc_tl } } \cs_set_eq:NN ^^M \__scontents_fcdef_saved_EOL: } \group_end: -\group_begin: - \catcode`|=0 - \catcode`[=1 - \catcode`]=2 - \catcode`\{=12 - \catcode`\}=12 - \catcode`\\=12 - |gdef|scxverbatim#1\end{verbatimsc}[#1|end[verbatimsc]] -|group_end: -\ProvideDocumentEnvironment {verbatimsc} { } +\use:x + { \cs_gset_protected:Npn \exp_not:N \__scontents_xverb:w ##1 \g__scontents_end_verbatimsc_tl } + { #1 \end{verbatimsc} } +\ProvideDocumentEnvironment { verbatimsc } { } { - \let\@xverbatim=\scxverbatim + \cs_set_eq:cN { @xverbatim } \__scontents_xverb:w \verbatim - }{} + } + { } \cs_new:Npn \__scontents_strip_scantokens:N #1 { \exp_args:NV \__scontents_strip_scantokens:n #1 } \cs_new:Npn \__scontents_strip_scantokens:n #1