避免输出中的信息消息(来自包注释)

避免输出中的信息消息(来自包注释)

我正在广泛使用软件包注释,它会产生很多我不想再阅读的信息消息。我该如何摆脱它们?(大概,我仍然希望收到警告和错误,但不希望收到以“排除”开头的任何消息。)

我尝试过使用该包silence但也许它只解决实际的警告/错误而不是纯信息消息?

\documentclass{article}

\usepackage{silence}
\WarningsOff[comment]
\ErrorsOff[comment]
\WarningFilter{comment}{Excluding}

\usepackage{comment}

\excludecomment{hint}

\begin{document}
Zero
\begin{hint}
  One
\end{hint}
\begin{hint}
  One
\end{hint}
\begin{hint}
  One
\end{hint}
\begin{hint}
  One
\end{hint}
\begin{hint}
  One
\end{hint}
\end{document}

我怎样才能避免上面的 MWE 在输出中显示所有这些“不包括‘提示’注释。”消息?

(/usr/local/texlive/2019/texmf-dist/tex/latex/base/size10.clo)) (/usr/local/texlive/2019/texmf-dist/tex/latex/silence/silence.sty) (/usr/local/texlive/2019/texmf-dist/tex/latex/comment/comment.sty Excluding comment 'comment') Excluding comment 'hint' (./test.aux) (/usr/local/texlive/2019/texmf-dist/tex/latex/base/omscmr.fd) Excluding 'hint' comment. Excluding 'hint' comment. Excluding 'hint' comment. Excluding 'hint' comment. Excluding 'hint' comment. Excluding 'hint' comment. [1{/usr/local/texlive/2019/texmf-var/fonts/map/pdftex/updmap/pdftex.map}] (./test.aux) )</usr/local/texlive/2019/texmf-dist/fonts/type1/public/amsfonts/cm/cmbx10.pfb></usr/local/texlive/2019/texmf-dist/fonts/type1/public/amsfonts/cm/cmr10.pfb></usr/local/texlive/2019/texmf-dist/fonts/type1/public/amsfonts/cm/cmsy10.pfb>          

答案1

正如问题下方的评论中所述,您可以重新定义comment定义以删除\message命令。您可以使用包来修补命令etoolbox,该包为命令提供了\patchcmd五个参数,首先是要修补的命令,然后是要修改的命令部分,然后是替换文本,然后是修补成功时要执行的代码,最后一个参数是修补失败时要执行的代码。最后两个参数可以为空。在这种情况下,您想用空值替换命令\message

梅威瑟:

\documentclass{article}

\usepackage{comment}
\usepackage{etoolbox}
\patchcmd{\excludecomment}{\message{Excluding '#1' comment.}}{}{}{}
\excludecomment{hint}

\begin{document}
Zero
\begin{hint}
  One
\end{hint}
\begin{hint}
  One
\end{hint}
\begin{hint}
  One
\end{hint}
\begin{hint}
  One
\end{hint}
\begin{hint}
  One
\end{hint}
\end{document}

结果:

Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
(/usr/share/texlive/texmf-dist/tex/latex/base/size10.clo))
(/usr/share/texlive/texmf-dist/tex/latex/comment/comment.sty
Excluding comment 'comment')
(/usr/share/texlive/texmf-dist/tex/latex/etoolbox/etoolbox.sty)
Excluding comment 'hint' (./excludemsg.aux) [1{/var/lib/texmf/fonts/map/pdftex/
updmap/pdftex.map}] (./excludemsg.aux) )</usr/share/texlive/texmf-dist/fonts/ty
pe1/public/amsfonts/cm/cmr10.pfb>
Output written on excludemsg.pdf (1 page, 10669 bytes).

或者,您可以重写宏以允许可选开关针对某些环境显示消息,而针对其他环境不显示消息。

梅威瑟:

\documentclass{article}
\usepackage{comment}
\usepackage{ifthen}

\renewcommand\excludecomment[2][]{\message{Excluding comment '#2'}%
    \ifthenelse{\equal{#1}{msg}}{%
    \csarg\def{#2}{\endgroup \message{Excluding '#2' comment.}%
        \begingroup
           \DefaultCutFileName \def\ProcessCutFile{}%
           \def\ThisComment####1{}\ProcessComment{#2}}%
    }{%
    \csarg\def{#2}{\endgroup %
        \begingroup
           \DefaultCutFileName \def\ProcessCutFile{}%
           \def\ThisComment####1{}\ProcessComment{#2}}%
    }
    \csarg\def{After#2Comment}{\CloseAndInputCutFile \endgroup}
    \CommentEndDef{#2}}

\excludecomment{hint}
\excludecomment[msg]{otherhint}

\begin{document}
Zero
\begin{hint}
  One
\end{hint}
\begin{otherhint}
  One
\end{otherhint}
\begin{hint}
  One
\end{hint}
\begin{hint}
  One
\end{hint}
\begin{otherhint}
  One
\end{otherhint}
\end{document}

结果(hint没有提到环境,但otherhint有提到环境):

Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
(/usr/share/texlive/texmf-dist/tex/latex/base/size10.clo))
(/usr/share/texlive/texmf-dist/tex/latex/comment/comment.sty
Excluding comment 'comment')
(/usr/share/texlive/texmf-dist/tex/latex/base/ifthen.sty)
Excluding comment 'hint' Excluding comment 'otherhint' (./excludemsg.aux)
Excluding 'otherhint' comment. Excluding 'otherhint' comment. [1{/var/lib/texmf
/fonts/map/pdftex/updmap/pdftex.map}] (./excludemsg.aux) )</usr/share/texlive/t
exmf-dist/fonts/type1/public/amsfonts/cm/cmr10.pfb>
Output written on excludemsg.pdf (1 page, 10669 bytes).

相关内容