Color of warning and error messages

26 views
Skip to first unread message

dogle

unread,
Apr 4, 2015, 3:55:12 PM4/4/15
to kn...@googlegroups.com
I would like the warnings and errors printed in the output chunk to be black rather than fuchsia and red, respectively.  I have attempted to follow the conversation here (github.com/yihui/knitr/issues/264) to fix this problem.  Here is what I have so far (first chunk).

\documentclass{article}
\begin{document}
<<echo=FALSE>>=
color_block
= function(color) {
 
function(x, options) sprintf('{\\color{%s}\\begin{verbatim}%s\\end{verbatim}}',color, x)
}
knit_hooks$set
(warning=color_block('black'),error=color_block('black'))
@

<<>>=
lens
<- c(10,20,30,40)
lens
+ c(100,200,300)
@
\end{document}

I have succeeded in changing the colors of the messages to be black but the messages now do not wrap to stay within the output chunk boundaries and there are extra spaces before and after the message (see result of second chunk).

From this SO discussion, I thought that a \raggedright might help but I don't understand this code well enough to appropriately modify it.

Any help would be appreciated.  Thank you in advance.

dogle

unread,
Apr 9, 2015, 2:20:12 PM4/9/15
to kn...@googlegroups.com
As a follow-up (I still don't have a solution to this yet), if I remove the hook below and simply knit my document, then I get warnings and errors in fuchsia and red.  However, in the .Tex document there are these definitions:

\definecolor{warningcolor}{rgb}{1, 0, 1}
\definecolor{errorcolor}{rgb}{1, 0, 0}

If I change both to 0,0,0 and compile the .Tex document, then the warnings and errors are in black as I want them.  Is there a way to set or define these colors in the .Rnw document?
Reply all
Reply to author
Forward
0 new messages