我可以暂时抑制 xparse 的日志消息吗?

我可以暂时抑制 xparse 的日志消息吗?

我知道我可以抑制所有那些烦人的xparse记录有关使用log-declarations=false包选项重新定义命令的消息。

我发现xparse加载后可以通过发出相关命令来执行此操作:

\msg_redirect_module:nnn { LaTeX / xparse } { info }    { none }
\msg_redirect_module:nnn { LaTeX / xparse } { warning } { none }

在适当的时机。然后我可以使用以下命令恢复它们:

\msg_redirect_module:nnn { LaTeX / xparse } { info }    { info }
\msg_redirect_module:nnn { LaTeX / xparse } { warning } { warning }

我的问题是:我能否找出以前的重定向,以便在恢复代码中将它们恢复为以前的值,而不是某些固定的选择?

答案1

命令\msg_redirect_module:nnn添加或更新属性列表变量中的项目或对其进行更新;但此变量是私有的(\l__msg_redirect_info_prop或类似的),因此不鼓励使用它。

然而,这似乎有效,但由于它访问私有变量,所以肯定不是推荐。可能在 LaTeX3 邮件列表中提出功能请求是合适的。

\RequirePackage{xparse}
\ExplSyntaxOn
\prop_new:N \l_stacey_redirect_store_info_prop
\prop_new:N \l_stacey_redirect_store_warning_prop
\prop_new:N \l_stacey_redirect_store_error_prop
\tl_new:N \l__stacey_temp_tl

\cs_new_protected:Npn \stacey_msg_redirect_module:nnn #1 #2 #3
 {
  \prop_if_in:cnTF { l__msg_redirect_#2_prop } { /#1 }
   {
    \prop_get:cnN { l__msg_redirect_#2_prop } { /#1 } \l__stacey_temp_tl
    \prop_put:cnV { l_stacey_redirect_store_#2_prop } { /#1 } \l__stacey_temp_tl
   }
   {
    \prop_put:cnn { l_stacey_redirect_store_#2_prop } { /#1 } { #2 }
   }
  \msg_redirect_module:nnn { #1 } { #2 } { #3 }
 }
\cs_new_protected:Npn \stacey_msg_restore_redirect_module:nn #1 #2
 {
  \prop_if_in:cnT { l_stacey_redirect_store_#2_prop } { /#1 }
   {
    \prop_get:cnN { l_stacey_redirect_store_#2_prop } { /#1 } \l__stacey_temp_tl
    \msg_redirect_module:nnV { #1 } { #2 } \l__stacey_temp_tl
   }
 }
\cs_generate_variant:Nn \msg_redirect_module:nnn { nnV }

\NewDocumentCommand{\foo}{}{}
\DeclareDocumentCommand{\foo}{}{}
\stacey_msg_redirect_module:nnn { LaTeX / xparse } { warning } { none }
\DeclareDocumentCommand{\foo}{}{}
\stacey_msg_restore_redirect_module:nn { LaTeX / xparse } { warning }
\DeclareDocumentCommand{\foo}{}{}

终端上的输出是

*************************************************
* LaTeX warning: "xparse/redefine-command"
*
* Redefining document command \foo with arg. spec. '' on line 31.
*************************************************
*************************************************
* LaTeX warning: "xparse/redefine-command"
*
* Redefining document command \foo with arg. spec. '' on line 35.
*************************************************

您会看到第二个\DeclareDocumentCommand没有发出警告。

相关内容