Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have checked no indent in the first paragraph in a section? but I think my question warrants a new thread, because my question is about Plain TeX.

I am using Plain TeX. I would like to write a \mysection macro that indents the paragraph following it, regardless of the whitespace that occurs between the invocation of \mysection and the paragraph.

As you can see below, \finickysection works but only if I am sure to put the % comments between its use and the paragraph. I would like \mysection to work with the invocation as written.

My MWE is:

\def\mysection#1{\vskip\baselineskip\noindent #1\vskip\baselineskip\everypar={\noindent\everypar={}}}
\def\finickysection#1{ \vskip\baselineskip \noindent #1 \vskip\baselineskip%
\noindent}


\finickysection{Hello}%
%
This is my first paragraph. Lorem ipsum dolor sit amet, consectetur adipisicing
elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim
ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat.

Duis aute irure dolor in reprehenderit in voluptate velit
esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat
non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

\mysection{Hi}


This is my third paragraph. It should not be indented. Lorem ipsum dolor sit
amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut
labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud
exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis
aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt
in culpa qui officia deserunt mollit anim id est laborum.

This is my fourth paragraph. Lorem ipsum dolor sit amet, consectetur adipisicing
elit, sed do eiusmod tempor.

\bye
share|improve this question

1 Answer 1

up vote 13 down vote accepted

I'd borrow from LaTeX for this:

\def\mysection#1{%
  \vskip\baselineskip
  \noindent #1\par
  \nobreak % IMPORTANT
  \vskip\baselineskip
  \everypar={{\setbox0\lastbox}\everypar={}}}

The token list in \everypar is inserted after the implied \indent and \setbox0\lastbox removes the indentation box: the indent is realized as an empty hbox \parindent wide.

Note that \par tokens generated by empty lines will not trigger the insertion of \everypar, which is used only after a paragraph has started.

share|improve this answer
    
Beautiful! Thank you! I was so happy when I discovered \everypar, but then putting \noindent didn't work and I was sunk. –  EfForEffort Dec 6 '12 at 17:10
    
@D.Bueno TeXbook p. 222, last but one dangerous paragraph. :) –  egreg Dec 6 '12 at 17:13
    
thanks! Super dangerous paragraph since it has 2 windyroads. –  EfForEffort Dec 6 '12 at 18:05
1  
@D.Bueno I've fixed the position of \nobreak. It's surely needed in your macro. You may also want to say \goodbreak instead of \vskip\baselineskip before the section title –  egreg Dec 6 '12 at 18:09
    
What was wrong about its position and what did you fix? I'm trying to learn.... =] Also, using \goodbreak instead of \vskip\baselineskip bunches the paragraph after my section up with the heading itself. Is that what you intended? –  EfForEffort Dec 6 '12 at 21:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.