1

I have used the verbatim package to comment out significant parts of my tex file.

1) I now wish to see these comments in my pdf document when I compile... in a different colour (say red), without having to go through the document and uncomment everything.

2) I also want to be able to compile only the comments perhaps as a seperate pdf...without having to copy and paste all the comments into a seperate tex file.

Is there an easy way to achieve 1 and 2? Thank you

MWE:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{verbatim}

\begin{document}
minimal example
\begin{comment}
  i want this to compile in the pdf, and look red (by typing something in the
  preamble of the doc perhaps). (and also be able to switch back to it being a
  comment easily).
\end{comment}
\end{document}
2
  • Please show us what you've done so far and post a minimal working example (MWE), so we can actually test things within your setup.
    – Skillmon
    Jul 24, 2018 at 11:19
  • What’s in the comment parts? Any TeX-special characters — such as {, _, and % — by any chance? And how do you want the commented material to be typeset, other than the use of the color red? Using a monospaced font, or the “regular” text font?
    – Mico
    Jul 24, 2018 at 13:15

1 Answer 1

3

For 1) You can use one of the following to put the comments into the text in red or the margin.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{verbatim}

\usepackage{xcolor}
\usepackage{environ}% needed only for into the margin


\renewenvironment{comment}{\color{red}}{}% red and in text
\RenewEnviron{comment}{\marginpar{\color{red}\BODY}}% red and in the margin


\begin{document}
minimal example
\begin{comment}
  i want this to compile in the pdf, and look red (by typing something in the
  preamble of the doc perhaps). (and also be able to switch back to it being a
  comment easily).
\end{comment}
\end{document}

For 2) A simple solution writing every comment into the file \jobname.comments. You can then use this file to create a separate document.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{verbatim}

\usepackage{environ}

\RenewEnviron{comment}
  {%
    \immediate\write\CommentsWrite{\unexpanded\expandafter{\BODY}}%
    \immediate\write\CommentsWrite{}%
  }
\newwrite\CommentsWrite
\immediate\openout\CommentsWrite=\jobname.comments
\AtEndDocument{\immediate\closeout\CommentsWrite}

\begin{document}
minimal example
\begin{comment}
  i want this to compile in the pdf, and look red (by typing something in the
  preamble of the doc perhaps). (and also be able to switch back to it being a
  comment easily).
\end{comment}
\begin{comment}
  A second comment
\end{comment}
\end{document}

You must log in to answer this question.

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