0

I am using the package comment extensively and it produces a lot of information messages I don't want to read anymore. How can I get rid of them? (presumably, I would still like to receive warnings and errors, but not any of the messages that start with "Excluding".)

I've tried using the package silence but maybe it only addresses actual warning/errors and not pure information messages?

\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}

How can I avoid the MWE above displaying all these "Excluding 'hint' comment." messages in the output?

(/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
  • 1
    comment uses \message for the messages. silence can not filter them, and you can only get rid of them by either redefining the primitive \message or by redefining the comment definitions. Commented Jun 1, 2020 at 10:58

1 Answer 1

1

As noted in the comment below the question you can redefine the comment definitions to remove the \message commands. You can patch a command using the etoolbox package, which provides the command \patchcmd with five arguments, first the command that you want to patch, then the part of the command that you want to modify, then the replacement text, then code to execute if the patch is succesful and as last argument code to execute if the patch fails. The final two arguments can be empty. In this case you want to replace the \message command with nothing.

MWE:

\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}

Result:

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).

Alternatively, you can rewrite the macro to allow for an optional switch to display the message for some environments and not for others.

MWE:

\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}

Result (the hint environments are not mentioned but the otherhint environments are):

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).
4
  • Thanks. I'm in the process of adapting your answer to my actual use case (that also involves \specialcomment and \includecomment. Can you explain to me what \def\ThisComment####1{} does?
    – Abdallah
    Commented Jun 1, 2020 at 14:27
  • @Abdallah as described in the comment package manual in section 3.3, the \ThisComment command is used in the 'before commands' for a special comment environment. For a normal comment environment defined with \excludecomment this can be empty (i.e., {}) but it still needs to be defined because \ThisComment is called for all comment environments (not just the 'special' environments). The syntax with all the # symbols has to do with escaping,
    – Marijn
    Commented Jun 1, 2020 at 17:19
  • 1
    normally you use #1 to indicate the first argument to a function, but the definition of \ThisComment is normally done within another command (cf. the manual), therefore you specify ##1 to indicate that it is a literal #1 and not the value of #1 in the surrounding command. Now, in the definition of \excludecomment there is a double nesting, it is a \def inside a \csarg\def inside a \newcommand (or inside a \def in the original version), therefore you need double escaping with four # symbols.
    – Marijn
    Commented Jun 1, 2020 at 17:23
  • Ok, thanks for the explanations!
    – Abdallah
    Commented Jun 1, 2020 at 20:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .