Advertisement
Guest User

scontents to expl3

a guest
Jul 16th, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Latex 22.32 KB | None | 0 0
  1. % arara: pdflatex: { interaction: batchmode }
  2. % arara: clean: { extensions: [ aux, log, tsc] }
  3. % \pdfinfoomitdate1
  4. % \pdfsuppressptexinfo-1
  5. % \pdftrailerid{}
  6. \RequirePackage{filecontents}
  7. \begin{filecontents*}{scontents.sty}
  8. \RequirePackage{filecontentsdef}[2019/04/20]
  9. \RequirePackage{l3keys2e}
  10. \RequirePackage{xparse}[2019/05/03]
  11. \RequirePackage{fvextra}
  12. \ProvidesExplPackage{scontents}{2019/07/12}{0.999999}
  13.  {Store LaTeX content in Sequences (l3seq)}
  14.  
  15. \ExplSyntaxOn
  16. % A common key val
  17. \keys_define:nn { scontents }
  18.  {
  19.    store-env .tl_set:N         = \l__scontents_name_seq_env_tl,
  20.    store-env .initial:n        = contents,
  21.    print-env .bool_set:N       = \l__scontents_print_env_bool,
  22.    print-env .initial:n        = false,
  23.    store-cmd .tl_set:N         = \l__scontents_name_seq_cmd_tl,
  24.    store-cmd .initial:n        = contents,
  25.    print-cmd .bool_set:N       = \l__scontents_print_cmd_bool,
  26.    print-cmd .initial:n        = false,
  27.    print-all .meta:n           = { print-env = true , print-cmd = true },
  28.    store-env .value_required:n = true,
  29.    store-cmd .value_required:n = true,
  30.    print-env .value_required:n = true,
  31.    print-cmd .value_required:n = true,
  32.    print-all .value_required:n = true
  33.  }
  34. % Process options for pkg
  35. \ProcessKeysOptions { scontents }
  36. % tl vars
  37. \tl_new:N \l__scontents_macro_tmp_tl
  38. \tl_new:N \l__scontents_fname_out_tl
  39. \tl_new:N \l__scontents_temp_tl
  40. % bool vars
  41. \bool_new:N \l__scontents_typeverb_env_bool
  42. \bool_new:N \l__scontents_write_file_bool
  43. \bool_new:N \l__scontents_macro_pass_bool
  44. % default
  45. \bool_set_true:N  \l__scontents_macro_pass_bool
  46. \bool_set_false:N \l__scontents_write_file_bool
  47. \bool_set_true:N  \l__scontents_typevrb_env_bool
  48. % Add keys to scontents environonment
  49. \keys_define:nn { scontents }
  50.  {
  51.    write-env .code:n           = {
  52.                                    \bool_set_true:N \l__scontents_write_file_bool
  53.                                    \tl_set:Nn \l__scontents_fname_out_tl {#1}
  54.                                  },
  55.    write-out .code:n           = {
  56.                                    \bool_set_false:N \l__scontents_macro_pass_bool
  57.                                    \bool_set_true:N  \l__scontents_write_file_bool
  58.                                    \tl_set:Nn \l__scontents_fname_out_tl {#1}
  59.                                  },
  60.    write-env .value_required:n = true,
  61.    write-out .value_required:n = true
  62.  }
  63.  
  64. % A sub/keys for command \Scontents
  65. \keys_define:nn { scontents / Scontents }
  66.  {
  67.    print-cmd .meta:nn = { scontents } { print-cmd = #1 },
  68.    store-cmd .meta:nn = { scontents } { store-cmd = #1 }
  69.  }
  70. % Append content to seq
  71. \cs_new_protected:Npn \__scontents_append_contents:nn #1#2
  72.   {
  73.    \tl_if_blank:nT {#1}
  74.      { \msg_error:nn { scontents } { empty-store-cmd } }
  75.    \seq_if_exist:cF { g__scontents_seq_name_#1_seq }
  76.      { \seq_new:c { g__scontents_seq_name_#1_seq } }
  77.    \seq_gput_right:cn { g__scontents_seq_name_#1_seq } {#2}
  78.  }
  79. % Get content stored in seq
  80. \cs_new:Npn \__scontents_getfrom_seq:nn #1#2
  81.   {
  82.    \seq_item:cn { g__scontents_seq_name_#2_seq } {#1}
  83.  }
  84. % Define scontents whit [key=val] (delaying)
  85. \ProvideDocumentEnvironment { scontents } { }
  86.  {
  87.    \char_set_catcode_active:N \^^M
  88.    \scontents_start_environment:w
  89.  }
  90.  {
  91.    \scontents_stop_environment:
  92.    \scontents_atend_environment:
  93.  }
  94. % key val for environment scontens
  95. \cs_new_protected:Npn \scontents_environment_keys:w [ #1 ]
  96.   {
  97.    \keys_set_known:nn { scontents } {#1}
  98.  }
  99. % The environment itself
  100. \group_begin:
  101.   \char_set_catcode_active:N \^^M
  102.   \cs_new_protected:Npn \scontents_start_environment:w #1 ^^M
  103.     {
  104.      \tl_if_blank:nF {#1} { \scontents_environment_keys:w #1 }
  105.      \group_begin:
  106.      \bool_if:NTF \l__scontents_write_file_bool
  107.        {
  108.          \use:c { filecontentsdef* } { \l__scontents_fname_out_tl }
  109.                                      { \l__scontents_macro_tmp_tl } ^^M
  110.        }
  111.        {
  112.          \filecontentsdefmacro { \l__scontents_macro_tmp_tl } ^^M
  113.        }
  114.    }
  115.  \cs_new_protected:Nn \scontents_stop_environment:
  116.    {
  117.      \bool_if:NTF \l__scontents_write_file_bool
  118.        { \endfilecontentsdef }
  119.        { \endfilecontentsdefmacro }
  120.      \group_end:
  121.    }
  122. \group_end:
  123. % A variant to expand grabed content in \l__scontents_macro_tmp_tl
  124.  
  125. \exp_args_generate:n { Vx }
  126. % Expand and stored content in seq
  127. \cs_gset_protected:Nn \__scontents_stored_to_seq:
  128.   {
  129.     % Replace \^^M to \^^J for multiple lines
  130.     \regex_replace_all:nnN { \^^M } { \^^J } \l__scontents_macro_tmp_tl
  131.    \tl_log:N \l__scontents_macro_tmp_tl
  132.    \exp_args:NVx \__scontents_append_contents:nn \l__scontents_name_seq_env_tl
  133.      { \exp_not:N \tex_scantokens:D { \tl_use:N \l__scontents_macro_tmp_tl } }
  134.  }
  135. % Code after scontent environment
  136. \cs_new_protected:Nn \scontents_atend_environment:
  137.   {
  138.    \bool_if:NT \l__scontents_macro_pass_bool
  139.      {
  140.        \__scontents_stored_to_seq:
  141.        \bool_if:NT \l__scontents_print_env_bool
  142.          { \exp_args:NnV \__scontents_getfrom_seq:nn { -1 } \l__scontents_name_seq_env_tl }
  143.      }
  144.    \tl_clear:N \l__scontents_macro_tmp_tl
  145.  }
  146. % Define verbatimsc environment to pass content stored by scontents env
  147. \DefineVerbatimEnvironment{verbatimsc}{Verbatim}{}
  148.  
  149. % Copy definition of macro \filecontentsdef@get
  150. \cs_new_eq:Nc \__scontents_fcdef_get:NN { filecontentsdef@get }
  151.  
  152. % Check and strip \scantokens stored in seq by scontents env
  153. \quark_new:N \q__scontents_strip_quark
  154. \cs_new:Npn \__scontents_strip_scantokens:N #1
  155.   {
  156.    \exp_args:NV \__scontents_strip_scantokens:n #1
  157.  }
  158. \cs_new:Npn \__scontents_strip_scantokens:n #1
  159.  {
  160.    \tl_if_head_is_N_type:nTF {#1}
  161.      {
  162.        \__scontents_if_scantokens:NwTF #1 \q__scontents_strip_quark
  163.          { \exp_not:o { \use_ii:nn #1 } }
  164.          { \exp_not:n {#1} }
  165.      }
  166.      { \exp_not:n {#1} }
  167.  }
  168. \prg_new_conditional:Npnn \__scontents_if_scantokens:Nw #1#2
  169. \q__scontents_strip_quark { TF }
  170.  {
  171.    \token_if_eq_meaning:NNTF \tex_scantokens:D #1
  172.      { \prg_return_true: }
  173.      { \prg_return_false: }
  174.  }
  175. % Pass stored content save by scontents env to verbatimsc env
  176. \group_begin:
  177.  \char_set_catcode_active:N \^^M
  178.  \cs_new_protected:Npn \__scontents_fcdef_print:N #1
  179.     {
  180.      \tl_if_blank:VT #1
  181.        { \msg_error:nnn { scontents } { empty-variable } {#1} }
  182.       \cs_set_eq:NN \__scontents_fcdef_saved_EOL: ^^M
  183.       \cs_set_eq:NN ^^M \scan_stop:
  184.       % Here I added a boleana variable, otherwise, added an extra blank
  185.       % line inside the verbatim environment.r
  186.       % (Phelype) \bool_if: is expandable, so instead of
  187.       %     \bool_if:NTF \l_some_bool { \use:x { code } } { \use:x { code ^^M } }
  188.       % you can do
  189.       %     \use:x { code \bool_if:NF \l_some_bool { ^^M } }
  190.       % which avoids code duplication.
  191.       \use:x
  192.         {
  193.          \exp_not:N \tex_scantokens:D
  194.            {
  195.              \exp_not:N \begin{verbatimsc} ^^M
  196.              \__scontents_strip_scantokens:N #1
  197.              \bool_if:NF \l__scontents_typeverb_env_bool { ^^M }
  198.              \c_backslash_str end \c_left_brace_str verbatimsc \c_right_brace_str
  199.            }
  200.        }
  201.      \cs_set_eq:NN ^^M \__scontents_fcdef_saved_EOL:
  202.    }
  203. \group_end:
  204. \msg_new:nnn { scontents } { empty-variable }
  205. { Variable~`#1'~empty~\msg_line_context:. }
  206.  
  207. % User command to setup module
  208. \ProvideDocumentCommand{ \setupsc }{ +m }
  209.  {
  210.    \keys_set:nn { scontents } {#1}
  211.  }
  212.  
  213. % User command to see content stored in seq
  214. % \cs_new_eq:Nc \__scontents_strip_prefix:NN { strip@prefix }
  215. \ProvideDocumentCommand { \meaningsc } { O{1} m }
  216.  {
  217.    \group_begin:
  218.      \tl_set:Nx \l__scontents_temp_tl { \__scontents_getfrom_seq:nn {#1} {#2} }
  219.      \tl_log:N \l__scontents_temp_tl
  220.      \regex_replace_once:nnN { ^ \c{tex_scantokens:D} \cB. (\c[^BE].*) \cE. } { \1 } \l__scontents_temp_tl
  221.      \regex_replace_all:nnN { \v{1,} } {   } \l__scontents_temp_tl
  222.       \ttfamily
  223.       % expl3 has \cs_replacement_spec:N, \cs_argument_spec:N, and \cs_replacement_spec:N
  224.       \cs_replacement_spec:N \l__scontents_temp_tl
  225.       % \exp_after:wN \__scontents_strip_prefix:NN \token_to_meaning:N \l__scontents_temp_tl
  226.     \group_end:
  227.   }
  228. % User command to print verbatim stored in seq
  229. \ProvideDocumentCommand { \typestored } { s O{1} m }
  230.  {
  231.    \group_begin:
  232.      \tl_set:Nx \l__scontents_temp_tl { \__scontents_getfrom_seq:nn {#2} {#3} }
  233.      \tl_log:N \l__scontents_temp_tl
  234.      \IfBooleanTF {#1}
  235.        { \bool_set_false:N \l__scontents_typeverb_env_bool }
  236.        { \bool_set_true:N  \l__scontents_typeverb_env_bool }
  237.        \__scontents_fcdef_get:NN \__scontents_fcdef_print:N \l__scontents_temp_tl
  238.    \group_end:
  239.  }
  240. % User command to extract stored content in seq
  241. \ProvideExpandableDocumentCommand { \getstored } { O{1} m }
  242.  {
  243.    \__scontents_getfrom_seq:nn {#1} {#2}
  244.  }
  245. \msg_new:nnn { scontents } { empty-stored-content }
  246.  { Empty~value~for~key~`getstored'~\msg_line_context:. }
  247.  
  248. % User command to count number of contents stored in seq
  249. \ProvideExpandableDocumentCommand{ \countsc }{ m }
  250.  {
  251.    \seq_count:c { g__scontents_seq_name_#1_seq }
  252.  }
  253. % A user command to clear (remove) a defined seq
  254. \ProvideExpandableDocumentCommand{ \cleanseqsc }{ m }
  255.  {
  256.    \seq_clear_new:c { g__scontents_seq_name_#1_seq }
  257.  }
  258. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  259. % Adaptation of Ulrich Diez's code:
  260. %
  261. % I understand when you thing Ulrich's code is complicated. His code is
  262. % mostly bullet-proof, but it can be quite complicated to understand.
  263. % I guess one is a direct consequence of the other.
  264. %
  265. % His \UD@CheckWhetherNull macro is exactly the same as expl3's
  266. % \tl_if_empty:nTF because it will always return false except if the argument
  267. % is exactly nothing. The only difference is that \UD@CheckWhetherNull doesn't
  268. % use e-TeX primitives. But expl3 requires e-TeX, so you can use \tl_if_empty:nTF.
  269. %
  270. % He uses the \begingroup<catcode setting>\@firstofone{\engroup<code>} trick to
  271. % have the <code> be executed under the <catcode> setting without actually executing
  272. % it in a group, I guess mostly because \newcommand isn't global. However expl3's
  273. % \cs_new:Npn are global, so we don't need to resort to that.
  274. %
  275. % The rest of the code is more or less a one-to-one translation from 2e code do expl3.
  276. \makeatletter
  277. \group_begin:
  278.   \char_set_catcode_other:N \^^M
  279.   \cs_new_protected:Npn \__scontents_end_lreplace:nn #1 #2
  280.     {
  281.      \exp:w \exp_end_continue_f:w
  282.      \__scontents_end_lreplace_aux:w {#2} #1 ^^M \q_mark { }
  283.    }
  284.  \cs_new_protected:Npn \__scontents_end_lreplace_aux:w #1#2 ^^M #3 \q_mark #4#5
  285.    {
  286.      \tl_if_empty:nTF {#3}
  287.        { ~ #5 { #4 #2 } }
  288.        { \__scontents_end_lreplace_aux:w {#1} #3 \q_mark { #4 #2 #1 } {#5} }
  289.    }
  290. \group_end:
  291. \cs_new_protected:Npn \__scontents_collect_verb_arg:nnn #1#2#3
  292.  {
  293.    \cs_if_exist_use:c { @bsphack }
  294.     \group_begin:
  295.     \seq_map_function:NN \l_char_special_seq \char_set_catcode_other:N
  296.     \char_set_catcode_group_begin:N \{
  297.     \char_set_catcode_space:N \ %
  298.     \peek_charcode:NTF \c_group_begin_token
  299.       {
  300.        \char_set_catcode_group_end:N \}
  301.        \__scontents_collect_verb_arg_aux:nnnn {#1} {#2} {#3} {}
  302.      }
  303.      {
  304.        \char_set_catcode_other:N \{
  305.        \__scontents_collect_verb_arg_aux:nnnn {#1} {#2} {#3}
  306.      }
  307.  }
  308. \cs_new_protected:Npn \__scontents_collect_verb_arg_aux:nnnn #1#2#3#4
  309.   {
  310.     \char_set_catcode_other:N \ %
  311.     \char_set_catcode_other:N \^^M
  312.     \cs_set_protected:Npn \__scontents_tmp:w ##1 #4
  313.       {
  314.        \tl_set:Nx \l__scontents_temp_tl { \tl_to_str:n {##1} }
  315.        \exp_args:NV \__scontents_end_lreplace:nn \l__scontents_temp_tl {#1} { \tl_set:Nn \l__scontents_temp_tl }
  316.        \exp_args:NV \__scontents_collect_verb_arg_end:nnn \l__scontents_temp_tl {#2} {#3}
  317.      }
  318.    \__scontents_tmp:w
  319. }
  320. \cs_new_protected:Npn \__scontents_collect_verb_arg_end:nnn #1#2#3
  321.  {
  322.    \group_end:
  323.    \cs_if_exist_use:c { @esphack }
  324.    #2 { #3 {#1} }
  325.  }
  326. % User command
  327. \ProvideDocumentCommand{ \Scontents }{!s O{} }
  328.  {
  329.    \group_begin:
  330.    \IfNoValueF {#2} { \keys_set_known:nn { scontents / Scontents } {#2} }
  331.    \IfBooleanTF {#1}
  332.      { \__scontents_collect_verb_arg:nnn {^^J} { \use:n } { \__scontents_append_vercmd:n } }
  333.      { \__scontents_append_stdcmd:n }
  334.  }
  335. % No verbatimized content, standard LaTeX mode
  336. \cs_new_protected:Npn \__scontents_append_stdcmd:n #1
  337.   {
  338.    \exp_args:NV  \__scontents_append_contents:nn \l__scontents_name_seq_cmd_tl {#1}
  339.    \bool_if:NT \l__scontents_print_cmd_bool
  340.       { \__scontents_getfrom_seq:nn { -1 } { \l__scontents_name_seq_cmd_tl } }
  341.    \group_end:
  342.  }
  343. % verbatimized content
  344. \cs_new_protected:Npn \__scontents_append_vercmd:n #1
  345.   {
  346.    \exp_args:NV \__scontents_append_contents:nn \l__scontents_name_seq_cmd_tl
  347.       { \tex_scantokens:D {#1} }
  348.    \bool_if:NT \l__scontents_print_cmd_bool
  349.       { \__scontents_getfrom_seq:nn { -1 } { \l__scontents_name_seq_cmd_tl } }
  350.    \group_end:
  351.  }
  352. % Finish package
  353. \file_input_stop:
  354. % I don't know whether to use a * or a key [verb=true] to be able to maintain both commands, or if
  355. % it's better to stay alone with the version (\Scontentv) and delete (\Scontent), theoretically
  356. % both fulfill the same function.
  357. \end{filecontents*}
  358. \documentclass{article}
  359. \usepackage{scontents}
  360. \RecustomVerbatimEnvironment{verbatimsc}{Verbatim}{numbers=left}
  361. % only example
  362. \usepackage[top=0.5in,bottom=0.5in, left=1in, right=1in]{geometry}
  363. \usepackage{pgffor}
  364. \setlength{\parindent}{0pt}
  365. \begin{document}
  366.  
  367. \section{Test \texttt{\textbackslash Scontents[key=val]}}
  368.  
  369. Test \verb+\Scontents[print-cmd=false]+\par
  370.  
  371. \Scontents[print-cmd=false]{
  372. Using \texttt{\textbackslash Scontents} command, \par
  373. no environment verbatim suport,\par
  374. but \Verb{fvextra inline yes}, save in seq \texttt{contents} with index $1$.}\par
  375.  
  376. Test \verb+\Scontents[print-cmd=true]+\par
  377.  
  378. \Scontents[print-cmd=true]{
  379. Using \texttt{\textbackslash Scontents} command, no environment verbatim suport,
  380. but \Verb{fvextra inline yes}, save in seq \texttt{contents} with index $2$.}
  381.  
  382. Test \verb+\Scontents[store-cmd=testcmd]+\par
  383.  
  384. \Scontents[store-cmd=testcmd]{
  385. Using \texttt{\textbackslash Scontents} command, no environment verbatim suport,
  386. but \Verb{fvextra inline yes}, save in seq \texttt{testcmd} with index 1.}
  387.  
  388. \subsection{Test \texttt{\textbackslash getstored[index]\{seq name\}}}
  389.  
  390. \noindent\hrulefill
  391.  
  392. Test \verb+\getstored[1]{contents}+:\par
  393.  
  394. \getstored[1]{contents}
  395.  
  396. \noindent\hrulefill
  397.  
  398. Test \verb+\getstored[2]{contents}+:\par
  399.  
  400. \getstored[2]{contents}
  401.  
  402. \noindent\hrulefill
  403.  
  404. Test \verb+\getstored[1]{testcmd}+:\par
  405.  
  406. \getstored[1]{testcmd}
  407.  
  408. \noindent\hrulefill
  409.  
  410. \subsection{Test \texttt{\textbackslash meaningsc[index]\{seq name\}}}
  411.  
  412. \noindent\hrulefill
  413.  
  414. Test \verb+\meaningsc[1]{contents}+:\par
  415.  
  416. \meaningsc[1]{contents}
  417.  
  418. \noindent\hrulefill
  419.  
  420. Test \verb+\meaningsc[2]{contents}+:\par
  421.  
  422. \meaningsc[2]{contents}
  423.  
  424. \noindent\hrulefill
  425.  
  426. Test \verb+\meaningsc[1]{testcmd}+:\par
  427.  
  428. \meaningsc[1]{testcmd}
  429.  
  430. \noindent\hrulefill
  431.  
  432. \section{Test \texttt{\textbackslash Scontents*[key=val]}}
  433.  
  434. Test \verb+\setupsc{store-cmd=testcmdvrb}+\par
  435. \setupsc{store-cmd=testcmdvrb}
  436.  
  437. Test \verb+\Scontents*[print-cmd=false]+\par
  438.  
  439. \Scontents*[print-cmd=false]{Using \texttt{\textbackslash Scontents*} command,
  440.  
  441. with verbatim suport.
  442.  
  443. \begin{verbatim*}
  444.      verbatim
  445.              environment
  446. \end{verbatim*}
  447.  
  448. \Verb{fvextra inline yes}, save in seq \texttt{testcmdvrb} with index 1.}
  449.  
  450. Test \verb+\Scontents*[print-cmd=true]+\par
  451. \Scontents*[print-cmd=true]|Using \verb/\Scontents*[print-cmd=true]+...+/ command, with verbatim suport,
  452.  
  453. \begin{verbatim}
  454.      more verbatim environment
  455. \end{verbatim}
  456.  
  457. And \Verb{fvextra inline yes}, save in seq \texttt{testcmdvrb} with index $2$.|
  458.  
  459. Test \verb+\Scontents[store-cmd=othervrb]+\par
  460. \Scontents*[store-cmd=othervrb]{
  461. Using \texttt{\textbackslash Scontents*} command, whit verbatim suport,
  462.  
  463. \begin{verbatim}
  464.      other verbatim  environment
  465. \end{verbatim}
  466.  
  467. And \Verb{fvextra inline yes}, save in seq \texttt{othervrb} with index $1$.}
  468.  
  469. \subsection{Test \texttt{\textbackslash getstored[index]\{seq name\}}}
  470.  
  471. \noindent\hrulefill
  472.  
  473. Test \verb+\getstored[1]{testcmdvrb}+:\par
  474.  
  475. \getstored[1]{testcmdvrb}
  476.  
  477. \noindent\hrulefill
  478.  
  479. Test \verb+\getstored[2]{testcmdvrb}+:\par
  480.  
  481. \getstored[2]{testcmdvrb}
  482.  
  483. \noindent\hrulefill
  484.  
  485. Test \verb+\getstored[1]{othervrb}+:\par
  486.  
  487. \getstored[1]{othervrb}
  488.  
  489. \noindent\hrulefill
  490.  
  491. \subsection{Test \texttt{\textbackslash meaningsc[index]\{seq name\}}}
  492.  
  493. \noindent\hrulefill
  494.  
  495. Test \verb+\meaningsc[1]{testcmdvrb}+:\par
  496.  
  497. \meaningsc[1]{testcmdvrb}
  498.  
  499. \noindent\hrulefill
  500.  
  501. Test \verb+\meaningsc[2]{testcmdvrb}+:\par
  502.  
  503. \meaningsc[2]{testcmdvrb}
  504.  
  505. \noindent\hrulefill
  506.  
  507. Test \verb+\meaningsc[1]{othervrb}+:\par
  508.  
  509. \meaningsc[1]{othervrb}
  510.  
  511. \noindent\hrulefill
  512.  
  513. \subsection{Test \texttt{\textbackslash typestored*[index]\{seq name\}}}
  514.  
  515. \noindent\hrulefill
  516.  
  517. Test \verb+\typestored*[1]{testcmdvrb}+:\par
  518.  
  519. \typestored*[1]{testcmdvrb}
  520.  
  521. \noindent\hrulefill
  522.  
  523. Test \verb+\typestored*[2]{testcmdvrb}+:\par
  524.  
  525. \typestored*[2]{testcmdvrb}
  526.  
  527. \noindent\hrulefill
  528.  
  529. Test \verb+\typestored*[1]{othervrb}+:\par
  530.  
  531. \typestored*[1]{othervrb}
  532.  
  533. \noindent\hrulefill
  534.  
  535. \section{Test \texttt{\textbackslash Scontents*} and \texttt{\textbackslash Scontents} back to default}
  536.  
  537. \Scontents[store-cmd=contents]{Using \texttt{\textbackslash Scontents} command whit braces,
  538. save in seq \texttt{contents} with index $3$.}
  539. \getstored[3]{contents}
  540.  
  541. \Scontents*|Using \texttt{\textbackslash Scontents*} command (verbatimized), save in seq \texttt{testcmdvrb} with index $3$.|
  542. \getstored[3]{testcmdvrb}
  543.  
  544.  
  545. \section{Test \texttt{\{scontents\}} environment}
  546. \setupsc{store-env=testenv, print-env=false}
  547. \subsection{no \texttt{[key=val]}}
  548. Test \verb+scontents+ no \verb+[key=val]+\par
  549.  
  550. \begin{scontents}
  551. Using \verb+scontents+ env no \verb+[key=val]+, save in seq \verb+testenv+ index 1.\par
  552. We have coded this in \LaTeX: $E=mc^2$.
  553.  
  554. Prove new \Verb*{ verbatim from fvextra whit braces } and environment \verb+Verbatim*+.
  555. \begin{Verbatim*}
  556.      (A) verbatim
  557.          environment
  558. \end{Verbatim*}
  559. \end{scontents}
  560.  
  561. \subsubsection{\Verb{\getstored[1]{testenv}}}
  562. \getstored[1]{testenv}
  563.  
  564. \subsubsection{\Verb{\meaningsc[1]{testenv}}}
  565. \meaningsc[1]{testenv}
  566.  
  567. \subsubsection{\Verb{\typestored[1]{testenv}}}
  568. \typestored[1]{testenv}
  569.  
  570. \subsection{whit \texttt{[key=val]}}
  571.  
  572. \subsubsection{\Verb{[write-env=\jobname.tsc]}}
  573.  
  574. \begin{scontents}[write-env=\jobname.tsc]
  575. Using \verb+scontents+ env with \verb+[write-env=\jobname.tsc]+, save in
  576. seq \verb+testenv+ with index 2 and write env body in file \verb+\jobname.tsc+.
  577.  
  578. We have coded this in \LaTeX: $E=mc^2$.\par
  579. \begin{verbatim*}
  580.      (B) verbatim
  581.          environment
  582. \end{verbatim*}
  583. \end{scontents}
  584.  
  585. \subsubsection{\Verb{\getstored[2]{testenv}}}
  586. \getstored[2]{testenv}
  587.  
  588. \subsubsection{\Verb{\meaningsc[2]{testenv}}}
  589. \meaningsc[2]{testenv}
  590.  
  591. \subsubsection{\Verb{\typestored[2]{testenv}}}
  592. \typestored[2]{testenv}
  593.  
  594. \subsubsection{\Verb{\VerbatimInput{\jobname.tsc}}}
  595.  
  596. \VerbatimInput[frame=single,numbers=left,numbersep=3pt]{\jobname.tsc}
  597.  
  598. \subsubsection{\Verb{[print-env=true]}}
  599.  
  600. \begin{scontents}[print-env=true]
  601. Using \verb+scontents+ env with \verb+[print-env=true]+, save in
  602. seq \verb+testenv+ with index 3.
  603.  
  604. We have coded this in \LaTeX: $E=mc^2$.\par
  605. \begin{verbatim*}
  606.      (C) verbatim
  607.          environment
  608. \end{verbatim*}
  609. \end{scontents}
  610.  
  611. \Verb{\getstored[3]{testenv}}\par
  612. \getstored[3]{testenv}\par
  613.  
  614. \Verb{\meaningsc[3]{testenv}}\par
  615. \meaningsc[3]{testenv}\par
  616.  
  617. \Verb{\typestored[3]{testenv}}\par
  618. \typestored[3]{testenv}
  619.  
  620. \subsubsection{\Verb{[print-env=true,write-env=\jobname-1.tsc]}}
  621.  
  622. \begin{scontents}[print-env=true,write-env=\jobname-1.tsc]
  623. Using \verb+scontents+ env with \verb+[print-env=true,write-env=\jobname-1.tsc]+, save in
  624. seq \verb+testenv+ with index 4.
  625.  
  626. We have coded this in \LaTeX: $E=mc^2$.\par
  627. \begin{verbatim*}
  628.      (D) verbatim
  629.          environment
  630. \end{verbatim*}
  631. \end{scontents}
  632.  
  633. \Verb{\getstored[4]{testenv}}\par
  634. \getstored[4]{testenv}\par
  635.  
  636. \Verb{\meaningsc[4]{testenv}}\par
  637. \meaningsc[4]{testenv}\par
  638.  
  639. \Verb{\typestored[4]{testenv}}\par
  640. \typestored[4]{testenv}
  641.  
  642. \Verb{\VerbatimInput{\jobname-1.tsc}}\par
  643.  
  644. \VerbatimInput[frame=single,numbers=left,numbersep=3pt]{\jobname-1.tsc}
  645.  
  646. \subsection{\Verb{[write-out=\jobname-2.tsc]}}
  647.  
  648. \begin{scontents}[write-out=\jobname-2.tsc]
  649. Using \verb+scontents+ env with \verb+[write-out=\jobname-2.tsc]+,
  650. not added to seq, only write a external file
  651. We have coded this in \LaTeX: $E=mc^2$.\par
  652. \begin{verbatim}
  653.      (E) verbatim
  654.          environment
  655. \end{verbatim}
  656. \end{scontents}
  657.  
  658. \Verb{\VerbatimInput{\jobname-2.tsc}}\par
  659.  
  660. \VerbatimInput[frame=single,numbers=left,numbersep=3pt]{\jobname-2.tsc}
  661.  
  662. \subsubsection{\Verb{[print-env=true,store-env=other]}}
  663.  
  664. \begin{scontents}[print-env=true,store-env=other]
  665. Using \verb+scontents+ env with \verb+[print-env=true,store-env=other]+, save in
  666. seq \verb+other+ with index 1.
  667.  
  668. We have coded this in \LaTeX: $E=mc^2$.\par
  669. \begin{verbatim*}
  670.      (F) verbatim
  671.          environment
  672. \end{verbatim*}
  673. \end{scontents}
  674.  
  675. \Verb{\getstored[1]{other}}\par
  676. \getstored[1]{other}\par
  677.  
  678. \Verb{\meaningsc[1]{other}}\par
  679. \meaningsc[1]{other}\par
  680.  
  681. \Verb{\typestored[1]{other}}\par
  682. \typestored[1]{other}
  683.  
  684. \section{A simple aplication}
  685. \setupsc{ store-env=answers, store-cmd= answers }
  686.  
  687. \newcounter{exeNr}
  688. \newenvironment{exercise}
  689.  {\refstepcounter{exeNr}\par\noindent This is exercise~\theexeNr}
  690.  {\par}
  691. \subsection{Exercises}
  692. \begin{exercise}
  693. \end{exercise}
  694. \begin{scontents}
  695. This is the answer to exercise 1, the shebang line for a Perl script
  696.  
  697. \begin{verbatim}
  698. #!/usr/bin/env perl
  699. \end{verbatim}
  700. \end{scontents}
  701.  
  702. \begin{exercise}
  703. \end{exercise}
  704. \begin{scontents}
  705. This is the answer to exercise 2
  706. \end{scontents}
  707.  
  708. \begin{exercise}
  709. \end{exercise}
  710. \Scontents[unknow]{This is the answer to exercise 3}
  711.  
  712. \subsection{Answers}
  713. \newcounter{ansNr}
  714. \newenvironment{answer}
  715.  {\refstepcounter{ansNr}\par\noindent Answer~\theansNr:}
  716.  {\par}
  717.  
  718. \foreach \i in {1,...,\countsc{answers}} {
  719. \begin{answer}
  720. \getstored[\i]{answers}
  721. \end{answer}
  722. }
  723. \subsection{typestored}
  724. % custom :)
  725. \RecustomVerbatimEnvironment{verbatimsc}{Verbatim}{frame=single,numbers=left}
  726. \typestored[1]{answers}
  727. \typestored[2]{answers}
  728. \end{document}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement