2

In a LaTeX document I'm writing, I'm using the Comment package to write personal notes that I can enable and disable at will, as in the next example:

\documentclass[12pt]{article}
\usepackage{color}
\definecolor{note_text}{rgb}{0.7,0,0}
\usepackage{comment}
\specialcomment{note}{\begingroup\color{note_text}}{\endgroup}
% Uncomment the next line for public version without personal notes
%\excludecomment{note}

\begin{document}

This is a serious sentence.

\begin{note}
This is a personal note
\end{note}

\end{document}

Then by toggling between \excludecomment{note} and %\excludecomment{note} in the preamble, I can choose whether the document includes my personal notes or not. So far, so good.

Now comes my question: how can I do something similar with inline text within a paragraph? I would like to do something like the following:

This is a serious \note{(or not??)} sentence.

But of course that doesn't work as "note" has been defined as an environment through the \specialcomment command. So, is there any way I can use the Comment package to do this? Or some other solution?

0

For example:

\newif\ifmynotes
\mynotestrue

\definecolor{notetext}{rgb}{0.7,0,0}
\def\mynote#1{\ifmynotes\textcolor{notetext}{#1}\else\fi}

With the usage \mynote{This ia a note}. And if you want to hide your notes, you write \mynotesfalse.

  • 1
    you might want to add an \ignorespaces between \else and \fi. Otherwise, you will have two spaces with \mynotesfalse. – jakun Sep 21 '17 at 10:04
  • This rocks, thanks! There's only a minor problem left, which I haven't been able to fix with @jakun's \ignorespaces. What if I have the inline comment in front of a punctutation mark, like This is a serious sentence\note{ (or not??)}.? Ideally, I'd like it to appear as either "This is a serious sentence." or "This is a serious sentence (or not??)." But I'm finding it tricky to get the space before the parenthesis when notes are enabled. – Ángel José Riesgo Sep 21 '17 at 12:39
  • @ÁngelJoséRiesgo replace \ignorespaces with \unskip. \ignorespaces eats up following spaces, \unskip eats up preceding spaces. (At first I thought it wouldn't matter which one to use here, but it seems I did not think far enough. Good point.) – jakun Sep 22 '17 at 9:16
  • Thanks, @jakun. That's great; it now works perfectly. I can now write 'This is a serious sentence \note{(or not??)}.' and the whitespace after "sentence" vanishes when disabling the notes. – Ángel José Riesgo Sep 22 '17 at 11:52

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.