33

Is there anyway by which I can comment out a word within a sentence?

Werner
  • 603,163
Reza
  • 433
  • Could you clarify what you mean by "comment[ing] out a word within a sentence"? Please provide us with an example. – Werner Nov 05 '15 at 06:03
  • In my case, I wanted to cite a few papers, but I was't sure if one of them was the correct reference. I wanted to leave a note for myself to check that specific reference later. – Reza Nov 05 '15 at 07:33
  • 3
    I'd suggest looking into using the todo package. Your goal seems different than the question though... – Werner Nov 05 '15 at 11:11

4 Answers4

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
    You could throw in a \ignorespaces – John Kormylo Jul 15 '16 at 22:35
  • 4
    Do 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
    Ja. Da. Oui. Si. (Is that 15 letters yet?) – John Kormylo Jul 16 '16 at 03:41
  • Perhaps even better than \ignorespaces is \newcommand{\cmmnt}[1]{\@bsphack\@esphack}. The \ignorespaces approach fails with Lorem\cmmnt{ipsum} dolor, while \@bsphack\@esphack don'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 \cite and 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.

See https://tex.stackexchange.com/a/178806/212801

Source

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