I'm trying to create a command that represents the code that is stored in a sequence without executing it (something like \meaning)
. When using \cs_log:N \l_scontents_macro_tmp_tl I get in the .log the content recorded in scontents environment before passed to seq.
Can I create a command like \typestored[number]{seqname} that gives me the same result in the document?
Which when run \typestored[1]{contents} take content stored in the sequence and shows in document:
Using \verb+scontents+ env no \verb+[key=val]+, save in \verb+contents+
with index $1$\footnote{AND footnotes !!}.%
Prove new \Verb*{ new fvextra whit braces } and environment \verb+Verbatim+
\begin{Verbatim}
(A) verbatim environment %
many space here and percent at end of line %
many space
\end{Verbatim}
No espace after, see \verb+https://tex.stackexchange.com/a/460967/7832+.\par
Use \verb|\relax|.\relax
I've tried to use :
% Fake \meaning
\tl_const:Nn \c_catcode_specials_tl { \ \\ \{ \} \$ \& \# \^ \_ \% \~ }
\cs_new_protected:Npn \_catcode_dospecials:
{
\tl_map_inline:Nn \c_catcode_specials_tl
{
\char_set_catcode_other:N ##1
}
}
\ProvideDocumentCommand{ \typestored }{ O{1} m }
{
\tl_put_right:Nx \l_tmpb_tl
{
\_catcode_dospecials:
\_scontents_getfrom_seq:nn { #1 }{ #2 }
}
\tl_show:N \l_tmpb_tl
}
But it doesn't work, I just want the representation of what's kept in the verbatim style, \l_tmpb_tl does not contain content that is stored in the sequence.
This is my MWE.
\documentclass{article}
\usepackage{filecontentsdef}[2019/04/20]
\usepackage{xparse}
\usepackage{fvextra}
\setlength{\parindent}{0pt} % just for the example
\ExplSyntaxOn
\tl_new:c { l_scontents_macro_tmp_tl }
\keys_define:nn { scontents }
{
save-env .tl_set:N = \l_scontents_name_seq_tl,
save-env .initial:n = contents,
show-env .bool_set:N = \l_scontents_show_env_bool,
show-env .initial:n = false
}
% Adapted from https://tex.stackexchange.com/a/215571/7832
\cs_new_protected:Npn \_scontents_append_contents:nn #1 #2
{
\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 }
}
\cs_new_protected:Npn \_scontents_getfrom_seq:nn #1 #2
{
\seq_item:cn { g_scontents_seq_name_#2_seq } { #1 }
}
\ProvideExpandableDocumentCommand{\getstored}{ O{1} m }
{
\_scontents_getfrom_seq:nn { #1 } { #2 }
}
% Define scontents (wrap \filecontentsdefmacro) whit [key=val] Delaying
% Adapted from https://tex.stackexchange.com/a/487746/7832
\ProvideDocumentEnvironment{ scontents }{}
{
\char_set_catcode_active:N \^^M
\scontents_start_environment:w
}
{
\scontents_stop_environment:
\scontents_atend_environment:
}
\cs_new_protected:Npn \scontents_environment_keys:w [#1]
{
\keys_set:nn { scontents } { #1 }
}
% Star environment
\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: % open group for env
\use:c { filecontentsdefmacro } { \l_scontents_macro_tmp_tl } ^^M
}
\group_end:
% Stop environment
\cs_new_protected:Nn \scontents_stop_environment:
{
\endfilecontentsdefmacro
\group_end: % close group for env
}
% A variant to replace \^^M for \^^J (need by Verb{..} from fvextra)
% https://tex.stackexchange.com/a/8971/7832
\cs_generate_variant:Nn \tl_replace_all:Nnn { Nxx }
% Expand \l_tmpa_tl and pass to seq
\cs_gset_protected:Nn \_scontents_macro_to_seq:
{
\regex_replace_all:nnN { \^^M } { \^^J } \l_scontents_macro_tmp_tl
\cs_log:N \l_scontents_macro_tmp_tl
\exp_args:NNx \_scontents_append_contents:nn \l_scontents_name_seq_tl
{
\exp_not:N \scantokens \exp_after:wN { \tl_use:c { l_scontents_macro_tmp_tl} } %
}
}
% Code after scontent environment \seq_item:cn { g_scontents_seq_name_#2_seq } { #1 }
\cs_new_protected:Nn \scontents_atend_environment:
{
\_scontents_macro_to_seq:
\bool_if:NT \l_scontents_show_env_bool
{
\_scontents_getfrom_seq:nn { -1 }{ \l_scontents_name_seq_tl }
}
\cs_undefine:N \l_scontents_macro_tmp_tl
}
% Fake \meaning
\tl_const:Nn \c_catcode_specials_tl { \ \\ \{ \} \$ \& \# \^ \_ \% \~ }
\cs_new_protected:Npn \_catcode_dospecials:
{
\tl_map_inline:Nn \c_catcode_specials_tl
{
\char_set_catcode_other:N ##1
}
}
\ProvideDocumentCommand{ \typestored }{ O{1} m }
{
\tl_put_right:Nx \l_tmpb_tl
{
\_catcode_dospecials:
\_scontents_getfrom_seq:nn { #1 }{ #2 }
}
%\tl_show:N \l_tmpb_tl
}
\ExplSyntaxOff
\begin{document}
\section*{Test environment}
Test \verb+\begin{scontents}+ no \verb+[key=val]+\par
\begin{scontents}
Using \verb+scontents+ env no \verb+[key=val]+, save in \verb+contents+
with index $1$\footnote{AND footnotes !!}.%
Prove new \Verb*{ new fvextra whit braces } and environment \verb+Verbatim+
\begin{Verbatim}
(A) verbatim environment %
many space here and percent at end of line %
many space
\end{Verbatim}
No espace after, see \verb+https://tex.stackexchange.com/a/460967/7832+.\par
Use \verb|\relax|.\relax
\end{scontents}
\section*{Show stored contents}
XX\getstored[1]{contents}NO space here :)\par
\section*{typestored}
%\typestored[1]{contents} % not work
\end{document}
If I remove the comments from \tl_show:l \l_tmpb_tl and \typestored[1]{contents} I get in log file:
\l_tmpb_tl=\_catcode_dospecials: \_scontents_getfrom_seq:nn {1}{contents}
As @David Carlisle put in his comment, which is not what I want. I hope it contains :
\l_tmpb_tl=Using \verb+scontents+ env no \verb+[key=val]+, save in
\verb+contents+
with index $1$\footnote{AND footnotes !!}.%
Prove new \Verb*{ new fvextra whit braces } and environment \verb+Verbatim+
\begin{Verbatim}
(A) verbatim environment %
many space here and percent at end of line %
many space
\end{Verbatim}
No espace after, see \verb+https://tex.stackexchange.com/a/460967/7832+.\par
Use \verb|\relax|.\relax
The author of the package provides the macro \filecontentsprint which I try to imitate using the content stored in the sequences. It should look something like this (or similar):
EDIT 1
A first attempt, by defining '\typestored' as follows:
\ProvideDocumentCommand{ \typestored }{ O{1} m }
{
\tl_put_right:Nx \l_tmpb_tl
{
\seq_item:cn { g_scontents_seq_name_#2_seq } { #1 }
}
\regex_replace_once:nnN { ^ \c{scantokens} } { \c{#2[#1]} } \l_tmpb_tl
\tl_show:N \l_tmpb_tl
\small\texttt{\meaning\l_tmpb_tl}
}
I get:
which is almost exactly what I want, of course, breaks the title of the question (I don't need to modify catcode), I would need to replace Ω and ΩΩ with a regex(I don't know how). I hope this clarifies better what I want (my English is not the best, Spanish is my language).
EDIT 2
Second attempt, I copied the definition of \filecontentsprint from the style file and added the newvbtm package to avoid conflicts with the classic verbatim environment. It's not at all elegant and doesn't follow the line I'm looking for, the code is a bit "obfuscated" for me but it works.
% Fake \meaning, copy direct from filecontensdef package
% Add \usepackage{newvbtm} to solve conflict whit verbatim nested
\newverbatim{typescverb}{}{}{}{}
\makeatletter
\gdef\filecontentsprint{\filecontentsdef@get\filecontents@print}%
\catcode`\^^M\active%
\gdef\filecontents@print #1{\let\filecontents@print@EOL^^M\let^^M\relax%
\begingroup\toks@\expandafter{#1}\edef\x{\endgroup%
\noexpand\begin{typescverb}^^M%
\the\toks@\@backslashchar end\string{typescverb\string}}\x^^M%
\filecontents@print@resetEOL}%
\gdef\filecontents@print@resetEOL{\let^^M\filecontents@print@EOL}%
\makeatother
\ProvideDocumentCommand{ \typestored }{ O{1} m }
{
\group_begin:
\tl_put_right:Nx \l_tmpb_tl
{
\seq_item:cn { g_scontents_seq_name_#2_seq } { #1 }
}
\filecontentsprint\l_tmpb_tl
\group_end:
}
What I was looking for, of course, in doing this you lose the spirit of using expl3 by mixing LaTeX2e code.
Greetings.


\meaningthat will put essentially the same in the document as\showwill show in the log? I must be missing something... – David Carlisle Jun 23 '19 at 18:11\scantokens, thefilecontentsdefpackage plays withcatcodesin ways I don't understand and I can't get the result I'm hoping for. – Pablo González L Jun 23 '19 at 18:14\meaning(\meaningreturns all characters with catcode 12 or 10 so initial catcodes should not matter) – David Carlisle Jun 23 '19 at 18:16\begin{verbatim}...\end{verbatim}, I've played a little and get"instead of\, and other symbol... – Pablo González L Jun 23 '19 at 18:25\texttt{\meaning\zzzzz}should be the same except possibly you need to do something about line ends, but that is all. – David Carlisle Jun 23 '19 at 18:26\tl_put_right:. – Pablo González L Jun 23 '19 at 18:34\tl_show:Nin your code then it shows a completely different definition\l_tmpb_tl=\_catcode_dospecials: \_scontents_getfrom_seq:nn {1}{contents}.– David Carlisle Jun 23 '19 at 18:51l3tl-analysispackage – siracusa Jun 24 '19 at 04:53l3tl-analysisbut it's above my level, I think what I want can't be done with sequences. If I understood the documentation,\seq_item:is\exp_not:n, maybe I should switch tol3propand use\prop_get:cn, but I've never usedl3prop. – Pablo González L Jun 24 '19 at 05:37^^Mand spaces to be active to map them to the correct output behavior. Also,{filecontentsdefmacro}should already give you letter-only characters, so the reassignment to other probably isn't necessary. – siracusa Jun 24 '19 at 07:24\scantokenshere if you are going to allow verbatim content inside the grabbed content if you then want the grabbed content to be used in normal typesetting: you have to go with thebeamerapproach of re-reading a temporary file. – Joseph Wright Jun 25 '19 at 07:06\seq_get_right:NN \l_my_seq \l_my_tlfollowed by\tl_to_str:N \l_my_tlwill work. I have a feeling you want more than that. – Joseph Wright Jun 26 '19 at 06:51expl3: You are interfacing LaTeX3 code with a 2ε document and using 2ε packages. It's unlikely that you will get away without any 2ε code at all. The LaTeX3 kernel itself uses\@currname,\input@path,\@filelist,\@unexpandable@protect, etc., and that is after the 2ε--3 interface code is already set up. My point is: if the code is doing what you want it to, then you should leave it be. Of course you can do a direct translation of syntax, but you will still need to use\filecontentsdef@get. That or rewritefilecontentsdefinexpl3... – Phelype Oleinik Jun 26 '19 at 11:392εcannot be completely dispensed with, but, one should try to follow the line proposed byexpl3, that is, if something can be written in terms ofexpl3it should be done directly. Clearly I should use\filecontentsdef@get, I can try to make translation, something likecs_gset_eq:N\myfcdefget \filecontentsdef@get(which is quite simple), but, the macros used\filecontentsprintare harder to pass through (\edef\xfor example), the code would be more readable (and nice). Rewritefilecontentsdefinexpl3is absolutely out of my level :( – Pablo González L Jun 26 '19 at 12:59\catcode`\^^M\activebecomes\char_set_catcode_active:N \^^M,\edef\x{...}\xbecomes\use:x{...}, and a few other changes... I also replaced the\tl_put_right:Nxby\tl_set:Nxbecause you weren't reusing the contents, sosetis better. – Phelype Oleinik Jun 26 '19 at 13:44newvbtmpackage because I didn't find a way to usefancyvrbto define a new environment, if you can use this package better, but as it is working perfectly. All this is part of an "idea" I have in mind (https://pastebin.com/1s8tzC22). PD: A macro like a\filecontentsdef@getinexpl3I'd be really pretty. – Pablo González L Jun 26 '19 at 18:17