2

Is there any way to bold or highlight all comments when using Sweave? Maybe a command to make all lines starting with # be bolded?

<<>>=
# I want this to be bold automatically
@
1

You can redefine \hlcom command.

% !Rnw weave = knitr
% !TeX program = pdfLaTeX

\documentclass[final,12pt]{article}

\usepackage[a4paper]{geometry}

\renewcommand{\hlcom}[1]{\textcolor[rgb]{0.678,0.584,0.686}{\textbf{#1}}}%

\begin{document}
<<>>=
  # commented text
@
\end{document}

And the result:

result

3
  • ! LaTeX Error: \hlcom undefined. Dec 1 '13 at 20:26
  • I'm using Sweave and not knitr. Is that the problem? (Would switching over be easy?) Dec 1 '13 at 20:47
  • @EarlBellinger It should be easy and you definitely should switch: yihui.name/knitr/demo/sweave (Disclaimer: I'm the knitr author, so I'm biased by definition)
    – Yihui Xie
    Dec 22 '13 at 2:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.