我正在尝试删除%
我添加到按序列存储的宏中的符号,以防止在使用处理参数时(^M/ASCII-Return)
添加该符号。TeX
\scantokens
一切都很完美,但是,通过使用,\meaning
我想删除%
我在末尾添加的符号。在我的示例中,输出为:
Using \verb+\Scontents+ command,verbatim support, using balanced
braces, save in seq nospaceafter with index $1$.No space after close
:)%
我想要的是:
Using \verb+\Scontents+ command,verbatim support, using balanced
braces, save in seq nospaceafter with index $1$.No space after close
:)
这是我的示例文件:
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\keys_define:nn { scontents }
{
store-cmd .tl_set:N = \l__scontents_name_seq_cmd_tl,
store-cmd .initial:n = contents,
}
\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:Npn \__scontents_getfrom_seq:nn #1#2
{
\seq_item:cn { g__scontents_seq_name_#2_seq } {#1}
}
\exp_args_generate:n { Vx }
% stored
\ProvideDocumentCommand{ \Scontents }{ O{} +v }
{
\group_begin:
\IfNoValueF {#1} { \keys_set_known:nn { scontents } {#1} }
\tl_set:Nn \l_tmpa_tl {#2}
\regex_replace_all:nnN { \^^M } { \^^J } \l_tmpa_tl
\exp_args:NVx \__scontents_append_contents:nn \l__scontents_name_seq_cmd_tl
{ \exp_not:N \tex_scantokens:D { \tl_use:N \l_tmpa_tl \c_percent_str} }
\group_end:
}
% get
\ProvideDocumentCommand{ \getstored } { O{1} m }
{
\__scontents_getfrom_seq:nn {#1} {#2}
}
% meaning
\ProvideDocumentCommand{ \meaningsc } { O{1} m }
{
\group_begin:
\tl_set:Nx \l_tmpb_tl { \__scontents_getfrom_seq:nn {#1} {#2} }
\regex_replace_once:nnN { ^ \c{tex_scantokens:D} \cB. (\c[^BE].*) \cE. } { \1 } \l_tmpb_tl
\regex_replace_all:nnN { \v{1,} } { } \l_tmpb_tl
% this not work
\tl_reverse:N \l_tmpb_tl % reverse
\tl_remove_once:Nn \l_tmpb_tl { \c_percent_str } % remove
\tl_reverse:N \l_tmpb_tl % reverse
\ttfamily
\cs_replacement_spec:N \l_tmpb_tl
\group_end:
}
\ExplSyntaxOff
\begin{document}
\Scontents[store-cmd=nospaceafter]{Using \verb+\Scontents+ command,
verbatim support, using balanced braces, save in seq nospaceafter with index $1$.
No space after close :)}
\Scontents[store-cmd=nospaceafter]|Using \verb+\Scontents+ command,
delimited by tbar, save in seq nospaceafter with index $2$. end by \verb+%+
\begin{verbatim*}
verbatim environment
with unbalanced } braces }
\end{verbatim*}
No space after close, one percent at end of line%|
\noindent\hrulefill
XX\getstored[1]{nospaceafter}.No space after :) YY\par
\noindent\hrulefill
XX\getstored[2]{nospaceafter}.No space after :) YY
\noindent\hrulefill
\meaningsc[1]{nospaceafter}
\noindent\hrulefill
\meaningsc[2]{nospaceafter}
\end{document}
我尝试过使用\tl_reverse:N
,但没有效果,我想也许可以用一些方法来实现regex
(对此我不太确定)。
问候语