Is there anyway by which I can comment out a word within a sentence?
Asked
Active
Viewed 4.5k times
4 Answers
36
You can do this:
\newcommand{\cmmnt}[1]{}
...
\begin{document}
Hello \cmmnt{commented text} bye.
\end{document}
A comment suggests eliminating undesired spaces around the comment:
\newcommand{\cmmnt}[1]{\ignorespaces}
...
(This should be part of some "comment" package, if it is not already.)
alfC
- 14,350
-
2
-
4Do you mean use
\newcommand{\cmmnt}[1]{\ignorespaces}to avoid creating spurious spaces in the text (coming from surrounding the command with actual spaces)? – alfC Jul 15 '16 at 23:41 -
16
-
Perhaps even better than
\ignorespacesis\newcommand{\cmmnt}[1]{\@bsphack\@esphack}. The\ignorespacesapproach fails withLorem\cmmnt{ipsum} dolor, while\@bsphack\@esphackdon't (these two macros are used by the LaTeX kernel for commands which don't produce typeset output, like\label. See: https://tex.stackexchange.com/a/201821/134574). – Phelype Oleinik Mar 18 '19 at 20:17 -
\newcommand{\cmmnt}[1]{\makebox[0cm]{}}is the best way out for me. – Rubem Pacelli Aug 31 '23 at 22:18 -
@RubemPacelli, do you know what would be the difference with using
\ignorespaces? – alfC Sep 01 '23 at 02:19 -
1@alfC If you use
\ignorespaces, in some cases (e.g., when you put it between a\citeand a period), you still get a white space. – Rubem Pacelli Sep 03 '23 at 15:24
20
This is probably the easiest way.
\documentclass{article}
\begin{document}
I like bacon, sausage,
% pork chops,
and ham.
% Note to self... try pork chops
\end{document}
James
- 4,587
- 1
- 12
- 27
3
I like the other solutions, but sometimes I wish that my comments would also appear in the output file. I tend to forget important comments that are buried in my source code.
I include
\usepackage[colorinlistoftodos]{todonotes}
in the preamble and can then add in-line comments with
\todo{This is a comment that will appear in the margin}
The result is beautiful "sticky note" comments which appear in the margins of my pdf. I can them remove them when I'm done with my draft.
abrac
- 198
- 7
2
You can put a phantom in a vbox without any height.
\vbox to0pt{\phantom{Some wise words.}}
The problem with this is, that the comment gets parsed and typeset and therefor must be valid TeX code.
ceving
- 761
todopackage. Your goal seems different than the question though... – Werner Nov 05 '15 at 11:11