[texhax] Why isn't \immediate\write outputting stuff from page 1?

Suresh Govindachar sgovindachar at yahoo.com
Mon Nov 18 02:44:32 CET 2013



   % In the following, why doesn't the toc.tex file contain
   % the line for the sections on the very first page?

   % In case the email messes up long lines, have attached
   % file test_toc.tex

   \newwrite\contents
   \openout\contents=toc.tex
   \newcount\sectioncount
   \sectioncount=0
   \def\mysection#1{\advance\sectioncount by 1%
   \vskip3mm%
   {\noindent\bf \the\sectioncount. #1}\par\noindent%
 
\immediate\write\contents{\string\line\string{\string\item\string{\the\sectioncount.\string} 
\string#1
   \string\dotfill{} \the\pageno\string} }
   }

   \hsize=6in
   \hoffset=0.25in

   \vskip5mm
   \input toc
   \vskip5mm
   \mysection{First On the first page}
   Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
   Aenean commodo ligula eget dolor. Aenean massa.

   \mysection{Second On the first page}
   Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
   Aenean commodo ligula eget dolor. Aenean massa.

   \vfil\eject
   \mysection{First On the second page}
   Cum sociis natoque penatibus et magnis dis parturient montes, 
nascetur ridiculus mus.

   \mysection{Second On the second page}
   Cum sociis natoque penatibus et magnis dis parturient montes, 
nascetur ridiculus mus.


   Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem.

   \bye

-------------- next part --------------

  % In the following, why doesn't the toc.tex file contain
  % the line for the sections on the very first page?

  \newwrite\contents
  \openout\contents=toc.tex
  \newcount\sectioncount
  \sectioncount=0
  \def\mysection#1{\advance\sectioncount by 1%
  \vskip3mm%
  {\noindent\bf \the\sectioncount. #1}\par\noindent%
  \immediate\write\contents{\string\line\string{\string\item\string{\the\sectioncount.\string} \string#1
  \string\dotfill{} \the\pageno\string} }
  }
  
  \hsize=6in
  \hoffset=0.25in
  
  \vskip5mm
  \input toc
  \vskip5mm
  \mysection{First On the first page}
  Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
  Aenean commodo ligula eget dolor. Aenean massa.
  
  \mysection{Second On the first page}
  Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
  Aenean commodo ligula eget dolor. Aenean massa.
  
  \vfil\eject
  \mysection{First On the second page}
  Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.

  \mysection{Second On the second page}
  Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.
  
  
  Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem.
  
  \bye
  


More information about the texhax mailing list