Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- % arara: pdflatex: { interaction: batchmode }
- % arara: clean: { extensions: [ aux, log, tsc] }
- % \pdfinfoomitdate1
- % \pdfsuppressptexinfo-1
- % \pdftrailerid{}
- \RequirePackage{filecontents}
- \begin{filecontents*}{scontents.sty}
- \RequirePackage{filecontentsdef}[2019/04/20]
- \RequirePackage{l3keys2e}
- \RequirePackage{xparse}[2019/05/03]
- \RequirePackage{fvextra}
- \ProvidesExplPackage{scontents}{2019/07/12}{0.999999}
- {Store LaTeX content in Sequences (l3seq)}
- \ExplSyntaxOn
- % A common key val
- \keys_define:nn { scontents }
- {
- store-env .tl_set:N = \l__scontents_name_seq_env_tl,
- store-env .initial:n = contents,
- print-env .bool_set:N = \l__scontents_print_env_bool,
- print-env .initial:n = false,
- store-cmd .tl_set:N = \l__scontents_name_seq_cmd_tl,
- store-cmd .initial:n = contents,
- print-cmd .bool_set:N = \l__scontents_print_cmd_bool,
- print-cmd .initial:n = false,
- print-all .meta:n = { print-env = true , print-cmd = true },
- store-env .value_required:n = true,
- store-cmd .value_required:n = true,
- print-env .value_required:n = true,
- print-cmd .value_required:n = true,
- print-all .value_required:n = true
- }
- % Process options for pkg
- \ProcessKeysOptions { scontents }
- % tl vars
- \tl_new:N \l__scontents_macro_tmp_tl
- \tl_new:N \l__scontents_fname_out_tl
- \tl_new:N \l__scontents_temp_tl
- % bool vars
- \bool_new:N \l__scontents_typeverb_env_bool
- \bool_new:N \l__scontents_write_file_bool
- \bool_new:N \l__scontents_macro_pass_bool
- % default
- \bool_set_true:N \l__scontents_macro_pass_bool
- \bool_set_false:N \l__scontents_write_file_bool
- \bool_set_true:N \l__scontents_typevrb_env_bool
- % Add keys to scontents environonment
- \keys_define:nn { scontents }
- {
- write-env .code:n = {
- \bool_set_true:N \l__scontents_write_file_bool
- \tl_set:Nn \l__scontents_fname_out_tl {#1}
- },
- write-out .code:n = {
- \bool_set_false:N \l__scontents_macro_pass_bool
- \bool_set_true:N \l__scontents_write_file_bool
- \tl_set:Nn \l__scontents_fname_out_tl {#1}
- },
- write-env .value_required:n = true,
- write-out .value_required:n = true
- }
- % A sub/keys for command \Scontents
- \keys_define:nn { scontents / Scontents }
- {
- print-cmd .meta:nn = { scontents } { print-cmd = #1 },
- store-cmd .meta:nn = { scontents } { store-cmd = #1 }
- }
- % Append content to seq
- \cs_new_protected:Npn \__scontents_append_contents:nn #1#2
- {
- \tl_if_blank:nT {#1}
- { \msg_error:nn { scontents } { empty-store-cmd } }
- \seq_if_exist:cF { g__scontents_seq_name_#1_seq }
- { \seq_new:c { g__scontents_seq_name_#1_seq } }
- \seq_gput_right:cn { g__scontents_seq_name_#1_seq } {#2}
- }
- % Get content stored in seq
- \cs_new:Npn \__scontents_getfrom_seq:nn #1#2
- {
- \seq_item:cn { g__scontents_seq_name_#2_seq } {#1}
- }
- % Define scontents whit [key=val] (delaying)
- \ProvideDocumentEnvironment { scontents } { }
- {
- \char_set_catcode_active:N \^^M
- \scontents_start_environment:w
- }
- {
- \scontents_stop_environment:
- \scontents_atend_environment:
- }
- % key val for environment scontens
- \cs_new_protected:Npn \scontents_environment_keys:w [ #1 ]
- {
- \keys_set_known:nn { scontents } {#1}
- }
- % The environment itself
- \group_begin:
- \char_set_catcode_active:N \^^M
- \cs_new_protected:Npn \scontents_start_environment:w #1 ^^M
- {
- \tl_if_blank:nF {#1} { \scontents_environment_keys:w #1 }
- \group_begin:
- \bool_if:NTF \l__scontents_write_file_bool
- {
- \use:c { filecontentsdef* } { \l__scontents_fname_out_tl }
- { \l__scontents_macro_tmp_tl } ^^M
- }
- {
- \filecontentsdefmacro { \l__scontents_macro_tmp_tl } ^^M
- }
- }
- \cs_new_protected:Nn \scontents_stop_environment:
- {
- \bool_if:NTF \l__scontents_write_file_bool
- { \endfilecontentsdef }
- { \endfilecontentsdefmacro }
- \group_end:
- }
- \group_end:
- % A variant to expand grabed content in \l__scontents_macro_tmp_tl
- \exp_args_generate:n { Vx }
- % Expand and stored content in seq
- \cs_gset_protected:Nn \__scontents_stored_to_seq:
- {
- % Replace \^^M to \^^J for multiple lines
- \regex_replace_all:nnN { \^^M } { \^^J } \l__scontents_macro_tmp_tl
- \tl_log:N \l__scontents_macro_tmp_tl
- \exp_args:NVx \__scontents_append_contents:nn \l__scontents_name_seq_env_tl
- { \exp_not:N \tex_scantokens:D { \tl_use:N \l__scontents_macro_tmp_tl } }
- }
- % Code after scontent environment
- \cs_new_protected:Nn \scontents_atend_environment:
- {
- \bool_if:NT \l__scontents_macro_pass_bool
- {
- \__scontents_stored_to_seq:
- \bool_if:NT \l__scontents_print_env_bool
- { \exp_args:NnV \__scontents_getfrom_seq:nn { -1 } \l__scontents_name_seq_env_tl }
- }
- \tl_clear:N \l__scontents_macro_tmp_tl
- }
- % Define verbatimsc environment to pass content stored by scontents env
- \DefineVerbatimEnvironment{verbatimsc}{Verbatim}{}
- % Copy definition of macro \filecontentsdef@get
- \cs_new_eq:Nc \__scontents_fcdef_get:NN { filecontentsdef@get }
- % Check and strip \scantokens stored in seq by scontents env
- \quark_new:N \q__scontents_strip_quark
- \cs_new:Npn \__scontents_strip_scantokens:N #1
- {
- \exp_args:NV \__scontents_strip_scantokens:n #1
- }
- \cs_new:Npn \__scontents_strip_scantokens:n #1
- {
- \tl_if_head_is_N_type:nTF {#1}
- {
- \__scontents_if_scantokens:NwTF #1 \q__scontents_strip_quark
- { \exp_not:o { \use_ii:nn #1 } }
- { \exp_not:n {#1} }
- }
- { \exp_not:n {#1} }
- }
- \prg_new_conditional:Npnn \__scontents_if_scantokens:Nw #1#2
- \q__scontents_strip_quark { TF }
- {
- \token_if_eq_meaning:NNTF \tex_scantokens:D #1
- { \prg_return_true: }
- { \prg_return_false: }
- }
- % Pass stored content save by scontents env to verbatimsc env
- \group_begin:
- \char_set_catcode_active:N \^^M
- \cs_new_protected:Npn \__scontents_fcdef_print:N #1
- {
- \tl_if_blank:VT #1
- { \msg_error:nnn { scontents } { empty-variable } {#1} }
- \cs_set_eq:NN \__scontents_fcdef_saved_EOL: ^^M
- \cs_set_eq:NN ^^M \scan_stop:
- % Here I added a boleana variable, otherwise, added an extra blank
- % line inside the verbatim environment.r
- % (Phelype) \bool_if: is expandable, so instead of
- % \bool_if:NTF \l_some_bool { \use:x { code } } { \use:x { code ^^M } }
- % you can do
- % \use:x { code \bool_if:NF \l_some_bool { ^^M } }
- % which avoids code duplication.
- \use:x
- {
- \exp_not:N \tex_scantokens:D
- {
- \exp_not:N \begin{verbatimsc} ^^M
- \__scontents_strip_scantokens:N #1
- \bool_if:NF \l__scontents_typeverb_env_bool { ^^M }
- \c_backslash_str end \c_left_brace_str verbatimsc \c_right_brace_str
- }
- }
- \cs_set_eq:NN ^^M \__scontents_fcdef_saved_EOL:
- }
- \group_end:
- \msg_new:nnn { scontents } { empty-variable }
- { Variable~`#1'~empty~\msg_line_context:. }
- % User command to setup module
- \ProvideDocumentCommand{ \setupsc }{ +m }
- {
- \keys_set:nn { scontents } {#1}
- }
- % User command to see content stored in seq
- % \cs_new_eq:Nc \__scontents_strip_prefix:NN { strip@prefix }
- \ProvideDocumentCommand { \meaningsc } { O{1} m }
- {
- \group_begin:
- \tl_set:Nx \l__scontents_temp_tl { \__scontents_getfrom_seq:nn {#1} {#2} }
- \tl_log:N \l__scontents_temp_tl
- \regex_replace_once:nnN { ^ \c{tex_scantokens:D} \cB. (\c[^BE].*) \cE. } { \1 } \l__scontents_temp_tl
- \regex_replace_all:nnN { \v{1,} } { } \l__scontents_temp_tl
- \ttfamily
- % expl3 has \cs_replacement_spec:N, \cs_argument_spec:N, and \cs_replacement_spec:N
- \cs_replacement_spec:N \l__scontents_temp_tl
- % \exp_after:wN \__scontents_strip_prefix:NN \token_to_meaning:N \l__scontents_temp_tl
- \group_end:
- }
- % User command to print verbatim stored in seq
- \ProvideDocumentCommand { \typestored } { s O{1} m }
- {
- \group_begin:
- \tl_set:Nx \l__scontents_temp_tl { \__scontents_getfrom_seq:nn {#2} {#3} }
- \tl_log:N \l__scontents_temp_tl
- \IfBooleanTF {#1}
- { \bool_set_false:N \l__scontents_typeverb_env_bool }
- { \bool_set_true:N \l__scontents_typeverb_env_bool }
- \__scontents_fcdef_get:NN \__scontents_fcdef_print:N \l__scontents_temp_tl
- \group_end:
- }
- % User command to extract stored content in seq
- \ProvideExpandableDocumentCommand { \getstored } { O{1} m }
- {
- \__scontents_getfrom_seq:nn {#1} {#2}
- }
- \msg_new:nnn { scontents } { empty-stored-content }
- { Empty~value~for~key~`getstored'~\msg_line_context:. }
- % User command to count number of contents stored in seq
- \ProvideExpandableDocumentCommand{ \countsc }{ m }
- {
- \seq_count:c { g__scontents_seq_name_#1_seq }
- }
- % A user command to clear (remove) a defined seq
- \ProvideExpandableDocumentCommand{ \cleanseqsc }{ m }
- {
- \seq_clear_new:c { g__scontents_seq_name_#1_seq }
- }
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % Adaptation of Ulrich Diez's code:
- %
- % I understand when you thing Ulrich's code is complicated. His code is
- % mostly bullet-proof, but it can be quite complicated to understand.
- % I guess one is a direct consequence of the other.
- %
- % His \UD@CheckWhetherNull macro is exactly the same as expl3's
- % \tl_if_empty:nTF because it will always return false except if the argument
- % is exactly nothing. The only difference is that \UD@CheckWhetherNull doesn't
- % use e-TeX primitives. But expl3 requires e-TeX, so you can use \tl_if_empty:nTF.
- %
- % He uses the \begingroup<catcode setting>\@firstofone{\engroup<code>} trick to
- % have the <code> be executed under the <catcode> setting without actually executing
- % it in a group, I guess mostly because \newcommand isn't global. However expl3's
- % \cs_new:Npn are global, so we don't need to resort to that.
- %
- % The rest of the code is more or less a one-to-one translation from 2e code do expl3.
- \makeatletter
- \group_begin:
- \char_set_catcode_other:N \^^M
- \cs_new_protected:Npn \__scontents_end_lreplace:nn #1 #2
- {
- \exp:w \exp_end_continue_f:w
- \__scontents_end_lreplace_aux:w {#2} #1 ^^M \q_mark { }
- }
- \cs_new_protected:Npn \__scontents_end_lreplace_aux:w #1#2 ^^M #3 \q_mark #4#5
- {
- \tl_if_empty:nTF {#3}
- { ~ #5 { #4 #2 } }
- { \__scontents_end_lreplace_aux:w {#1} #3 \q_mark { #4 #2 #1 } {#5} }
- }
- \group_end:
- \cs_new_protected:Npn \__scontents_collect_verb_arg:nnn #1#2#3
- {
- \cs_if_exist_use:c { @bsphack }
- \group_begin:
- \seq_map_function:NN \l_char_special_seq \char_set_catcode_other:N
- \char_set_catcode_group_begin:N \{
- \char_set_catcode_space:N \ %
- \peek_charcode:NTF \c_group_begin_token
- {
- \char_set_catcode_group_end:N \}
- \__scontents_collect_verb_arg_aux:nnnn {#1} {#2} {#3} {}
- }
- {
- \char_set_catcode_other:N \{
- \__scontents_collect_verb_arg_aux:nnnn {#1} {#2} {#3}
- }
- }
- \cs_new_protected:Npn \__scontents_collect_verb_arg_aux:nnnn #1#2#3#4
- {
- \char_set_catcode_other:N \ %
- \char_set_catcode_other:N \^^M
- \cs_set_protected:Npn \__scontents_tmp:w ##1 #4
- {
- \tl_set:Nx \l__scontents_temp_tl { \tl_to_str:n {##1} }
- \exp_args:NV \__scontents_end_lreplace:nn \l__scontents_temp_tl {#1} { \tl_set:Nn \l__scontents_temp_tl }
- \exp_args:NV \__scontents_collect_verb_arg_end:nnn \l__scontents_temp_tl {#2} {#3}
- }
- \__scontents_tmp:w
- }
- \cs_new_protected:Npn \__scontents_collect_verb_arg_end:nnn #1#2#3
- {
- \group_end:
- \cs_if_exist_use:c { @esphack }
- #2 { #3 {#1} }
- }
- % User command
- \ProvideDocumentCommand{ \Scontents }{!s O{} }
- {
- \group_begin:
- \IfNoValueF {#2} { \keys_set_known:nn { scontents / Scontents } {#2} }
- \IfBooleanTF {#1}
- { \__scontents_collect_verb_arg:nnn {^^J} { \use:n } { \__scontents_append_vercmd:n } }
- { \__scontents_append_stdcmd:n }
- }
- % No verbatimized content, standard LaTeX mode
- \cs_new_protected:Npn \__scontents_append_stdcmd:n #1
- {
- \exp_args:NV \__scontents_append_contents:nn \l__scontents_name_seq_cmd_tl {#1}
- \bool_if:NT \l__scontents_print_cmd_bool
- { \__scontents_getfrom_seq:nn { -1 } { \l__scontents_name_seq_cmd_tl } }
- \group_end:
- }
- % verbatimized content
- \cs_new_protected:Npn \__scontents_append_vercmd:n #1
- {
- \exp_args:NV \__scontents_append_contents:nn \l__scontents_name_seq_cmd_tl
- { \tex_scantokens:D {#1} }
- \bool_if:NT \l__scontents_print_cmd_bool
- { \__scontents_getfrom_seq:nn { -1 } { \l__scontents_name_seq_cmd_tl } }
- \group_end:
- }
- % Finish package
- \file_input_stop:
- % I don't know whether to use a * or a key [verb=true] to be able to maintain both commands, or if
- % it's better to stay alone with the version (\Scontentv) and delete (\Scontent), theoretically
- % both fulfill the same function.
- \end{filecontents*}
- \documentclass{article}
- \usepackage{scontents}
- \RecustomVerbatimEnvironment{verbatimsc}{Verbatim}{numbers=left}
- % only example
- \usepackage[top=0.5in,bottom=0.5in, left=1in, right=1in]{geometry}
- \usepackage{pgffor}
- \setlength{\parindent}{0pt}
- \begin{document}
- \section{Test \texttt{\textbackslash Scontents[key=val]}}
- Test \verb+\Scontents[print-cmd=false]+\par
- \Scontents[print-cmd=false]{
- Using \texttt{\textbackslash Scontents} command, \par
- no environment verbatim suport,\par
- but \Verb{fvextra inline yes}, save in seq \texttt{contents} with index $1$.}\par
- Test \verb+\Scontents[print-cmd=true]+\par
- \Scontents[print-cmd=true]{
- Using \texttt{\textbackslash Scontents} command, no environment verbatim suport,
- but \Verb{fvextra inline yes}, save in seq \texttt{contents} with index $2$.}
- Test \verb+\Scontents[store-cmd=testcmd]+\par
- \Scontents[store-cmd=testcmd]{
- Using \texttt{\textbackslash Scontents} command, no environment verbatim suport,
- but \Verb{fvextra inline yes}, save in seq \texttt{testcmd} with index 1.}
- \subsection{Test \texttt{\textbackslash getstored[index]\{seq name\}}}
- \noindent\hrulefill
- Test \verb+\getstored[1]{contents}+:\par
- \getstored[1]{contents}
- \noindent\hrulefill
- Test \verb+\getstored[2]{contents}+:\par
- \getstored[2]{contents}
- \noindent\hrulefill
- Test \verb+\getstored[1]{testcmd}+:\par
- \getstored[1]{testcmd}
- \noindent\hrulefill
- \subsection{Test \texttt{\textbackslash meaningsc[index]\{seq name\}}}
- \noindent\hrulefill
- Test \verb+\meaningsc[1]{contents}+:\par
- \meaningsc[1]{contents}
- \noindent\hrulefill
- Test \verb+\meaningsc[2]{contents}+:\par
- \meaningsc[2]{contents}
- \noindent\hrulefill
- Test \verb+\meaningsc[1]{testcmd}+:\par
- \meaningsc[1]{testcmd}
- \noindent\hrulefill
- \section{Test \texttt{\textbackslash Scontents*[key=val]}}
- Test \verb+\setupsc{store-cmd=testcmdvrb}+\par
- \setupsc{store-cmd=testcmdvrb}
- Test \verb+\Scontents*[print-cmd=false]+\par
- \Scontents*[print-cmd=false]{Using \texttt{\textbackslash Scontents*} command,
- with verbatim suport.
- \begin{verbatim*}
- verbatim
- environment
- \end{verbatim*}
- \Verb{fvextra inline yes}, save in seq \texttt{testcmdvrb} with index 1.}
- Test \verb+\Scontents*[print-cmd=true]+\par
- \Scontents*[print-cmd=true]|Using \verb/\Scontents*[print-cmd=true]+...+/ command, with verbatim suport,
- \begin{verbatim}
- more verbatim environment
- \end{verbatim}
- And \Verb{fvextra inline yes}, save in seq \texttt{testcmdvrb} with index $2$.|
- Test \verb+\Scontents[store-cmd=othervrb]+\par
- \Scontents*[store-cmd=othervrb]{
- Using \texttt{\textbackslash Scontents*} command, whit verbatim suport,
- \begin{verbatim}
- other verbatim environment
- \end{verbatim}
- And \Verb{fvextra inline yes}, save in seq \texttt{othervrb} with index $1$.}
- \subsection{Test \texttt{\textbackslash getstored[index]\{seq name\}}}
- \noindent\hrulefill
- Test \verb+\getstored[1]{testcmdvrb}+:\par
- \getstored[1]{testcmdvrb}
- \noindent\hrulefill
- Test \verb+\getstored[2]{testcmdvrb}+:\par
- \getstored[2]{testcmdvrb}
- \noindent\hrulefill
- Test \verb+\getstored[1]{othervrb}+:\par
- \getstored[1]{othervrb}
- \noindent\hrulefill
- \subsection{Test \texttt{\textbackslash meaningsc[index]\{seq name\}}}
- \noindent\hrulefill
- Test \verb+\meaningsc[1]{testcmdvrb}+:\par
- \meaningsc[1]{testcmdvrb}
- \noindent\hrulefill
- Test \verb+\meaningsc[2]{testcmdvrb}+:\par
- \meaningsc[2]{testcmdvrb}
- \noindent\hrulefill
- Test \verb+\meaningsc[1]{othervrb}+:\par
- \meaningsc[1]{othervrb}
- \noindent\hrulefill
- \subsection{Test \texttt{\textbackslash typestored*[index]\{seq name\}}}
- \noindent\hrulefill
- Test \verb+\typestored*[1]{testcmdvrb}+:\par
- \typestored*[1]{testcmdvrb}
- \noindent\hrulefill
- Test \verb+\typestored*[2]{testcmdvrb}+:\par
- \typestored*[2]{testcmdvrb}
- \noindent\hrulefill
- Test \verb+\typestored*[1]{othervrb}+:\par
- \typestored*[1]{othervrb}
- \noindent\hrulefill
- \section{Test \texttt{\textbackslash Scontents*} and \texttt{\textbackslash Scontents} back to default}
- \Scontents[store-cmd=contents]{Using \texttt{\textbackslash Scontents} command whit braces,
- save in seq \texttt{contents} with index $3$.}
- \getstored[3]{contents}
- \Scontents*|Using \texttt{\textbackslash Scontents*} command (verbatimized), save in seq \texttt{testcmdvrb} with index $3$.|
- \getstored[3]{testcmdvrb}
- \section{Test \texttt{\{scontents\}} environment}
- \setupsc{store-env=testenv, print-env=false}
- \subsection{no \texttt{[key=val]}}
- Test \verb+scontents+ no \verb+[key=val]+\par
- \begin{scontents}
- Using \verb+scontents+ env no \verb+[key=val]+, save in seq \verb+testenv+ index 1.\par
- We have coded this in \LaTeX: $E=mc^2$.
- Prove new \Verb*{ verbatim from fvextra whit braces } and environment \verb+Verbatim*+.
- \begin{Verbatim*}
- (A) verbatim
- environment
- \end{Verbatim*}
- \end{scontents}
- \subsubsection{\Verb{\getstored[1]{testenv}}}
- \getstored[1]{testenv}
- \subsubsection{\Verb{\meaningsc[1]{testenv}}}
- \meaningsc[1]{testenv}
- \subsubsection{\Verb{\typestored[1]{testenv}}}
- \typestored[1]{testenv}
- \subsection{whit \texttt{[key=val]}}
- \subsubsection{\Verb{[write-env=\jobname.tsc]}}
- \begin{scontents}[write-env=\jobname.tsc]
- Using \verb+scontents+ env with \verb+[write-env=\jobname.tsc]+, save in
- seq \verb+testenv+ with index 2 and write env body in file \verb+\jobname.tsc+.
- We have coded this in \LaTeX: $E=mc^2$.\par
- \begin{verbatim*}
- (B) verbatim
- environment
- \end{verbatim*}
- \end{scontents}
- \subsubsection{\Verb{\getstored[2]{testenv}}}
- \getstored[2]{testenv}
- \subsubsection{\Verb{\meaningsc[2]{testenv}}}
- \meaningsc[2]{testenv}
- \subsubsection{\Verb{\typestored[2]{testenv}}}
- \typestored[2]{testenv}
- \subsubsection{\Verb{\VerbatimInput{\jobname.tsc}}}
- \VerbatimInput[frame=single,numbers=left,numbersep=3pt]{\jobname.tsc}
- \subsubsection{\Verb{[print-env=true]}}
- \begin{scontents}[print-env=true]
- Using \verb+scontents+ env with \verb+[print-env=true]+, save in
- seq \verb+testenv+ with index 3.
- We have coded this in \LaTeX: $E=mc^2$.\par
- \begin{verbatim*}
- (C) verbatim
- environment
- \end{verbatim*}
- \end{scontents}
- \Verb{\getstored[3]{testenv}}\par
- \getstored[3]{testenv}\par
- \Verb{\meaningsc[3]{testenv}}\par
- \meaningsc[3]{testenv}\par
- \Verb{\typestored[3]{testenv}}\par
- \typestored[3]{testenv}
- \subsubsection{\Verb{[print-env=true,write-env=\jobname-1.tsc]}}
- \begin{scontents}[print-env=true,write-env=\jobname-1.tsc]
- Using \verb+scontents+ env with \verb+[print-env=true,write-env=\jobname-1.tsc]+, save in
- seq \verb+testenv+ with index 4.
- We have coded this in \LaTeX: $E=mc^2$.\par
- \begin{verbatim*}
- (D) verbatim
- environment
- \end{verbatim*}
- \end{scontents}
- \Verb{\getstored[4]{testenv}}\par
- \getstored[4]{testenv}\par
- \Verb{\meaningsc[4]{testenv}}\par
- \meaningsc[4]{testenv}\par
- \Verb{\typestored[4]{testenv}}\par
- \typestored[4]{testenv}
- \Verb{\VerbatimInput{\jobname-1.tsc}}\par
- \VerbatimInput[frame=single,numbers=left,numbersep=3pt]{\jobname-1.tsc}
- \subsection{\Verb{[write-out=\jobname-2.tsc]}}
- \begin{scontents}[write-out=\jobname-2.tsc]
- Using \verb+scontents+ env with \verb+[write-out=\jobname-2.tsc]+,
- not added to seq, only write a external file
- We have coded this in \LaTeX: $E=mc^2$.\par
- \begin{verbatim}
- (E) verbatim
- environment
- \end{verbatim}
- \end{scontents}
- \Verb{\VerbatimInput{\jobname-2.tsc}}\par
- \VerbatimInput[frame=single,numbers=left,numbersep=3pt]{\jobname-2.tsc}
- \subsubsection{\Verb{[print-env=true,store-env=other]}}
- \begin{scontents}[print-env=true,store-env=other]
- Using \verb+scontents+ env with \verb+[print-env=true,store-env=other]+, save in
- seq \verb+other+ with index 1.
- We have coded this in \LaTeX: $E=mc^2$.\par
- \begin{verbatim*}
- (F) verbatim
- environment
- \end{verbatim*}
- \end{scontents}
- \Verb{\getstored[1]{other}}\par
- \getstored[1]{other}\par
- \Verb{\meaningsc[1]{other}}\par
- \meaningsc[1]{other}\par
- \Verb{\typestored[1]{other}}\par
- \typestored[1]{other}
- \section{A simple aplication}
- \setupsc{ store-env=answers, store-cmd= answers }
- \newcounter{exeNr}
- \newenvironment{exercise}
- {\refstepcounter{exeNr}\par\noindent This is exercise~\theexeNr}
- {\par}
- \subsection{Exercises}
- \begin{exercise}
- \end{exercise}
- \begin{scontents}
- This is the answer to exercise 1, the shebang line for a Perl script
- \begin{verbatim}
- #!/usr/bin/env perl
- \end{verbatim}
- \end{scontents}
- \begin{exercise}
- \end{exercise}
- \begin{scontents}
- This is the answer to exercise 2
- \end{scontents}
- \begin{exercise}
- \end{exercise}
- \Scontents[unknow]{This is the answer to exercise 3}
- \subsection{Answers}
- \newcounter{ansNr}
- \newenvironment{answer}
- {\refstepcounter{ansNr}\par\noindent Answer~\theansNr:}
- {\par}
- \foreach \i in {1,...,\countsc{answers}} {
- \begin{answer}
- \getstored[\i]{answers}
- \end{answer}
- }
- \subsection{typestored}
- % custom :)
- \RecustomVerbatimEnvironment{verbatimsc}{Verbatim}{frame=single,numbers=left}
- \typestored[1]{answers}
- \typestored[2]{answers}
- \end{document}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement