Debian Codegraph @

texmf-dist/source/latex/scontents/scontents.dtx

raw
1 % \iffalse meta-comment
2 %
3 % Copyright (C) 2019-2025 by Pablo González L <[email protected]>
4 %
5 % This work may be distributed and/or modified under the conditions of the
6 % LaTeX Project Public License, either version 1.3c of this license or (at
7 % your option) any later version. The latest version of this license is in
8 %
9 % https://www.latex-project.org/lppl.txt
10 %
11 % and version 1.3c or later is part of all distributions of LaTeX version
12 % 2005/12/01 or later.
13 %
14 % This work is "maintained" (as per the LPPL maintenance status)
15 % by Pablo González Luengo.
16 %
17 % This work consists of the files scontents.dtx and
18 % scontents.ins,
19 % and the derived files scontents.sty,
20 % scontents.tex,
21 % t-scontents.mkiv and
22 % scontents-code.tex.
23 %
24 %<*driver>
25 \documentclass[full]{l3doc}
26 % imakeidx also opens a write stream for the .idx file, and that conflicts
27 % with the one opened by l3doc. Here we close that write stream:
28 \makeatletter
29 \immediate\closeout\@indexfile
30 \makeatother
31 % and later we will copy the write stream opened by imakeidx into \@indexfile
32 % so that entries written to both streams end up in the same file.
33 \usepackage[english]{babel}
34 \usepackage[top=0.5in,bottom=0.3in,left=2in,right=0.7in,footskip=0.2in,headheight=1cm,headsep=0.27cm]{geometry}
35 \usepackage[llscaled=0.95]{libertine} % need by setup-texlive-action@v3
36 \usepackage[osf,nomath,mono=false,ScaleSF=0.95,ScaleRM=0.95]{libertinus-otf}
37 % Set Monospace font, fix 'quotes' in verbatim
38 \usepackage{sourcecodepro}
39 \defaultfontfeatures[\ttfamily]
40 {
41 Numbers = OldStyle,
42 Scale = 0.80,
43 Extension = .otf,
44 }
45 \setmonofont[
46 UprightFont = *-Regular,
47 ItalicFont = *-RegularIt,
48 BoldFont = *-Semibold,
49 BoldItalicFont = *-SemiboldIt,
50 RawFeature = {+zero,+ss06}]{SourceCodePro}
51 \newfontfamily\mysourcecodeprolight{SourceCodePro-Regular.otf}[
52 Scale = 0.80,FakeStretch =0.75,
53 FontFace = {m}{it}{Font =SourceCodePro-RegularIt.otf,Color=FF0000}]
54 \RenewDocumentCommand{\MacroLongFont}{}
55 {
56 \mysourcecodeprolight\small
57 }
58 % The character of visible space is now taken from Latin Modern Mono
59 % to prevent fonts in T1. The original definition for xetex/luatex is
60 % \def\verbvisiblespace{\usefont{OT1}{cmtt}{m}{n}\asciispace}
61 \def\verbvisiblespace{{\fontfamily{lmtt}\selectfont\char"2423}}
62
63 \usepackage{unicode-math}
64 % Unicode-math changes the position of the glyphs, so the position 26A is now
65 % a letter `j'. The doc package ensures that mathcode and the | actually prints
66 % a j inside docstrip guards. This changes the mathcode of | to 07C:
67 \makeatletter
68 \def\mod@math@codes{\mathcode`\|="207C \mathcode`\&="2026 %
69 \mathcode`\-="702D \mathcode`\+="702B
70 \mathcode`\:="703A \mathcode`\=="703D }
71 \makeatother
72 \setmathfont[Scale = 0.95]{latinmodern-math.otf}
73 \usepackage{fontawesome5}
74 \newfontfamily\fetamontotf{ffmw10.otf}[
75 Scale = 0.95,%
76 RawFeature = {+latn,+rand,+kern,+size},%
77 FontFace = {b}{n}{ffmw10.otf},% fix replace font
78 ]
79 \usepackage[svgnames]{xcolor}
80 \usepackage[sf,bf,compact,medium,pagestyles]{titlesec}
81 \usepackage{lastpage,microtype,attachfile2}
82 \usepackage{adjustbox,multicol,listings,accsupp,titletoc}
83 \usepackage{imakeidx}
84 \usepackage{scontents} % main
85 \usepackage[contents]{colordoc}
86 % \show\docCodelineNo
87 \def\textnew#1{\color{color-def}#1\/}
88 \def\AltMacroFont{\fontencoding\encodingdefault
89 \fontfamily\ttdefault
90 \fontseries\mddefault
91 \fontshape\updefault
92 \small
93 }%
94
95 % Patching colordoc.sty to work with l3doc.cls
96 \ExplSyntaxOn
97 \cs_new_eq:cN { liii@xmacro@code } \__codedoc_xmacro_code:n
98 \ExplSyntaxOff
99 \begingroup
100 \makeatletter
101 \catcode`\[\@ne\catcode`\]\tw@
102 \@makebracesactive
103 \gdef{[\@openingbrace[\char'173]]
104 \gdef}[\@closingbrace[\char'175]]
105 \catcode`\|\z@\catcode`\%12
106 \catcode`\ \active\catcode`\\\active
107 |gdef|xmacro@code#1% \end{macrocode}[|liii@xmacro@code[#1]|end[macrocode]]
108 |catcode`| 12|gdef|sxmacro@code#1% \end{macrocode*}[|liii@xmacro@code[#1]|end[macrocode*]]
109 |endgroup
110
111 % Patching colordoc.sty to work with doc v3 (TeX Live 2022 & lualatex-dev)
112 \usepackage{etoolbox}
113 \makeatletter
114 \@ifpackagelater{doc}{2022-06-01}%
115 {\patchcmd\macro@finish
116 {\ifnot@excluded % \if
117 \edef\@tempa{\noexpand\SpecialIndex{\bslash\macro@namepart}}%
118 \@tempa \fi}%
119 {\maybe@index@macro \macro@namepart}
120 {}{\FAILED}%
121 \let\default@color\current@color
122 }%
123 {}
124 \makeatother
125
126 \EnableCrossrefs
127 % \PageIndex % \CodelineIndex undoes what \PageIndex does
128 % \CodelineIndex tries to open another write stream for the index file. We don't
129 % want that, so we temporarily make \makeindex a no-op:
130 \let\ORGmakeindex\makeindex
131 \def\makeindex{}
132 \CodelineIndex
133 \let\makeindex\ORGmakeindex
134 \DoNotIndex{\ , \1,\^}
135 \expandafter\DoNotIndex\expandafter{\string\{}
136 \expandafter\DoNotIndex\expandafter{\string\}}
137 \expandafter\DoNotIndex\expandafter{\string\begin}
138 \newcommand{\HP}[1]{\emph{\hyperpage{#1}}\normalsize}
139 \ExplSyntaxOn
140 \cs_new_protected:Npn \StartImplementation
141 { \bool_set_true:N \l__codedoc_in_implementation_bool }
142 \bool_set_false:N \l__codedoc_in_implementation_bool
143 \cs_new_protected:Npn \MYSortIndex #1 #2
144 {
145 \bool_if:NTF \l__codedoc_in_implementation_bool
146 { \index{#1\actualchar#2|HP} }
147 { \index[userdoc]{#1\actualchar#2|HP} }
148 }
149 \ExplSyntaxOff
150
151 \indexsetup{level=\section,firstpagestyle=myheader,othercode=\pagestyle{myheader}}
152 \makeindex[name=userdoc,options={-q -s gind.ist},columnsep=15pt,title={Index of Documentation}]
153 \makeindex[options={-q -s gind.ist},columnsep=15pt,title={Index of Implementation}]
154 % Now, after imakeidx opens the write stream for the index file, we copy
155 % the reference to \@indexfile:
156 \makeatletter
157 \expandafter\let\expandafter\@indexfile\csname \jobname @idxfile\endcsname
158 \makeatother
159
160 \setlength{\parindent}{0pt}
161
162 % Colors
163 \definecolor{optcolor}{rgb}{0.281,0.275,0.485}
164 \definecolor{pkgcolor}{rgb}{0,0.5,0.5}
165 \definecolor{araracolor}{rgb}{0, 0.72, 0.28}
166 \definecolor{linkcolor}{rgb}{0.04,0.38,0.04}
167 \definecolor{rulecolor}{rgb}{0.96,0.96,0.96}
168
169 % Only for arara... I like arara :)
170 \usepackage[scale=0.85]{comfortaa}
171 \newcommand{\araratext}[1]{{\small\normalfont\comfortaa\color{araracolor}\bfseries#1}}
172 \newcommand*\arara{\araratext{ar\kern-.03emar\kern-.03ema}}
173
174 % User level commands
175 \ExplSyntaxOn
176 % Logo with fetamont font
177 \NewDocumentCommand \pkglogo {}
178 {
179 \group_begin:
180 \fetamontotf{\textcolor{pkgcolor}{s}\textcolor{OrangeRed}{content}\textcolor{pkgcolor}{s}}
181 \group_end:
182 }
183
184 % Custom \meta[...]{...}, \marg[...]{...} and \oarg[...]{...} with color
185 \NewDocumentCommand \mymeta {O{}m}
186 {
187 \userdoc_meta_generic:Nnn \userdoc_meta:n { #1 } { #2 }
188 }
189 \NewDocumentCommand \mymarg {O{}m}
190 {
191 \userdoc_meta_generic:Nnn \userdoc_marg:n { #1 } { #2 }
192 }
193 \NewDocumentCommand \myoarg {O{}m}
194 {
195 \userdoc_meta_generic:Nnn \userdoc_oarg:n { #1 } { #2 }
196 }
197 % Variables and keys
198 \tl_new:N \l_userdoc_meta_font_tl
199
200 \keys_define:nn { userdoc / mymeta }
201 {
202 type .choice:,
203 type / tt .code:n = \tl_set:Nn \l_userdoc_meta_font_tl { \ttfamily },
204 type / rm .code:n = \tl_set:Nn \l_userdoc_meta_font_tl { \rmfamily },
205 type .initial:n = tt,
206 cf .tl_set:N = \l_userdoc_meta_color_tl,
207 cf .initial:n = optcolor,
208 ac .tl_set:N = \l_userdoc_meta_anglecolor_tl,
209 ac .initial:n = lightgray,
210 sbc .tl_set:N = \l_userdoc_meta_brackcolor_tl,
211 sbc .initial:n = gray,
212 cbc .tl_set:N = \l_userdoc_meta_bracecolor_tl,
213 cbc .initial:n = gray,
214 }
215 % Internal commands
216 \cs_new_protected:Npn \userdoc_meta_generic:Nnn #1 #2 #3
217 {
218 \group_begin:
219 \keys_set:nn { userdoc / mymeta } { #2 }
220 \color{ \l_userdoc_meta_color_tl }
221 \l_userdoc_meta_font_tl
222 #1 { #3 } % #1 is \userdoc_meta:n, \userdoc_marg:n or \userdoc_oarg:n
223 \group_end:
224 }
225 \cs_new_protected:Npn \userdoc_meta:n #1
226 {
227 \userdoc_meta_angle:n { \textlangle }
228 \userdoc_meta_meta:n { #1 }
229 \userdoc_meta_angle:n { \textrangle }
230 }
231 \cs_new_protected:Npn \userdoc_marg:n #1
232 {
233 \userdoc_meta_brace:n { \textbraceleft }
234 \userdoc_meta:n { #1 }
235 \userdoc_meta_brace:n { \textbraceright }
236 }
237 \cs_new_protected:Npn \userdoc_oarg:n #1
238 {
239 \userdoc_meta_brack:n { [ }
240 \userdoc_meta:n { #1 }
241 \userdoc_meta_brack:n { ] }
242 }
243 \cs_new_protected:Npn \userdoc_meta_meta:n #1
244 {
245 \textnormal{\textit{#1}}
246 }
247 \cs_new_protected:Npn \userdoc_meta_angle:n #1
248 {
249 \group_begin:
250 \fontfamily{lmr}\selectfont
251 \textcolor{\l_userdoc_meta_anglecolor_tl}{#1}
252 \group_end:
253 }
254 \cs_new_protected:Npn \userdoc_meta_brace:n #1
255 {
256 \group_begin:
257 \color{\l_userdoc_meta_bracecolor_tl}
258 #1
259 \group_end:
260 }
261 \cs_new_protected:Npn \userdoc_meta_brack:n #1
262 {
263 \textcolor{\l_userdoc_meta_brackcolor_tl}{#1}
264 }
265 % \envexamp{m}
266 \newsavebox{\boxexaenv}
267 \NewDocumentCommand \envexamp {m}
268 {
269 \begin{lrbox}{\boxexaenv}%
270 \begin{minipage}[t]{\marginparwidth}%
271 \raggedright\ttfamily\small
272 \textcolor{gray}{\textbackslash begin\{\textcolor{pkgcolor}{{#1}}\}\myoarg
273 [type=tt,sbc=gray,ac=lightgray,cf=optcolor]{key \textnormal{\textcolor{gray}{=}} val}}\par%
274 \hspace{0.5cm}\mymeta[type=tt,ac=lightgray,cf=gray]{body ~ env}\par%
275 \textcolor{gray}{\textbackslash end\{{\textcolor{pkgcolor}{{#1}}}\}}\par
276 \end{minipage}%
277 \end{lrbox}%
278 \usebox{\boxexaenv}
279 }
280 \NewDocumentCommand \envexaplain {O{} m O{end}}
281 {
282 \begin{lrbox}{\boxexaenv}%
283 \begin{minipage}[t]{\marginparwidth}%
284 \raggedright\ttfamily\small
285 \textcolor{pkgcolor}{{\textbackslash#1#2}}\myoarg
286 [type=tt,sbc=gray,ac=lightgray,cf=optcolor]{key \textnormal{\textcolor{gray}{=}} val}\par%
287 \hspace{0.5cm}\mymeta[type=tt,ac=lightgray,cf=gray]{body ~ env}\par%
288 \textcolor{pkgcolor}{{\textbackslash #3#2}}\par
289 \end{minipage}%
290 \end{lrbox}%
291 \usebox{\boxexaenv}
292 }
293
294 % \cmdexamp{s m o m o}
295 \DeclareDocumentCommand \cmdexamp {o m o m o}
296 {
297 \group_begin:
298 \small\ttfamily
299 \textcolor{pkgcolor}{\textbackslash#2}
300 \IfValueT{#1}{ \textcolor{MediumOrchid}{#1} }
301 \IfValueT{#3}{ \myoarg[type=tt,sbc=gray,ac=lightgray,cf=optcolor]{#3} }
302 \IfValueTF{#5}
303 {
304 \mymeta[ac=gray,type=tt,cf=MediumOrchid]{#5}%
305 \mymeta[type=tt,ac=gray,cf=optcolor]{#4}
306 \mymeta[ac=gray,type=tt,cf=MediumOrchid]{#5}%
307 }
308 { \mymarg[type=tt,cbc=gray,ac=lightgray,cf=optcolor]{#4} }
309 \par
310 \group_end:
311 }
312
313 % \keyexamp*{m m m}
314 \NewDocumentCommand \keyexamp{s m m m }
315 {
316 \adjustbox{outer=-\marginparsep}{\textcolor{optcolor}{\small\ttfamily{#2}}}
317 \IfBooleanTF{#1}
318 {
319 \hphantom{\textcolor{white}{\,\bfseries\texttt{=}}\,{}}
320 \mymeta[type=tt,cbc=gray,ac=lightgray,cf=lightgray]{\small{#3}}
321 }
322 {
323 \textcolor{gray}{\,\bfseries\texttt{=}}\,{}
324 \mymarg[type=tt,cbc=gray,ac=lightgray,cf=optcolor]{\small{#3}}
325 }
326 \hfill\textcolor{gray}{\small\textsf{default}:~\emph{#4}}\par%
327 \MYSortIndex{Keys}{Keys ~ provide ~ by ~ \pkglogo :>\texttt{#2}}
328 }
329
330 % \mykey{m}
331 \NewDocumentCommand \mykey { m }
332 {
333 \textcolor{optcolor}{\texttt{#1}}
334 \MYSortIndex{Keys}{Keys ~ provide ~ by ~\pkglogo :>\texttt{#1}}%
335 }
336
337 % \mypkg{sm}
338 \NewDocumentCommand \mypkg {sm}
339 {
340 \group_begin:
341 \IfBooleanTF{#1}
342 {
343 \pkglogo
344 \MYSortIndex{packages}{Packages:>\texttt{#2}}
345 }
346 {
347 \textcolor{OrangeRed}{\textsf{#2}}
348 \MYSortIndex{packages}{Packages:>\texttt{#2}}%
349 }
350 \group_end:
351 }
352
353 % \myenv{sm}
354 \NewDocumentCommand \myenv {sm}
355 {
356 \IfBooleanTF{#1}
357 {
358 \textcolor{pkgcolor}{\ttfamily{#2}}%
359 \MYSortIndex{environment}{Environments ~ provide ~ by ~\pkglogo :>\texttt{#2}}
360 }
361 {
362 \textcolor{optcolor}{\ttfamily{#2}}%
363 \MYSortIndex{environment}{Environments:>\texttt{#2}}
364 }
365 }
366
367 % \ics{sm}
368 \NewDocumentCommand \ics {sm}
369 {
370 \IfBooleanTF{#1}
371 {
372 \tl_set:Nn \l_tmpa_tl { #2 }
373 \regex_replace_once:nnN { (\*) } { \c{textcolor}\cB\{MediumOrchid\cE\}\cB\{\1\cE\} } \l_tmpa_tl
374 \textcolor{pkgcolor}{\ttfamily\textbackslash{\tl_use:N \l_tmpa_tl}}
375 \MYSortIndex{Commands}{ Commands ~ provide ~ by ~ \pkglogo :>\texttt{\textbackslash#2}}
376 }
377 {
378 \textcolor{darkgray}{\ttfamily\textbackslash{#2}}
379 \MYSortIndex{#2}{\texttt{\textbackslash#2}}
380 }
381 }
382 % \bomba
383 \NewDocumentCommand \bomba { }
384 {
385 \par\hspace*{-0.5\marginparsep}%
386 \makebox[0pt][r]
387 {
388 \makebox[\marginparsep][r]
389 {
390 \footnotesize\textcolor{pkgcolor}{\faIcon{bomb}}
391 }
392 }
393 \hskip 0.5\marginparsep
394 }
395 \NewDocumentEnvironment{important}{ s }
396 {
397 \small\sffamily
398 \IfBooleanTF{#1}
399 { \bomba }
400 { \color{OrangeRed} }
401 }{}
402 \ExplSyntaxOff
403
404 % email https://tex.stackexchange.com/a/663
405 \catcode`\_=11\relax%
406 \newcommand\email[1]{\_email #1\q_nil}%
407 \def\_email#1@#2\q_nil{%
408 \href{mailto:#1@#2}{{\emailfont #1\emailampersat #2}}%
409 }%
410 \newcommand\emailfont{\sffamily}%
411 \newcommand\emailampersat{{\color{optcolor}\footnotesize @}}%
412 \catcode`\_=8\relax%
413
414 % Custom vertamimsc
415 \makeatletter
416 \let\verbatimsc\@undefined
417 \let\endverbatimsc\@undefined
418 \makeatother
419 \usepackage{listings}
420 \lstnewenvironment{verbatimsc}
421 {
422 \lstset{
423 language =,%
424 basicstyle = \ttfamily\small,
425 gobble = 2,%
426 }
427 }{}
428 \makeatother
429
430 % Don't copy numbers in code example
431 \newcommand*{\noaccsupp}[1]{\BeginAccSupp{ActualText={}}#1\EndAccSupp{}}
432
433 % Create a language for documentation
434 \lstdefinelanguage{scontents-doc}{
435 texcsstyle = *,%
436 escapechar = Ç,%
437 extendedchars = true,%
438 keepspaces = true,%
439 stringstyle = {\color{red}},%
440 basicstyle = \ttfamily\small,%
441 alsoletter = {-,@,.},%
442 % comments
443 morecomment = [l]{\%},%
444 commentstyle = \ttfamily\small\color{lightgray},%
445 % Important words 1
446 keywordstyle = [1]{\color{gray}},%
447 keywords = [1]{begin,end,env,myseq,false,ExplSyntaxOff,ExplSyntaxOn,%
448 NTF, N,x,e,n,nn,nnn,D,Nnn,DocumentMetadata,IfDocumentMetadataTF,},%
449 % Other words 2 (LaTeX)
450 keywordstyle = [2]{\color{blue!75}},%
451 keywords = [2]{usepackage,section,documentclass,input,usemodule,%
452 subsection,RequirePackage,%
453 ProvidesExplPackage,obeyedline,lstinline,Verb,macro,%
454 makebox,verb,detokenize,meaning,RenewDocumentCommand,%
455 definetyping,lstset,small,ttfamily,tiny,color,scantokens,%
456 peek_charcode_ignore_spaces,cs_argument_spec,cs_parameter_spec,%
457 regex_replace_all,tl_replace_all,tex_scantokens,tex_endinput,%
458 file_input_stop,peek_charcode,cs_undefine,tl_rescan,int_to_roman,tl_retokenize,%
459 int_step_tokens,keys_set,l_keys_key_str,tl_gset_rescan,contextlmtxmode,},%
460 % Other words 3
461 keywordstyle = [3]{\color{optcolor!85}},%
462 keywords = [3]{document,article,setlength,pagestyle,definecolor,myenvstore},%
463 % Reserved words 4 (scontents pkg)
464 keywordstyle = [4]{\color{pkgcolor}},%
465 keywords = [4]{scontents,Scontents,getstored,typestored,verbatimsc,mergesc, %
466 endverbatimsc,countsc,meaningsc,foreachsc,newenvsc,setupsc,cleanseqsc,%
467 endverbatim, endscontents,startscontents,stopscontents,scontents.tex},%
468 % Reserved words 5 (in red)
469 keywordstyle = [5]{\color{red}},%
470 keywords = [5]{makeatletter, makeatother, let, @undefined, def,@bsphack, @esphack,%
471 par,item,parindent,@ifpackagelater,[email protected], MakeFile,%
472 [email protected],l__scontents_ver_str,dospecials,do@noligs,char,outer,jobname,inner},%
473 % Reserved words 6 (optcolor)
474 keywordstyle = [6]{\color{optcolor}},%
475 keywords = [6]{store-cmd,store-env,print-env,print-cmd,write-env,verb-font,%
476 start,stopt,wrapper,sep,step,before,after,write-out,write-cmd,%
477 overwrite,width-tab,force-eol,inner,outer,I,J,M,L,Ascheol,store-all,
478 1-end,Verbatim,lang,pdfversion,pdfstandard,testphase,tagging,},%
479 % Reserved words 7 (OrangeRed)
480 keywordstyle = [7]{\color{OrangeRed}},%
481 keywords = [7]{DefineVerbatimEnvironment,lstnewenvironment,newminted,%
482 newtheorem,newenvironment,VerbatimEnvironment,listings,minted,},%
483 % literate
484 literate =*{\{}{{{\color{gray}{\char`\{}}}}{1}
485 {\}}{{{\color{gray}{\char`\}}}}}{1}
486 {\|}{{{\color{gray}{\char`\|}}}}{1}
487 {\$}{{{\color{gray}{\char`\$}}}}{1}
488 {\#}{{{\color{optcolor}{\char`\#}}}}{1}
489 {[}{{\textcolor{gray}{[}}}{1}
490 {]}{{\textcolor{gray}{]}}}{1}
491 {,}{{\textcolor{gray}{,}}}{1}
492 {;}{{\textcolor{gray}{;}}}{1}
493 {:}{{\textcolor{MediumOrchid}{:}}}{1}
494 {`}{{\textcolor{gray}{\textasciigrave}}}{1}
495 {\&}{{\textcolor{gray}{\&}}}{1}
496 {>}{{\textcolor{OrangeRed}{\guillemotright}}}{1}
497 {<}{{\textcolor{OrangeRed}{\guillemotleft}}}{1}
498 {*}{{\textcolor{MediumOrchid}{*}}}{1}
499 {\^}{{\textcolor{optcolor}{\textasciicircum}}}{1}
500 {0}{{\textcolor{MediumOrchid}{0}}}{1}
501 {1}{{\textcolor{MediumOrchid}{1}}}{1}
502 {2}{{\textcolor{MediumOrchid}{2}}}{1}
503 {3}{{\textcolor{MediumOrchid}{3}}}{1}
504 {4}{{\textcolor{MediumOrchid}{4}}}{1}
505 {5}{{\textcolor{MediumOrchid}{5}}}{1}
506 {6}{{\textcolor{MediumOrchid}{6}}}{1}
507 {7}{{\textcolor{MediumOrchid}{7}}}{1}
508 {8}{{\textcolor{MediumOrchid}{8}}}{1}
509 {9}{{\textcolor{MediumOrchid}{9}}}{1}
510 {.0}{{\textcolor{MediumOrchid}{.0}}}{2}% Following is to ensure that only periods
511 {.1}{{\textcolor{MediumOrchid}{.1}}}{2}% followed by a digit are changed.
512 {.2}{{\textcolor{MediumOrchid}{.2}}}{2}
513 {.3}{{\textcolor{MediumOrchid}{.3}}}{2}
514 {.4}{{\textcolor{MediumOrchid}{.4}}}{2}
515 {.5}{{\textcolor{MediumOrchid}{.5}}}{2}
516 {.6}{{\textcolor{MediumOrchid}{.6}}}{2}
517 {.7}{{\textcolor{MediumOrchid}{.7}}}{2}
518 {.8}{{\textcolor{MediumOrchid}{.8}}}{2}
519 {.9}{{\textcolor{MediumOrchid}{.9}}}{2}
520 {=}{{\textcolor{gray}{=}}}{1},%
521 }[keywords,tex,comments,strings]% end language
522
523 % \begin{examplecode}[key=val]...\end{examplecode}
524 \lstnewenvironment{examplecode}[1][]{%
525 \lstset{
526 language = scontents-doc,%
527 stringstyle = {\color{red}},%
528 basicstyle = \ttfamily\small,%
529 columns = fullflexible,%
530 fontadjust = true,%
531 aboveskip = 8pt,%
532 belowskip = 5pt,%
533 rulecolor = \color{gray!50},%
534 framesep = \fboxsep,%
535 framerule = \fboxrule,%
536 xleftmargin = \dimexpr\fboxsep+\fboxrule\relax,%
537 xrightmargin= \dimexpr\fboxsep+\fboxrule\relax,%
538 #1,%
539 }% close lstset
540 }{}% close examplecode
541
542 % \lstinline[style=inline]|...|
543 \lstdefinestyle{inline}
544 {
545 language = scontents-doc,%
546 upquote = true,%
547 numbersep = 1em,%
548 numberstyle = \tiny\color{lightgray}\noaccsupp,%
549 literate =*{\%}{{\textcolor{gray}{\%}}}{1}
550 }
551
552 % Set default \lstinline style
553 \lstset{style=inline}
554
555 % Set short §...§
556 \lstMakeShortInline[language=scontents-doc,basicstyle=\ttfamily]§
557
558 % Get file info
559 \GetFileInfo{scontents.sty}
560
561 % Config hyperref
562 \hypersetup{
563 allcolors = linkcolor,
564 colorlinks = true,
565 linktoc = all,
566 pdftitle = {.:: The scontents package --- \fileinfo{} ::.},
567 pdfauthor = {Pablo González L},
568 pdfsubject = {Documentation for \fileversion{} [\filedate] },
569 pdfkeywords = {sequences, contents, external files, expl3, l3seq, store contents},
570 bookmarksopenlevel = 1
571 }
572
573 % Configuration titleps and titlesec
574 \settitlemarks{section}
575 \renewpagestyle{plain}[\color{optcolor}\small\sffamily]{%
576 \setfoot{\rlap{\hskip\dimexpr-\oddsidemargin-1in\relax%
577 \parbox{1.93\paperwidth}{\hfil\thepage\,/\,\pageref{LastPage}}}}%
578 {}%
579 {}%
580 }
581 \newpagestyle{myheader}[\color{optcolor}\small\sffamily]{%
582 \renewcommand\makeheadrule{%
583 \rlap{\hskip\dimexpr-\oddsidemargin-1in\relax
584 \color{rulecolor}\rule[0.3cm]{\paperwidth}{0.7cm}}\hss
585 }
586 \setfoot{\rlap{\hskip\dimexpr-\oddsidemargin-1in\relax%
587 \parbox{1.93\paperwidth}{\hfil\thepage\,/\,\pageref{LastPage}}}}%
588 {\parbox{\textwidth}{\raggedright \textcolor{gray}{\raisebox{-1pt}{\textcopyright}{}2019--2025 by Pablo González L}}}%
589 {}%
590 \sethead{\llap{\raisebox{0.55cm}{\parbox{\dimexpr\oddsidemargin+1in\relax}{\makebox[0pt][l]{\hspace{15pt}\pkglogo\space\fileversion}}}}}
591 {\raisebox{0.55cm}{\parbox{\textwidth}{\hspace*{-\oddsidemargin}\centering\small\S.\thesection\space\sectiontitle}}}%
592 {}%
593 }
594
595 \titlecontents{section}[0mm]{}%
596 {\bfseries\contentspush{\makebox[5mm][l]{\thecontentslabel\hfill}}}%
597 {\hspace*{-5mm}}% numberless
598 {\hspace{0.25em}\titlerule*[6pt]{.}\contentspage}%
599 \titlecontents{subsection}[5mm]{}%
600 {\contentspush{\makebox[6mm][l]{\thecontentslabel\hfill}}}
601 {\hspace*{-11mm}}% numberless
602 {\hspace{0.25em}\titlerule*[6pt]{.}\contentspage}%
603
604 % Table of contents
605 \makeatletter
606 \renewcommand\tableofcontents{%
607 \begingroup%
608 \section*{\contentsname\quad{\color{gray}\leaders\hrule height 5pt depth -4.4pt\hfill}%
609 \@mkboth{%
610 \MakeUppercase\contentsname}{\MakeUppercase\contentsname}}%
611 \vspace*{-14pt}
612 \setlength{\columnsep}{10pt}%
613 \begin{multicols}{2}%
614 \@starttoc{toc}%
615 \end{multicols}%
616 \vspace*{-3pt}{\color{gray}\hrule height 0.6pt}%
617 \vspace*{5pt}
618 \endgroup
619 }
620 \makeatother
621 % thanks
622 \makeatletter
623 \renewcommand*{\@fnsymbol}[1]{\ensuremath{\ifcase#1\or \textcolor{pkgcolor}{*}
624 \or \textcolor{pkgcolor}{\dagger} \or \ddagger\or \mathsection
625 \or \mathparagraph\or \|\or **\or \dagger\dagger
626 \or \ddagger\ddagger \else\@ctrerr\fi}}
627 \makeatother
628 \begin{document}
629 \DocInput{\jobname.dtx}
630 \end{document}
631 %</driver>
632 % \fi
633 %
634 % \title{
635 % \scalebox{1.72}{\pkglogo}\\[1pt]
636 % \Large
637 % \textcolor{gray}{\fetamontotf{stores} \hologo{LaTeX} \fetamontotf{contents}}\\[3pt]
638 % \fileversion \quad \filedate\thanks{
639 % This file describes a documentation for \fileversion, last revised
640 % \filedate.}\\[25pt]
641 % \author{
642 % \large
643 % \raisebox{-1pt}{\textcopyright}{}2019--2025 by Pablo González L\thanks{
644 % E-mail: \textcolor{OrangeRed}{\textsf{\guillemotleft}}\email{[email protected]}\textcolor{OrangeRed}{\textsf{\guillemotright}}.
645 % }%
646 % }
647 % \small
648 % \textsc{ctan}: \url{https://www.ctan.org/pkg/scontents}\\
649 % \textcolor{gray}{\scriptsize\faIcon[regular]{github}}\,\,\,\url{https://github.com/pablgonz/scontents}
650 % \vspace*{-2cm}
651 % }
652 % \date{}
653 % \maketitle
654 %
655 % \begin{scontents}[store-env=abstract, print-env=true]
656 % \begin{abstract}
657 % This package allows to store \hologo{LaTeX} code, including \enquote{\emph{verbatim}},
658 % in \mymeta{sequences} using the \mypkg{l3seq} module of \mypkg{expl3}. The \mymeta{stored
659 % content} can be used as many times as desired in the document, additionally you can write
660 % to \mymeta{external files} or show it in \mymeta{verbatim style}.
661 % \end{abstract}
662 % \end{scontents}
663 %
664 % \tableofcontents
665 %
666 % \setlength{\parskip}{3pt}
667 %
668 % \section{Description of the package}
669 %
670 % \begin{scontents}[store-env=description, print-env=true]
671 % The \mypkg*{scontents} package allows to \mymeta{store contents} in \mymeta{sequences}
672 % or \mymeta{external files}. In some ways it is similar to the \mypkg{filecontentsdef}
673 % package, with the difference in which the \mymeta{content} is stored. The idea behind
674 % this package is to get an approach to \hologo{ConTeXt} \emph{\enquote{buffers}} by
675 % making use \mymeta{sequences}.
676 % \end{scontents}
677 %
678 % \section{Motivation and Acknowledgments}
679 %
680 % In \hologo{LaTeX} there is no direct way to record content for later use, although
681 % you can do this using §\macro§, recording \mymeta{verbatim content} is a
682 % problem, usually you can avoid this by creating external files or boxes.
683 %
684 % The general idea of this package is to try to imitate this implementation
685 % \enquote{\emph{buffers}} that has \hologo{ConTeXt} which allows you to save content in
686 % memory, including \emph{verbatim}, to be used later. The \mypkg{filecontentsdef}\cite{filecontentsdef}
687 % package solves this problem and since \mypkg{expl3}\cite{expl3} has an excellent way to manage data,
688 % ideas were combined giving rise to this package.
689 %
690 % This package would not be possible without the great work of \textsc{Jean
691 % Fran\c{c}ois Burnol} who was kind enough to take my requirements into account
692 % and add the \myenv{filecontentsdefmacro} environment to \mypkg{filecontentsdef} package.
693 % Also a special thanks to Phelype Oleinik who has collaborated and adapted a large part of the code and
694 % all \hologo{LaTeX} team for their great work and to the different members
695 % of the \href{https://tex.stackexchange.com}{TeX-SX} community who have provided
696 % great answers and ideas. Here a note of the main ones:
697 %
698 % \begin{enumerate}[left=0pt, labelsep=5pt, noitemsep, nosep, label=\small\arabic*.]
699 % \item \href{https://tex.stackexchange.com/q/45946/7832}{Stack datastructure using LaTeX}
700 %
701 % \item \href{https://tex.stackexchange.com/q/5338/7832}{LaTeX equivalent of ConTeXt buffers}
702 %
703 % \item \href{https://tex.stackexchange.com/q/215563/7832}{Storing an array of strings in a command}
704 %
705 % \item \href{https://tex.stackexchange.com/q/184503/7832}{Collecting contents of environment and store them for later retrieval}
706 %
707 % \item \href{https://tex.stackexchange.com/q/373647/7832}{Collect contents of an environment (that contains verbatim content)}
708 % \end{enumerate}
709 %
710 % \begin{important}*
711 % Starting with version 2.3 the \mypkg*{scontents} package is fully
712 % compatible with \emph{tagged} \texttt{PDF} and will have \LaTeX{}
713 % release 2025-06-01 (\TeX{} Live 2025) and \mypkg{expl3} 2025-07-08 as a minimum requirement.
714 % \end{important}
715 %
716 % \thispagestyle{plain}
717 % \newpage
718 % \pagestyle{myheader}
719 %
720 % \section{License and Requirements}
721 % \label{sec:licence}
722 %
723 % Permission is granted to copy, distribute and/or modify this software under
724 % the terms of the LaTeX Project Public License (lppl), version 1.3 or later
725 % (\url{https://www.latex-project.org/lppl.txt}). The software has the status
726 % \enquote{maintained}.
727 %
728 % The package \mypkg*{scontents} requires an updated version of \LaTeX{} to work
729 % (minimum required to \LaTeX{} release 2025-11-01 and \mypkg{expl3} 2025-07-08).
730 % This package can be used with "plain", "context", "xelatex", "lualatex", "pdflatex"
731 % and the classical workflow §latex>dvips>ps2pdf§.
732 %
733 % \section{The \texttt{scontents} package}
734 % \label{sec:pkgscontents}
735 %
736 % \subsection{Installation}
737 %
738 % The package \mypkg*{scontents} is present in \hologo{TeX} Live and \hologo{MiKTeX},
739 % use the package manager to install. For manual installation, download
740 % \href{https://mirrors.ctan.org/macros/latex/contrib/scontents.zip}{scontents.zip}
741 % and unzip it, run \lstinline[language=scontents-doc,basicstyle=\ttfamily]+luatex scontents.ins+
742 % and move all files to appropriate locations, then run "mktexlsr". To produce the documentation
743 % with source code run \lstinline[language=scontents-doc,basicstyle=\ttfamily]+luatex scontents.ins+ and
744 % "lualatex scontents.dtx" three times.
745 %
746 % \iffalse
747 %<*example>
748 % \fi
749 \begin{examplecode}[frame=single,language={}]
750 scontents.tex > TDS:tex/generic/scontents/
751 scontents-code.tex > TDS:tex/generic/scontents/
752 scontents.sty > TDS:tex/latex/scontents/
753 t-scontents.mkiv > TDS:tex/context/third/scontents/
754 scontents.pdf > TDS:doc/latex/scontents/
755 README.md > TDS:doc/latex/scontents/
756 scontents.dtx > TDS:source/latex/scontents/
757 scontents.ins > TDS:source/latex/scontents/
758 \end{examplecode}
759 % \iffalse
760 %</example>
761 % \fi
762 %
763 % \subsection{Loading and options}
764 %
765 % The package is loaded in the usual way:
766 %
767 % \subsubsection*{For \hologo{LaTeX} users}
768 %
769 % \iffalse
770 %<*example>
771 % \fi
772 \begin{examplecode}[frame=single]
773 \usepackageÇ\small\myoarg{key \textnormal{\textcolor{gray}{=}} val}Ç{scontents}
774 \end{examplecode}
775 % \iffalse
776 %</example>
777 % \fi
778 %
779 % \subsubsection*{For \hologo{plainTeX} users}
780 %
781 % \iffalse
782 %<*example>
783 % \fi
784 \begin{examplecode}[frame=single]
785 \input scontents.tex
786 \end{examplecode}
787 % \iffalse
788 %</example>
789 % \fi
790 %
791 % \subsubsection*{For \hologo{ConTeXt} users}
792 %
793 % \iffalse
794 %<*example>
795 % \fi
796 \begin{examplecode}[frame=single]
797 \usemodule{scontents}
798 \end{examplecode}
799 % \iffalse
800 %</example>
801 % \fi
802 %
803 % \begin{important}*
804 % The package options are not available for \hologo{plainTeX} and
805 % \hologo{ConTeXt} and must be passed using §\setupsc§ (see \S\ref{sec:confopt}).
806 % \hologo{ConTeXt} users should use |-luatex|, the implementation does
807 % not support LuaMetaTeX.
808 % \end{important}
809 %
810 % \subsection{The TAB character}
811 % \label{sec:tabcharacter}
812 %
813 % Some users use the horizontal \texttt{TAB} `\LKeyTab' from keyboard to
814 % indent the source code of the document and depending on the text editor
815 % used, some will use real \texttt{TAB} (\emph{hard tabs}), others with
816 % \emph{soft tabs} (\verb*| | or \verb*| |) or both.
817 %
818 % At first glance it may seem the same, but the way in which \texttt{TAB} (\emph{hard tabs})
819 % are processed according to the context in which they are found within
820 % a file, both in \mymeta{reading}\footnote{Check the answer given by Ulrich Diez
821 % in \href{https://tex.stackexchange.com/a/508103/7832}{Keyboard TAB
822 % character in argument v (xparse)}.} and \mymeta{writing}\footnote{Check the answer
823 % given by Enrico Gregorio in \href{https://tex.stackexchange.com/a/58740/7832}{How to output a
824 % tabulation into a file}.} are different and may have adverse consequences.
825 %
826 % In a standard \hologo{LaTeX} document, the character \texttt{TAB} `\LKeyTab'
827 % are treated as explicit spaces (in most contexts) and is the behavior when
828 % \mymeta{stored content}, but when \mymeta{writing files} these are preserved.
829 %
830 % With a \hologo{TeX} Live distribution, the \texttt{TAB} character is \emph{printable}
831 % for "latex", "pdflatex" and "lualatex", but if you use "xelatex" you
832 % must add the \texttt{\textcolor{optcolor}{-8bit}} option on the command
833 % line, otherwise you will get \hologo{TeX} character \texttt{TAB} `§^^I§'
834 % in the \mymeta{output file}.
835 %
836 % As a general recommendation \emph{\enquote{Do not use \texttt{TAB} character unless strictly
837 % necessary}}, for example within a \emph{\enquote{verbatim environment}} that supports
838 % this character such as \myenv{Verbatim} of the packages \mypkg{fancyvrb}\cite{fancyvrb},
839 % \mypkg{fvextra}\cite{fvextra} or \myenv{lstlisting} of the package \mypkg{listings}\cite{listings}
840 % or when you want to generate a §MakeFile§ file.
841 %
842 % \subsection{Configuration of the options}
843 % \label{sec:confopt}
844 %
845 % Most of the options can be passed directly to the package or using the
846 % command \ics*{setupsc}. All boolean keys can be passed using the
847 % equal sign `\textnormal{\textcolor{gray}{=}}' or just the
848 % name of the key, all unknown \mymeta{keys} will return an error. In this section
849 % are described some of the options, a summary of all options is shown in \S\ref{sec:optover}.
850 %
851 % \vspace*{-10pt}
852 %
853 % \begin{function}{\setupsc}
854 % \begin{syntax}
855 % \cmdexamp{setupsc}{key \textnormal{\textcolor{gray}{=}} val}
856 % \end{syntax}
857 %
858 % The command \ics*{setupsc} sets the \mymeta{keys} in a global way,
859 % it can be used both in the preamble and in the body of the document
860 % as many times as desired. However, options set in the declaration of
861 % an environment (with \ics*{newenvsc}) have precedence over options
862 % set with \ics*{setupsc}.
863 %
864 % Options in the optional arguments of environments and
865 % commands have the highest precedence, overriding both
866 % options in \ics*{newenvsc}, and in \ics*{setupsc}.
867 % \end{function}
868 %
869 % \keyexamp{verb-font}{font family}{\textnormal{\ttfamily\textbackslash{}ttfamily}}
870 % Sets the \mymeta{font family} used to display the \mymeta{stored content} for
871 % \ics*{typestored}, \ics*{mergesc} and \ics*{meaningsc} commands. This key
872 % is only available as a package option or using \ics*{setupsc}.
873 %
874 % \medskip
875 %
876 % \keyexamp{store-all}{seq name}{not used}
877 % It is a \mymeta{meta-key} that sets the \mykey{store-env} key of the \myenv*{scontents}
878 % environment and the \mykey{store-cmd} key of the \ics*{Scontents} command. This key is
879 % only available as a package option or using \ics*{setupsc}.
880 %
881 % \medskip
882 %
883 % \keyexamp{overwrite}{true \textnormal{\textcolor{lightgray}{\textbar}} false}{false}
884 % Sets whether the \mymeta{files} generated by \mykey{write-out} and \mykey{write-env}
885 % from the \myenv*{scontents} environment will be rewritten. This key is available as
886 % a package option, for \ics*{setupsc}, for \ics*{Scontents*} and for the environment
887 % \myenv*{scontents}.
888 %
889 % \medskip
890 %
891 % \keyexamp{print-all}{true \textnormal{\textcolor{lightgray}{\textbar}} false}{false}
892 % It is a \mymeta{meta-key} that sets the \mykey{print-env} key of the \myenv*{scontents}
893 % environment and the \mykey{print-cmd} key of the \ics*{Scontents} command. This key is
894 % only available as a package option or using \ics*{setupsc}.
895 %
896 % \keyexamp{force-eol}{true \textnormal{\textcolor{lightgray}{\textbar}} false}{false}
897 % Sets if the \emph{last end of line} for the \mymeta{stored content} is hidden or not.
898 % This key is necessary only if the \emph{last line} is the closing of some
899 % environment defined by \mypkg{fancyvrb}\cite{fancyvrb} or \mypkg{fvextra}\cite{fvextra}
900 % packages as §\end{Verbatim}§ or another environment that does not support
901 % a comments `\texttt{\textcolor{gray}{\%}}' after closing §\end{<env>}%§.
902 % This key is available for the \myenv*{scontents} environment and the \ics*{Scontents*} command.
903 %
904 % \keyexamp{width-tab}{integer}{1}
905 % Sets the equivalence in \mymeta{spaces} for the character \texttt{TAB}
906 % used when displaying \mymeta{stored content} in \emph{verbatim style}. The value
907 % must be a \mymeta{positive integer}. This key is available for \ics*{typestored},
908 % \ics*{mergesc} and \ics*{meaningsc} commands.
909 %
910 % \subsection{Options Overview}
911 % \label{sec:optover}
912 %
913 % \newcommand*{\xmark}{\textcolor{OrangeRed}{✘}}%
914 % \newcommand*{\cmark}{\textcolor{linkcolor}{✔}}%
915 %
916 % Summary of available options:
917 %
918 % \setlength{\tabcolsep}{0.25em}
919 % \vspace*{-\baselineskip}
920 % \begin{center}
921 % \small
922 % \begin{tabular}{lcccccccc}
923 % \toprule
924 % \texttt{key} & \texttt{package} &\ics*{setupsc} &\myenv*{scontents} &\ics*{Scontents} &\ics*{Scontents*} &\ics*{typestored} &\ics*{meaningsc} &\ics*{mergesc}\\
925 % \midrule
926 % \mykey{store-env} & \cmark & \cmark & \cmark & \xmark & \xmark & \xmark & \xmark & \xmark \\
927 % \mykey{store-cmd} & \cmark & \cmark & \xmark & \cmark & \cmark & \xmark & \xmark & \xmark \\
928 % \mykey{print-env} & \cmark & \cmark & \cmark & \xmark & \xmark & \xmark & \xmark & \xmark \\
929 % \mykey{print-cmd} & \cmark & \cmark & \xmark & \cmark & \cmark & \cmark & \cmark & \cmark \\
930 % \mykey{print-all} & \cmark & \cmark & \xmark & \xmark & \xmark & \xmark & \xmark & \xmark \\
931 % \mykey{store-all} & \cmark & \cmark & \xmark & \xmark & \xmark & \xmark & \xmark & \xmark \\
932 % \mykey{write-env} & \xmark & \xmark & \cmark & \xmark & \xmark & \xmark & \xmark & \xmark \\
933 % \mykey{write-cmd} & \xmark & \xmark & \xmark & \xmark & \cmark & \xmark & \xmark & \xmark \\
934 % \mykey{write-out} & \xmark & \xmark & \cmark & \xmark & \cmark & \cmark & \cmark & \cmark \\
935 % \mykey{overwrite} & \cmark & \cmark & \cmark & \xmark & \cmark & \cmark & \cmark & \cmark \\
936 % \mykey{width-tab} & \cmark & \cmark & \xmark & \xmark & \xmark & \cmark & \cmark & \cmark \\
937 % \mykey{force-eol} & \cmark & \cmark & \cmark & \xmark & \cmark & \xmark & \xmark & \xmark \\
938 % \mykey{verb-font} & \cmark & \cmark & \xmark & \xmark & \xmark & \xmark & \xmark & \xmark \\
939 % \mykey{typestored} & \xmark & \xmark & \xmark & \xmark & \xmark & \xmark & \xmark & \cmark \\
940 % \mykey{meaningsc} & \xmark & \xmark & \xmark & \xmark & \xmark & \xmark & \xmark & \cmark \\
941 % \bottomrule
942 % \end{tabular}
943 % \end{center}
944 %
945 % \section{User interface}
946 % \label{sec:interface}
947 %
948 % The user interface consists in \myenv*{scontents} environment, \ics*{Scontents}
949 % and \ics*{Scontents*} commands to \mymeta{stored content}, \ics*{getstored}
950 % command to get the \mymeta{stored content}, \ics*{typestored} and \ics*{mergesc} commands to print
951 % \emph{verbatim style} the \mymeta{stored content} along with other utilities described
952 % in this documentation.
953 %
954 % \subsection{The environment \texttt{scontents}}
955 % \label{sec:envscontents}
956 %
957 % \vspace*{-10pt}
958 %
959 % \begin{function}[label=SCONTENTS]{scontents}
960 % \begin{syntax}
961 % \envexamp{scontents}
962 % \end{syntax}
963 %
964 % The \myenv*{scontents} environment processes \mymarg{body env} and
965 % \emph{\enquote{stores}} it in a \mymeta{sequence} or \emph{\enquote{writes}}
966 % it to an \mymeta{external file} if desired, including \emph{verbatim
967 % material}. After the package has been loaded, the environment can be
968 % used both in the preamble and in the body of the document.
969 %
970 % For the correct operation §\begin{scontents}§ and §\end{scontents}§ must
971 % be in \emph{different lines}, all \mymeta{keys} must be passed separated by
972 % commas and \emph{without spaces} `\verb*+ +' of the start of the
973 % environment.
974 % \end{function}
975 %
976 % Comments `\texttt{\textcolor{gray}{\%}}' or \emph{any character} after
977 % §\begin{scontents}§ or \myoarg{key \textnormal{\textcolor{gray}{=}} val} on
978 % the \emph{same line} are NOT supported, the package will return an \enquote{error} message if this happens.
979 % In a similar way comments `\texttt{\textcolor{gray}{\%}}' or \emph{any character}
980 % after §\end{scontents}§ on the \emph{same line} the package will return a \enquote{warning} message.
981 %
982 % The environment can be \emph{\enquote{nested}} if it is properly balanced and
983 % does not appear \emph{\enquote{literally}} in commented lines or in some \emph{verbatim}
984 % environment or command. As an example:
985 %
986 % \iffalse
987 %<*example>
988 % \fi
989 \begin{examplecode}[frame=single]
990 \begin{scontents}[store-env=outer]
991 This text is in the outer environment (before nested).
992 \begin{scontents}[store-env=inner]
993 This text is found in the inner environment (inside of nested).
994 \end{scontents}
995 This text is in the outer environment (after nested).
996 \end{scontents}
997 \end{examplecode}
998 % \iffalse
999 %</example>
1000 % \fi
1001 %
1002 % Of course, the \mymeta{stored content} in the \emph{sequence} \mymarg{inner}
1003 % is \emph{only available} after \mymeta{stored content} in the \emph{sequence}
1004 % \mymarg{outer} one has been retrieved, either by using the key \mykey{print-env}
1005 % or \ics*{getstored} command.
1006 %
1007 % \begin{important}*
1008 % It is advisable to \mymeta{stored content} within \emph{sequences} with
1009 % different names, so as not to get lost in the order (position) in which
1010 % they are stored.
1011 % \end{important}
1012 %
1013 % \subsection*{Notes for \hologo{plainTeX} and \hologo{ConTeXt} users}
1014 %
1015 % In \hologo{plainTeX} there is not environments as in \hologo{LaTeX}.
1016 % Instead of using the environment \myenv*{scontents}, one should use a
1017 % \emph{\enquote{pseudo environment}} delimited by \ics*{scontents} and \ics*{endscontents}.
1018 %
1019 % \vspace*{-10pt}
1020 % \begin{function}{\scontents,\endscontents}
1021 % \begin{syntax}
1022 % \envexaplain{scontents}
1023 % \end{syntax}
1024 % \end{function}
1025 %
1026 % \hologo{ConTeXt} users should use \ics*{startscontents} and \ics*{stopscontents}.
1027 % \vspace*{-10pt}
1028 % \begin{function}{\startscontents,\stopscontents}
1029 % \begin{syntax}
1030 % \envexaplain[start]{scontents}[stop]
1031 % \end{syntax}
1032 % \end{function}
1033 %
1034 % \subsection*{Options for environment}
1035 %
1036 % The environment options can be configured globally using option
1037 % in package or the \ics*{setupsc} command and locally using
1038 % \myoarg{key \textnormal{\textcolor{gray}{=}} val} in the environment.
1039 % The key \mykey{force-eol} is available for this environment.
1040 %
1041 % \keyexamp{store-env}{seq name}{contents}
1042 % Sets the \emph{name} of the \emph{sequence} in which the \mymarg{body env} will be
1043 % stored. If the \emph{sequence} does not exist, it will be created globally.
1044 %
1045 % \medskip
1046 %
1047 % \keyexamp{print-env}{true \textnormal{\textcolor{lightgray}{\textbar}} false}{false}
1048 % Sets if the \mymeta{stored content} is displayed or not at the time of
1049 % running the environment. The \mymeta{stored content} is extracted from
1050 % the \emph{sequence} \mymarg{seq name} set by the key \mykey{store-env}
1051 % at the time it is executed.
1052 %
1053 % \medskip
1054 %
1055 % \keyexamp{write-env}{file.ext}{not used}
1056 % Sets the \emph{name} of the \mymeta{external file} in which the \mymarg{body env} of
1057 % the environment will be written. The \mymeta{file.ext} will be created
1058 % in the working directory and the \mymarg{body env} will be \emph{stored}
1059 % in the \emph{sequence} set by the key \mykey{store-env}
1060 % at the time it is executed. If \mymeta{file.ext} does not exist, it will
1061 % be created or overwritten if the \mykey{overwrite} key is used.
1062 %
1063 % \medskip
1064 %
1065 % \keyexamp{write-out}{file.ext}{not used}
1066 % Sets the \emph{name} of the \mymeta{external file} in which the \mymarg{body env} of
1067 % the environment will be written. The \mymeta{file.ext} will be created
1068 % in the working directory and the \mymarg{body env} will NOT be \emph{stored}
1069 % in the \emph{sequence} set by the key \mykey{store-env}
1070 % at the time it is executed. If \mymeta{file.ext} does not exist, it will
1071 % be created or overwritten if the \mykey{overwrite} key is used.
1072 %
1073 % \begin{important}*
1074 % In the keys \mykey{write-env} and \mykey{write-out} the character
1075 % \texttt{TAB} will be written in \mymeta{file.ext},
1076 % relative or absolute paths are not supported. \hologo{XeLaTeX} users
1077 % using character \texttt{TAB} must add \texttt{\textcolor{optcolor}{-8bit}}
1078 % at the command line, otherwise you will get \hologo{TeX} character
1079 % \texttt{TAB} `§^^I§' in \mymeta{file.ext}.
1080 % \end{important}
1081 %
1082 % \subsection{The command \cs{newenvsc}}
1083 % \label{sec:newenvsc}
1084 %
1085 % \newsavebox{\exaboxtmp}
1086 % \begin{lrbox}{\exaboxtmp}
1087 % \small\ttfamily
1088 % \textcolor{pkgcolor}{\textbackslash newenvsc}\mymarg{env name}\myoarg{initial keys}
1089 % \end{lrbox}
1090 %
1091 % \vspace*{-10pt}
1092 %
1093 % \begin{function}{\newenvsc}
1094 % \begin{syntax}
1095 % \usebox{\exaboxtmp}
1096 % \end{syntax}
1097 % \end{function}
1098 %
1099 % The command \ics*{newenvsc} allows you to create \mymeta{new environments}
1100 % based on the same characteristics of the \myenv*{scontents} environment.
1101 % The values entered in \myoarg{initial keys} will be considered as the
1102 % default values for this new environment and the valid \mymeta{keys} are
1103 % \mykey{store-env} and \mykey{print-env}. For example:
1104 %
1105 % \iffalse
1106 %<*example>
1107 % \fi
1108 \begin{examplecode}[frame=single]
1109 \newenvsc{myenvstore}[store-env=myseq,print-env=false]
1110 \end{examplecode}
1111 % \iffalse
1112 %</example>
1113 % \fi
1114 %
1115 % created the environment §myenvstore§ that \mymeta{stored content} in
1116 % the \emph{sequence} \mymarg{myseq} and will NOT display the \mymeta{stored content}
1117 % when the environment it is executed.
1118 %
1119 % \subsection{The command \cs{Scontents}}
1120 % \label{sec:Scontents}
1121 %
1122 % \vspace*{-10pt}
1123 %
1124 % \begin{function}{\Scontents}
1125 % \begin{syntax}
1126 % \cmdexamp{Scontents}[key \textnormal{\textcolor{gray}{=}} val]{argument}
1127 % \cmdexamp[*]{Scontents}[key \textnormal{\textcolor{gray}{=}} val]{argument}
1128 % \cmdexamp[*]{Scontents}[key \textnormal{\textcolor{gray}{=}} val]{argument}[del]
1129 % \end{syntax}
1130 % \end{function}
1131 %
1132 % The \ics*{Scontents} command reads the \mymarg{argument} in standard
1133 % mode and \emph{\enquote{stores}} it in the \emph{sequence} set
1134 % by the key \mykey{store-cmd} at the time it is executed. It is not
1135 % possible to pass \emph{verbatim things}, but it is possible to use
1136 % the implementation of §\Verb§ delimited by \emph{braces}
1137 % `\texttt{\textcolor{gray}{\{}} \texttt{\textcolor{gray}{\}}}'
1138 % provided by the \mypkg{fvextra}\cite{fvextra} package for \emph{verbatim one line}
1139 % and §\lstinline§ from \mypkg{listings}\cite{listings} package, but it
1140 % is preferable to use the \emph{starred argument} `§*§'.
1141 %
1142 % The \ics*{Scontents*} command reads the \mymarg{argument} under \emph{verbatim catcode}
1143 % regimen and \emph{\enquote{stores}} it in the \emph{sequence} set
1144 % by the key \mykey{store-cmd} at the time it is executed. If its \emph{\enquote{first}}
1145 % delimiter is a \emph{brace} `\texttt{\textcolor{gray}{\{}}', it will be
1146 % assumed that the \mymarg{argument} is nested within \emph{braces}. Otherwise it
1147 % will be assumed that \mymarg{argument} is delimited by that
1148 % first delimiter \mymeta[cf=MediumOrchid]{del} like command §\verb§.
1149 % Blank lines are preserved, escaped braces `\texttt{\textcolor{gray}{\textbackslash\{}}' and
1150 % `\texttt{\textcolor{gray}{\textbackslash\}}}' must also be
1151 % balanced if the \mymarg{argument} is used with \emph{braces} and character \texttt{TAB} typed
1152 % from the keyboard are converted into spaces.
1153 %
1154 % The \emph{starred argument} `§*§' and \myoarg{key \textnormal{\textcolor{gray}{=}} val}
1155 % must NOT be separated by \emph{spaces} `\verb*+ +' between them and the command.
1156 % Both versions can be used anywhere in the document and cannot be used
1157 % as an \mymarg{argument} for other command.
1158 %
1159 % \subsection*{Options for command}\label{sec:optcmdsc}
1160 %
1161 % The command options can be configured globally using option in package
1162 % or the \ics*{setupsc} command and locally using \myoarg{key \textnormal{\textcolor{gray}{=}} val}.
1163 %
1164 % \keyexamp{store-cmd}{seq name}{contents}
1165 % Sets the \emph{name} of the \emph{sequence} in which the \mymarg{argument}
1166 % is stored. If the \emph{sequence} does not exist, it will be created globally.
1167 %
1168 % \medskip
1169 %
1170 % \keyexamp{print-cmd}{true \textnormal{\textcolor{lightgray}{\textbar}} false}{false}
1171 % Sets if the \mymeta{stored content} is displayed or not at the time of
1172 % running the command. The \mymeta{stored content} is extracted from the \emph{sequence}
1173 % \mymarg{seq name} set by the key \mykey{store-cmd} at the time it is executed.
1174 %
1175 % \subsection*{Options only for starred version}
1176 %
1177 % The \mykey{force-eol} and \mykey{overwrite} keys is available for this \emph{starred version}.
1178 %
1179 % \keyexamp{write-cmd}{file.ext}{not used}
1180 % Sets the \emph{name} of the \mymeta{external file} in which the \mymarg{argument}
1181 % will be written. The \mymeta{file.ext} will be created in the working
1182 % directory and the \mymarg{argument} will be \emph{stored}
1183 % in the \emph{sequence} set by the key \mykey{store-cmd}
1184 % at the time it is executed. If \mymeta{file.ext} does not exist, it will
1185 % be created or overwritten if the \mykey{overwrite} key is used.
1186 %
1187 % \keyexamp{write-out}{file.ext}{not used}
1188 % Sets the \emph{name} of the \mymeta{external file} in which the \mymarg{argument}
1189 % will be written. The \mymeta{file.ext} will be created in the working
1190 % directory and the \mymarg{argument} will NOT be \emph{stored}
1191 % in any \emph{sequence} set by the key \mykey{store-cmd}
1192 % at the time it is executed. If \mymeta{file.ext} does not exist, it will
1193 % be created or overwritten if the \mykey{overwrite} key is used.
1194 %
1195 % \begin{important}*
1196 % In the keys \mykey{write-cmd} and \mykey{write-out} the character
1197 % \texttt{TAB} will be written in \mymeta{file.ext}, relative or absolute
1198 % paths are not supported. \hologo{XeLaTeX} users using character \texttt{TAB}
1199 % must add \texttt{\textcolor{optcolor}{-8bit}} at the command line, otherwise
1200 % you will get \hologo{TeX} character \texttt{TAB} `§^^I§' in \mymeta{file.ext}.
1201 % \end{important}
1202 %
1203 % \subsection{The command \cs{getstored}}
1204 % \label{sec:getstored}
1205 %
1206 % \vspace*{-10pt}
1207 %
1208 % \begin{function}{\getstored}
1209 % \begin{syntax}
1210 % \cmdexamp{getstored}[index]{seq name}
1211 % \end{syntax}
1212 % \end{function}
1213 %
1214 % The \ics*{getstored} command retrieves the \mymeta{stored content}
1215 % according to the \emph{integer value} set in \mymeta{index} which
1216 % corresponds to the \emph{position} of the \mymeta{stored content}
1217 % in the \emph{sequence} \mymarg{seq name}.
1218 %
1219 % The command is robust and can be used as an \mymarg{argument} for
1220 % another command. If the \emph{optional argument} is not passed,
1221 % the default value is the \emph{\enquote{last}} \mymeta{stored content}
1222 % in the \emph{sequence} \mymarg{seq name}.
1223 %
1224 % \subsection{The command \cs{foreachsc}} \label{sec:foreachsc}
1225 %
1226 % \vspace*{-10pt}
1227 %
1228 % \begin{function}{\foreachsc}
1229 % \begin{syntax}
1230 % \cmdexamp{foreachsc}[key \textnormal{\textcolor{gray}{=}} val]{seq name}
1231 % \end{syntax}
1232 % \end{function}
1233 %
1234 % The command \ics*{foreachsc} iterates through and executes the command §\getstored§
1235 % on the \mymeta{stored content} in the \emph{sequence} \mymarg{seq name}. If the
1236 % \emph{optional argument} is not passed run §\getstored§ on all \mymeta{stored content}
1237 % in the \emph{sequence} \mymarg{seq name}.
1238 %
1239 % \subsubsection*{Options for command}
1240 % \label{sec:optcmdfor}
1241 %
1242 % \keyexamp{sep}{code}{empty}
1243 % Establishes the \emph{separation} between each \mymeta{stored content}
1244 % in the \emph{sequence} \mymarg{seq name}.
1245 % For example, you can use §sep={\\[10pt]}§ for vertical separation of
1246 % \mymeta{stored contents}.
1247 %
1248 % \keyexamp{step}{integer}{1}
1249 % Sets the \emph{increment} (\mymeta{step}) applied to the value set by key §start§
1250 % for each \mymeta{stored content} in the \emph{sequence} \mymarg{seq name}.
1251 % The value must be a \mymeta{positive integer}.
1252 %
1253 % \keyexamp{start}{integer}{1}
1254 % Set the \emph{position} of the \mymeta{stored content} within the
1255 % \emph{sequence} \mymarg{seq name} from which to \emph{start} executing.
1256 % The value must be a \mymeta{positive integer}.
1257 %
1258 % \keyexamp{stop}{integer}{total}
1259 % Set the \emph{position} of the \mymeta{stored content} within the
1260 % \emph{sequence} \mymarg{seq name} at which execution ends. The value
1261 % must be a \mymeta{positive integer}.
1262 %
1263 % \keyexamp{before}{code}{empty}
1264 % Sets the \mymarg{code} that will be executed \emph{before} each \mymeta{stored content}
1265 % within the \emph{sequence} \mymarg{seq name}. The \mymarg{code} must
1266 % be passed \emph{between braces} `\texttt{\textcolor{gray}{\{}} \texttt{\textcolor{gray}{\}}}'.
1267 %
1268 % \keyexamp{after}{code}{empty}
1269 % Sets the \mymarg{code} that will be executed \emph{after} each \mymeta{stored content}
1270 % within the \emph{sequence} \mymarg{seq name}. The \mymarg{code} must
1271 % be passed \emph{between braces} `\texttt{\textcolor{gray}{\{}} \texttt{\textcolor{gray}{\}}}'.
1272 %
1273 % \newsavebox{\hashbox}
1274 % \begin{lrbox}{\hashbox}
1275 % \lstinline[language=scontents-doc,basicstyle=\small\ttfamily]+{#1}+
1276 % \end{lrbox}
1277 %
1278 % \keyexamp{wrapper}{code{} \space\usebox{\hashbox} more code}{empty}
1279 % Wraps the \mymeta{stored content} within the \emph{sequence} \mymarg{seq name}
1280 % referenced by §{#1}§. The \mymarg{code} must be passed \emph{between braces}
1281 % `\texttt{\textcolor{gray}{\{}} \texttt{\textcolor{gray}{\}}}'.
1282 % For example §\foreachsc[wrapper={\makebox[1em][l]{#1}}]{contents}§.
1283 %
1284 % \subsection{The command \cs{typestored}}
1285 % \label{sec:typestored}
1286 %
1287 % \vspace*{-10pt}
1288 %
1289 % \begin{function}{\typestored}
1290 % \begin{syntax}
1291 % \cmdexamp{typestored}[index\textnormal{\textcolor{gray}{,}} start-stop\textnormal{\textcolor{gray}{,}} 1-end\textnormal{\textcolor{gray}{,}} keys]{seq name}
1292 % \end{syntax}
1293 % The command \ics*{typestored} places the \mymeta{stored content} in
1294 % the \emph{sequence} \mymarg{seq name} into the internally \myenv*{verbatimsc}
1295 % environment (\S\ref{sec:verbatimsc}). The \emph{integer value} set at \mymeta{index} corresponds
1296 % to the \emph{position} of the \mymeta{stored content} in the \emph{sequence}
1297 % \mymarg{seq name} will be printed, if \mymeta{1-end} is used \emph{\enquote{all}}
1298 % \mymeta{stored content} in the \emph{sequence} \mymarg{seq name} will be printed.
1299 % \end{function}
1300 %
1301 % The \emph{integer values} ​​set by \mymeta{start-stop} define the \emph{range}
1302 % of the \mymeta{stored content} in the \emph{sequence} \mymarg{seq name}
1303 % that will be printed, the rest of the accepted \mymeta{keys} are \mykey{print-cmd}
1304 % with default value \textcolor{gray}{\texttt{true}}, \mykey{write-out}, \mykey{width-tab}
1305 % and \mykey{overwrite}.
1306 %
1307 % If the \emph{optional argument} is not passed, the \emph{first} \mymeta{stored content}
1308 % in the \emph{sequence} \mymarg{seq name} will be printed.
1309 %
1310 % \begin{important}*
1311 % In the key \mykey{write-out} the character \texttt{TAB} will be written
1312 % in \mymeta{file.ext}, relative or absolute paths are not supported.
1313 % \hologo{XeLaTeX} users using character \texttt{TAB} must add \texttt{\textcolor{optcolor}{-8bit}}
1314 % at the command line, otherwise you will get \hologo{TeX} character
1315 % \texttt{TAB} `§^^I§' in \mymeta{file.ext}.
1316 % \end{important}
1317 %
1318 % \subsection{The command \cs{meaningsc}}
1319 % \label{sec:meaningsc}
1320 %
1321 % \vspace*{-10pt}
1322 %
1323 % \begin{function}{\meaningsc}
1324 % \begin{syntax}
1325 % \cmdexamp{meaningsc}[index\textnormal{\textcolor{gray}{,}} start-stop\textnormal{\textcolor{gray}{,}} 1-end\textnormal{\textcolor{gray}{,}} keys]{seq name}
1326 % \end{syntax}
1327 % The command \ics*{meaningsc} executes §\meaning§ on the \mymeta{stored content}
1328 % in the \emph{sequence} \mymarg{seq name}. The \mymeta{index},
1329 % \mymeta{start-stop}, \mymeta{1-end} and \mymeta{keys} they have the
1330 % same behavior as in the command §\typestored§. If the \emph{optional argument}
1331 % is not passed it defaults to the first \mymeta{stored content} in the
1332 % \emph{sequence} \mymarg{seq name}.
1333 % \end{function}
1334 %
1335 %
1336 %
1337 % \subsection{The command \cs{mergesc}}
1338 % \label{sec:mergesc}
1339 %
1340 % \vspace*{-10pt}
1341 %
1342 % \newsavebox{\argmergesc}
1343 % \begin{lrbox}{\argmergesc}
1344 % \small\mymarg{seq A}\myoarg{index}\textcolor{gray}{, }\mymarg{seq B}\myoarg{start \textcolor{gray}{-} stop}\textcolor{gray}{, }\mymarg{seq C}\myoarg{1-end}
1345 % \end{lrbox}
1346 %
1347 % \begin{function}{\mergesc}
1348 % \begin{syntax}
1349 % \cmdexamp{mergesc}[typestored \textnormal{\textcolor{lightgray}{\textbar}} meaningsc\textcolor{lightgray}{, }keys]{\usebox{\argmergesc}}
1350 % \end{syntax}
1351 % The command \ics*{mergesc} assembles the \mymeta{stored content}
1352 % in the \emph{sequences} \mymarg{seq A}§[1]§, \mymarg{seq B}§[2-5]§ and
1353 % \mymarg{seq C}§[1-§\textcolor{optcolor}{\texttt{end}}§]§ and then executes
1354 % §\typestored§ (\S\ref{sec:typestored}) if the \mykey{typestored} key is
1355 % active or §\meaningsc§ (\S\ref{sec:meaningsc}) if the \mykey{meaningsc}
1356 % key is active.
1357 % \end{function}
1358 %
1359 % The \mymarg{argument} taken by this command is a \emph{comma separated list}
1360 % of the form \mymarg{seq name} followed by either \myoarg{index},
1361 % \myoarg{start-stop} or \myoarg{1-end}.
1362 % The use of the keys \mykey{typestored} or \mykey{meaningsc} are
1363 % \emph{\enquote{mandatory}} and disjoint from each other, the rest of the
1364 % accepted \mymeta{keys} are \mykey{print-cmd}, \mykey{write-out},
1365 % \mykey{width-tab} and \mykey{overwrite}.
1366 %
1367 % The use of the \mykey{write-out} key with this command follows the same
1368 % rules already described, the main advantage is that allows joining
1369 % \mymeta{stored content} \emph{without rewriting} the file over and over again,
1370 % by design \hologo{TeX} does not have an \emph{append mode} for writing
1371 % files, this effectively allows you to write chunks of code and then
1372 % merge them into a single file.
1373 %
1374 %^^A \newpage
1375 %
1376 % \subsection{The environment \env{verbatimsc}}
1377 % \label{sec:verbatimsc}
1378 %
1379 % \vspace*{-10pt}
1380 %
1381 % \begin{function}{verbatimsc}
1382 % The environment used by \ics*{typestored} and \ics*{mergesc} to
1383 % display the \mymeta{stored content} in \emph{verbatim style}.
1384 % The environment is compatible with \emph{tagged} \texttt{PDF} and can
1385 % be customized in the following ways after loading the \mypkg*{scontents}
1386 % package:
1387 % \end{function}
1388 %
1389 % Using the packages \mypkg{fvextra}\cite{fvextra} or \mypkg{fancyvrb}\cite{fancyvrb}:
1390 % \iffalse
1391 %<*example>
1392 % \fi
1393 \begin{examplecode}[frame=single]
1394 \ExplSyntaxOn
1395 \cs_undefine:N \verbatimsc
1396 \cs_undefine:N \endverbatimsc
1397 \ExplSyntaxOff
1398 \usepackage{fancyvrb}
1399 \DefineVerbatimEnvironment{verbatimsc}{Verbatim}{numbers=left}
1400 \end{examplecode}
1401 % \iffalse
1402 %</example>
1403 % \fi
1404 % Using the package \mypkg{minted}\cite{minted}:
1405 % \iffalse
1406 %<*example>
1407 % \fi
1408 \begin{examplecode}[frame=single]
1409 \ExplSyntaxOn
1410 \cs_undefine:N \verbatimsc
1411 \cs_undefine:N \endverbatimsc
1412 \ExplSyntaxOff
1413 \usepackage{minted}
1414 \newminted{tex}{linenos}
1415 \newenvironment{verbatimsc}{\VerbatimEnvironment\begin{texcode}}{\end{texcode}}
1416 \end{examplecode}
1417 % \iffalse
1418 %</example>
1419 % \fi
1420 % Using the package \mypkg{listings}\cite{listings}:
1421 % \iffalse
1422 %<*example>
1423 % \fi
1424 \begin{examplecode}[frame=single]
1425 \ExplSyntaxOn
1426 \cs_undefine:N \verbatimsc
1427 \cs_undefine:N \endverbatimsc
1428 \ExplSyntaxOff
1429 \usepackage{listings}
1430 \lstnewenvironment{verbatimsc}
1431 {
1432 \lstset{
1433 basicstyle=\small\ttfamily,
1434 columns=fullflexible,
1435 language=[LaTeX]TeX,
1436 numbers=left,
1437 numberstyle=\tiny\color{gray},
1438 keywordstyle=\color{red}
1439 }
1440 }{}
1441 \end{examplecode}
1442 % \iffalse
1443 %</example>
1444 % \fi
1445 %
1446 % \begin{important}*
1447 % At the moment, the \mypkg{fvextra}\cite{fvextra} and \mypkg{fancyvrb}\cite{fancyvrb}
1448 % packages partially support \emph{tagged} \texttt{PDF}.
1449 % \end{important}
1450 %
1451 % \section{Other commands provided}
1452 %
1453 % \subsection{The command \cs{countsc}}
1454 % \label{sec:countsc}
1455 %
1456 % \vspace*{-10pt}
1457 %
1458 % \begin{function}{\countsc}
1459 % \begin{syntax}
1460 % \cmdexamp{countsc}{seq name}
1461 % \end{syntax}
1462 % The command \ics*{countsc} counts a number of \mymeta{stored content} in the
1463 % \emph{sequence} \mymarg{seq name}.
1464 % \end{function}
1465 %
1466 % \subsection{The command \cs{cleanseqsc}}
1467 % \label{sec:cleansc}
1468 %
1469 % \vspace*{-10pt}
1470 %
1471 % \begin{function}{\cleanseqsc}
1472 % \begin{syntax}
1473 % \cmdexamp{cleanseqsc}{seq name}
1474 % \end{syntax}
1475 % The command \ics*{cleanseqsc} removes all \mymeta{stored content} in the
1476 % \emph{sequence} \mymarg{seq name}.
1477 % \end{function}
1478 %
1479 % \section[The \textnormal{\texttt{scontents}} package in action]{The \mypkg*{scontents} package in action}
1480 %
1481 % Remember the abstract on the first page?, this is it:
1482 %
1483 % \getstored{abstract}
1484 %
1485 % And the description of the package?
1486 %
1487 % \getstored{description}
1488 %
1489 % \medskip
1490 %
1491 % I've only written:
1492 %
1493 % \typestored{abstract}
1494 %
1495 % and
1496 %
1497 % \typestored{description}
1498 %
1499 % Of course, I didn't copy and paste. The real code they were written with is:
1500 %
1501 % \iffalse
1502 %<*example>
1503 % \fi
1504 \begin{examplecode}[numbers=left]
1505 \begin{scontents}[store-env=abstract,print-env=true]
1506 \begin{abstract}
1507 This package allows to store \hologo{LaTeX} code, including \enquote{\emph{verbatim}},
1508 in \mymeta{sequences} using the \mypkg{l3seq} module of \mypkg{expl3}. The \mymeta{stored
1509 content} can be used as many times as desired in the document, additionally you can write
1510 to \mymeta{external files} or show it in \mymeta{verbatim style}.
1511 \end{abstract}
1512 \end{scontents}
1513 \end{examplecode}
1514 % \iffalse
1515 %</example>
1516 % \fi
1517 %
1518 % and
1519 %
1520 % \iffalse
1521 %<*example>
1522 % \fi
1523 \begin{examplecode}[numbers=left]
1524 \begin{scontents}[store-env=description, print-env=true]
1525 The \mypkg*{scontents} package allows to \mymeta{store contents} in \mymeta{sequences}
1526 or \mymeta{external files}. In some ways it is similar to the \mypkg{filecontentsdef}
1527 package, with the difference in which the \mymeta{content} is stored. The idea behind
1528 this package is to get an approach to \hologo{ConTeXt} \emph{\enquote{buffers}} by
1529 making use \mymeta{sequences}.
1530 \end{scontents}
1531 \end{examplecode}
1532 % \iffalse
1533 %</example>
1534 % \fi
1535 %
1536 % I stored the content in memory and then ran §\getstored§ and
1537 % §\typestored§. This is one of the ways you can use \mypkg*{scontents}.
1538 %
1539 % \section{Examples}
1540 %
1541 % These are some adapted examples that have served as inspiration for
1542 % the creation of this package. The examples are attached to this documentation
1543 % and can be extracted from your PDF viewer or from the command line by running:
1544 % \iffalse
1545 %<*example>
1546 % \fi
1547 \begin{examplecode}[frame=single]
1548 $ pdfdetach -saveall scontents.pdf
1549 \end{examplecode}
1550 % \iffalse
1551 %</example>
1552 % \fi
1553 % and then you can use the excellent \arara\footnote{The cool \TeX\ automation tool:
1554 % \url{https://www.ctan.org/pkg/arara}} tool to compile them.
1555 %
1556 % \subsection{From \texttt{answers} package}
1557 %
1558 % \subsubsection*{Example 1}
1559 %
1560 % \iffalse
1561 %<*example>
1562 % \fi
1563 \begin{scontents}[write-out=scexamp1.ltx]
1564 % arara: pdflatex
1565 % arara: clean: { extensions: [ aux, log] }
1566 \documentclass{article}
1567 \usepackage[store-cmd=solutions]{scontents}
1568 \newtheorem{ex}{Exercise}
1569 \setlength{\parindent}{0pt}
1570 \pagestyle{empty}
1571 \begin{document}
1572 \section{Problems}
1573 \begin{ex}
1574 First exercise
1575 \Scontents{First solution.}
1576 \end{ex}
1577
1578 \begin{ex}
1579 Second exercise
1580 \Scontents{Second solution.}
1581 \end{ex}
1582
1583 \section{Solutions}
1584 \foreachsc[sep={\\[10pt]}]{solutions}
1585 \end{document}
1586 \end{scontents}
1587 % \iffalse
1588 %</example>
1589 % \fi
1590 %
1591 % Adaptation of example 1 of the package \mypkg{answers}\cite{answers}
1592 % \textattachfile[color=linkcolor,print=false]{scexamp1.ltx}{\faFile*[regular]}.
1593 % \lstinputlisting[language=scontents-doc,numbers=left]{scexamp1.ltx}
1594 %
1595 % \subsection{From \texttt{filecontentsdef} package}
1596 %
1597 % \subsubsection*{Example 2}
1598 %
1599 % \iffalse
1600 %<*example>
1601 % \fi
1602 \begin{scontents}[write-out=scexamp2.ltx]
1603 % arara: pdflatex
1604 % arara: clean: { extensions: [ aux, log] }
1605 \documentclass{article}
1606 \usepackage[store-env=defexercise,store-cmd=defexercise]{scontents}
1607 \setlength{\parindent}{0pt}
1608 \pagestyle{empty}
1609 \begin{document}
1610 % not starred
1611 \Scontents{
1612 Prove that \[x^n+y^n=z^n\] is not solvable in positive integers if $n$ is at
1613 most $-3$.\par
1614 }
1615 % starred
1616 \Scontents*|Refute the existence of black holes in less than $140$ characters.|
1617 % write environment to \jobname.txt
1618 \begin{scontents}[write-env=\jobname.txt]
1619 \def\NSA{NSA}%
1620 Prove that factorization is easily done via probabilistic algorithms and
1621 advance evidence from knowledge of the names of its employees in the
1622 seventies that the \NSA\ has known that for 40 years.\par
1623 \end{scontents}
1624 % see all stored
1625 \begin{itemize}
1626 \foreachsc[before={\item }]{defexercise}
1627 \end{itemize}
1628 % \getstored are robust :)
1629 \section{\getstored[2]{defexercise}}
1630 \end{document}
1631 \end{scontents}
1632 % \iffalse
1633 %</example>
1634 % \fi
1635 %
1636 % Adaptation of example from package \mypkg{filecontentsdef}\cite{filecontentsdef}
1637 % \textattachfile[color=linkcolor,print=false]{scexamp2.ltx}{\faFile*[regular]}.
1638 % \lstinputlisting[language=scontents-doc,numbers=left]{scexamp2.ltx}
1639 %
1640 % \subsection{From TeX-SX}
1641 %
1642 % \subsubsection*{Example 3}
1643 %
1644 % \iffalse
1645 %<*example>
1646 % \fi
1647 \begin{scontents}[write-out=scexamp3.ltx]
1648 % arara: pdflatex
1649 % arara: clean: { extensions: [ aux, log] }
1650 \documentclass{article}
1651 \usepackage[store-cmd=tikz]{scontents}
1652 \usepackage{tikz}
1653 \setlength{\parindent}{0pt}
1654 \pagestyle{empty}
1655 \Scontents{\matrix{ \node (a) {$a$} ; & \node (b) {$b$} ; \\ } ;}
1656 \Scontents{\matrix[ampersand replacement=\&]
1657 { \node (a) {$a$} ; \& \node (b) {$b$} ; \\ } ;}
1658 \Scontents{\matrix{\node (a) {$a$} ; & \node (b) {$b$} ; \\ } ; }
1659 \begin{document}
1660 \section{tikzpicture}
1661 \begin{tikzpicture}
1662 \getstored[1]{tikz}
1663 \end{tikzpicture}
1664
1665 \begin{tikzpicture}
1666 \getstored[2]{tikz}
1667 \end{tikzpicture}
1668
1669 \begin{tikzpicture}
1670 \getstored{tikz}
1671 \end{tikzpicture}
1672
1673 \begin{scontents}[store-env=buffer]
1674 Hello World!
1675
1676 This is a \verb*|fake poor man's buffer :)|.
1677 \end{scontents}
1678
1679 \section{source tikz}
1680 \typestored[1]{tikz}
1681 \typestored[2]{tikz}
1682 \typestored[3]{tikz}
1683
1684 \section{fake buffer}
1685 \subsection{real content}
1686 \getstored[1]{buffer}
1687 \subsection{verbatim style}
1688 \typestored[1]{buffer}
1689 \subsection{meaning}
1690 \meaningsc[1]{buffer}
1691
1692 \section{tikz again}
1693 \foreachsc[before={\begin{tikzpicture}},after={\end{tikzpicture}},sep={\\[10pt]}]{tikz}
1694 \end{document}
1695 \end{scontents}
1696 % \iffalse
1697 %</example>
1698 % \fi
1699 %
1700 % Adapted from \href{https://tex.stackexchange.com/q/5338/7832}{LaTeX equivalent of ConTeXt buffers}
1701 % \textattachfile[color=linkcolor,print=false]{scexamp3.ltx}{\faFile*[regular]}.
1702 % \lstinputlisting[language=scontents-doc,numbers=left]{scexamp3.ltx}
1703 %
1704 % \subsubsection*{Example 4}
1705 %
1706 % \iffalse
1707 %<*example>
1708 % \fi
1709 \begin{scontents}[write-out=scexamp4.ltx]
1710 % arara: pdflatex
1711 % arara: clean: { extensions: [ aux, log] }
1712 \documentclass{article}
1713 \usepackage{scontents}
1714 \setlength{\parindent}{0pt}
1715 \pagestyle{empty}
1716 \begin{document}
1717 \begin{scontents}[store-env=main]
1718 Something for main A.
1719 \end{scontents}
1720
1721 \begin{scontents}[store-env=main]
1722 Something for \verb|main B|.
1723 \end{scontents}
1724
1725 \begin{scontents}[store-env=other]
1726 Something for \verb|other|.
1727 \end{scontents}
1728
1729 \textbf{Let's print them}
1730
1731 This is first stored in main: \getstored[1]{main}\par
1732 This is second stored in main: \getstored{main}\par
1733 This is stored in other: \getstored{other}
1734
1735 \textbf{Print all of stored in main}\par
1736 \foreachsc[sep={\\[10pt]}]{main}
1737 \end{document}
1738 \end{scontents}
1739 % \iffalse
1740 %</example>
1741 % \fi
1742 %
1743 % Adapted from \href{https://tex.stackexchange.com/q/184503/7832}{Collecting contents of environment and store them for later retrieval}
1744 % \textattachfile[color=linkcolor,print=false]{scexamp4.ltx}{\faFile*[regular]}.
1745 % \lstinputlisting[language=scontents-doc,numbers=left]{scexamp4.ltx}
1746 %
1747 % \subsubsection*{Example 5}
1748 %
1749 % \iffalse
1750 %<*example>
1751 % \fi
1752 \begin{scontents}[write-out=scexamp5.ltx]
1753 % arara: pdflatex
1754 % arara: clean: { extensions: [ aux, log] }
1755 \documentclass{article}
1756 \usepackage{scontents}
1757 \setlength{\parindent}{0pt}
1758 \pagestyle{empty}
1759 \begin{document}
1760 \section{Problem stated the first time}
1761 \begin{scontents}[print-env=true,store-env=problem]
1762 This is normal text.
1763 \verb|This is from the verb command.|
1764 \verb*|This is from the verb* command.|
1765 This is normal text.
1766 \begin{verbatim}
1767 This is from the verbatim environment:
1768 &%{}~
1769 \end{verbatim}
1770 \end{scontents}
1771 \section{Problem restated}
1772 \getstored[1]{problem}
1773 \section{Problem restated once more}
1774 \getstored[1]{problem}
1775 \end{document}
1776 \end{scontents}
1777 % \iffalse
1778 %</example>
1779 % \fi
1780 %
1781 % Adapted from \href{https://tex.stackexchange.com/q/373647/7832}{Collect contents of an environment (that contains verbatim content)}
1782 % \textattachfile[color=linkcolor,print=false]{scexamp5.ltx}{\faFile*[regular]}.
1783 % \lstinputlisting[language=scontents-doc,numbers=left]{scexamp5.ltx}
1784 %
1785 % \subsubsection*{Example 6}
1786 %
1787 % \iffalse
1788 %<*example>
1789 % \fi
1790 \begin{scontents}[write-out=scexamp6.ltx]
1791 % arara: pdflatex
1792 % arara: clean: { extensions: [ aux, log] }
1793 \documentclass[10pt]{article}
1794 \usepackage{scontents}
1795 \newenvsc{forshort}[store-env=forshort,print-env=false]
1796 \setlength{\parindent}{0pt}
1797 \pagestyle{empty}
1798 \begin{document}
1799
1800 Something in the whole course.
1801
1802 \begin{forshort}
1803 Just a summary...
1804 \end{forshort}
1805
1806 \end{document}
1807 \end{scontents}
1808 % \iffalse
1809 %</example>
1810 % \fi
1811 %
1812 % Adapted from \href{https://tex.stackexchange.com/q/509595/7832}{Environment hiding its content}
1813 % \textattachfile[color=linkcolor,print=false]{scexamp6.ltx}{\faFile*[regular]}.
1814 % \lstinputlisting[language=scontents-doc,numbers=left]{scexamp6.ltx}
1815 %
1816 % \subsection{Customization of \texttt{verbatimsc}}
1817 %
1818 % \subsubsection*{Example 7}
1819 %
1820 % \iffalse
1821 %<*example>
1822 % \fi
1823 \begin{scontents}[write-out=scexamp7.ltx]
1824 % arara: pdflatex
1825 % arara: clean: { extensions: [ aux, log] }
1826 \documentclass{article}
1827 \usepackage{scontents}
1828 \ExplSyntaxOn
1829 \cs_undefine:N \verbatimsc
1830 \cs_undefine:N \endverbatimsc
1831 \ExplSyntaxOff
1832 \usepackage{fvextra}
1833 \usepackage{xcolor}
1834 \definecolor{mygray}{gray}{0.9}
1835 \usepackage{tcolorbox}
1836 \newenvironment{verbatimsc}%
1837 {\VerbatimEnvironment
1838 \begin{tcolorbox}[colback=mygray, boxsep=0pt, arc=0pt, boxrule=0pt]
1839 \begin{Verbatim}[fontsize=\scriptsize, breaklines, breakafter=*, breaksymbolsep=0.5em,
1840 breakaftersymbolpre={\,\tiny\ensuremath{\rfloor}}]}%
1841 {\end{Verbatim}%
1842 \end{tcolorbox}}
1843 \setlength{\parindent}{0pt}
1844 \pagestyle{empty}
1845 \begin{document}
1846 \section{Test \texttt{\textbackslash begin\{scontents\}} with \texttt{fancyvrb}}
1847 Test \verb+{scontents}+ \par
1848
1849 \begin{scontents}
1850 Using \verb+scontents+ env no \verb+[key=val]+, save in seq \verb+contents+
1851 with index 1.
1852
1853 Prove new \Verb*{ fancyvrb with braces } and environment \verb+Verbatim*+
1854 \begin{verbatim}
1855 verbatim environment
1856 \end{verbatim}
1857 \end{scontents}
1858
1859 \section{Test \texttt{\textbackslash Scontents} with \texttt{fancyvrb}}
1860 \Scontents{ We have coded this in \LaTeX: $E=mc^2$.}
1861
1862 \section{Test \texttt{\textbackslash getstored}}
1863 \getstored[1]{contents}\par
1864 \getstored{contents}
1865
1866 \section{Test \texttt{\textbackslash meaningsc}}
1867 \meaningsc[1]{contents}\par
1868 \meaningsc[2]{contents}
1869
1870 \section{Test \texttt{\textbackslash typestored}}
1871 \typestored[1]{contents}
1872 \typestored[2]{contents}
1873 \end{document}
1874 \end{scontents}
1875 % \iffalse
1876 %</example>
1877 % \fi
1878 %
1879 % Customization of \myenv*{verbatimsc} using the \mypkg{fvextra}\cite{fvextra} and
1880 % \mypkg{tcolorbox}\cite{tcolorbox} package
1881 % \textattachfile[color=linkcolor,print=false]{scexamp7.ltx}{\faFile*[regular]}.
1882 % \lstinputlisting[language=scontents-doc,numbers=left]{scexamp7.ltx}
1883 %
1884 % \subsubsection*{Example 8}
1885 %
1886 % \iffalse
1887 %<*example>
1888 % \fi
1889 \begin{scontents}[write-out=scexamp8.ltx]
1890 % arara: pdflatex
1891 % arara: clean: { extensions: [ aux, log] }
1892 \documentclass{article}
1893 \usepackage{scontents}
1894 \ExplSyntaxOn
1895 \cs_undefine:N \verbatimsc
1896 \cs_undefine:N \endverbatimsc
1897 \ExplSyntaxOff
1898 \usepackage{xcolor}
1899 \usepackage{listings}
1900 \lstnewenvironment{verbatimsc}
1901 {
1902 \lstset{
1903 basicstyle=\small\ttfamily,
1904 breaklines=true,
1905 columns=fullflexible,
1906 language=[LaTeX]TeX,
1907 numbers=left,
1908 numbersep=1em,
1909 numberstyle=\tiny\color{gray},
1910 keywordstyle=\color{red}
1911 }
1912 }{}
1913 \setlength{\parindent}{0pt}
1914 \pagestyle{empty}
1915 \begin{document}
1916 \section{Test \texttt{\textbackslash begin\{scontents\}} with \texttt{listings}}
1917 Test \verb+{scontents}+ \par
1918
1919 \begin{scontents}
1920 Using \verb+scontents+ env no \verb+[key=val]+, save in seq \verb+contents+ with index 1.\par
1921
1922 Prove \lstinline[basicstyle=\ttfamily]| lstinline | and environment \verb+Verbatim*+
1923 \begin{verbatim}
1924 verbatim environment
1925 \end{verbatim}
1926 \end{scontents}
1927
1928 \section{Test \texttt{\textbackslash Scontents*} with \texttt{listings}}
1929
1930 \Scontents*+We have coded this in \lstinline[basicstyle=\ttfamily]|\LaTeX: $E=mc^2$|
1931 and more.+
1932
1933 \section{Test \texttt{\textbackslash getstored}}
1934 \getstored{contents}\par
1935 \getstored[1]{contents}
1936
1937 \section{Test \texttt{\textbackslash typestored}}
1938 \typestored[1]{contents}
1939 \typestored[2]{contents}
1940 \end{document}
1941 \end{scontents}
1942 % \iffalse
1943 %</example>
1944 % \fi
1945 %
1946 % Customization of \myenv*{verbatimsc} using the \mypkg{listings}\cite{listings} package
1947 % \textattachfile[color=linkcolor,print=false]{scexamp8.ltx}{\faFile*[regular]}.
1948 % \lstinputlisting[language=scontents-doc,numbers=left]{scexamp8.ltx}
1949 %
1950 % \subsubsection*{Example 9}
1951 %
1952 % \iffalse
1953 %<*example>
1954 % \fi
1955 \begin{scontents}[write-out=scexamp9.ltx]
1956 % arara: xelatex: {shell: true, options: [-8bit]}
1957 % arara: xelatex: {shell: true, options: [-8bit]}
1958 % arara: clean: { extensions: [ aux, log] }
1959 \documentclass{article}
1960 \usepackage{scontents}
1961 \ExplSyntaxOn
1962 \cs_undefine:N \verbatimsc
1963 \cs_undefine:N \endverbatimsc
1964 \ExplSyntaxOff
1965 \usepackage{minted}
1966 \newminted{tex}{linenos}
1967 \newenvironment{verbatimsc}{\VerbatimEnvironment\begin{texcode}}{\end{texcode}}
1968 \pagestyle{empty}
1969 \setlength{\parindent}{0pt}
1970 \begin{document}
1971 \section{Test \texttt{\textbackslash begin\{scontents\}} with \texttt{minted}}
1972 Test \verb+{scontents}+ \par
1973
1974 \begin{scontents}[overwrite,write-env=\jobname.tsc,force-eol=true]
1975 Using \verb+scontents+ env no \verb+[key=val]+, save in seq \verb+contents+
1976 with index 1.\par
1977
1978 Prove new \Verb*{ new fvextra with braces } and environment \verb+Verbatim*+
1979 \begin{Verbatim}[obeytabs, showtabs, tab=\rightarrowfill, tabcolor=red]
1980 No tab
1981 One real tab
1982 Two real Tab plus one tab
1983 \end{Verbatim}
1984 \end{scontents}
1985
1986 \section{See \Verb{\jobname.tsc}}
1987 Read \Verb{\jobname.tsc} (shows TABs as red arrows):
1988 \VerbatimInput[obeytabs, showtabs, tab=\rightarrowfill, tabcolor=red]{\jobname.tsc}
1989
1990 \section{Test \texttt{\textbackslash Scontents} with \texttt{minted}}
1991
1992 \Scontents{ We have coded \par this in \LaTeX: $E=mc^2$.}
1993
1994 \section{Test \texttt{\textbackslash getstored}}
1995 \getstored[1]{contents}\par
1996 \getstored{contents}
1997
1998 \section{Test \texttt{\textbackslash typestored}}
1999 \typestored[1]{contents}
2000 \typestored[2]{contents}
2001 \end{document}
2002 \end{scontents}
2003 % \iffalse
2004 %</example>
2005 % \fi
2006 %
2007 % Customization of \myenv*{verbatimsc} using the \mypkg{minted}\cite{minted} package
2008 % \textattachfile[color=linkcolor,print=false]{scexamp9.ltx}{\faFile*[regular]}.
2009 % \lstinputlisting[language=scontents-doc,numbers=left]{scexamp9.ltx}
2010 %
2011 % \subsection{The command \texttt{\textbackslash{}mergesc} in action}
2012 %
2013 % \iffalse
2014 %<*example>
2015 % \fi
2016 \begin{scontents}[write-out=scexamp10.ltx]
2017 % arara: pdflatex
2018 % arara: clean: { extensions: [ aux, log] }
2019 \documentclass{article}
2020 \usepackage{scontents}
2021 % Fix part of a MCE that should go before babel's loading
2022 \begin{scontents}[store-env=mce]
2023 \documentclass[french]{article}
2024 \usepackage[T1]{fontenc}
2025 \usepackage[utf8]{inputenc}
2026 \usepackage{lmodern}
2027 \usepackage[a4paper]{geometry}
2028 \end{scontents}
2029 % Fix part of a MCE that should go after (>=) babel's loading
2030 \begin{scontents}[store-env=mce]
2031 \usepackage{babel}
2032 \begin{document}
2033 \end{scontents}
2034 % Fix part of a MCE that should go after its body
2035 \begin{scontents}[store-env=mce]
2036 \end{document}
2037 \end{scontents}
2038 \begin{document}
2039 \section{First annswer}
2040 % Variable part of a MCE that should added to the fixed preamble, before babel's loading
2041 \begin{scontents}[store-env=mce-1]
2042 \usepackage{amsmath}
2043 \end{scontents}
2044 % Variable part of a MCE being the code snippet
2045 \begin{scontents}[store-env=mce-1]
2046 \begin{align}
2047 0 & \neq 1 \\
2048 1 & \neq 0
2049 \end{align}
2050 \end{scontents}
2051 \begin{description}
2052 \item[Preamble's addition]\leavevmode
2053 \typestored[1]{mce-1}
2054 \item[Code snippet]\leavevmode
2055 \typestored[2]{mce-1}
2056 \item[MCE]\leavevmode
2057 \mergesc[typestored, print-cmd=true]
2058 {
2059 {mce}[1], {mce-1}[1], {mce}[2], {mce-1}[2], {mce}[3]
2060 }
2061 \end{description}
2062 \section{Second annswer}
2063 % Variable part of a MCE that should added to the fixed preamble, before babel's loading
2064 \begin{scontents}[store-env=mce-2]
2065 \usepackage{amsmath}
2066 \end{scontents}
2067 % Variable part of a MCE being the code snippet
2068 \begin{scontents}[store-env=mce-2]
2069 \begin{flalign}
2070 0 & \neq 1 \\
2071 1 & \neq 0
2072 \end{flalign}
2073 \end{scontents}
2074
2075 \begin{description}
2076 \item[Preamble's addition]\leavevmode
2077 \typestored[1]{mce-2}
2078 \item[Code snippet]\leavevmode
2079 \typestored[2]{mce-2}
2080 \item[MCE]\leavevmode
2081 \mergesc[typestored, print-cmd=true, write-out=mce.txt, overwrite=true]
2082 {
2083 {mce}[1], {mce-2}[1], {mce}[2], {mce-2}[2], {mce}[3]
2084 }
2085 \end{description}
2086 \end{document}
2087 \end{scontents}
2088 % \iffalse
2089 %</example>
2090 % \fi
2091 % The command §\mergesc§ in action, adapted from Denis Bitouzé request
2092 % at \url{https://github.com/pablgonz/scontents/issues/2}
2093 % \textattachfile[color=linkcolor,print=false]{scexamp10.ltx}{\faFile*[regular]}.
2094 % \lstinputlisting[language=scontents-doc,numbers=left]{scexamp10.ltx}
2095 %
2096 % \subsection{The tagged PDF example}
2097 %
2098 % \iffalse
2099 %<*example>
2100 % \fi
2101 \begin{scontents}[write-out=scexamp11.ltx]
2102 % arara: lualatex
2103 % arara: lualatex
2104 % arara: clean: { extensions: [ aux, log] }
2105 \DocumentMetadata{tagging=on, lang=en-US, pdfversion=2.0, pdfstandard=ua-2}
2106 \documentclass{article}
2107 \usepackage{scontents,unicode-math,hyperref}
2108 \hypersetup{pdftitle = {Test scontents package},}
2109 \begin{document}
2110 Some
2111
2112 \begin{scontents}[print-env=true]
2113 First code \verb|\foo|
2114
2115 And more code \verb|\bar|
2116 \end{scontents}
2117
2118 Text
2119
2120 \begin{scontents}[print-env=true]
2121 Second code \verb|\foo|
2122
2123 And more code \verb|\bar|
2124 \end{scontents}
2125
2126 Text
2127
2128 \Scontents*{code \verb|\baz|}
2129
2130 % \typestored
2131 \typestored[1]{contents}
2132
2133 % \mergesc
2134 \mergesc[typestored]{ {contents}[1-end] }
2135
2136 % \getstored
2137 \getstored[2]{contents}
2138 \end{document}
2139 \end{scontents}
2140 % \iffalse
2141 %</example>
2142 % \fi
2143 %
2144 % This example is just to show the compatibility of \mypkg*{scontents} with
2145 % \emph{tagged} \texttt{PDF} using |lualatex|. The attached files here
2146 % are just for testing \textattachfile[color=linkcolor,print=false]{scexamp11.ltx}{\faFile*[regular]}.
2147 % \lstinputlisting[language=scontents-doc,numbers=left]{scexamp11.ltx}
2148 %
2149 % \begin{important}*
2150 % This example have been checked using \href{https://dev.verapdf-rest.duallab.com}{\texttt{veraPDF}}
2151 % together with \href{https://ngpdf.com}{\texttt{ngpdf}}.
2152 % \end{important}
2153 %
2154 %
2155 % \newpage
2156 %
2157 % \section{Change history}
2158 % \label{sec:changes}
2159 %
2160 % In this section you will find some (not all) of the changes in \mypkg*{scontents}
2161 % development, from the first public implementation using the \mypkg{filecontentsdef}\cite{filecontentsdef}
2162 % package to the current version with only \mypkg{expl3}\cite{expl3}.
2163 %
2164 % \medskip
2165 %
2166 % \setlist[itemize,1]{label=\textendash,wide=0.5em,nosep,noitemsep,leftmargin=10pt}
2167 % \newlength\descrwidth
2168 % \settowidth{\descrwidth}{\textsf{v1.0a, (ctan), 2019-07-30} }
2169 %
2170 % \begin{description}[font=\small\sffamily,wide=0pt,style=multiline,leftmargin=\descrwidth,nosep,noitemsep]
2171 % \item [\fileversion{} (ctan), \filedate]
2172 % \begin{itemize}
2173 % \item Internal environment §verbatimsc§ update for \emph{tagged} \texttt{PDF}.
2174 % \item Update requirement to \hologo{LaTeX} release 2025-11-01.
2175 % \end{itemize}
2176 % \item [v2.5 (ctan), 2025-11-01]
2177 % \begin{itemize}
2178 % \item Replacing §\scantokens§ (primitive) with §\tl_retokenize:n§.
2179 % \item Cleanup warnings and details returned by |expltools|.
2180 % \item Update minimum required of \mypkg{expl3} to 2025-07-08.
2181 % \end{itemize}
2182 % \item [v2.4 (ctan), 2025-05-15]
2183 % \begin{itemize}
2184 % \item Optimization of expansion code from `§x§' to `§e§'.
2185 % \item Restructuring code for documentation and implementation.
2186 % \item Add new keys for §\typestored§ and §\meaningsc§.
2187 % \item Check the version of \mypkg{expl3} in \hologo{plainTeX} and \hologo{ConTeXt}.
2188 % \end{itemize}
2189 % \item [v2.3 (ctan), 2025-04-23]
2190 % \begin{itemize}
2191 % \item Adapting the §verbatimsc§ environment for \emph{tagged} \texttt{PDF}.
2192 % \item Update minimum required to \LaTeX{} release 2024-11-01.
2193 % \item Safer code for replacement §\obeyedline§.
2194 % \end{itemize}
2195 % \item [v2.2 (ctan), 2025-03-26]
2196 % \begin{itemize}
2197 % \item Fix internal definition for some functions.
2198 % \item Replace §\peek_charcode_ignore_spaces:NTF§ by §\peek_charcode:NTF§.
2199 % \item Set correct code for §\obeyedline§ implement in \LaTeX{} release 2024-06-01.
2200 % \end{itemize}
2201 % \item [v2.1 (ctan), 2024-06-14]
2202 % \begin{itemize}
2203 % \item Fix §\cleanseqsc§ command.
2204 % \item Add §\mergesc§ command.
2205 % \item Fix internal definition for seq var.
2206 % \item Fix internal code for §\typestored§.
2207 % \item Replace §\cs_argument_spec:N§ by §\cs_parameter_spec:N§.
2208 % \item Detect \mypkg{l3keys2e} package (obsolete in june 2022 \LaTeX{} release).
2209 % \item Minor adjustments in the documentation.
2210 % \end{itemize}
2211 % \item [v2.0 (ctan), 2022-04-04]
2212 % \begin{itemize}
2213 % \item Adapting the §verbatimsc§ environment (compatibility \mypkg{verbatim} package).
2214 % \item Removed compatibility layer for older \hologo{LaTeX} releases.
2215 % \item Fix loader in \hologo{plainTeX} and \hologo{ConTeXt}.
2216 % \item Minor adjustments in the documentation.
2217 % \end{itemize}
2218 % \item [v1.9 (ctan), 2020-01-21]
2219 % \begin{itemize}
2220 % \item Update and improvements in the internal code.
2221 % \item Updating the generic code for |I/O| verification.
2222 % \item Add §write-cmd§ and §write-out§ keys for §\Scontents*§.
2223 % \item Fix §sep§ key in §\foreachsc§.
2224 % \end{itemize}
2225 % \item [v1.8 (ctan), 2019-11-18]
2226 % \begin{itemize}
2227 % \item Add §\newenvsc§ command.
2228 % \item Fix nested environment in \hologo{plainTeX} and \hologo{ConTeXt}.
2229 % \item Modified default value in §\getstored§.
2230 % \item Add §overwrite§ key to reduce |I/O| operations.
2231 % \item Deleted an unnecessary group in the code.
2232 % \end{itemize}
2233 % \item [v1.7 (ctan), 2019-10-29]
2234 % \begin{itemize}
2235 % \item The §verbatimsc§ environment was rewritten.
2236 % \item Minor adjustments in documentation.
2237 % \end{itemize}
2238 % \item [v1.6 (ctan), 2019-10-26]
2239 % \begin{itemize}
2240 % \item The internal behavior of §\getstored§ has been modified.
2241 % \item The internal behavior of §\foreachsc§ has been modified.
2242 % \item Corrected file extension for \hologo{ConTeXt}.
2243 % \item Remove spurious warning.
2244 % \end{itemize}
2245 % \item [v1.5 (ctan), 2019-10-24]
2246 % \begin{itemize}
2247 % \item Add support for \hologo{plainTeX} and \hologo{ConTeXt}.
2248 % \item Split internal code for optimization.
2249 % \item Add support for vertical spaces in \myoarg{key \textnormal{\textcolor{gray}{=}} val}.
2250 % \item Add §\foreachsc§ command.
2251 % \item Check if \mypkg{verbatim} package is loaded.
2252 % \end{itemize}
2253 % \item [v1.4 (ctan), 2019-10-03]
2254 % \begin{itemize}
2255 % \item Add §store-all§ key.
2256 % \item Messages and keys were separated.
2257 % \item Restructuring of documentation.
2258 % \item Now the version of \mypkg{expl3} is checked instead of \mypkg{xparse}.
2259 % \item The internal behavior of §force-eol§ has been modified.
2260 % \end{itemize}
2261 % \item [v1.3 (ctan), 2019-09-24]
2262 % \begin{itemize}
2263 % \item The environment §scontents§ can now nest.
2264 % \item Added §force-eol§, §verb-font§ and §width-tab§ keys.
2265 % \item The extra space has been removed when you run §\getstored§.
2266 % \item Internal code has been rewritten more efficiently.
2267 % \item Remove \emph{starred argument} `§*§' for §\typestored§.
2268 % \item Remove \mypkg{filecontentsdef} dependency.
2269 % \item Changing §\regex_replace_all:§ for §\tl_replace_all:§.
2270 % \end{itemize}
2271 % \item [v1.2 (ctan), 2019-08-28]
2272 % \begin{itemize}
2273 % \item Restructuring of documentation.
2274 % \item Added copy of §\tex_scantokens:§.
2275 % \end{itemize}
2276 % \item [v1.1 (ctan), 2019-08-12]
2277 % \begin{itemize}
2278 % \item Extension of documentation.
2279 % \item Replace §\tex_endinput:D§ by §\file_input_stop:§.
2280 % \end{itemize}
2281 % \item [v1.0 (ctan), 2019-07-30]
2282 % \begin{itemize}
2283 % \item First public release.
2284 % \end{itemize}
2285 % \end{description}
2286 %
2287 % \newpage
2288 %
2289 % \indexprologue{
2290 % The italic numbers denote the pages where the corresponding entry is
2291 % described.}
2292 %
2293 % \printindex[userdoc]
2294 %
2295 % \let\stdsection\section
2296 % \def\section*#1{\stdsection{#1}}
2297 %
2298 % \begin{thebibliography}{10}
2299 % \bibitem{expl3} The \hologo{LaTeX} Project. \enquote{The \textsf{expl3}
2300 % package}. Available from
2301 % \textsc{ctan}, \url{https://www.ctan.org/pkg/expl3}, 2025.
2302 %
2303 % \bibitem{filecontentsdef} \textsc{Burnol, Jean François}. \enquote{The
2304 % \textsf{filecontentsdef} package}. Available from
2305 % \textsc{ctan}, \url{https://ctan.org/pkg/filecontentsdef}, 2019.
2306 %
2307 % \bibitem{xparse} The \hologo{LaTeX} Project. \enquote{The \textsf{xparse}
2308 % package}. Available from
2309 % \textsc{ctan}, \url{https://www.ctan.org/pkg/xparse}, 2024.
2310 %
2311 % \bibitem{xsim} \textsc{Niederberger, Clemens}. \enquote{\textsf{xsim} – eXercise
2312 % Sheets IMproved}. Available from
2313 % \textsc{ctan}, \url{https://www.ctan.org/pkg/xsim}, 2023.
2314 %
2315 % \bibitem{fancyvrb} \textsc{Van Zandt, Timothy}. \enquote{The \textsf{fancyvrb}
2316 % package - Fancy Verbatims in \hologo{LaTeX}}. Available from
2317 % \textsc{ctan}, \url{https://www.ctan.org/pkg/fancyvrb}, 2024.
2318 %
2319 % \bibitem{listings} \textsc{Hoffmann, Jobst}. \enquote{The \textsf{listings}
2320 % package}. Available from
2321 % \textsc{ctan}, \url{https://www.ctan.org/pkg/listings}, 2024.
2322 %
2323 % \bibitem{fvextra} \textsc{Poore, Geoffrey M}. \enquote{The \textsf{fvextra}
2324 % package - Highlighted source code in \hologo{LaTeX}}. Available from
2325 % \textsc{ctan}, \url{https://www.ctan.org/pkg/minted}, 2025.
2326 %
2327 % \bibitem{minted} \textsc{Poore, Geoffrey M}. \enquote{The \textsf{minted}
2328 % package - Highlighted source code in \hologo{LaTeX}}. Available from
2329 % \textsc{ctan}, \url{https://www.ctan.org/pkg/minted}, 2025.
2330 %
2331 % \bibitem{inter3} The \hologo{LaTeX} Project. \enquote{The \hologo{LaTeX}3
2332 % Interfaces}. Available from
2333 % \textsc{ctan}, \url{https://www.ctan.org/pkg/l3kernel}, 2025.
2334 %
2335 % \bibitem{latex2e} The \hologo{LaTeX} Project. \enquote{The \hologo{LaTeX2e}
2336 % sources}. Available from
2337 % \textsc{ctan}, \url{https://ctan.org/tex-archive/macros/latex/base}, 2025.
2338 %
2339 % \bibitem{userguide} The \hologo{LaTeX} Project. \enquote{\hologo{LaTeX} for authors
2340 % current version}. Available from
2341 % \textsc{ctan}, \url{https://ctan.org/pkg/latex-base}, 2025.
2342 %
2343 % \bibitem{tagpdf} \textsc{Fischer, Ulrike}. \enquote{\textsf{tagpdf} – \hologo{LaTeX}
2344 % kernel code for PDF tagging}. Available from
2345 % \textsc{ctan}, \url{https://www.ctan.org/pkg/tagpdf}, 2025.
2346 %
2347 % \bibitem{latexlab} The \hologo{LaTeX} Project. \enquote{\textsf{latex-lab} – \hologo{LaTeX}
2348 % laboratory}. Available from
2349 % \textsc{ctan}, \url{https://www.ctan.org/pkg/latex-lab}, 2025.
2350 %
2351 % \bibitem{tcolorbox} \textsc{F. Sturm, Thomas}. \enquote{\textsf{tcolorbox} – Coloured boxes,
2352 % for \hologo{LaTeX} examples and theorems, etc}. Available from
2353 % \textsc{ctan}, \url{https://ctan.org/pkg/tcolorbox}, 2025.
2354 %
2355 % \bibitem{verbatim} The \hologo{LaTeX} Project. \enquote{\textsf{verbatim} – Reimplementation
2356 % of and extensions to \hologo{LaTeX} \textsf{verbatim}}. Available from
2357 % \textsc{ctan}, \url{https://www.ctan.org/pkg/verbatim}, 2023.
2358 %
2359 % \bibitem{keyval} \textsc{Wright, Joseph}. \enquote{Programming
2360 % \textsf{key–value} in \textsf{expl3}}. Available from
2361 % \textsc{TUGboat},
2362 % \url{https://www.tug.org/TUGboat/tb31-1/tb97wright-l3keys.pdf}, 2010.
2363 %
2364 % \bibitem{answers} \textsc{Wright, Joseph}. \enquote{\textsf{answers} – Setting
2365 % questions (or exercises) and answers}. Available from
2366 % \textsc{ctan},
2367 % \url{https://ctan.org/pkg/answers}, 2014.
2368 % \end{thebibliography}
2369 %
2370 % \let\section\stdsection
2371 %
2372 % \newpage
2373 %
2374 % \StartImplementation
2375 %
2376 % \StopEventually{^^A
2377 % \newgeometry{top=0.5in,bottom=0.3in,left=1.0in,right=0.5in,footskip=0.2in,headheight=1cm,headsep=0.27cm}
2378 % \addtocontents{toc}{\protect\setcounter{tocdepth}{2}}
2379 % \cleardoublepage
2380 % \phantomsection
2381 % \indexprologue{
2382 % The italic numbers denote the pages where the corresponding entry is
2383 % described, the numbers underlined and all others indicate the line on
2384 % which they are implemented in the package code.
2385 % }
2386 % \printindex
2387 % }
2388 %
2389 % \section{Implementation}
2390 % \label{sec:Implementation}
2391 % \addtocontents{toc}{\protect\setcounter{tocdepth}{0}}
2392 %
2393 % The most recent publicly released version of \mypkg*{scontents} is available at
2394 % \textsc{ctan}: \url{https://www.ctan.org/pkg/scontents}. Historical and
2395 % developmental versions are available at \textcolor{gray}{\scriptsize\faIcon[regular]{github}}
2396 % \url{https://github.com/pablgonz/scontents}. While general feedback via email is
2397 % welcomed, specific bugs or feature requests should be reported through the issue
2398 % tracker: \url{https://github.com/pablgonz/scontents/issues}.
2399 %
2400 % \begin{important}*
2401 % All variables and functions defined in this package are private and
2402 % are NOT intended to work or be used by another package or module.
2403 % \end{important}
2404 %
2405 % \subsection{Declaration of the package}
2406 %
2407 % First we set up the module name for \pkg{DocStrip} \pkg{l3doc} class:
2408 % \begin{macrocode}
2409 %<@@=scontents>
2410 % \end{macrocode}
2411 %
2412 % Now we define some common macros to hold the package date and version:
2413 % \begin{macrocode}
2414 %<*loader>
2415 \def\ScontentsFileDate{2025-11-20}%
2416 \def\ScontentsFileVersion{2.6}%
2417 \def\ScontentsFileDescription{Stores LaTeX contents in memory or files}%
2418 % \end{macrocode}
2419 %
2420 % The \LaTeX{} loader is quite simple, we just need to make sure of the
2421 % minimum version for correct operation and then set interfaces up.
2422 % The choice of \LaTeX{} release 2025-11-01 is the latest available in
2423 % \TeX{} Live 2025 and is necessary to be able to implement
2424 % the package's full compatibility with \emph{tagged} \texttt{PDF}.
2425 %
2426 % \begin{macrocode}
2427 %<*latex>
2428 \NeedsTeXFormat{LaTeX2e}[2025-11-01]
2429 \ProvidesExplPackage
2430 {scontents} {\ScontentsFileDate} {\ScontentsFileVersion} {\ScontentsFileDescription}
2431 %</latex>
2432 % \end{macrocode}
2433 %
2434 % \subsubsection{Load \texttt{expl3-generic} and \texttt{xparse-generic} in \hologo{plainTeX} and \hologo{ConTeXt}}\label{comp:layer}
2435 %
2436 % \begin{macro}[int]{\c_@@_version_str, \l_@@_char_value_int}
2437 % The \hologo{plainTeX} and \hologo{ConTeXt} loaders are similar
2438 % (probably because I don't know how to make a proper \hologo{ConTeXt}
2439 % module :-). We define a string variable \cs{c_@@_version_str} with
2440 % version info (just in case) and add §\ExplSyntaxOn§ to be able to load
2441 % the frozen \mypkg{xparse}\cite{xparse}.
2442 % \begin{macrocode}
2443 %<*!latex>
2444 %<context>\writestatus{loading}{User Module scontents v\ScontentsFileVersion}
2445 %<context>\unprotect
2446 \input expl3-generic.tex
2447 \ExplSyntaxOn
2448 \str_const:ce { c_@@_version_str } { \ScontentsFileDate\space
2449 v\ScontentsFileVersion\space \ScontentsFileDescription }
2450 \iow_log:e { Package: ~ scontents ~ \str_use:c { c_@@_version_str } }
2451 % \end{macrocode}
2452 % Outside of \LaTeX{} we can't usually use \mypkg{xparse}\cite{xparse}
2453 % now \mypkg{ltcmd}\cite{latex2e} part of the \LaTeX{} kernel. However
2454 % since the old \mypkg{xparse}\cite{xparse} provide \texttt{xparse-generic.tex}
2455 % is loadable in any format.
2456 % \begin{macrocode}
2457 \int_new:N \l_@@_char_value_int
2458 \int_set:Nn \l_@@_char_value_int { \char_value_catcode:n { `\@ } }
2459 \char_set_catcode_letter:N \@
2460 \file_input:n { xparse-generic.tex }
2461 \char_set_catcode:nn { `\@ } { \l_@@_char_value_int }
2462 %</!latex>
2463 % \end{macrocode}
2464 % \end{macro}
2465 %
2466 % \subsubsection{Checking \texttt{expl3} version}
2467 %
2468 % For \hologo{plainTeX}, \hologo{LaTeX} and \hologo{ConTeXt} we must check
2469 % the minimum requirement, in this case §\tl_retokenize:n§ which
2470 % was added in release 2025-07-08 of \mypkg{expl3} included in
2471 % \hologo{TeX} Live 2025.
2472 % \begin{macrocode}
2473 \cs_if_exist:NF \tl_retokenize:n
2474 {
2475 \msg_new:nnn { scontents } { expl-too-old }
2476 {
2477 Please~install~an~up~to~date~TeX~distribution~or~update~using~
2478 your~TeX~package~manager~or~from~CTAN. \\
2479 See~documentation.~Loading~scontents~will~abort!
2480 }
2481 \msg_fatal:nn { scontents } { expl-too-old }
2482 \ExplSyntaxOff
2483 \file_input_stop:
2484 }
2485 % \end{macrocode}
2486 %
2487 % \subsubsection{Preventing double loading in \hologo{plainTeX}}
2488 %
2489 % In \hologo{plainTeX}, check that the package isn't being loaded twice
2490 % (\LaTeX{} and \hologo{ConTeXt} already defend against that):
2491 % \begin{macrocode}
2492 %<*plain>
2493 \tl_if_exist:NT \l_@@_cmd_name_tl
2494 {
2495 \msg_new:nnn { scontents } { already-loaded }
2496 {
2497 The~'scontents'~package~is~already~loaded.~Aborting~input~\msg_line_context:.
2498 }
2499 \msg_warning:nn { scontents } { already-loaded }
2500 \ExplSyntaxOff
2501 \file_input_stop:
2502 }
2503 %</plain>
2504 %</loader>
2505 % \end{macrocode}
2506 %
2507 % \subsubsection{Checking proper loader}
2508 %
2509 % Checking that the package was loaded with the proper loader code. This code
2510 % was copied from \texttt{expl3-code.tex}.
2511 % \begin{macrocode}
2512 %<*core>
2513 \def\ScontentsCoreFileDate{2025-11-20}%
2514 \begingroup
2515 \catcode32=10
2516 \endlinechar=32
2517 \def\next{\endgroup}%
2518 \expandafter\ifx\csname PackageError\endcsname\relax
2519 \begingroup
2520 \def\next{\endgroup\endgroup}%
2521 \def\PackageError#1#2#3%
2522 {%
2523 \endgroup
2524 \errhelp{#3}%
2525 \errmessage{#1 Error: #2!}%
2526 }%
2527 \fi
2528 \expandafter\ifx\csname ScontentsFileDate\endcsname\relax
2529 \def\next
2530 {%
2531 \PackageError{scontents}{No scontents loader detected}
2532 {%
2533 You have attempted to use the scontents code directly rather than using
2534 the correct loader. Loading of scontents will abort.
2535 }%
2536 \endgroup
2537 \endinput
2538 }%
2539 \else
2540 \ifx\ScontentsFileDate\ScontentsCoreFileDate
2541 \else
2542 \def\next
2543 {%
2544 \PackageError{scontents}{Mismatched scontents files detected}
2545 {%
2546 You have attempted to load scontents with mismatched files:
2547 probably you have one or more files 'locally installed' which
2548 are in conflict. Loading of scontents will abort.
2549 }%
2550 \endgroup
2551 \endinput
2552 }%
2553 \fi
2554 \fi
2555 \next
2556 %</core>
2557 % \end{macrocode}
2558 %
2559 % \subsection{Variables and functions by format}
2560 %
2561 % We define and set variables and one function that must be handled separately in order
2562 % to work properly with \hologo{plainTeX}, \LaTeX{} and \hologo{ConTeXt}.
2563 %
2564 % \begin{macro}{\@@_format_case:nnn}
2565 % Sometimes we need to detect the format from within a macro:
2566 % \begin{macrocode}
2567 %<*loader>
2568 \cs_new:Npn \@@_format_case:nnn #1 #2 #3
2569 %<latex> {#1} % LaTeX
2570 %<plain> {#2} % Plain/Generic
2571 %<context> {#3} % ConTeXt
2572 % \end{macrocode}
2573 % \end{macro}
2574 %
2575 % \begin{macro}{\c_@@_newline_tl}
2576 % A constant token list \cs{c_@@_newline_tl} to store `§^^J§' according to the formats
2577 % \begin{macrocode}
2578 %<*!context>
2579 \tl_const:Ne \c_@@_newline_tl { \iow_char:N \^^J }
2580 %</!context>
2581 % \end{macrocode}
2582 % \end{macro}
2583 %
2584 % In \hologo{ConTeXt} we must take a precaution when running under LMTX.
2585 % This is an adaptation of the file \texttt{t-lua-widow-control.mkxl} part
2586 % of Max Chernoff's \mypkg{lua-widow-control} package, §\contextlmtxmode§
2587 % is described at \url{https://source.contextgarden.net/tex/context/base/mkxl/context.mkxl}.
2588 % \begin{macrocode}
2589 %<*context>
2590 \bool_if:NTF \contextlmtxmode
2591 {
2592 \msg_new:nnn { scontents } { luametatex }
2593 {
2594 The~'scontents'~package~doesn't~work~under~LMTX.
2595 }
2596 % \msg_error:nn { scontents } { luametatex }
2597 \tl_const:Ne \c_@@_newline_tl { \syst_obeyed_line }
2598 }
2599 {
2600 \tl_const:Ne \c_@@_newline_tl { \iow_char:N \^^J }
2601 }
2602 %</context>
2603 % \end{macrocode}
2604 % Por alguna razón desconocida para mi, no funciona |\^^J| bajo LMTX,
2605 % Max me dio esto en el chat....preguntar que es lo que hace
2606 % |\syst_obeyed_line| y donde se encuentra documentado.
2607 % |https://chat.stackexchange.com/transcript/message/68011831#68011831|.
2608 %
2609 % \begin{macro}{\g_@@_end_verbatimsc_tl, \c_@@_end_env_tl,
2610 % \l_@@_env_name_tl,}
2611 % The global token list \cs{g_@@_end_verbatimsc_tl} match when ending
2612 % §verbatimsc§ (\S\ref{env:verbatimsc}).
2613 % \begin{macrocode}
2614 \tl_new:N \g_@@_end_verbatimsc_tl
2615 \tl_gset_rescan:Nnn \g_@@_end_verbatimsc_tl
2616 {
2617 \char_set_catcode_other:N \\
2618 %<*latex>
2619 \char_set_catcode_other:N \{
2620 \char_set_catcode_other:N \}
2621 %</latex>
2622 }
2623 %<latex> { \end{verbatimsc} }
2624 %<plain> { \endverbatimsc }
2625 %<context> { \stopverbatimsc }
2626 % \end{macrocode}
2627 % The constant token list \cs{c_@@_end_env_tl} match when ending
2628 % environments defined by §\newenvsc§, the token list\cs{l_@@_env_name_tl}
2629 % storing the \emph{name} of environments defined by §\newenvsc§ (\S\ref{cmd:newenvsc}).
2630 % \begin{macrocode}
2631 \tl_new:N \l_@@_env_name_tl
2632 \tl_const:Ne \c_@@_end_env_tl
2633 {
2634 \c_backslash_str
2635 %<latex|plain> end
2636 %<context> stop
2637 %<latex> \c_left_brace_str
2638 \exp_not:N \l_@@_env_name_tl
2639 %<latex> \c_right_brace_str
2640 }
2641 % \end{macrocode}
2642 % \end{macro}
2643 %
2644 % \subsection{Loading the package core}
2645 %
2646 % Now we load the core \mypkg*{scontents} code:
2647 % \begin{macrocode}
2648 \file_input:n { scontents-code.tex }
2649 %</loader>
2650 % \end{macrocode}
2651 %
2652 % \subsection{Keys for the package}
2653 %
2654 % \begin{macro}[int]{store-env, store-cmd,verb-font,print-env,print-cmd,
2655 % force-eol, overwrite, width-tab, print-all, store-all}
2656 % We create some common \mymeta{keys} that will be used by the options
2657 % passed to the package as well as by the environments and commands
2658 % defined.
2659 % \begin{macrocode}
2660 %<*core>
2661 \keys_define:nn { scontents }
2662 {
2663 store-env .tl_set:N = \l_@@_name_seq_env_tl,
2664 store-env .initial:n = contents,
2665 store-env .value_required:n = true,
2666 store-cmd .tl_set:N = \l_@@_name_seq_cmd_tl,
2667 store-cmd .initial:n = contents,
2668 store-cmd .value_required:n = true,
2669 verb-font .tl_set:N = \l_@@_verb_font_tl,
2670 verb-font .value_required:n = true,
2671 print-env .bool_set:N = \l_@@_print_env_bool,
2672 print-env .initial:n = false,
2673 print-env .default:n = true,
2674 print-cmd .bool_set:N = \l_@@_print_cmd_bool,
2675 print-cmd .initial:n = false,
2676 print-cmd .default:n = true,
2677 force-eol .bool_set:N = \l_@@_forced_eol_bool,
2678 force-eol .initial:n = false,
2679 force-eol .default:n = true,
2680 overwrite .bool_set:N = \l_@@_overwrite_bool,
2681 overwrite .initial:n = false,
2682 overwrite .default:n = true,
2683 width-tab .int_set:N = \l_@@_tab_width_int,
2684 width-tab .initial:n = 1,
2685 width-tab .value_required:n = true,
2686 print-all .meta:n = { print-env = #1, print-cmd = #1 },
2687 print-all .default:n = true,
2688 store-all .meta:n = { store-env = #1, store-cmd = #1 },
2689 store-all .value_required:n = true
2690 }
2691 %</core>
2692 % \end{macrocode}
2693 % Set default value for §verb-font§ key.
2694 % \begin{macrocode}
2695 %<loader>\keys_define:nn { scontents }
2696 %<latex> { verb-font .initial:n = \ttfamily }
2697 %<plain|context> { verb-font .initial:n = \tt }
2698 % \end{macrocode}
2699 % In \LaTeX{} mode process the \mymeta{keys} as options passed on to the
2700 % package and will return an error when they are.
2701 % \begin{macrocode}
2702 %<*latex>
2703 \ProcessKeyOptions [ scontents ]
2704 %</latex>
2705 % \end{macrocode}
2706 % \end{macro}
2707 %
2708 % \subsection{Internal variables}
2709 %
2710 % \begin{macro}{\l_@@_save_every_body_lines_tl, \l_@@_processed_body_lines_tl,
2711 % \l_@@_environment_keys_tl, \l_@@_nesting_env_int,
2712 % \l_@@_nesting_aux_int,}
2713 % The token list \cs{l_@@_save_every_body_lines_tl} holds the
2714 % \mymarg{body env} of an environment, §scontents§ by default, as it's
2715 % being read, the token list \cs{l_@@_processed_body_lines_tl} saves
2716 % all sanitized lines saved in \cs{l_@@_save_every_body_lines_tl}.
2717 %
2718 % The token list \cs{l_@@_environment_keys_tl} saves the \mymeta{keys}
2719 % passed to the \emph{optional argument} after they are sanitized and
2720 % the integer variables \cs{l_@@_nesting_env_int} together with
2721 % \cs{l_@@_nesting_aux_int} are used to analyze the nesting of the
2722 % environment.
2723 % \begin{important}*
2724 % All of these variables are used in the implementation of §\newenvsc§
2725 % (\S\ref{cmd:newenvsc}) and the environments base functions (\S\ref{fun:base:env}).
2726 % \end{important}
2727 % \begin{macrocode}
2728 %<*core>
2729 \tl_new:N \l_@@_save_every_body_lines_tl
2730 \tl_new:N \l_@@_processed_body_lines_tl
2731 \tl_new:N \l_@@_environment_keys_tl
2732 \int_new:N \l_@@_nesting_env_int
2733 \int_new:N \l_@@_nesting_aux_int
2734 % \end{macrocode}
2735 % \end{macro}
2736 %
2737 % \begin{macro}{\l_@@_cmd_name_tl,}
2738 % The token list \cs{l_@@_cmd_name_tl} saves the \emph{name} of the
2739 % commands §\Scontents§, §\foreachsc§, §\typestored§, §\meaningsc§
2740 % and §\mergesc§.
2741 % \begin{macrocode}
2742 \tl_new:N \l_@@_cmd_name_tl
2743 % \end{macrocode}
2744 % \end{macro}
2745 %
2746 % \begin{macro}{\l_@@_Scontents_arg_tl, \l_@@_foreachsc_arg_tl,
2747 % \l_@@_typestored_arg_tl, \l_@@_meaningsc_arg_tl,
2748 % \l_@@_mergesc_arg_tl,}
2749 % The token lists \cs{l_@@_Scontents_arg_tl}, \cs{l_@@_foreachsc_arg_tl},
2750 % \cs{l_@@_typestored_arg_tl} and \cs{l_@@_meaningsc_arg_tl} save the
2751 % \mymarg{argument} passed to the §\Scontents§ (\S\ref{cmd:Scontents}),
2752 % §\foreachsc§ (\S\ref{cmd:foreachsc}), §\typestored§ (\S\ref{cmd:typestored})
2753 % and §\meaningsc§ (\S\ref{cmd:meaningsc}) commands.
2754 % \begin{macrocode}
2755 \tl_new:N \l_@@_Scontents_arg_tl
2756 \tl_new:N \l_@@_foreachsc_arg_tl
2757 \tl_new:N \l_@@_typestored_arg_tl
2758 \tl_new:N \l_@@_meaningsc_arg_tl
2759 % \end{macrocode}
2760 % \end{macro}
2761 %
2762 % \begin{macro}{\l_@@_mergesc_arg_tl, \l_@@_mergesc_keys_tl,
2763 % \l_@@_current_seq_name_str,}
2764 % The token list \cs{l_@@_mergesc_arg_tl} save the \mymarg{argument}
2765 % and the token list \cs{l_@@_mergesc_keys_tl} save the \mymeta{keys}
2766 % passed to the §\mergesc§ (\S\ref{cmd:mergesc}) command.
2767 %
2768 % The string variable \cs{l_@@_current_seq_name_str} stores the name of
2769 % the \emph{current sequence} passed as an \mymarg{argument} to the
2770 % §\typestored§ and §\meaningsc§ commands and is used by the function
2771 % \cs{@@_parse_type_meaning_key:n}.
2772 % \begin{macrocode}
2773 \tl_new:N \l_@@_mergesc_arg_tl
2774 \tl_new:N \l_@@_mergesc_keys_tl
2775 \str_new:N \l_@@_current_seq_name_str
2776 % \end{macrocode}
2777 % \end{macro}
2778 %
2779 % \begin{macro}{\l_@@_file_name_tl, \l_@@_file_write_iow,
2780 % \l_@@_writing_bool, l_@@_storing_bool,
2781 % \l_@@_writable_bool,}
2782 % The token list \cs{l_@@_file_name_tl} is used for store the name of
2783 % the \mymeta{output file}, when there's one. Its value is set by the
2784 % keys §write-env§, §write-out§ and §write-cmd§ (\S\ref{keys:env}).
2785 %
2786 % The variable \cs{l_@@_file_write_iow} is an \emph{output stream} for
2787 % write the \mymarg{body env} of an environment or \mymarg{argument}
2788 % for command to a \mymeta{output file} when the keys §write-env§,
2789 % §write-out§ or §write-cmd§ are active.
2790 %
2791 % The boolean variables \cs{l_@@_writing_bool} and \cs{l_@@_storing_bool}
2792 % (true by default) set by the §write-out§, §write-env§ and §write-cmd§ keys determine
2793 % whether the content is stored and written or just written to a \mymeta{output file}.
2794 %
2795 % The boolean variable \cs{l_@@_writable_bool} keeps track of whether
2796 % we should write to a file, it is in write-only or in mode overwrite
2797 % when the key §overwrite§ is used.
2798 % \begin{important}*
2799 % This variable is used by the function \cs{@@_file_if_writable:nTF}
2800 % (see \ref{fun:save:body}).
2801 % \end{important}
2802 %
2803 % \begin{macrocode}
2804 \tl_new:N \l_@@_file_name_tl
2805 \iow_new:N \l_@@_file_write_iow
2806 \bool_new:N \l_@@_writing_bool
2807 \bool_new:N \l_@@_storing_bool
2808 \bool_set_true:N \l_@@_storing_bool
2809 \bool_new:N \l_@@_writable_bool
2810 % \end{macrocode}
2811 % \end{macro}
2812 %
2813 % \begin{macro}{\l_@@_foreach_print_seq, \g_@@_foreach_exec_tl,
2814 % \l_@@_foreach_before_tl, \l_@@_foreach_before_bool,
2815 % \l_@@_foreach_after_tl, \l_@@_foreach_after_bool,
2816 % \l_@@_foreach_stop_int, \l_@@_foreach_before_bool,
2817 % \l_@@_foreach_wrapper_bool}
2818 % Internal variables used by \mymeta{keys} (\S\ref{keys:foreachsc})
2819 % and implementation of §\foreachsc§ command (\S\ref{cmd:foreachsc}).
2820 % \begin{macrocode}
2821 \seq_new:N \l_@@_foreach_print_seq
2822 \tl_new:N \g_@@_foreach_exec_tl
2823 \tl_new:N \l_@@_foreach_before_tl
2824 \bool_new:N \l_@@_foreach_before_bool
2825 \tl_new:N \l_@@_foreach_after_tl
2826 \bool_new:N \l_@@_foreach_after_bool
2827 \int_new:N \l_@@_foreach_stop_int
2828 \bool_new:N \l_@@_foreach_stop_bool
2829 \bool_new:N \l_@@_foreach_wrapper_bool
2830 % \end{macrocode}
2831 % \end{macro}
2832 %
2833 % \begin{macro}{\l_@@_seq_item_seq, \g_@@_name_sc!internal_seq,}
2834 % The sequence variable \cs{l_@@_seq_item_seq} save the \mymeta{indexes} in the
2835 % \emph{sequence} of the items requested to §\typestored§, §\mergesc§
2836 % or §\meaningsc§ and the sequence \cs{g_@@_name_sc!internal_seq} assemble this.
2837 % \begin{macrocode}
2838 \seq_new:N \l_@@_seq_item_seq
2839 \seq_new:c { g_@@_name_sc!internal_seq }
2840 % \end{macrocode}
2841 % \end{macro}
2842 %
2843 % \begin{macro}{\g_@@_last_stored_tl}
2844 % The token list \cs{g_@@_last_stored_tl} used by the function
2845 % \cs{@@_lastfrom_seq:n} (\S\ref{impl:seq:funct}) to execute the
2846 % last \mymeta{stored content} outside the group.
2847 % \begin{macrocode}
2848 \tl_new:N \g_@@_last_stored_tl
2849 % \end{macrocode}
2850 % \end{macro}
2851 %
2852 % \begin{macro}{\c_@@_hidden_space_str,}
2853 % The variable \cs{c_@@_hidden_space_str} is a constant \emph{string}
2854 % to used to hide the \mymeta{forced space} added by \hologo{TeX} when
2855 % recording content in a macro. This \emph{string} contains the \emph{reserved phrase}
2856 % `§%§§^^Ascheol%§' which is added to the end of the \mymarg{argument} stored
2857 % in \emph{sequence} when the key §force-eol§ is false.
2858 % \begin{macrocode}
2859 \str_const:Ne \c_@@_hidden_space_str
2860 { \c_percent_str \c_circumflex_str \c_circumflex_str A scheol \c_percent_str }
2861 % \end{macrocode}
2862 % \end{macro}
2863 %
2864 % \begin{macro}{\l_@@_save_sf_int,\l_@@_save_skip}
2865 % Internal variables used by functions \cs{@@_bsphack:} and
2866 % \cs{@@_esphack:} (\S\ref{func:sphack}).
2867 % \begin{macrocode}
2868 \int_new:N \l_@@_save_sf_int
2869 \skip_new:N \l_@@_save_skip
2870 % \end{macrocode}
2871 % \end{macro}
2872 %
2873 % \begin{macro}{\q_@@_stop,\q_@@_mark,\s_@@_stop,\s_@@_mark}
2874 % Some quarks and scan's used along the code as macro delimiters.
2875 % \begin{macrocode}
2876 \quark_new:N \q_@@_stop
2877 \quark_new:N \q_@@_mark
2878 \scan_new:N \s_@@_stop
2879 \scan_new:N \s_@@_mark
2880 %</core>
2881 % \end{macrocode}
2882 % \end{macro}
2883 %
2884 % \begin{macro}{\l_@@_plain_bool}
2885 % The boolean variable \cs{l_@@_plain_bool} used in the \hologo{plainTeX}
2886 % implementation of the §verbatimsc§ environment (\S\ref{env:verbatimsc}).
2887 % \begin{macrocode}
2888 %<*plain>
2889 \bool_new:N \l_@@_plain_bool
2890 %</plain>
2891 % \end{macrocode}
2892 % \end{macro}
2893 %
2894 % \subsection{Utility functions}
2895 %
2896 % \begin{macro}[int]{\tl_if_empty:fTF,\tl_replace_all:NeV,\tl_retokenize:e}
2897 % Some nonstandard kernel variant.
2898 % \begin{macrocode}
2899 %<*core>
2900 \prg_generate_conditional_variant:Nnn \tl_if_empty:n { f } { p, TF }
2901 \cs_generate_variant:Nn \tl_replace_all:Nnn { NeV }
2902 \cs_generate_variant:Nn \tl_retokenize:n { e }
2903 % \end{macrocode}
2904 % \end{macro}
2905 %
2906 % \begin{macro}{\@@_use_delimit_by_s_stop:nw,
2907 % \@@_use_i_delimit_by_s_stop:nw,
2908 % \@@_use_none_delimit_by_s_stop:w,
2909 % \@@_use_none_delimit_by_q_stop:w,}
2910 % Some functions used in the implementation of §\mergesc§ (\S\ref{cmd:mergesc})
2911 % and §scontents§ (\S\ref{env:scontents}).
2912 % \begin{macrocode}
2913 \cs_new:Npn \@@_use_delimit_by_s_stop:nw #1 \s_@@_stop {#1}
2914 \cs_new:Npn \@@_use_i_delimit_by_s_stop:nw #1 #2 \s_@@_stop {#1}
2915 \cs_new:Npn \@@_use_none_delimit_by_s_stop:w #1 \s_@@_stop { }
2916 \cs_new:Npn \@@_use_none_delimit_by_q_stop:w #1 \q_@@_stop { }
2917 % \end{macrocode}
2918 % \end{macro}
2919 %
2920 % \begin{macro}[TF]{\@@_tl_if_head_is_q_mark:n}
2921 % The conditional function \cs{@@_tl_if_head_is_q_mark:n} tests
2922 % if the head of the token list is \cs{q_@@_mark}.
2923 % \begin{macrocode}
2924 \prg_new_protected_conditional:Npnn \@@_tl_if_head_is_q_mark:n #1
2925 { T, F, TF }
2926 {
2927 \exp_after:wN \if_meaning:w
2928 \exp_after:wN
2929 \q_@@_mark \@@_use_i_delimit_by_s_stop:nw #1 ? \s_@@_stop
2930 \prg_return_true:
2931 \else:
2932 \prg_return_false:
2933 \fi:
2934 }
2935 % \end{macrocode}
2936 % \end{macro}
2937 %
2938 % \begin{macro}{\@@_file_if_writable:n, \@@_file_if_writable:nT,
2939 % \@@_file_if_writable:nF, \@@_file_if_writable:nTF,}
2940 % The conditional function \cs{@@_file_if_writable:n} used by the §write-env§,
2941 % §write-cmd§, §write-out§ and §overwrite§ keys.
2942 % \begin{macrocode}
2943 \prg_new_protected_conditional:Npnn \@@_file_if_writable:n #1 { T, F, TF }
2944 {
2945 \bool_if:NTF \l_@@_writing_bool
2946 {
2947 \file_if_exist:nTF {#1}
2948 {
2949 \bool_if:NTF \l_@@_overwrite_bool
2950 {
2951 \msg_warning:nne { scontents } { overwrite-file } {#1}
2952 \prg_return_true:
2953 }
2954 {
2955 \msg_warning:nne { scontents } { not-writing } {#1}
2956 \prg_return_false:
2957 }
2958 }
2959 {
2960 \msg_warning:nne { scontents } { writing-file } {#1}
2961 \prg_return_true:
2962 }
2963 }
2964 { \prg_return_false: }
2965 }
2966 % \end{macrocode}
2967 % \end{macro}
2968 %
2969 % \begin{macro}{\@@_file_write_cmd:nn, \@@_file_write_cmd:VV,}
2970 % The function \cs{@@_file_write_cmd:nn} used by the §write-env§,
2971 % §write-cmd§, §write-out§ and §overwrite§ keys for commands.
2972 % \begin{macrocode}
2973 \cs_new_protected:Npn \@@_file_write_cmd:nn #1#2
2974 {
2975 \@@_file_if_writable:nT {#1}
2976 {
2977 \iow_open:Nn \l_@@_file_write_iow {#1}
2978 \iow_now:Nn \l_@@_file_write_iow {#2}
2979 \iow_close:N \l_@@_file_write_iow
2980 }
2981 }
2982 \cs_generate_variant:Nn \@@_file_write_cmd:nn { VV }
2983 % \end{macrocode}
2984 % \end{macro}
2985 %
2986 % \subsubsection{Functions for \texttt{TAB} and \texttt{verbatimsc}}
2987 %
2988 % \begin{macro}{\@@_tab:,\@@_par:}
2989 % Control sequences to replace tab `§^^I§' and form feed `§^^L§'
2990 % characters.
2991 % \begin{macrocode}
2992 \cs_new:Ne \@@_tab: { \c_space_tl }
2993 \cs_new:Nn \@@_par: { ^^J ^^J }
2994 % \end{macrocode}
2995 % \end{macro}
2996 %
2997 % \begin{macro}{\@@_tabs_to_spaces:}
2998 % In a \emph{verbatim} context the \texttt{TAB} character is made active
2999 % and set equal to \cs{@@_tabs_to_spaces:}, to produce as many spaces as
3000 % the §width-tab§ key was set to.
3001 % \begin{macrocode}
3002 \cs_new:Nn \@@_tabs_to_spaces:
3003 { \prg_replicate:nn { \l_@@_tab_width_int } { ~ } }
3004 % \end{macrocode}
3005 % \end{macro}
3006 %
3007 % \begin{macro}{\@@_do_noligs:N}
3008 % The function \cs{@@_do_noligs:N} is an alternative definition for \LaTeXe's
3009 % §\do@noligs§ which makes sure to not consume following space
3010 % tokens. The \LaTeXe{} version ends with §\char`#1§, which
3011 % leaves \TeX{} still looking for an \mymeta{optional~space}.
3012 % \begin{macrocode}
3013 \cs_new_protected:Npn \@@_do_noligs:N #1
3014 {
3015 \char_set_catcode_active:N #1
3016 \cs_set:cpe { @@_active_char_ \token_to_str:N #1 : }
3017 {
3018 \mode_leave_vertical:
3019 \tex_kern:D \c_zero_dim
3020 \tex_char:D `\exp_not:N #1
3021 }
3022 \char_set_active_eq:Nc #1 { @@_active_char_ \token_to_str:N #1 : }
3023 }
3024 % \end{macrocode}
3025 % \end{macro}
3026 %
3027 % \begin{macro}{
3028 % \@@_set_active_eq:NN, \@@_make_control_chars_active:,
3029 % \@@_plain_disable_outer_par:}
3030 % Shortcut definitions for common catcode changes.
3031 % The `§^^L§' needs a special treatment in non-\LaTeX{} mode
3032 % because in \hologo{plainTeX} it is an §\outer§ token.
3033 % \begin{macrocode}
3034 \cs_new_protected:Npn \@@_set_active_eq:NN #1
3035 {
3036 \char_set_catcode_active:N #1
3037 \char_set_active_eq:NN #1
3038 }
3039 %</core>
3040 %<*loader>
3041 \group_begin:
3042 %<plain> \char_set_catcode_active:n { `\* }
3043 \cs_new_protected:Nn \@@_plain_disable_outer_par:
3044 %<*plain>
3045 {
3046 \group_begin:
3047 \char_set_lccode:nn { `\* } { `\^^L }
3048 \tex_lowercase:D { \group_end:
3049 \tex_let:D * \scan_stop:
3050 }
3051 }
3052 %</plain>
3053 %<latex|context> { }
3054 \group_end:
3055 %</loader>
3056 %<*core>
3057 \group_begin:
3058 \char_set_catcode_active:N \*
3059 \cs_new_protected:Nn \@@_make_control_chars_active:
3060 {
3061 \@@_plain_disable_outer_par:
3062 \@@_set_active_eq:NN \^^I \@@_tab:
3063 \@@_set_active_eq:NN \^^L \@@_par:
3064 \@@_set_active_eq:NN \^^M \@@_ret:w
3065 }
3066 \group_end:
3067 %</core>
3068 % \end{macrocode}
3069 % \end{macro}
3070 %
3071 % \subsubsection{Functions \cs{@bsphack} and \cs{@esphack}}\label{func:sphack}
3072 %
3073 % \begin{macro}{\@@_bsphack:,\@@_esphack:}
3074 % We emulate §\@bsphack§ and §\@esphack§ for \hologo{plainTeX}.
3075 % This is necessary to prevent \emph{unwanted spaces} when the §print-cmd§
3076 % key is false.
3077 % \begin{macrocode}
3078 %<*core>
3079 \cs_new_protected:Nn \@@_bsphack:
3080 {
3081 \scan_stop:
3082 \mode_if_horizontal:T
3083 {
3084 \skip_set_eq:NN \l_@@_save_skip \tex_lastskip:D
3085 \int_set_eq:NN \l_@@_save_sf_int \tex_spacefactor:D
3086 }
3087 }
3088 \cs_new_protected:Nn \@@_esphack:
3089 {
3090 \scan_stop:
3091 \mode_if_horizontal:T
3092 {
3093 \int_set_eq:NN \tex_spacefactor:D \l_@@_save_sf_int
3094 \dim_compare:nNnT { \l_@@_save_skip } > { \c_zero_skip }
3095 {
3096 \skip_if_eq:nnT { \tex_lastskip:D } { \c_zero_skip }
3097 {
3098 \nobreak
3099 \skip_horizontal:n { \c_zero_skip }
3100 }
3101 \tex_ignorespaces:D
3102 }
3103 }
3104 }
3105 %</core>
3106 %<*latex>
3107 \cs_gset_eq:NN \@@_bsphack: \@bsphack
3108 \cs_gset_eq:NN \@@_esphack: \@esphack
3109 %</latex>
3110 % \end{macrocode}
3111 % \end{macro}
3112 %
3113 % \subsection{Keys for environment}\label{keys:env}
3114 %
3115 % \begin{macro}[int]{write-env,write-out,print-env,store-env,force-eol,
3116 % overwrite,unknown,}
3117 % We define a set of \mymeta{keys} for environment §scontents§.
3118 % \begin{macrocode}
3119 %<*core>
3120 \keys_define:nn { scontents / scontents }
3121 {
3122 write-env .code:n = {
3123 \bool_set_true:N \l_@@_storing_bool
3124 \bool_set_true:N \l_@@_writing_bool
3125 \tl_set:Nn \l_@@_file_name_tl {#1}
3126 },
3127 write-out .code:n = {
3128 \bool_set_false:N \l_@@_storing_bool
3129 \bool_set_true:N \l_@@_writing_bool
3130 \tl_set:Nn \l_@@_file_name_tl {#1}
3131 },
3132 write-env .value_required:n = true,
3133 write-out .value_required:n = true,
3134 print-env .meta:nn = { scontents } { print-env = #1 },
3135 print-env .default:n = true,
3136 store-env .meta:nn = { scontents } { store-env = #1 },
3137 force-eol .meta:nn = { scontents } { force-eol = #1 },
3138 force-eol .default:n = true,
3139 overwrite .meta:nn = { scontents } { overwrite = #1 },
3140 overwrite .default:n = true,
3141 unknown .code:n = { \@@_unknown_keys_env:n {#1} },
3142 }
3143 % \end{macrocode}
3144 % \end{macro}
3145 %
3146 % \subsubsection{Handling unknown keys for environment \env{scontents}}
3147 %
3148 % The \mymeta{keys} are save in the string variable §\l_keys_key_str§
3149 % and the value (if any) is passed as an argument to each \mymeta{function}.
3150 %
3151 % \begin{macro}{\@@_unknown_keys_env:n,
3152 % \@@_unknown_keys_env:nn}
3153 % We check the \mymeta{keys} passed to the environment
3154 % §scontents§ and process it with \cs{@@_parse_environment_keys:n}
3155 % if the \mymeta{key} is \emph{unknown} we return an error message.
3156 % \begin{macrocode}
3157 \cs_new_protected:Npn \@@_unknown_keys_env:n #1
3158 { \exp_args:NV \@@_unknown_keys_env:nn \l_keys_key_str {#1} }
3159 \cs_new_protected:Npn \@@_unknown_keys_env:nn #1#2
3160 {
3161 \tl_if_blank:nTF {#2}
3162 { \msg_error:nnn { scontents } { env-key-unknown } {#1} }
3163 { \msg_error:nnnn { scontents } { env-key-value-unknown } {#1} {#2} }
3164 }
3165 % \end{macrocode}
3166 % \end{macro}
3167 %
3168 % \subsection{Keys for commands}\label{keys:all}
3169 %
3170 % We add the \mymeta{keys} divided into subgroups to handle \emph{errors}
3171 % and \emph{unknown} \mymeta{keys} separately.
3172 %
3173 % \subsubsection{Keys for command \cs{Scontents}}
3174 %
3175 % \begin{macro}[int]{write-cmd,write-out,print-cmd,store-cmd,force-eol,
3176 % overwrite,unknown,}
3177 % We define a set of \mymeta{keys} for commands §\Scontents§ and
3178 % §\Scontents*§.
3179 % \begin{macrocode}
3180 \keys_define:nn { scontents / Scontents }
3181 {
3182 write-cmd .code:n = {
3183 \bool_set_true:N \l_@@_storing_bool
3184 \bool_set_true:N \l_@@_writing_bool
3185 \tl_set:Nn \l_@@_file_name_tl {#1}
3186 },
3187 write-out .code:n = {
3188 \bool_set_false:N \l_@@_storing_bool
3189 \bool_set_true:N \l_@@_writing_bool
3190 \tl_set:Nn \l_@@_file_name_tl {#1}
3191 },
3192 write-cmd .value_required:n = true,
3193 write-out .value_required:n = true,
3194 print-cmd .meta:nn = { scontents } { print-cmd = #1 },
3195 print-cmd .default:n = true,
3196 store-cmd .meta:nn = { scontents } { store-cmd = #1 },
3197 force-eol .meta:nn = { scontents } { force-eol = #1 },
3198 force-eol .default:n = true,
3199 overwrite .meta:nn = { scontents } { overwrite = #1 },
3200 overwrite .default:n = true,
3201 unknown .code:n = { \@@_unknown_keys_cmd:n {#1} },
3202 }
3203 % \end{macrocode}
3204 % \end{macro}
3205 %
3206 % \subsubsection{Keys for command \cs{foreachsc}}\label{keys:foreachsc}
3207 %
3208 % \begin{macro}[int]{before, after, start, stop, step, wrapper, sep,
3209 % unknown,}
3210 % We define a set of \mymeta{keys} for command §\foreachsc§.
3211 % \begin{macrocode}
3212 \keys_define:nn { scontents / foreachsc }
3213 {
3214 before .code:n = {
3215 \bool_set_true:N \l_@@_foreach_before_bool
3216 \tl_set:Nn \l_@@_foreach_before_tl {#1}
3217 },
3218 before .value_required:n = true,
3219 after .code:n = {
3220 \bool_set_true:N \l_@@_foreach_after_bool
3221 \tl_set:Nn \l_@@_foreach_after_tl {#1}
3222 },
3223 after .value_required:n = true,
3224 start .int_set:N = \l_@@_foreach_start_int,
3225 start .value_required:n = true,
3226 start .initial:n = 1,
3227 stop .code:n = {
3228 \bool_set_true:N \l_@@_foreach_stop_bool
3229 \int_set:Nn \l_@@_foreach_stop_int {#1}
3230 },
3231 stop .value_required:n = true,
3232 step .int_set:N = \l_@@_foreach_step_int,
3233 step .value_required:n = true,
3234 step .initial:n = 1,
3235 wrapper .code:n = {
3236 \bool_set_true:N \l_@@_foreach_wrapper_bool
3237 \cs_set_protected:Npn
3238 \@@_foreach_wrapper:n ##1 {#1}
3239 },
3240 wrapper .value_required:n = true,
3241 sep .tl_set:N = \l_@@_foreach_sep_tl,
3242 sep .initial:n = { },
3243 sep .value_required:n = true,
3244 unknown .code:n = { \@@_unknown_keys_cmd:n {#1} },
3245 }
3246 % \end{macrocode}
3247 % \end{macro}
3248 %
3249 % \subsubsection{Handling unknown keys for \cs{Scontents} and \cs{foreachsc}}
3250 %
3251 % \begin{macro}{\@@_unknown_keys_cmd:n,
3252 % \@@_unknown_keys_cmd:nn}
3253 % We check the \mymeta{keys} passed to commands §\Scontents§, §\Scontents*§ or
3254 % §\foreachsc§ and process it with \cs{@@_unknown_keys_cmd:n}
3255 % if the \mymeta{key} is \emph{unknown} we return an error message.
3256 % \begin{macrocode}
3257 \cs_new_protected:Npn \@@_unknown_keys_cmd:n #1
3258 { \exp_args:NV \@@_unknown_keys_cmd:nn \l_keys_key_str {#1} }
3259 \cs_new_protected:Npn \@@_unknown_keys_cmd:nn #1#2
3260 {
3261 \tl_if_blank:nTF {#2}
3262 { \msg_error:nnn { scontents } { cmd-key-unknown } {#1} }
3263 { \msg_error:nnnn { scontents } { cmd-key-value-unknown } {#1} {#2} }
3264 }
3265 % \end{macrocode}
3266 % \end{macro}
3267 %
3268 % \subsubsection{Keys for commands \cs{typestored} and \cs{meaningsc}}\label{keys:typemeaning}
3269 %
3270 % \begin{macro}[int]{width-tab,write-out,overwrite,print-cmd, unknown,}
3271 % We define a \mymeta{keys} for command §\typestored§ and §\meaningsc§.
3272 % Both commands accept the same type of \emph{optional arguments}, just define
3273 % a common \mymeta{keys}.
3274 % Here we will implement the §write-out§, §overwrite§ and §print-cmd§
3275 % keys which are necessary in the implementation of the §\mergesc§
3276 % command (\S\ref{cmd:mergesc}).
3277 % \begin{macrocode}
3278 \keys_define:nn { scontents / typemeaning }
3279 {
3280 width-tab .meta:nn = { scontents } { width-tab = #1 },
3281 write-out .code:n = {
3282 \bool_set_false:N \l_@@_storing_bool
3283 \bool_set_true:N \l_@@_writing_bool
3284 \tl_set:Nn \l_@@_file_name_tl {#1}
3285 },
3286 write-out .value_required:n = true,
3287 overwrite .meta:nn = { scontents } { overwrite = #1 },
3288 overwrite .default:n = true,
3289 print-cmd .bool_set:N = \l_@@_print_verb_style_bool,
3290 print-cmd .initial:n = true,
3291 print-cmd .default:n = true,
3292 unknown .code:n = { \@@_parse_type_meaning_key:n {#1} },
3293 }
3294 % \end{macrocode}
3295 % \end{macro}
3296 %
3297 % \subsubsection{Keys for command \cs{mergesc}}\label{keys:mergesc}
3298 %
3299 % \begin{macro}[int]{typestored, meaningsc, \@@_mergesc_cmd:nn,}
3300 % We define two \mymeta{keys} \mykey{typestored} and \mykey{meaningsc}
3301 % as \emph{mandatory}, returning an \enquote{error} through the function
3302 % \cs{@@_mergesc_cmd:nn}.
3303 % \begin{macrocode}
3304 \keys_define:nn { scontents / mergesc }
3305 {
3306 typestored .code:n =
3307 {
3308 \cs_set_eq:NN \@@_mergesc_cmd:nn \@@_typestored:nn
3309 },
3310 typestored .value_forbidden:n = true,
3311 meaningsc .code:n =
3312 {
3313 \cs_set_eq:NN \@@_mergesc_cmd:nn \@@_meaningsc:nn
3314 },
3315 meaningsc .value_forbidden:n = true,
3316 }
3317 \cs_new_protected:Npn \@@_mergesc_cmd:nn #1 #2
3318 {
3319 \msg_error:nn { scontents } { mergesc-missing-key }
3320 }
3321 % \end{macrocode}
3322 % \end{macro}
3323 %
3324 % \subsubsection{Parsing keys for \cs{typestored}, \cs{meaningsc} and \cs{mergesc}}
3325 %
3326 % \begin{macro}{\@@_parse_type_meaning_key:n, \@@_parse_type_meaning_key:nn,
3327 % \@@_parse_type_meaning_range:w, \@@_range_parser:nnnn,
3328 % \@@_range_parser:nnen, \@@_range_parser_aux:nnn,}
3329 % The §\typestored§, §\meaningsc§ and §\mergesc§ commands (which
3330 % internally uses the previous two) accept an \emph{optional argument}
3331 % containing the \mymeta{index} position, \mymeta{1-end} or the range of
3332 % \mymeta{start-stop} positions of the \mymeta{stored content} in the
3333 % \emph{sequence} along with other \mymeta{keys}.
3334 %
3335 % To avoid the awkward §\typestored[...]§\myoarg{keys}§{...}§ syntax, we'll make the
3336 % commands have a single \emph{optional argument} which is processed by
3337 % \mypkg{l3keys}\cite{inter3}, and the \emph{unknown} \mymeta{keys} are brought here to
3338 % \cs{@@_parse_typemeaning_key:n} to process.
3339 %
3340 % First we check if the \mymeta{key} is an integer using §\int_to_roman:n§.
3341 % If it is, we check that the value passed to the \mymeta{key} is blank
3342 % (otherwise something odd as §1=1§ might have been used). If everything
3343 % is correct, then set the value of the integer which holds the \mymeta{index},
3344 % otherwise raise an error about an \emph{unknown} option.
3345 % \begin{macrocode}
3346 \cs_new_protected:Npn \@@_parse_type_meaning_key:n #1
3347 { \exp_args:NV \@@_parse_type_meaning_key:nn \l_keys_key_str {#1} }
3348 \cs_new_protected:Npn \@@_parse_type_meaning_key:nn #1#2
3349 {
3350 \tl_if_blank:nTF {#2}
3351 { \@@_parse_type_meaning_range:w #1 - \q_@@_mark - \s_@@_mark }
3352 { \msg_error:nnee { scontents } { cmd-key-value-unknown } {#1} {#2} }
3353 }
3354 \cs_new_protected:Npn \@@_parse_type_meaning_range:w #1 - #2 - #3 \s_@@_mark
3355 {
3356 \@@_range_parser:nnen {#1} {#2}
3357 { \seq_count:c { g_@@_name_ \l_@@_current_seq_name_str _seq } }
3358 { \msg_error:nnn { scontents } { cmd-key-unknown } {#1} }
3359 }
3360 \cs_new_protected:Npn \@@_range_parser:nnnn #1 #2 #3 #4
3361 {
3362 \exp_args:Nee \@@_range_parser_aux:nnn
3363 { \str_if_eq:nnTF {#1} { end } {#3} { \exp_not:n {#1} } }
3364 { \str_if_eq:nnTF {#2} { end } {#3} { \exp_not:n {#2} } }
3365 { #4 }
3366 }
3367 \cs_generate_variant:Nn \@@_range_parser:nnnn { nnen }
3368 \cs_new_protected:Npn \@@_range_parser_aux:nnn #1 #2 #3
3369 {
3370 \@@_tl_if_head_is_q_mark:nTF {#2}
3371 {
3372 \tl_if_empty:fTF { \int_to_roman:n { -0 #1 } }
3373 { \seq_put_right:Ne \l_@@_seq_item_seq { \int_eval:n {#1} } }
3374 { #3 {#1} }
3375 }
3376 {
3377 \bool_lazy_and:nnTF
3378 { \tl_if_empty_p:f { \int_to_roman:n { -0 #1 } } }
3379 { \tl_if_empty_p:f { \int_to_roman:n { -0 #2 } } }
3380 {
3381 \int_compare:nNnTF {#2} > {#1}
3382 { \int_step_inline:nnnn {#1} { 1 } {#2} }
3383 { \int_step_inline:nnnn {#1} { -1 } {#2} }
3384 { \seq_put_right:Nn \l_@@_seq_item_seq {##1} }
3385 }
3386 { #3 { #1-#2 } }
3387 }
3388 }
3389 %</core>
3390 % \end{macrocode}
3391 % \end{macro}
3392 %
3393 % \subsection{Functions for sequences}\label{impl:seq:funct}
3394 %
3395 % The \emph{storage system} of the package \mypkg*{scontents} is done
3396 % using |seq| variables. Here we set up the macros that will manage
3397 % the variables.
3398 %
3399 % \begin{macro}{\@@_append_contents:nn,\@@_append_contents:Ve}
3400 % The function \cs{@@_append_contents:nn} creates a \emph{sequence}
3401 % \mymarg{seq name} pass to §#1§ if one didn't exist and appends the
3402 % \mymarg{body env} for environments or \mymarg{argument} for commands
3403 % to the right of the \emph{sequence} \mymarg{seq name} pass to §#2§.
3404 % \begin{macrocode}
3405 %<*core>
3406 \cs_new_protected:Npn \@@_append_contents:nn #1#2
3407 {
3408 \tl_if_blank:nT {#1}
3409 { \msg_error:nn { scontents } { empty-store-cmd } }
3410 \seq_if_exist:cF { g_@@_name_#1_seq }
3411 { \seq_new:c { g_@@_name_#1_seq } }
3412 \seq_gput_right:cn { g_@@_name_#1_seq } {#2}
3413 }
3414 \cs_generate_variant:Nn \@@_append_contents:nn { Ve }
3415 % \end{macrocode}
3416 % \end{macro}
3417 %
3418 % \begin{macro}{\@@_store_to_seq:NN}
3419 % The function \cs{@@_store_to_seq:NN} writes the recorded contents
3420 % in §#1§ to the log and stores it in §#2§.
3421 % \begin{macrocode}
3422 \cs_new_protected:Npn \@@_store_to_seq:NN #1#2
3423 {
3424 \tl_log:N #1
3425 \@@_append_contents:Ve #2 { \exp_not:V #1 }
3426 }
3427 % \end{macrocode}
3428 % \end{macro}
3429 %
3430 % \begin{macro}{\@@_finish_storing:NNN}
3431 % The \cs{@@_finish_storing:NNN} function will first check if we are in
3432 % standard \emph{storing mode}, that is, the §write-out§ key is NOT active, then
3433 % the state of the variable \cs{l_@@_forced_eol_bool} set by the
3434 % §force-eol§ key is checked and if this is \enquote{false} (default value)
3435 % we will add \cs{c_@@_hidden_space_str} to the end of the token list passed
3436 % in §{#1}§ which contains \mymarg{body env} for the generic environment §scontents§
3437 % and the \mymarg{argument} for the §\Scontents§ command.
3438 %
3439 % Then the function \cs{@@_store_to_seq:NN} is applied to \enquote{store}
3440 % in the \emph{sequence} passed in §{#2}§ and finally the state of the
3441 % boolean variable passed in §{#3}§ established by the §print-env§ and §print-cmd§
3442 % keys is checked and if it is \enquote{true}, \mymarg{body env} or \mymarg{argument}
3443 % will be printed from the \emph{sequence} in which it was stored by means
3444 % of the \cs{@@_lastfrom_seq:V} function.
3445 % \begin{macrocode}
3446 \cs_new_protected:Npn \@@_finish_storing:NNN #1 #2 #3
3447 {
3448 \bool_if:NT \l_@@_storing_bool
3449 {
3450 \bool_if:NF \l_@@_forced_eol_bool
3451 { \tl_put_right:Ne #1 { \c_@@_hidden_space_str } }
3452 \@@_store_to_seq:NN #1 #2
3453 \bool_if:NT #3 { \@@_lastfrom_seq:V #2 }
3454 }
3455 }
3456 % \end{macrocode}
3457 % \end{macro}
3458 %
3459 % \begin{macro}{\@@_getfrom_seq:Nn, \@@_getfrom_seq:nNn, \@@_getfrom_seq_aux:nnn,
3460 % \@@_getfrom_seq:nn, \@@_getfrom_seq:nnn,}
3461 % The function \cs{@@_getfrom_seq:Nn} retrieves the \mymeta{stored content}
3462 % pass to §{#1}§ from the \emph{sequence} \mymarg{seq name} pass to §{#2}§.
3463 % \begin{macrocode}
3464 \cs_new:Npn \@@_getfrom_seq:Nn #1#2
3465 {
3466 \seq_if_exist:cTF { g_@@_name_#2_seq }
3467 {
3468 \exp_args:Nf \@@_getfrom_seq:nNn
3469 { \seq_count:c { g_@@_name_#2_seq } } #1 {#2}
3470 }
3471 { \msg_expandable_error:nnn { scontents } { undefined-storage } {#2} }
3472 }
3473 \cs_new:Npn \@@_getfrom_seq:nNn #1 #2 #3
3474 {
3475 \seq_map_tokens:Nn #2 { \@@_getfrom_seq_aux:nnn {#1} {#3} }
3476 }
3477 \cs_new:Npn \@@_getfrom_seq_aux:nnn #1 #2 #3
3478 {
3479 \exp_args:Nnf \use:n { \@@_getfrom_seq:nnn {#1} } { \int_eval:n {#3} } {#2}
3480 }
3481 \cs_new:Npn \@@_getfrom_seq:nn #1#2
3482 {
3483 \seq_if_exist:cTF { g_@@_name_#2_seq }
3484 {
3485 \exp_args:Nf \@@_getfrom_seq:nnn
3486 { \seq_count:c { g_@@_name_#2_seq } }
3487 {#1} {#2}
3488 }
3489 { \msg_expandable_error:nnn { scontents } { undefined-storage } {#2} }
3490 }
3491 \cs_new:Npn \@@_getfrom_seq:nnn #1#2#3
3492 {
3493 \bool_lazy_or:nnTF
3494 { \int_compare_p:nNn {#2} = { 0 } }
3495 { \int_compare_p:nNn { \int_abs:n {#2} } > {#1} }
3496 { \msg_expandable_error:nnnnn { scontents } { index-out-of-range } {#2} {#3} {#1} }
3497 { \seq_item:cn { g_@@_name_#3_seq } {#2} }
3498 }
3499 % \end{macrocode}
3500 % \end{macro}
3501 %
3502 % \begin{macro}{\@@_lastfrom_seq:n,\@@_lastfrom_seq:V}
3503 % The function \cs{@@_lastfrom_seq:n} save the last \mymeta{stored content}
3504 % from the \emph{sequence} pass to §#1§ in \cs{g_@@_last_tl}
3505 % then rescan with the function §\tl_retokenize:V§ when the keys §print-env§
3506 % or §print-cmd§ are active.
3507 % \begin{macrocode}
3508 \cs_new_protected:Npn \@@_lastfrom_seq:n #1
3509 {
3510 \tl_gset:Ne \g_@@_last_stored_tl
3511 {
3512 \seq_item:cn { g_@@_name_#1_seq } { -1 }
3513 }
3514 \group_insert_after:N \tl_retokenize:V
3515 \group_insert_after:N \g_@@_last_stored_tl
3516 \group_insert_after:N \tl_gclear:N
3517 \group_insert_after:N \g_@@_last_stored_tl
3518 }
3519 \cs_generate_variant:Nn \@@_lastfrom_seq:n { V }
3520 %</core>
3521 % \end{macrocode}
3522 % \end{macro}
3523 %
3524 % \subsection{Base functions for environments}\label{fun:base:env}
3525 %
3526 % In version 1.8 (2019-11-18) the command §\newenvsc§ (\S\ref{cmd:newenvsc})
3527 % was implemented, allowing you to create environments with the same
3528 % behavior as the base environment §scontents§. Since that version,
3529 % the base environment §scontents§ (\S\ref{env:scontents}) is defined
3530 % using §\newenvsc§.
3531 %
3532 % The references to §\begin{scontents}§ or §\end{scontents}§ described in
3533 % this section are for illustrative purposes only, but apply to any
3534 % environment defined using §\newenvsc§.
3535 %
3536 % \subsubsection{Functions for keyval of environment}
3537 %
3538 % \begin{macro}{\@@_grab_opt_arg:n,\@@_grab_opt_arg:w}
3539 % The function \cs{@@_grab_opt_arg:w} is called from the
3540 % §scontents§ environment with the tokens following the
3541 % §\begin{scontents}§ when the next character is a `§[§'. This function
3542 % is defined using \mypkg{ltcmd}\cite{latex2e} to exploit its delimited
3543 % argument processor.
3544 % \begin{macrocode}
3545 %<*core>
3546 \NewDocumentCommand \@@_grab_opt_arg:w { r[] }
3547 {
3548 \@@_grab_opt_arg:n {#1}
3549 }
3550 % \end{macrocode}
3551 % The function is called from a context where `§^^M§' is active, so
3552 % \cs{@@_normalise_line_ends:N} is used to replace active `§^^M§'
3553 % characters by spaces.
3554 % \begin{macrocode}
3555 \cs_new_protected:Npn \@@_grab_opt_arg:n #1
3556 {
3557 \tl_if_novalue:nF {#1}
3558 {
3559 \tl_set:Nn \l_@@_environment_keys_tl {#1}
3560 \@@_normalise_line_ends:N \l_@@_environment_keys_tl
3561 \keys_set:nV { scontents / scontents } \l_@@_environment_keys_tl
3562 }
3563 \@@_start_after_option:w
3564 }
3565 %</core>
3566 % \end{macrocode}
3567 % \end{macro}
3568 %
3569 % \subsubsection{Functions for save the body of environment}\label{fun:save:body}
3570 %
3571 % \begin{macro}{\@@_start_environment:w,\@@_start_after_option:w,
3572 % \@@_check_line_process:en,\@@_stop_environment:}
3573 % Here we make `§^^I§', `§^^L§' and `§^^M§' active characters so that the end of
3574 % line can be \enquote{seen} to be used as a delimiter, and \hologo{TeX} doesn't try to
3575 % eliminate space-like characters.
3576 %
3577 % First we check if the immediate next token after §\begin{scontents}§
3578 % is a `§[§'. If it is, then \cs{@@_grab_opt_arg:w} is called
3579 % to do the heavy lifting. \cs{@@_grab_opt_arg:w} processes the optional
3580 % argument and calls \cs{@@_start_after_option:w}.
3581 %
3582 % The function \cs{@@_start_after_option:w} also checks for trailing
3583 % tokens after the optional argument and issues an error if any.
3584 % In all cases, the function \cs{@@_check_line_process:en} checks that
3585 % everything past §\begin{scontents}§ is empty and then process
3586 % the environment.
3587 %
3588 % The function \cs{@@_check_line_process:en} calls the function
3589 % \cs{@@_file_tl_write_start:V} which will then read the contents
3590 % of the environment and optionally store them in a token list or write to
3591 % an \mymeta{external file}.
3592 %
3593 % When that's done, the function \cs{@@_file_write_stop:N} does the
3594 % cleanup. This part of the code is inspired and adapted from the code of
3595 % the package \mypkg{xsim}\cite{xsim} by Clemens Niederberger.
3596 % \begin{macrocode}
3597 %<*core>
3598 \group_begin:
3599 \char_set_catcode_active:N \^^I
3600 \char_set_catcode_active:N \^^L
3601 \char_set_catcode_active:N \^^M
3602 \cs_new_protected:Npn \@@_normalise_line_ends:N #1
3603 { \tl_replace_all:Nnn #1 { ^^M } { ~ } }
3604 \cs_new_protected:Npn \@@_start_environment:w #1 ^^M
3605 {
3606 \tl_if_head_is_N_type:nTF {#1}
3607 {
3608 \str_if_eq:eeTF { \tl_head:n {#1} } { [ }
3609 { \@@_grab_opt_arg:w #1 ^^M }
3610 { \@@_check_line_process:en { } {#1} }
3611 }
3612 { \@@_check_line_process:en { } {#1} }
3613 }
3614 \cs_new_protected:Npn \@@_start_after_option:w #1 ^^M
3615 { \@@_check_line_process:en { [...] } {#1} }
3616 \cs_new_protected:Npn \@@_check_line_process:en #1 #2
3617 {
3618 \tl_if_blank:nF {#2}
3619 {
3620 \msg_error:nnee { scontents } { junk-after-begin }
3621 { after~\c_backslash_str begin { \l_@@_env_name_tl } #1 } {#2}
3622 }
3623 \@@_make_control_chars_active:
3624 \@@_file_tl_write_start:V \l_@@_file_name_tl
3625 }
3626 \cs_new_protected:Nn \@@_stop_environment:
3627 {
3628 \@@_file_write_stop:N \l_@@_processed_body_lines_tl
3629 \bool_lazy_and:nnT
3630 { \l_@@_storing_bool }
3631 { \tl_if_empty_p:N \l_@@_processed_body_lines_tl }
3632 {
3633 \msg_warning:nne { scontents } { empty-environment } { \l_@@_env_name_tl }
3634 }
3635 }
3636 % \end{macrocode}
3637 % \end{macro}
3638 %
3639 % \begin{macro}{
3640 % \@@_file_tl_write_start:n,
3641 % \@@_file_tl_write_start:V,
3642 % \@@_verb_processor_iterate:w,
3643 % \@@_verb_processor_iterate:nnn,
3644 % \@@_setup_verb_processor:,
3645 % \@@_file_write_stop:N,
3646 % \@@_remove_leading_nl:n,
3647 % \@@_remove_leading_nl:w,
3648 % }
3649 % This is the main macro/function to collect the \mymarg{body env} of a verbatim
3650 % environment. The function \cs{@@_file_tl_write_start:n} starts a \emph{group},
3651 % opens the \mymeta{output file}, if necessary, sets \emph{verbatim catcodes},
3652 % and then issues `§^^M§' (set equal to \cs{@@_ret:w}) to read \mymarg{body env}
3653 % of the environment line by line until reaching its end. The output token list
3654 % will be appended with an active `§^^J§' character and the line just read, and
3655 % this line is written to the \mymeta{output file}, if any. At the end of the
3656 % environment the \mymeta{output file} is closed (if it was open), and the
3657 % output token list is smuggled out of the verbatim group. A leading `§^^J§'
3658 % is removed from the token list using \cs{@@_remove_leading_nl:n}, which
3659 % expects an active `§^^J§' token at the head of the token list; a low level
3660 % \hologo{TeX} \enquote{error} is raised otherwise.
3661 % \begin{macrocode}
3662 \cs_new_protected:Npn \@@_file_tl_write_start:n #1
3663 {
3664 \group_begin:
3665 \@@_file_if_writable:nTF {#1}
3666 {
3667 \bool_set_true:N \l_@@_writable_bool
3668 \iow_open:Nn \l_@@_file_write_iow {#1}
3669 }
3670 { \bool_set_false:N \l_@@_writable_bool }
3671 \tl_clear:N \l_@@_save_every_body_lines_tl
3672 \seq_map_function:NN \l_char_special_seq \char_set_catcode_other:N
3673 \int_step_function:nnnN { 128 } { 1 } { 255 } \char_set_catcode_letter:n
3674 \cs_set_protected:Npe \@@_ret:w ##1 ^^M
3675 {
3676 \exp_not:N \@@_verb_processor_iterate:w
3677 ##1 \c_@@_end_env_tl
3678 \c_@@_end_env_tl
3679 \exp_not:N \q_@@_stop
3680 }
3681 \@@_make_control_chars_active:
3682 \@@_ret:w
3683 }
3684 \cs_new:Nn \@@_setup_verb_processor:
3685 {
3686 \use:e
3687 {
3688 \cs_set:Npn \exp_not:N \@@_verb_processor_iterate:w
3689 ##1 \c_@@_end_env_tl
3690 ##2 \c_@@_end_env_tl
3691 ##3 \exp_not:N \q_@@_stop
3692 } { \@@_verb_processor_iterate:nnn {##1} {##2} {##3} }
3693 }
3694 \cs_new:Npn \@@_verb_processor_iterate:nnn #1 #2 #3
3695 {
3696 \tl_if_blank:nTF {#3}
3697 {
3698 \@@_analyse_nesting:n {#1}
3699 \@@_verb_processor_output:n {#1}
3700 }
3701 {
3702 \@@_if_nested:TF
3703 {
3704 \@@_nesting_decr:
3705 \@@_verb_processor_output:e
3706 { \exp_not:n {#1} \c_@@_end_env_tl \exp_not:n {#2} }
3707 }
3708 {
3709 \tl_if_blank:nF {#1}
3710 { \@@_verb_processor_output:n {#1} }
3711 \cs_set_protected:Npe \@@_ret:w
3712 {
3713 \@@_env_end_function:
3714 \bool_lazy_or:nnF
3715 { \tl_if_blank_p:n {#2} }
3716 { \str_if_eq_p:ee {#2} { \c_percent_str } }
3717 {
3718 \str_if_eq:VnF \c_@@_hidden_space_str {#2}
3719 {
3720 \msg_warning:nnnn { scontents } { rescanning-text }
3721 {#2} { \tl_use:N \l_@@_env_name_tl }
3722 }
3723 \tl_retokenize:n {#2}
3724 }
3725 }
3726 \char_set_active_eq:NN ^^M \@@_ret:w
3727 }
3728 }
3729 ^^M
3730 }
3731 \cs_new:Nn \@@_env_end_function:
3732 {
3733 \@@_format_case:nnn
3734 { \exp_not:N \end { \if_false: } \fi: }
3735 { \exp_after:wN \exp_not:N \cs:w end }
3736 { \exp_after:wN \exp_not:N \cs:w stop }
3737 \tl_use:N \l_@@_env_name_tl
3738 \@@_format_case:nnn
3739 { \if_false: { \fi: } }
3740 { \cs_end: }
3741 { \cs_end: }
3742 }
3743 \cs_new_protected:Npn \@@_file_write_stop:N #1
3744 {
3745 \bool_if:NT \l_@@_writable_bool
3746 { \iow_close:N \l_@@_file_write_iow }
3747 \use:e
3748 {
3749 \group_end:
3750 \bool_if:NT \l_@@_storing_bool
3751 {
3752 \tl_set:Nn \exp_not:N #1
3753 {
3754 \exp_args:NV
3755 \@@_remove_leading_nl:n \l_@@_save_every_body_lines_tl
3756 }
3757 }
3758 }
3759 }
3760 \cs_new:Npn \@@_remove_leading_nl:n #1
3761 {
3762 \tl_if_head_is_N_type:nTF {#1}
3763 {
3764 \exp_args:Nf
3765 \@@_remove_leading_nl:nn
3766 { \tl_head:n {#1} } {#1}
3767 }
3768 { \exp_not:n {#1} }
3769 }
3770 \cs_new:Npn \@@_remove_leading_nl:nn #1 #2
3771 {
3772 \token_if_eq_meaning:NNTF ^^J #1
3773 { \exp_not:o { \@@_remove_leading_nl:w #2 } }
3774 { \exp_not:n {#2} }
3775 }
3776 \cs_new:Npn \@@_remove_leading_nl:w ^^J { }
3777 % \end{macrocode}
3778 % \end{macro}
3779 %
3780 % \begin{macro}{\@@_verb_processor_output:n,\@@_verb_processor_output:e}
3781 % The function \cs{@@_verb_processor_output:n} does the output of
3782 % each line read, to a token list and to a file, depending on the
3783 % booleans \cs{l_@@_writing_bool} and \cs{l_@@_storing_bool}.
3784 % \begin{macrocode}
3785 \cs_new_protected:Npn \@@_verb_processor_output:n #1
3786 {
3787 \bool_if:NT \l_@@_writable_bool
3788 { \iow_now:Nn \l_@@_file_write_iow {#1} }
3789 \bool_if:NT \l_@@_storing_bool
3790 { \tl_put_right:Nn \l_@@_save_every_body_lines_tl { ^^J #1 } }
3791 }
3792 \group_end:
3793 \cs_generate_variant:Nn \@@_verb_processor_output:n { e }
3794 \cs_generate_variant:Nn \@@_file_tl_write_start:n { V }
3795 % \end{macrocode}
3796 % \end{macro}
3797 %
3798 % \begin{macro}{
3799 % \@@_analyse_nesting:n,
3800 % \@@_analyse_nesting:w,
3801 % \@@_nesting_decr:,
3802 % \@@_use_none_delimit_by_q_stop:w,
3803 % }
3804 % \begin{macro}[TF]{\@@_if_nested:}
3805 % The function \cs{@@_analyse_nesting:n} scans nested §\begin{scontents}§
3806 % and steps a \cs{l_@@_nesting_env_int} counter. The \cs{@@_if_nested:}
3807 % conditional tests if we're in a nested environment, and \cs{@@_nesting_decr:}
3808 % reduces the nesting level, if an §\end{scontents}§ is found.
3809 % \begin{macrocode}
3810 \cs_new_protected:Npn \@@_analyse_nesting:n #1
3811 {
3812 \int_zero:N \l_@@_nesting_aux_int
3813 \@@_analyse_nesting_format:n {#1}
3814 \int_compare:nNnT { \l_@@_nesting_aux_int } > { 1 }
3815 { \msg_warning:nn { scontents } { multiple-begin } }
3816 }
3817 \cs_new_protected:Nn \@@_nesting_incr:
3818 {
3819 \int_incr:N \l_@@_nesting_env_int
3820 \int_incr:N \l_@@_nesting_aux_int
3821 }
3822 \cs_new_protected:Nn \@@_nesting_decr:
3823 {
3824 \int_decr:N \l_@@_nesting_env_int
3825 }
3826 \prg_new_protected_conditional:Npnn \@@_if_nested: { TF }
3827 {
3828 \int_compare:nNnTF { \l_@@_nesting_env_int } > { \c_zero_int }
3829 { \prg_return_true: }
3830 { \prg_return_false: }
3831 }
3832 % \end{macrocode}
3833 %
3834 % \begin{important}*
3835 % Multiple §\end{scontents}§ in the same line are NOT supported\dots
3836 % \end{important}
3837 %
3838 % In \LaTeX{}, environments start with §\begin{<env>}§, so checking if a
3839 % string contains §\begin{scontents}§ is straightforward. Since no §}§ can
3840 % appear inside §<env>§, then just a macro delimited by `§}§' is enough.
3841 % \begin{macrocode}
3842 \use:e
3843 {
3844 \cs_new_protected:Npn \exp_not:N \@@_analyse_nesting_latex:w #1
3845 \c_backslash_str begin \c_left_brace_str #2 \c_right_brace_str
3846 } {
3847 \@@_tl_if_head_is_q_mark:nTF {#2}
3848 { \@@_use_none_delimit_by_q_stop:w }
3849 {
3850 \str_if_eq:VnT \l_@@_env_name_tl {#2}
3851 { \@@_nesting_incr: }
3852 \@@_analyse_nesting_latex:w
3853 }
3854 }
3855 \cs_new_protected:Npe \@@_analyse_nesting_latex:n #1
3856 {
3857 \@@_analyse_nesting_latex:w #1
3858 \c_backslash_str begin
3859 \c_left_brace_str \exp_not:N \q_@@_mark \c_right_brace_str
3860 \exp_not:N \q_@@_stop
3861 }
3862 % \end{macrocode}
3863 % In other formats, however, we don't have an \enquote{end anchor} to delimit the
3864 % environment name, so a delimited macro won't help. We have to search for
3865 % the entire environment command (usually §\scontents§ and §\startscontents§).
3866 % \begin{macrocode}
3867 \cs_new_protected:Npn \@@_analyse_nesting_generic_process:nn #1 #2
3868 {
3869 \tl_if_head_is_N_type:nTF {#2}
3870 {
3871 \@@_tl_if_head_is_q_mark:nF {#2}
3872 {
3873 \@@_nesting_incr:
3874 \@@_analyse_nesting_generic:w #2 \q_@@_stop
3875 }
3876 }
3877 { \@@_analyse_nesting_generic:w #2 \q_@@_stop }
3878 }
3879 \cs_new_protected:Npn \@@_analyse_nesting_generic:nn #1 #2
3880 {
3881 \@@_define_generic_nesting_function:n {#1}
3882 \use:e
3883 {
3884 \exp_not:N \@@_analyse_nesting_generic:w #2
3885 \c_backslash_str #1 \tl_use:N \l_@@_env_name_tl
3886 \exp_not:N \q_@@_mark \exp_not:N \q_@@_stop
3887 }
3888 }
3889 \cs_new_protected:Npn \@@_define_generic_nesting_function:n #1
3890 {
3891 \use:e
3892 {
3893 \cs_set_protected:Npn \exp_not:N \@@_analyse_nesting_generic:w ##1
3894 \c_backslash_str #1 \tl_use:N \l_@@_env_name_tl
3895 ##2 \exp_not:N \q_@@_stop
3896 } { \@@_analyse_nesting_generic_process:nn {##1} {##2} }
3897 }
3898 %</core>
3899 % \end{macrocode}
3900 % Now we just need to call the \cs{@@_analyse_nesting_format:n}
3901 % function to analyze the nesting.
3902 % \begin{macrocode}
3903 %<*loader>
3904 %<latex>\cs_new_eq:NN \@@_analyse_nesting_format:n
3905 %<latex> \@@_analyse_nesting_latex:n
3906 %<!latex>\cs_new_protected:Npn \@@_analyse_nesting_format:n
3907 %<plain> { \@@_analyse_nesting_generic:nn { } }
3908 %<context> { \@@_analyse_nesting_generic:nn { start } }
3909 %</loader>
3910 % \end{macrocode}
3911 % \end{macro}
3912 % \end{macro}
3913 %
3914 % \subsection{The command \cs{newenvsc}}\label{cmd:newenvsc}
3915 %
3916 % In version 1.8 (2019-11-18) the command §\newenvsc§ was implemented,
3917 % allowing you to create environments with the same behavior as the base
3918 % environment §scontents§. To achieve this, we will create new environments
3919 % so that they wrap around the base functions (\S\ref{fun:base:env}).
3920 %
3921 % \begin{macro}{\@@_generic_begin:,\@@_generic_end:,}
3922 % The function \cs{@@_generic_begin:} leaves the `§^^M§' character
3923 % active and calls the generic environment start function
3924 % \cs{@@_start_environment:w}.
3925 % \begin{macrocode}
3926 %<*core>
3927 \cs_new_protected:Npn \@@_generic_begin:
3928 {
3929 \char_set_catcode_active:N \^^M
3930 \@@_start_environment:w
3931 }
3932 % \end{macrocode}
3933 % The function \cs{@@_generic_end:} calls the generic environment stop
3934 % function \cs{@@_stop_environment:} and finally calls the function
3935 % \cs{@@_finish_storing:NNN} which stores \mymarg{body env} in
3936 % the \emph{sequence} \mymarg{seq name} and prints it from the \emph{sequence}
3937 % if the §print-env§ key is active.
3938 % \begin{macrocode}
3939 \cs_new_protected:Npn \@@_generic_end:
3940 {
3941 \@@_stop_environment:
3942 \@@_finish_storing:NNN
3943 \l_@@_processed_body_lines_tl
3944 \l_@@_name_seq_env_tl
3945 \l_@@_print_env_bool
3946 }
3947 % \end{macrocode}
3948 % \end{macro}
3949 %
3950 % \begin{macro}{\@@_setting_env:nn,\@@_define_env:nnn,}
3951 % The function \cs{@@_setting_env:nn} receives the environment \emph{name}
3952 % passed in §{#1}§ and save it in the variable \cs{l_@@_env_name_tl}
3953 % along with the initial \mymeta{keys} passed in §{#2}§.
3954 %
3955 % Two functions will be created \cs[no-index]{@@_\#1_begin:} and
3956 % \cs[no-index]{@@_\#1_end:} which will internally call the
3957 % \cs{@@_generic_begin:} and \cs{@@_generic_end:} functions and expand
3958 % the arguments of the function \cs{@@_define_env:nnn} function.
3959 % \begin{macrocode}
3960 \cs_new_protected:Npn \@@_setting_env:nn #1 #2
3961 {
3962 \cs_new_protected:cpn { @@_#1_begin: }
3963 {
3964 \tl_set:Nn \l_@@_env_name_tl {#1}
3965 \keys_set:nn { scontents } {#2}
3966 \@@_setup_verb_processor:
3967 \@@_generic_begin:
3968 }
3969 \cs_new_protected:cpn { @@_#1_end: }
3970 { \@@_generic_end: }
3971 \exp_args:Nooo \@@_define_env:nnn % http://nooooooooooooooo.com :) jeje
3972 { \tl_to_str:n {#1} }
3973 { \cs:w @@_#1_begin: \cs_end: }
3974 { \cs:w @@_#1_end: \cs_end: }
3975 }
3976 %</core>
3977 % \end{macrocode}
3978 % The function \cs{@@_define_env:nnn} will create the environments for
3979 % \hologo{LaTeX}, \hologo{plainTeX} and \hologo{ConTeXt}.
3980 % \begin{macrocode}
3981 %<*loader>
3982 \cs_new_protected:Npn \@@_define_env:nnn #1 #2 #3
3983 {
3984 %<latex|plain> \NewDocumentEnvironment {#1} { }
3985 %<context> \cs_new_protected:cpn { start #1 }
3986 {
3987 %<!latex> \group_begin:
3988 #2
3989 }
3990 %<context> \cs_new_protected:cpn { stop #1 }
3991 {
3992 #3
3993 %<!latex> \group_end:
3994 }
3995 }
3996 % \end{macrocode}
3997 % \end{macro}
3998 %
3999 % \begin{macro}{\newenvsc,}
4000 % Now we just need to create the user command §\newenvsc§
4001 % for \hologo{LaTeX}, \hologo{plainTeX} and \hologo{ConTeXt}.
4002 % \begin{macrocode}
4003 \NewDocumentCommand \newenvsc { m O{} }
4004 {
4005 %<latex|plain> \cs_if_exist:cTF { #1 }
4006 %<context> \cs_if_exist:cTF { start #1 }
4007 { \msg_error:nnn { scontents } { env-already-defined } {#1} }
4008 { \@@_setting_env:nn {#1} {#2} }
4009 }
4010 %</loader>
4011 % \end{macrocode}
4012 % \end{macro}
4013 %
4014 % \subsection{The environment \env{scontents}}\label{env:scontents}
4015 %
4016 % \begin{macro}{
4017 % scontents,
4018 % \scontents,
4019 % \endscontents,
4020 % \startscontents,
4021 % \stopscontents,
4022 % }
4023 % Finally defining the §scontents§ environment should be easy :)
4024 % \begin{macrocode}
4025 %<*loader>
4026 \newenvsc{scontents}
4027 %</loader>
4028 % \end{macrocode}
4029 % \end{macro}
4030 %
4031 % \subsection{The environment \env{verbatimsc}}\label{env:verbatimsc}
4032 %
4033 % The §verbatimsc§ environment is, in a way, a customized version of the
4034 % standard \myenv{verbatim} environment provided by \hologo{LaTeX}. For
4035 % correct operation in \hologo{plainTeX}, \hologo{LaTeX} and \hologo{ConTeXt},
4036 % we must add a couple of additional functions.
4037 %
4038 % \begin{macro}[int]{\dospecials}
4039 % The \myenv{verbatim} environment in \LaTeX requires §\dospecials§.
4040 % In case it doesn't exist (at the time \mypkg*{scontents} is loaded)
4041 % we define §\dospecials§
4042 % to use the \cs{l_char_special_seq}.
4043 % \begin{macrocode}
4044 %<*!latex>
4045 \cs_if_exist:NF \dospecials
4046 {
4047 \cs_new:Npn \dospecials
4048 { \seq_map_function:NN \l_char_special_seq \do }
4049 }
4050 %</!latex>
4051 % \end{macrocode}
4052 % \end{macro}
4053 %
4054 % \begin{macro}[int]{\@@_xverb:w,\end{verbatimsc},\endverbatimsc,\stopverbatimsc}
4055 % The environment §verbatimsc§ needs to literally find the end of
4056 % this §\end{verbatimsc}§ in the case of \hologo{LaTeX}. Here we set this
4057 % for \hologo{plainTeX}, \hologo{LaTeX}, and \hologo{ConTeXt}.
4058 % \begin{macrocode}
4059 %<*loader>
4060 %<*!context>
4061 \use:e
4062 {
4063 \cs_new_protected:Npn \exp_not:N \@@_xverb:w
4064 #1 \g_@@_end_verbatimsc_tl
4065 %<latex> { #1 \exp_not:N \end{verbatimsc} }
4066 %<plain> { #1 \exp_not:N \endverbatimsc }
4067 %<context> { #1 \exp_not:N \stopverbatimsc }
4068 }
4069 %</!context>
4070 %</loader>
4071 % \end{macrocode}
4072 % \end{macro}
4073 %
4074 % \subsubsection{\hologo{plainTeX} version off \texttt{verbatimsc}}
4075 %
4076 % \begin{macro}[int]{\verbatimsc,\endverbatimsc,\@@_verbatimsc_aux:,
4077 % \@@_vobeyspaces:,\@@_xverb:,\@@_nolig_list:,\@@_xobeysp:}
4078 % In \hologo{plainTeX} we emulate \LaTeX's \myenv{verbatim} environment.
4079 % \begin{macrocode}
4080 %<*plain>
4081 \cs_new_protected:Npn \verbatimsc
4082 {
4083 \group_begin:
4084 \@@_verbatimsc_aux: \frenchspacing \@@_vobeyspaces:
4085 \@@_xverb:
4086 }
4087 \cs_new_protected:Npn \endverbatimsc
4088 { \group_end: }
4089 \cs_new_protected:Nn \@@_verbatimsc_aux:
4090 {
4091 \skip_vertical:N \parskip
4092 \dim_zero:N \parindent
4093 \skip_set:Nn \parfillskip { 0pt plus 1fil }
4094 \skip_set:Nn \parskip { 0pt plus0pt minus0pt }
4095 \tex_par:D
4096 \bool_set_false:N \l_@@_plain_bool
4097 \cs_set:Npn \par
4098 {
4099 \bool_if:NTF \l_@@_plain_bool
4100 {
4101 \mode_leave_vertical:
4102 \null
4103 \tex_par:D
4104 \penalty \interlinepenalty
4105 }
4106 {
4107 \bool_set_true:N \l_@@_plain_bool
4108 \mode_if_horizontal:T
4109 { \tex_par:D \penalty \interlinepenalty }
4110 }
4111 }
4112 \cs_set_eq:NN \do \char_set_catcode_other:N
4113 \dospecials \obeylines
4114 \tl_use:N \l_@@_verb_font_tl
4115 \cs_set_eq:NN \do \@@_do_noligs:N
4116 \@@_nolig_list:
4117 \tex_everypar:D \exp_after:wN
4118 { \tex_the:D \tex_everypar:D \tex_unpenalty:D }
4119 }
4120 \cs_new_protected:Nn \@@_nolig_list:
4121 { \do\`\do\<\do\>\do\,\do\'\do\- }
4122 \cs_new_protected:Nn \@@_vobeyspaces:
4123 { \@@_set_active_eq:NN \ \@@_xobeysp: }
4124 \cs_new_protected:Nn \@@_xobeysp:
4125 { \mode_leave_vertical: \nobreak \ }
4126 %</plain>
4127 % \end{macrocode}
4128 % \end{macro}
4129 %
4130 % \subsubsection{\hologo{ConTeXt} version off \texttt{verbatimsc}}
4131 %
4132 % \begin{macro}[int]{\startverbatimsc,\stopverbatimsc,}
4133 % In \hologo{ConTeXt} we use our own tool §\definetyping§.
4134 % \begin{macrocode}
4135 %<*loader>
4136 %<context>\definetyping[verbatimsc]
4137 %</loader>
4138 % \end{macrocode}
4139 % \end{macro}
4140 %
4141 % \subsubsection{\hologo{LaTeX} version off \texttt{verbatimsc}}
4142 %
4143 % \begin{macro}{\@@_verbatimsc_instance:,verbatimsc}
4144 % To be compatible with \emph{tagged} \texttt{PDF} we must define the
4145 % environment §verbatimsc§ in terms of the \mypkg{xtemplate}\cite{latex2e}
4146 % module integrated into the \LaTeX{} kernel and the new \texttt{blocks-code}
4147 % from \mypkg{latex-lab}\cite{latexlab}. This code is adapted directly
4148 % from Mrs. Ulrike Fischer's answer to \href{https://tex.stackexchange.com/a/741178/7832}{New verbatim environment with block code (tagged-pdf)}.
4149 % \begin{macrocode}
4150 %<*loader>
4151 %<*latex>
4152 \cs_new_protected:Nn \@@_verbatimsc_instance:
4153 {
4154 \DeclareInstance{blockenv}{verbatimsc}{display}
4155 {
4156 name = verbatimsc,
4157 tag-name = verbatim,
4158 tagging-recipe = standard,
4159 increment-level = false,
4160 tagging-suppress-paras = true,
4161 setup-code = ,
4162 block-instance = verbatimblock ,
4163 para-instance = justify ,
4164 inner-instance = ,
4165 final-code = \legacyverbatimsetup,%\tag_tool:n {paratag=codeline},
4166 }
4167 }
4168 \NewDocumentEnvironment { verbatimsc } { }
4169 {
4170 \IfDocumentMetadataTF
4171 {
4172 \@@_verbatimsc_instance:
4173 \UseInstance{blockenv}{verbatimsc}{}
4174 \@setupverbinvisiblespace\frenchspacing\@vobeyspaces
4175 \@@_xverb:
4176 }
4177 {
4178 \cs_set_eq:cN { @xverbatim } \@@_xverb:
4179 \verbatim
4180 }
4181 }
4182 % \end{macrocode}
4183 % The §\endverbatim§ in the second argument of the §verbatimsc§
4184 % environment is only needed for compatibility with the \mypkg{verbatim}\cite{verbatim}
4185 % package.
4186 % \begin{macrocode}
4187 {
4188 \IfDocumentMetadataTF
4189 {
4190 \endblockenv
4191 }
4192 { \endverbatim }
4193 }
4194 %</latex>
4195 %</loader>
4196 % \end{macrocode}
4197 % \end{macro}
4198 %
4199 % \subsection{The command \cs{Scontents}}\label{cmd:Scontents}
4200 %
4201 % \begin{macro}{
4202 % \Scontents,
4203 % \@@_Scontents_code:nn,
4204 % \@@_Scontents_norm_arg:n,
4205 % \@@_Scontents_verb_arg:w,
4206 % }
4207 % User command §\Scontents§ to \mymeta{stored content} in a \emph{sequence},
4208 % adapted from code by Ulrich Diez in \href{https://tex.stackexchange.com/a/472044/7832}{Stringify
4209 % input - \textbackslash string on token list}
4210 % and code by user \texttt{@siracusa} in
4211 % \href{https://tex.stackexchange.com/a/500281/7832}{Convert a macro from Latex2e to expl3}.
4212 % \begin{macrocode}
4213 %<*core>
4214 \NewDocumentCommand \Scontents { !s !O{} }
4215 {
4216 \tl_set:Nn \l_@@_cmd_name_tl { Scontents }
4217 \@@_Scontents_code:nn {#1} {#2}
4218 }
4219 % \end{macrocode}
4220 % The internal function \cs{@@_Scontents_code:nn} first executes
4221 % \cs{@@_bsphack:}, opens a group and checks the \mymeta{keys} passed in
4222 % §{#2}§, leaves the \texttt{TAB} character active and then checks the
4223 % \emph{starred argument} `§*§' passed in §{#1}§. If the latter is present
4224 % it will call the function \cs{@@_Scontents_verb_arg:w} otherwise it will
4225 % call the function \cs{@@_Scontents_norm_arg:n}.
4226 % \begin{macrocode}
4227 \cs_new_protected:Npn \@@_Scontents_code:nn #1 #2
4228 {
4229 \@@_bsphack:
4230 \group_begin:
4231 \tl_if_novalue:nF {#2}
4232 { \keys_set:nn { scontents / Scontents } {#2} }
4233 \char_set_catcode_active:n { 9 }
4234 \bool_if:NTF #1
4235 { \@@_Scontents_verb_arg:w }
4236 { \@@_Scontents_norm_arg:n }
4237 }
4238 % \end{macrocode}
4239 % The function \cs{@@_Scontents_verb_arg:w} saves the \mymarg{argument}
4240 % passed in §{#1}§ under the \emph{verbatim catcode} using |v-|type
4241 % argument from \mypkg{ltcmd} in \cs{l_@@_Scontents_arg_tl}
4242 % and replaces all `§^^M§' and §\obeyedline§ added in \hologo{LaTeX}
4243 % release 2024-06-01 by `§^^J§' and then calls the function \cs{@@_Scontents_finish:}.
4244 % Here we will apply §\RenewDocumentCommand§ since §\obeyedline§ can be
4245 % modified by the user and if so the code would return a low-level error.
4246 % \begin{macrocode}
4247 \NewDocumentCommand \@@_Scontents_verb_arg:w { +v }
4248 {
4249 \tl_set:Nn \l_@@_Scontents_arg_tl {#1}
4250 \tl_if_empty:NT \l__enumext_ref_key_arg_tl
4251 {
4252 \msg_warning:nne { scontents } { empty-argument-command } { \l_@@_Scontents_arg_tl }
4253 }
4254 \cs_if_exist:NT \obeyedline
4255 {
4256 \RenewDocumentCommand \obeyedline { } { \iow_char:N \^^M }
4257 \tl_replace_all:Nee \l_@@_Scontents_arg_tl { \obeyedline } { \iow_char:N \^^M }
4258 }
4259 \tl_replace_all:NeV \l_@@_Scontents_arg_tl { \iow_char:N \^^M } \c_@@_newline_tl
4260 \@@_Scontents_finish:
4261 }
4262 % \end{macrocode}
4263 % The function \cs{@@_Scontents_norm_arg:n} saves the \mymarg{argument}
4264 % passed in §{#1}§ in the \emph{standard catcode} regimen and then
4265 % calls the function \cs{@@_Scontents_finish:}.
4266 % \begin{macrocode}
4267 \cs_new_protected:Npn \@@_Scontents_norm_arg:n #1
4268 {
4269 \tl_set:Nn \l_@@_Scontents_arg_tl {#1}
4270 \@@_Scontents_finish:
4271 }
4272 % \end{macrocode}
4273 % The function \cs{@@_Scontents_finish:} will first call the function
4274 % \cs{@@_file_write_cmd:VV} used by the §write-out§ and §write-cmd§ keys,
4275 % then call the function \cs{@@_finish_storing:NNN} to \emph{store} the
4276 % \mymarg{argument} passed to the §\Scontents§ command saved in
4277 % the \cs{l_@@_Scontents_arg_tl} variable in the \emph{sequence} \cs{l_@@_name_seq_cmd_tl}
4278 % and print it from this \emph{sequence} according to the state of
4279 % the \cs{l_@@_print_cmd_bool} variable set by the §print-cmd§ key.
4280 % Finally it will close the \emph{group} opened at the beginning of
4281 % the command definition and run \cs{@@_esphack:} if the §print-cmd§
4282 % key is not active.
4283 % \begin{macrocode}
4284 \cs_new_protected:Nn \@@_Scontents_finish:
4285 {
4286 \@@_file_write_cmd:VV \l_@@_file_name_tl \l_@@_Scontents_arg_tl
4287 \@@_finish_storing:NNN
4288 \l_@@_Scontents_arg_tl \l_@@_name_seq_cmd_tl \l_@@_print_cmd_bool
4289 \use:e
4290 {
4291 \group_end:
4292 \bool_if:NF \l_@@_print_cmd_bool { \@@_esphack: }
4293 }
4294 }
4295 % \end{macrocode}
4296 % \end{macro}
4297 %
4298 % \subsection{The command \cs{getstored}}\label{cmd:getstored}
4299 %
4300 % \begin{macro}{\getstored,\@@_getstored:nn}
4301 % User command §\getstored§ to extract \mymeta{stored content} in
4302 % \emph{sequence} (robust).
4303 % \begin{macrocode}
4304 \NewDocumentCommand \getstored { O{-1} m }
4305 {
4306 \@@_getstored:nn {#1} {#2}
4307 }
4308 % \end{macrocode}
4309 % The internal function \cs{@@_getstored:nn} will set the end of line
4310 % then apply the function §\tl_retokenize:e§ on the \mymeta{stored content}
4311 % at the \mymeta{index} given by §{#1}§ in the sequence §{#2}§ via
4312 % the function \cs{@@_getfrom_seq:nn}.
4313 % \begin{macrocode}
4314 \cs_new_protected:Npn \@@_getstored:nn #1 #2
4315 {
4316 \tl_retokenize:e
4317 {
4318 \@@_getfrom_seq:nn {#1} {#2}
4319 }
4320 }
4321 % \end{macrocode}
4322 % \end{macro}
4323 %
4324 % \subsection{The command \cs{foreachsc}}\label{cmd:foreachsc}
4325 %
4326 % \begin{macro}{\foreachsc,\@@_foreachsc:nn,\@@_foreach_add_body:n}
4327 % User command §\foreachsc§ to loop over \mymeta{stored content} in \emph{sequence}.
4328 % \begin{macrocode}
4329 \NewDocumentCommand \foreachsc { o m }
4330 {
4331 \tl_set:Nn \l_@@_cmd_name_tl { foreachsc }
4332 \@@_foreachsc:nn {#1} {#2}
4333 }
4334 \cs_new_protected:Npn \@@_foreachsc:nn #1 #2
4335 {
4336 \group_begin:
4337 \tl_if_novalue:nF {#1} { \keys_set:nn { scontents / foreachsc } {#1} }
4338 \tl_set:Nn \l_@@_foreachsc_arg_tl {#2}
4339 \seq_clear:N \l_@@_foreach_print_seq
4340 \bool_if:NF \l_@@_foreach_stop_bool
4341 {
4342 \int_set:Nn \l_@@_foreach_stop_int
4343 { \seq_count:c { g_@@_name_#2_seq } }
4344 }
4345 \int_step_function:nnnN
4346 { \l_@@_foreach_start_int }
4347 { \l_@@_foreach_step_int }
4348 { \l_@@_foreach_stop_int }
4349 \@@_foreach_add_body:n
4350 \tl_gset:Ne \g_@@_foreach_exec_tl
4351 {
4352 \exp_args:NNV \seq_use:Nn
4353 \l_@@_foreach_print_seq \l_@@_foreach_sep_tl
4354 }
4355 \group_end:
4356 \exp_after:wN \tl_gclear:N
4357 \exp_after:wN \g_@@_foreach_exec_tl
4358 \g_@@_foreach_exec_tl
4359 }
4360 \cs_new_protected:Npn \@@_foreach_add_body:n #1
4361 {
4362 \seq_put_right:Ne \l_@@_foreach_print_seq
4363 {
4364 \bool_if:NT \l_@@_foreach_before_bool
4365 { \exp_not:V \l_@@_foreach_before_tl }
4366 \bool_if:NTF \l_@@_foreach_wrapper_bool
4367 { \@@_foreach_wrapper:n }
4368 { \use:n }
4369 { \getstored [#1] { \tl_use:N \l_@@_foreachsc_arg_tl } }
4370 \bool_if:NT \l_@@_foreach_after_bool
4371 { \exp_not:V \l_@@_foreach_after_tl }
4372 }
4373 }
4374 % \end{macrocode}
4375 % \end{macro}
4376 %
4377 % \subsection{The command \cs{typestored}}\label{cmd:typestored}
4378 %
4379 % \begin{macro}{\typestored,\@@_typestored:nn,\@@_typestored:N,
4380 % \@@_xverb:w}
4381 % The §\typestored§ commands fetches a buffer from memory, prints it
4382 % to the log file, and then calls \cs{@@_typestored:N}.
4383 % \begin{macrocode}
4384 \NewDocumentCommand \typestored { o m }
4385 {
4386 \tl_set:Nn \l_@@_cmd_name_tl { typestored }
4387 \@@_typestored:nn {#1} {#2}
4388 }
4389 \cs_new_protected:Npn \@@_typestored:nn #1 #2
4390 {
4391 \@@_bsphack:
4392 \group_begin:
4393 \seq_clear:N \l_@@_seq_item_seq
4394 \str_set:Ne \l_@@_current_seq_name_str {#2}
4395 \tl_if_novalue:nF {#1} { \keys_set:nn { scontents / typemeaning } {#1} }
4396 \seq_if_empty:NT \l_@@_seq_item_seq
4397 { \seq_set_from_clist:Nn \l_@@_seq_item_seq { 1 } }
4398 \tl_set:Ne \l_@@_typestored_arg_tl
4399 { \@@_getfrom_seq:Nn \l_@@_seq_item_seq {#2} }
4400 \@@_remove_trailing_eol:N \l_@@_typestored_arg_tl
4401 \tl_replace_all:NeV \l_@@_typestored_arg_tl { \c_@@_hidden_space_str } \c_@@_newline_tl
4402 \tl_log:N \l_@@_typestored_arg_tl
4403 \tl_if_empty:NF \l_@@_typestored_arg_tl
4404 {
4405 \bool_if:NT \l_@@_print_verb_style_bool
4406 {
4407 \@@_typestored:N \l_@@_typestored_arg_tl
4408 }
4409 }
4410 \@@_file_write_cmd:VV \l_@@_file_name_tl \l_@@_typestored_arg_tl
4411 \use:e
4412 {
4413 \group_end:
4414 \bool_if:NF \l_@@_print_verb_style_bool { \@@_esphack: }
4415 }
4416 }
4417 % \end{macrocode}
4418 % The \cs{@@_typestored:N} macro is defined with active carriage return
4419 % (\textsc{ascii} 13) characters to \emph{mimic} an actual §verbatim§ environment
4420 % \enquote{on the loose}. The contents of the environment are placed in a
4421 % §verbatimsc§ environment and rescanned using §\tl_retokenize:e§.
4422 % \begin{macrocode}
4423 \group_begin:
4424 \char_set_catcode_active:N \^^M
4425 \cs_new_protected:Npn \@@_typestored:N #1
4426 {
4427 \tl_if_blank:VT #1
4428 { \msg_error:nnn { scontents } { empty-variable } {#1} }
4429 \cs_set_eq:NN \@@_verb_print_EOL: ^^M
4430 \cs_set_eq:NN ^^M \scan_stop:
4431 \cs_set_eq:cN { do@noligs } \@@_do_noligs:N
4432 \int_set:Nn \tex_newlinechar:D { `\^^J }
4433 \tl_retokenize:e
4434 {
4435 \@@_format_case:nnn
4436 { \exp_not:N \begin{verbatimsc} } % LaTeX
4437 { \verbatimsc } % Plain/Generic
4438 { \startverbatimsc } % ConTeXt
4439 ^^M
4440 \exp_not:V #1 ^^M
4441 \g_@@_end_verbatimsc_tl
4442 }
4443 \cs_set_eq:NN ^^M \@@_verb_print_EOL:
4444 }
4445 \group_end:
4446 \cs_new_protected:Nn \@@_xverb:
4447 {
4448 \char_set_catcode_active:n { 9 }
4449 \char_set_active_eq:nN { 9 } \@@_tabs_to_spaces:
4450 \@@_xverb:w
4451 }
4452 % \end{macrocode}
4453 % \end{macro}
4454 %
4455 % \subsection{The command \cs{meaningsc}}\label{cmd:meaningsc}
4456 %
4457 % \begin{macro}{\meaningsc,\@@_meaningsc:nn,\@@_meaningsc:n}
4458 % User command §\meaningsc§ to see content stored in |seq|.
4459 % \begin{macrocode}
4460 \NewDocumentCommand \meaningsc { o m }
4461 {
4462 \tl_set:Nn \l_@@_cmd_name_tl { meaningsc }
4463 \@@_meaningsc:nn {#1} {#2}
4464 }
4465 \cs_new_protected:Npn \@@_meaningsc:nn #1 #2
4466 {
4467 \@@_bsphack:
4468 \group_begin:
4469 \seq_clear:N \l_@@_seq_item_seq
4470 \str_set:Ne \l_@@_current_seq_name_str {#2}
4471 \tl_if_novalue:nF {#1} { \keys_set:nn { scontents / typemeaning } {#1} }
4472 \seq_if_empty:NT \l_@@_seq_item_seq
4473 { \seq_set_from_clist:Nn \l_@@_seq_item_seq { 1 } }
4474 \@@_meaningsc:n {#2}
4475 \use:e
4476 {
4477 \group_end:
4478 \bool_if:NF \l_@@_print_verb_style_bool { \@@_esphack: }
4479 }
4480 }
4481 \group_begin:
4482 \char_set_catcode_active:N \^^I
4483 \cs_new_protected:Npn \@@_meaningsc:n #1
4484 {
4485 \tl_set:Ne \l_@@_meaningsc_arg_tl
4486 { \@@_getfrom_seq:Nn \l_@@_seq_item_seq {#1} }
4487 \tl_replace_all:Nen \l_@@_meaningsc_arg_tl { \iow_char:N \^^J } { ~ }
4488 \tl_replace_all:Nen \l_@@_meaningsc_arg_tl { \c_@@_hidden_space_str } { ~ }
4489 \tl_log:N \l_@@_meaningsc_arg_tl
4490 \tl_use:N \l_@@_verb_font_tl
4491 \tl_replace_all:Nne \l_@@_meaningsc_arg_tl { ^^I } { \@@_tabs_to_spaces: }
4492 \tl_if_empty:NF \l_@@_meaningsc_arg_tl
4493 {
4494 \bool_if:NT \l_@@_print_verb_style_bool
4495 {
4496 \cs_replacement_spec:N \l_@@_meaningsc_arg_tl
4497 }
4498 }
4499 \@@_file_write_cmd:VV \l_@@_file_name_tl \l_@@_meaningsc_arg_tl
4500 }
4501 \group_end:
4502 % \end{macrocode}
4503 % \end{macro}
4504 %
4505 % \subsection{The command \cs{mergesc}}\label{cmd:mergesc}
4506 %
4507 % The §\mergesc§ command parses a comma separated list given as \mymarg{argument},
4508 % and just assembles it as a temporary \emph{internal sequence}, then
4509 % passes it to the §\typestored§ or §\meaningsc§ command.
4510 %
4511 % \begin{macro}{\mergesc, \@@_mergesc_code:nn, \@@_mergesc_parse_list:n,
4512 % \@@_remove_trailing_eol:N, \@@_remove_trailing_eol:w,
4513 % \@@_parse_mergesc:nw, \@@_parse_mergesc_aux:nw, \@@_parse_mergesc_range:nw,}
4514 % The §\mergesc§ command parses a list given as argument, and just assembles
4515 % it as a temporary internal sequence, then passes it to the requested command.
4516 % \begin{macrocode}
4517 \NewDocumentCommand \mergesc { o m }
4518 {
4519 \tl_set:Nn \l_@@_cmd_name_tl { mergesc }
4520 \@@_mergesc_code:nn {#1} {#2}
4521 }
4522 \cs_new_protected:Npn \@@_mergesc_code:nn #1 #2
4523 {
4524 \group_begin:
4525 \tl_clear:N \l_@@_mergesc_keys_tl
4526 \tl_if_novalue:nF {#1}
4527 {
4528 \keys_set_known:nnN { scontents / mergesc } {#1} \l_@@_mergesc_keys_tl
4529 }
4530 \seq_gclear:c { g_@@_name_sc!internal_seq }
4531 \@@_mergesc_parse_list:n {#2}
4532 \exp_args:Ne \@@_mergesc_cmd:nn
4533 { 1-end, \exp_not:V \l_@@_mergesc_keys_tl } { sc!internal }
4534 \group_end:
4535 }
4536 % \end{macrocode}
4537 % \begin{macrocode}
4538 \cs_new_protected:Npn \@@_mergesc_parse_list:n #1
4539 {
4540 \clist_map_inline:nn {#1} { \@@_parse_mergesc:nw ##1 \s_@@_stop }
4541 \seq_gpop_right:cN { g_@@_name_sc!internal_seq } \l_@@_mergesc_arg_tl
4542 \@@_remove_trailing_eol:N \l_@@_mergesc_arg_tl
4543 \seq_gput_right:cV { g_@@_name_sc!internal_seq } \l_@@_mergesc_arg_tl
4544 }
4545 \cs_new_protected:Npe \@@_remove_trailing_eol:N #1
4546 {
4547 \exp_not:N \exp_after:wN \exp_not:N \@@_remove_trailing_eol:w
4548 #1 \s_@@_stop \c_@@_hidden_space_str \s_@@_stop \s_@@_mark #1
4549 }
4550 \use:e
4551 {
4552 \cs_new_protected:Npn \exp_not:N \@@_remove_trailing_eol:w #1
4553 \c_@@_hidden_space_str \s_@@_stop #2 \s_@@_mark #3
4554 } {
4555 \tl_set:Ne #3
4556 {
4557 \tl_if_empty:nTF {#2}
4558 { \exp_not:o { \@@_use_delimit_by_s_stop:nw #1 } }
4559 { \exp_not:n {#1} }
4560 }
4561 }
4562 \cs_new_protected:Npn \@@_parse_mergesc:nw #1
4563 {
4564 \peek_remove_spaces:n
4565 {
4566 \peek_charcode:NTF [ % ]
4567 { \@@_parse_mergesc_aux:nw {#1} }
4568 { \@@_parse_mergesc_aux:nw {#1} [ 1-\seq_count:c { g_@@_name_#1_seq } ] }
4569 }
4570 }
4571 \cs_new_protected:Npn \@@_parse_mergesc_aux:nw #1 [#2]
4572 {
4573 \seq_clear:N \l_@@_seq_item_seq
4574 \clist_map_inline:nn {#2}
4575 { \@@_parse_mergesc_range:nw {#1} ##1 - \q_@@_mark - \s_@@_mark }
4576 \seq_map_inline:Nn \l_@@_seq_item_seq
4577 {
4578 \seq_gput_right:ce { g_@@_name_sc!internal_seq }
4579 { \seq_item:cn { g_@@_name_#1_seq } {##1} }
4580 }
4581 \@@_use_none_delimit_by_s_stop:w
4582 }
4583 \cs_new_protected:Npn \@@_parse_mergesc_range:nw #1 #2 - #3 - #4 \s_@@_mark
4584 {
4585 \cs_set_protected:Npn \@@_tmp:w ##1
4586 {
4587 \msg_error:nneee { scontents } { index-out-of-range }
4588 {##1} {#1} { \seq_count:c { g_@@_name_#1_seq } }
4589 }
4590 \@@_range_parser:nnen {#2} {#3}
4591 { \seq_count:c { g_@@_name_#1_seq } }
4592 { \@@_tmp:w }
4593 }
4594 % \end{macrocode}
4595 % \end{macro}
4596 %
4597 % \subsection{The command \cs{setupsc}}
4598 %
4599 % \begin{macro}{\setupsc}
4600 % User command §\setupsc§ to setup module for §\keys_set:nn { scontents }§.
4601 % \begin{macrocode}
4602 \NewDocumentCommand \setupsc { +m }
4603 {
4604 \keys_set:nn { scontents } {#1}
4605 }
4606 % \end{macrocode}
4607 % \end{macro}
4608 %
4609 % \subsection{The command \cs{countsc}}
4610 %
4611 % \begin{macro}{\countsc}
4612 % User command §\countsc§ to count number of \mymeta{stored contents}
4613 % in the \emph{sequence}.
4614 % \begin{macrocode}
4615 \NewExpandableDocumentCommand \countsc { m }
4616 {
4617 \seq_count:c { g_@@_name_#1_seq }
4618 }
4619 % \end{macrocode}
4620 % \end{macro}
4621 %
4622 % \subsection{The command \cs{cleanseqsc}}
4623 %
4624 % \begin{macro}{\cleanseqsc}
4625 % A user command §\cleanseqsc§ to clear (remove) all \mymeta{stored contents}
4626 % in the \emph{sequence}.
4627 % \begin{macrocode}
4628 \NewDocumentCommand \cleanseqsc { m }
4629 {
4630 \seq_gclear_new:c { g_@@_name_#1_seq }
4631 }
4632 % \end{macrocode}
4633 % \end{macro}
4634 %
4635 % \subsection{Warning and error messages}
4636 %
4637 % Warning and error messages used throughout the package.
4638 %
4639 % \begin{macrocode}
4640 \msg_new:nnn { scontents } { junk-after-begin }
4641 {
4642 Junk~characters~#1~\msg_line_context: :
4643 \\ \\
4644 #2
4645 }
4646 \msg_new:nnnn { scontents } { env-already-defined }
4647 { Environment~'#1'~already~defined! }
4648 {
4649 You~have~used~\newenvsc
4650 with~an~environment~that~already~has~a~definition. \\ \\
4651 The~existing~definition~of~'#1'~will~not~be~altered.
4652 }
4653 \msg_new:nnn { scontents } { empty-argument-command }
4654 { Empty~~argument~for~'Scontents'~\msg_line_context:. }
4655 \msg_new:nnn { scontents } { empty-environment }
4656 { environment~'#1'~empty~\msg_line_context:. }
4657 \msg_new:nnn { scontents } { empty-variable }
4658 { Variable~'#1'~empty~\msg_line_context:. }
4659 \msg_new:nnn { scontents } { overwrite-file }
4660 { Overwriting~file~'#1'. }
4661 \msg_new:nnn { scontents } { writing-file }
4662 { Writing~file~'#1'. }
4663 \msg_new:nnn { scontents } { not-writing }
4664 { File~`#1'~already~exists.~Not~writing. }
4665 \msg_new:nnn { scontents } { rescanning-text }
4666 { Rescanning~text~'#1'~after~\c_backslash_str end{#2}~\msg_line_context:.}
4667 \msg_new:nnn { scontents } { multiple-begin }
4668 { Multiple~\c_backslash_str begin{ \l_@@_env_name_tl }~\msg_line_context:.}
4669 \msg_new:nnn { scontents } { undefined-storage }
4670 { Storage~named~'#1'~is~not~defined. }
4671 \msg_new:nnnn { scontents } { mergesc-missing-key }
4672 {
4673 Need~mandatory~key~'typestored'~or~'meaningsc'~for~\\
4674 command~\c_backslash_str mergesc~\msg_line_context:.
4675 }
4676 {
4677 The~command~\c_backslash_str mergesc~need~a~mandatory~key~typestored~or~meaningsc.\\
4678 Check~that~you~have~spelled~the~key~name~correctly.
4679 }
4680 \msg_new:nnn { scontents } { index-out-of-range }
4681 {
4682 \int_compare:nNnTF {#1} = { 0 }
4683 { Index~of~sequence~cannot~be~zero. }
4684 {
4685 Index~'#1'~out~of~range~for~'#2'.~
4686 \int_compare:nNnTF {#1} > { 0 }
4687 { Max = } { Min = -} #3.
4688 }
4689 }
4690 \msg_new:nnnn { scontents } { env-key-unknown }
4691 {
4692 The~key~'#1'~is~unknown~by~environment~
4693 '\l_@@_env_name_tl'~and~is~being~ignored.
4694 }
4695 {
4696 The~environment~'\l_@@_env_name_tl'~does~not~have~a~key~called~'#1'.\\
4697 Check~that~you~have~spelled~the~key~name~correctly.
4698 }
4699 \msg_new:nnnn { scontents } { env-key-value-unknown }
4700 {
4701 The~key~'#1=#2'~is~unknown~by~environment~
4702 '\l_@@_env_name_tl'~and~is~being~ignored.
4703 }
4704 {
4705 The~environment~'\l_@@_env_name_tl'~does~not~have~a~key~called~'#1'.\\
4706 Check~that~you~have~spelled~the~key~name~correctly.
4707 }
4708 \msg_new:nnnn { scontents } { cmd-key-unknown }
4709 {
4710 The~key~'#1'~is~unknown~by~command~\c_backslash_str \l_@@_cmd_name_tl \c_space_tl
4711 and~is~being~ignored~ \msg_line_context:.
4712 }
4713 {
4714 The~command~\c_backslash_str \l_@@_cmd_name_tl \c_space_tl
4715 does~not~have~a~key~called~'#1'.\\
4716 Check~that~you~have~spelled~the~key~name~correctly.
4717 }
4718 \msg_new:nnnn { scontents } { cmd-key-value-unknown }
4719 {
4720 The~key~'#1=#2'~is~unknown~by~command~\c_backslash_str \l_@@_cmd_name_tl \c_space_tl
4721 and~is~being~ignored~ \msg_line_context:.
4722 }
4723 {
4724 The~command~\c_backslash_str \l_@@_cmd_name_tl \c_space_tl
4725 does~not~have~a~key~called~'#1'.\\
4726 Check~that~you~have~spelled~the~key~name~correctly.
4727 }
4728 %</core>
4729 % \end{macrocode}
4730 %
4731 % \subsection{Finish package}
4732 %
4733 % Finish package implementation.
4734 %
4735 % \begin{macrocode}
4736 %<plain|context>\ExplSyntaxOff
4737 %<plain|context>\endinput
4738 %<latex|core>\file_input_stop:
4739 % \end{macrocode}
4740 %
4741 % \Finale