How can I write notes in a LaTeX file, that don't appear in the PDF file?
7 Answers
Smaller text can be marked as comment with the %
character. TeX ignores everything behind it till the end of the line. (You probably knew that already)
For longer text you can use the comment
package to define environments which are ignored by LaTeX.
\usepackage{comment}
% ...
\begin{comment}
This text is ignored
\end{comment}
If your notes are simple text without any special TeX macros (especially not \if...
macros) then you can use \iffalse ... \fi
for this
\iffalse
This text is ignored, but should not include `if...` and `fi` macros
\fi
-
73In fact, the comment package also allows one to define your own comment-like environments. This can be useful to quickly generate two different versions of a document (say, one with and one without answers to exercises). One simply writes
\includecomment{answer}
or\excludecomment{answer}
in the preamble, and then write each answer in an answer environment. Feb 16, 2011 at 4:42
Of course, you can always use the standard method, placing %
before each line, to convert some text into a comment. But if you have tons of comments about contents that at some time you prefer to show in the PDF (for example, in a draft to your thesis supervisor) and you want to distinguish of comments to understand the next piece of LaTeX codes or disable it, then this standard method is not enough.
Here are two approaches to easily hide/unhide another type of comments:
Hide all comments (those without %
).
Define in the preamble a new command (wasting imagination I thought in
\comment
) that simply do nothing (see the MWE). Then you can use safely comments as\comment{
The boss is too stupid to understand this paragraph, write it with simple words.}
Use the
todonotes
package with the optiondisable
.
Unhide comments
- Disable the new command
\comment
in the preamble (with as%
before) and define again to show their content (better with some different format that the body text). - In
todonotes
package remove the optiondisable
. Bonus advantage: a pretty to-do list.
I hope that both approaches are self-explained in this MWE:
\documentclass{article}
\usepackage{xcolor}
\usepackage{lipsum} % dummy text for the MWE
% Put % before of what you want disabled
% Select what to do with todonotes:
% \usepackage[disable]{todonotes} % notes not showed
\usepackage[draft]{todonotes} % notes showed
% Select what to do with command \comment:
% \newcommand{\comment}[1]{} %comment not showed
\newcommand{\comment}[1]
{\par {\bfseries \color{blue} #1 \par}} %comment showed
\begin{document}
\lipsum[1]
\todo{This is a to do note at margin}
\lipsum[2]
\comment{This is a simple comment between text}
\lipsum[3]
\todo[inline]{This is a todo note inline}
\comment{This is the end, check the to-do list}
\listoftodos
\end{document}
-
3
-
3Just a note that this package is a performance trojan horse. Had to remove it from one of my projects due to high compile time. Aug 10, 2017 at 14:04
-
1@Jerry This example in my computer is compiled roughly in 0.35 second. Of these, only 0.19 seconds are due to todonotes. Tikz-based solutions as well as other complex packages always has this disadvantage but depend of the project/machine if this is serious. The issue is if the delay is enough to allow yourself a coffee while you wait, or only to stress you.– FranAug 10, 2017 at 19:37
-
2@Fran I use Overleaf and they provide me 1 minute of compile time before it times out (in the free version). I removed the package and never experienced a timeout even though I had a dozen eps files. I use overleaf since it provides real-time collaboration between peers. So, in this case todonotes was a performance trojan. Aug 11, 2017 at 4:29
-
In order to avoid unwanted consecutive blank spaces I would define the variant for not showing the comment as
\newcommand\comment[1]{\@bsphack\@esphack}
. Jan 31, 2021 at 21:52
If I understand your question correct, use a %
at the beginning of the line. The percentage sign indicates a comment, which is text that isn't typeset.
\documentclass{article}
\begin{document}
This text will be in the PDF.
% This is a comment, and will not appear.
\end{document}
To print a percentage sign in the text, use \%
.
A solution I use is the following: I defined a command to write my comments in:
\newcommand{\rood}[1]{\textcolor{red}{[#1]}} %for displaying red texts
("rood" is Dutch for "red"). A comment looks like this:
\rood{This comment is displayed in red}
When I want to create my final version, I simply remove the second part of this comment, meaning that all text simply is not displayed:
\newcommand{\rood}[1]{} %for displaying red texts
Apart from the package for displaying the color (xcolor
), no other packages are necessary!
-
1with one CAVEAT though (I think): make sure you only have a single space either before or after the comment, not both, else you'll end up with extra gaps when using
\newcommand{\rood}[1]{}
before going to press... correct me if I'm wrong, I'm a beginner! Apr 29, 2013 at 18:58 -
Yes, that seems to be true. When I create a PDF from my code the way you describe, it seems a "double-width" space is put in, i.e. it looks like two spaces (which is undesired), but copy-pasting the PDF text into a text editor only copies one space. Also watch out with no spaces before and after!– JokerAug 8, 2013 at 14:26
-
I do something similar, without
todonotes
too, defining\comment
as\marginpar{\parbox{...}{#1}}
and to hide just comment the definition out:%\marginpar{\parbox{...}{#1}}
Jan 21, 2014 at 10:05 -
1I tested
\newcommand{\rood}[1]{\ignorespaces}
and it seems to correct the problem of two spaces. May 26, 2015 at 2:51 -
\newcommand{\rood}[1]{\@bsphack\@esphack}
corrects the problem of two spaces. Jan 31, 2021 at 21:54
You could use the fixme
package if you want to make comments in the pdf-file that you can turn on or off.
The package can be found here: http://www.ctan.org/pkg/fixme.
You can implement it by putting something like this in your preamble:
\usepackage[draft]{fixme}
\fxsetup{layout=footnote, marginclue}
You then make a comment in the text by using \fxnote{...}
. If you put in final
instead of draft
your comments will not be visible in the pdf-file.
You can get a list of all the notes by using the command \listoffixmes
. This is the most simple use of fixme
but it offers loads of other possibilities like annotations and highlighting of the text.
Anything after \end{document}
will be completely ignored by the compiler and doesn't need any comment environment. It won't end up in the output file, as well.
-
2+1 an easy and effective way to keep "bulk" blocks together with the document without cluttering it. I use this technique frequently to keep for a while all those paragraphs or complete chapters I delete or have to rewrite.– DanielApr 8, 2017 at 21:27
-
I often place a second
\end{document}
earlier in the text to just typeset the part before it.– lblbApr 9, 2017 at 12:30
I've been using this simple verbatim solution for longer notes:
% Use `todos' as environment for large lists verbatim-printed. Use fancyvrb
\DefineVerbatimEnvironment{todos}
{Verbatim}
{fontsize=\footnotesize,formatcom=\color{blue}}
% Uncomment to remove the notes from PDF. Use the comment package
%\excludecomment{todos}
Example
\begin{todos}
- Proofread for minor typos
- Include missing references
- Enable all latex warnings
- Search Google Scholar for Bibtex entries
\end{todos}
Pro
- You can write down quick notes freely without caring about formatting, itemizing, etc.
Cons
- Not convenient for formatting actual text that might go into the manuscript: no automatic line breaking, etc.
- No list of notes generation (I never use this anyways)