3

I'm new to TeX and I'm a bit lost. Could someone tell me how this should be written (marked 'PROBLEM HERE' in the code)

Situation: When argument #2 is space (empty paragraph), I want to use next paragraph

\def\adjustParagraph#1\par{...some code here (which works ok)...}

\def\headline#1#2\par      % takes headline (#1) and the paragraph which follows (#2)
   {\myFont#1\par      % headline
   \if #2 {\adjustParagraph}   % if argument #2 is a space (empty paragraph) <= PROBLEM HERE
   \else{\adjustParagraph#2\par}   % argument #2 is text
   \fi}

\headline{This is headline}
Lorem ipsum dolor sit amet consectetuer ...

\headline{Another headline}

This time, argument 2 is that blank space above this line...
  • 1
    egreg's answer here is plain tex (some of the others assume latex) tex.stackexchange.com/questions/89365/… (by the way if you are new, using plain TeX is a slightly odd choice: most people use a format designed for document production such as latex or context) – David Carlisle Dec 13 '13 at 22:53
3

I wouldn't use delimited arguments. Moreover \headline conflicts with the output routine, so I used \Headline for your macro instead.

\def\adjustParagraph#1\par{...some code here (which works ok)...}

\def\Headline#1#2\par      % takes headline (#1) and the paragraph which follows (#2)
  {\myFont#1\par      % headline
   \expandafter\ifx\space#2
     \expandafter\adjustParagraph
   \else
     \adjustParagraph#2\par   % argument #2 is text
   \fi
}

\Headline{This is headline}
Lorem ipsum dolor sit amet consectetuer ...

\Headline{Another headline}

This time, argument 2 is that blank space above this line...

\bye

Two points to be noted:

  1. \expandafter\ifx\space#2 will detect if #2 starts with a space token (and the rest will be ignored in case it doesn't.

  2. \expandafter\adjustParagraph must be used in the “true” branch to get rid of \else.

  • It didn't work with (1.). However, without (1.) and with (2.) (\if #2 \expandafter\adjustParagraph...) works, so thanks a lot. – McLayn Dec 14 '13 at 1:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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