1

I've defined a Comment macro in the MWE below. I want it to start a new line after the comment, without an indent. If I were to remove the blank line after the macro, there would be no indent, but I don't always remember to do that. Is there a way to force a once-off no indent that will override the effect of the blank line? Thanks for any recommendation. Note that I dont want to force noindent globally (that's trivial), just in this particular instance.

\documentclass{amsart}
\usepackage{lipsum}
\parindent=10 pt
\def\CommentCR#1{{\sf #1\leavevmode\newline\noindent}}
\begin{document}
\lipsum[1]
\CommentCR{I want no indentation even if I leave a space after this line.}

\lipsum[1]
\end{document}

3 Answers 3

1

Off the cuff, but I suppose there are more elegant solutions:

\documentclass{amsart}
\usepackage{lipsum}
\parindent=10pt
\parskip=20pt

\makeatletter
\newcommand\CommentCR[1]{%
  % If you wish the comment not to form a paragraph on its own,
  % but to be part of the paragraph which LaTeX is about to create,
  % then uncomment "\ifhmode\else" and "\fi".
  %\ifhmode\else
    \par
    % If you don't wish vertical \parskip-gap to the next line,
    % uncomment "\vskip-\parskip".
    %\vskip-\parskip
    \noindent
  %\fi
  {\sffamily#1}\par
  % If you don't wish vertical \parskip-gap to the next line,
  % uncomment "\vskip-\parskip".
  %\vskip-\parskip
  \noindent
  \@ifnextchar\par{\@afterindentfalse\@afterheading\vskip-\parskip}{}%
}%
\makeatother

\begin{document}

\lipsum[1]
\CommentCR{I want no indentation even if I leave a space after this line.} 

\lipsum[1]

\lipsum[1]

\newpage

\lipsum[1]
\CommentCR{I want no indentation even if I leave a space after this line.}
\par\lipsum[1]

\lipsum[1]

\newpage

\lipsum[1]
\CommentCR{I want no indentation even if I leave a space after this line.}
\lipsum[1]

\lipsum[1]

\end{document}
3
  • Thanks @UlrichDiez and #egreg, both gave me exactly what I wanted (after uncommenting out the vskips as proposed.) I selected the second answer because it seems a little easier to follow.
    – Leo Simon
    May 17, 2020 at 17:43
  • @LeoSimon Be aware that egreg's solution is much better than mine if you do not necessarily want the line to be broken after the comment. Mine has the side-effect of actually starting a new paragraph in any case (and hiding that fact by doing negative vertical skips for undoing the vertical \parskip-glue) which implies the carrying out of \everypar in places where you probably don't want it. Also egreg's solution avoids \@ifnextchar which might be redefined by some package. May 18, 2020 at 6:31
  • so far yours works fine, will upgrade to egreg's if I need to. Thanks!
    – Leo Simon
    May 19, 2020 at 3:26
1

Your specification is quite incomplete. Here's a set of macros that check what comes along; if it is \par or <space>\par, then \par\noindent is issued. Otherwise nothing gets done.

It is assumed that you don't play nasty tricks and your input is plain as you showed.

Please, note that \sf has been deprecated for more than 25 years.

\documentclass{amsart}
\usepackage{lipsum}

\setlength{\parindent}{10pt}

\makeatletter
\newcommand\CommentCR[1]{%
  {\sffamily#1}\suppress@start
}
\newcommand\suppress@start{%
  \futurelet\CR@a\suppress@parindent
}
\newcommand\suppress@parindent{%
  \ifx\CR@a\par
    \let\CR@b\suppress@par
  \else
    \let\CR@b\suppress@space
  \fi
  \CR@b
}
\newcommand{\suppress@par}[1]{\par\noindent}
\newcommand{\suppress@space}{%
  \ifx\CR@a\@sptoken
    \long\def\CR@c##1{\space\suppress@start##1}%
  \else
    \let\CR@c\relax
  \fi
  \CR@c
}
\makeatother

\begin{document}

\lipsum[1][1-3]
\CommentCR{I want no indentation even if I leave a space after this line.}%

\lipsum[1][1-3]

\lipsum[1][1-3]
\CommentCR{I want no indentation even if I leave a space after this line.}

\lipsum[1][1-3]

\lipsum[1][1-3]
\CommentCR{I want no indentation even if I leave a space after this line.}
\lipsum[1][1-3]

\lipsum[1][1-3]
\CommentCR{I want no indentation even if I leave a space after this line.}xyz
\lipsum[1][1-3]

\end{document}

enter image description here

0

Maybe what you want is this

\documentclass{amsart}
\usepackage{lipsum}
\parindent=10 pt
\def\CommentCR#1{{\sf #1\leavevmode\\\mbox{}\\}}
\begin{document}
\lipsum[1]
\CommentCR{I want no indentation even if I leave a space after this line.}
\lipsum[1]
\end{document}
1
  • this wouldn't work at all if in the case asked for where there us a blank line after teh comment macro May 16, 2020 at 22:23

You must log in to answer this question.

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