4

I am confused whether the below macro is for section or what? If yes can anybody help me to explain this piece of code

 \def\Section #1 \par
    {
    \bigbreak\vskip\parskip
    \need 1.5 in
    \global\advance\secno by 1
    \subno=0\subsubno=0
    \noindent
    {\SectionTitleFont \the\secno.\hskip 1em #1}
    \par
    }
7
  • 2
    It certainly looks like a it's supposed to make a new section, but it's not plain TeX or standard Latex. For example I don't think that either defines a \need command. Can you give some more context? – Thruston Jan 4 '15 at 13:19
  • 2
    What's the source of this macro? A package? If so, which one? – Mico Jan 4 '15 at 13:20
  • 3
    @user69898 Without so more more context we can't explain this macro, at least not with confidence. As already noted, it's not a standard plain TeX macro and it's not one from LaTeX or ConTeXt either. So we need some clue as to where you found it, at least. Certainly the name indicates a sectioning command. – Joseph Wright Jan 4 '15 at 13:29
  • 4
    Ah: I found socs.acadiau.ca/~jdiamond/tex-reference-material/tex-intro.pdf. It says there 'examine this example only if you enjoy programming and plan to use (plain) TeX'. It looks to be a bit of a hodge-podge introduction. Notably, this code snippet seems to be a demo with no further examination or source: as such I would not choose to use it to learn from. – Joseph Wright Jan 4 '15 at 13:38
  • 5
    The macro includes two potential problems. First one is at the beginning of the title text. When we write \Subsection Plus something <empty line> then the \hskip 1em is followed by Plus (i.e. the reserved word in \hskip parameter). The error "Missing number treated as zero" occurs. The second problem is at the end of the title parameter. After \Section An introduction to \TeX <empty line> there is no space at the end of the title and the text cannot be separated by <space>\par. – wipet Jan 4 '15 at 17:55
11

The macro \Section has an argument delimited by a space and a \par token, so it's supposed to be called like

\Section Whatever title I want

The text of the section following the title.

Note the blank line after the end of the section title.

The macro will store Whatever title I want (the actual title, of course) discarding the space produced by the end of line as #1.

Now the macro executes

  1. \bigbreak, which issues \par and then examines the last vertical space; if this space is less than \bigskipamount, TeX removes it and inserts, in its place, a penalty of value -200 and \bigskip, making this quite a good point for breaking a page;

  2. \need 1.5in that's not defined in Plain TeX, but seems to be aimed at looking into the current values of \pagegoal and \pagetotal; if the difference between the former and the latter is less than 1.5in, a \vfill\eject command is probably issued; possible definition

    \def\need{\afterassignment\checkneed\dimen0 }
    \def\checkneed{\advance\dimen0 by \pagetotal
      \ifdim\dimen0>\pagegoal \vfill\eject\fi}
    

    or just \eject if pages are to be filled up.

  3. The counters \secno is advanced by 1; this is supposed to contain the section number; the counters \subno and \subsubno, that are supposed to contain the subsection and subsubsection numbers are set to 0.

  4. \noindent starts a paragraph; the the title is set using \SectionTitleFont (a font choice command to be defined) preceded by the section number and a quad of space; grouping ensures the font setting does not propagate.

  5. \par makes a new paragraph.

Note that 1.5in is supposed to ensure that the section title, the interline skip and at least two lines of the subsequent paragraph fit.


As wipet correctly remarks in a comment, this macro has a few defects.

  • If the title is Good programming in \TeX, an unscrutable error would be issued

    Runaway argument?
    Good programming in \TeX 
    ! Paragraph ended before \Section was complete.
    <to be read again> 
                       \par 
    

    There is no need to have <space>\par as the delimiter, because the trailing space would be removed anyway by the final \par in the replacement text, provided we remove the space in the replacement text.

  • An even more unscrutable error would be issued by a title such as Plusvalence:

    ! Missing number, treated as zero.
    <to be read again> 
                       v
    <argument> Plusv
                    alence
    

    because TeX would see \hskip 1em Plusvalence and interpret Plus as a keyword.

Fixed code:

\def\Section #1\par
  {%
   \bigbreak\vskip\parskip
   \need 1.5 in
   \global\advance\secno by 1
   \subno=0\subsubno=0
   \noindent
   {\SectionTitleFont \the\secno.\hskip 1em\relax #1}\par
  }
1
  • 2
    +1 for the forensic analysis of code remains. There is no a badge for that? :) – Fran Jan 4 '15 at 18:04

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.