\newcount\secnum 
\newwrite\fileref \newread\filetest

\def\ifnextchar#1#2#3{\let\tznak=#1\def\bodyA{#2}\def\bodyB{#3}%
    \futurelet\znak\testuj}
\def\testuj{\ifx\znak\tznak\let\next=\bodyA\else\let\next=\bodyB\fi\next}
\def\softinput #1 {\let\next=\relax \openin\filetest=#1
  \ifeof\filetest
    \message{VAROV�N�: soubor #1 nenalezen, TeXujte je�t� jednou.}%
  \else \closein\filetest \def\next{\input #1 }\fi
  \next}  

\def\cite[#1]{\expandafter\ifx\csname l:#1\endcsname\relax
    ??\message{VAROV�N�: nez�m� label [#1]}%
    \else\csname l:#1\endcsname \fi}
\def\pgcite[#1]{\expandafter\ifx\csname p:#1\endcsname\relax
    ??\message{VAROV�N�: nez�m� p-label [#1]}%
    \else\csname p:#1\endcsname \fi}
\def\lab[#1]{\edef\act{\write\fileref
    {\noexpand\string\noexpand
     \labref[#1]{\cislo}{\noexpand\the\pageno}}}\act}
\def\labref[#1]#2#3{\expandafter\def\csname l:#1\endcsname{#2}
    \expandafter\def\csname p:#1\endcsname{#3}}

\softinput \jobname.ref
\immediate\openout\fileref=\jobname.ref

\def\sekce{\advance\secnum by1 \edef\cislo{\the\secnum}%
    \ifnextchar[{\labelsekce}{\def\delejlab{}\tisksekce}}
\def\labelsekce[#1] {\def\delejlab{\lab[#1]}\tisksekce}
\def\tisksekce #1\par{%
  \indent{\bf\llap{\the\secnum. }\bf#1}\delejlab\par\nobreak\medskip}
\def\obr#1:{\def\cislo{#1}Obr�zek #1:}

\input epsf

\hsize=6cm \vsize=5.5cm \raggedbottom

\def\bl{bla bla bla bla bla bla bla bal bla bla bla }
\def\bla{\bl\bl\bl\bl\bl\bl\bl\bl\bl}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\sekce �vod
%%%%%%%%%%%

\bl viz obr�zek~\cite[obr chrousta] 
na stran�~\pgcite[obr chrousta], \bla

\bla viz t� sekci~\cite[chrousti] na 
stran�~\pgcite[chrousti], \bl

\bla

\sekce[chrousti] O~nesmrtelnosti chroust�
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\bl

\bla

\medskip
\centerline{\epsfxsize=2cm \epsfbox{chroust.eps}}
\nobreak
\centerline{\obr AA: chroust\lab[obr chrousta]}
\medskip

\bla

\end
