Skip to content

Commit

Permalink
Some adjustments to expl3 syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
PhelypeOleinik authored Jul 29, 2019
1 parent bf9f31f commit 2de6255
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 33 deletions.
46 changes: 27 additions & 19 deletions sources/scontents.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1639,33 +1655,25 @@ 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:
}
\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}
%
Expand Down Expand Up @@ -1787,4 +1795,4 @@ conditions of the [LaTeX Project Public License](https://www.latex-project.org/l
% \iffalse
%</package>
% \fi
% \Finale
% \Finale
32 changes: 18 additions & 14 deletions sources/scontents.sty
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
{
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2de6255

Please sign in to comment.