% povetron.tex - Povetron magazine typesetting macros
% Miroslav Broz, miroslav.broz@email.cz
% Aug 24th 2001

%% input

\input epsf

\newread\softread
\def\softinput#1{
  \openin\softread #1
  \ifeof\softread
  \else\closein\softread \input #1\fi
}

%% mathops

\def\arctg{\mathop{\rm arctg}\nolimits}
\def\promile{{\rm\char141}}

%% other macros

\def\put#1#2#3{\raise#2\rlap{\kern#1 #3}\ignorespaces}
\def\,{\ifmmode\mskip\thinmuskip\else\leavevmode\thinspace\fi}

%% page mirror

\nopagenumbers
\hsize=12.4cm
\vsize=17.2cm
\hoffset-13mm
\voffset-1cm

\clubpenalty=10000
\widowpenalty=10000

\ifx\pdfimage\udefined
\else
  \pdfimageresolution=300
  \pdfpagewidth=148.5mm
  \pdfpageheight=210mm
\fi

%% hyphenations

\hyphenation{da-le-ko-hled}

%% fonts definitions

\font\titlefnt=ptmr8z at 48pt
\font\subtitlefnt=csr12 scaled 1300
\font\specialfnt=csr12 at 36pt
\font\bigfnt=csr12 at 28pt
\font\articlefnt=csbx12
\font\paragraphfnt=csbx10
\font\sectionfnt=csbx10
\font\noticefnt=csr9
\font\noticeitfnt=csti9
\font\smallfnt=csr8
\font\scfnt=cscsc10
\font\smallitfnt=csti8
\font\smallttfnt=cstt8
\font\smallbffnt=csbx8
\font\smallscfnt=cscsc10 at 8pt	% cscsc8 is not Type1

\font\rmlg=csr8 \font\rms=csr6 \font\rmss=csr5
\font\mthlg=cmmi8 \font\mths=cmmi6 \font\mthss=cmmi5
\font\symlg=cmsy8 \font\syms=cmsy6 \font\symss=cmsy5

\let\em=\it
\let\web=\tt
\let\sc=\scfnt

\def\smallfonts{%
\textfont0=\rmlg \scriptfont0=\rms \scriptscriptfont1=\rmss%
\textfont1=\mthlg \scriptfont1=\mths \scriptscriptfont1=\mthss%
\textfont2=\symlg \scriptfont2=\syms \scriptscriptfont2=\symss%
\global\def\rm{\fam0\rmlg}%
\let\it=\smallitfnt%
\let\tt=\smallttfnt%
\let\bf=\smallbffnt%
\let\sc=\smallscfnt%
\let\em=\it
\let\web=\tt
\rm%
}

\newdimen\smallbaselineskip
\smallbaselineskip=10pt

%% table of contents with PDF hyperrefs

\catcode`*=11
\newwrite\toc
\def\tableofcontents{%
  \pagenumbers	% this page already numbered
  \bigskip
  \noindent\line{{\articlefnt Obsah}\hfil strana}
  \medskip
  \softinput{\jobname.toc} 
  \immediate\openout\toc \jobname.toc
}
\def\addcontentline#1#2#3{
  \write\toc {\string\contentline{\noexpand #1}{\noexpand #2}{#3}}
}

\newcount\contentlinecnt
\contentlinecnt=0
\ifx\pdfimage\undefined\else\input pdfcolor\fi

\def\contentline#1#2#3{
%  \noindent\hbox to 2em{\hfil #3}\hskip 1em {\bf #1} --- #2\par
  \noindent \ifx:#2:\else #2:\ \fi {\em%
  \ifx\pdfimage\undefined%
    #1%
  \else%
    \global\advance \contentlinecnt by 1%
    \pdfannotlink attr {/Border [0 0 0]} goto num \the\contentlinecnt%
    \setcolor\cmykViolet #1\setcolor\cmykBlack\pdfendlink%
  \fi%
  } \leaders\hbox to.6em{\hfil .\hfil}\hfill\hbox to1em{\hfill#3}\par
  \smallskip
}

%% references

\newcount\numeq
\newcount\captionmode
\newcount\tabcaptionmode
\newcount\footnotemode
\newcount\bibitemmode
\let\bibcaption=\relax
\newcount\secnum
\newcount\subsecnum
\numeq=0\captionmode=0\tabcaptionmode=0\footnotemode=0

\def\refdef#1#2{%
  \expandafter\def\csname label:#1\endcsname{#2}%
}

\softinput{\jobname.ref}
\newwrite\refs
\immediate\openout\refs \jobname.ref

\def\label#1{%
  \ifmmode%
    \global\advance\numeq by 1%
    \eqno{(\the\numeq)}%
    \immediate\write\refs{\string\refdef{#1}{(\the\numeq)}}%
  \else\ifinner%
    \global\advance\numeq by 1%
    (\the\numeq)%
    \immediate\write\refs{\string\refdef{#1}{(\the\numeq)}}%
  \else\ifnum\captionmode = 1%
    \immediate\write\refs{\string\refdef{#1}{\the\figurenum}}%
  \else\ifnum\tabcaptionmode = 1%
    \immediate\write\refs{\string\refdef{#1}{\the\tablenum}}%
  \else\ifnum\footnotemode = 1%
    \immediate\write\refs{\string\refdef{#1}{$^{\the\footnotecnt}$}}%
  \else\ifnum\bibitemmode = 1%
    \immediate\write\refs{\string\refdef{#1}{\bibitemref{\bibcaption}}}%
  \else\ifnum\subsecnum = 0%
    \immediate\write\refs{\string\refdef{#1}{\the\secnum}}%
  \else%
    \immediate\write\refs{\string\refdef{#1}{\the\secnum.\the\subsecnum}}%
  \fi\fi\fi\fi\fi\fi\fi%
}

\def\ref#1{%
  \expandafter\ifx\csname label:#1\endcsname\relax%
    \message{Warning: label #1 undefined.}%
    ??%
  \else%
    \csname label:#1\endcsname%
  \fi%
}

%% bibliography

\newcount\bibnum
\def\bibliography{\bibnum=0\bigskip}
\def\endbibliography{\smallskip}
\def\bibitem#1#2#3{%
  \advance\bibnum by 1%
  \bibitemnum{\the\bibnum}{#1}{#2}{#3}
}
\def\bibitemref#1{[#1]}
\let\bibref=\ref
\def\bibdot{.}
\def\bibitemnum#1#2#3#4{%
  \bibitemmode=1%
  \gdef\bibcaption{#1}%
  \noindent\hangindent 2cm\hangafter 1%
  \hbox to 18pt{\hfil \bibitemref{#1}}%
  \kern 4pt #2%
  \if:#2:\else\if:#3:, \else:\kern 4pt \fi\fi%
  \if:#3:\else{\it #3\bibdot\/} \fi%
  #4 \par\vskip-\parskip%
  \bibitemmode=0%
}
\def\urlref#1#2{\noindent\catcode`\~=12\relax{\web #1} | #2\par\vskip-\parskip\catcode`\~=\active}
\def\etal{aj.}
\def\ie{i.$\!$ e.}
\def\editor{({\it editor\/})}
\def\vol#1{{\bf #1}}

\def\bibline#1{\noindent\line{\hfil #1}\par\vskip-\parskip}

%% figures

\newdimen\tmpdim
\def\pdfwd{}\def\pdfht{}
\def\imgxsize#1{\epsfxsize=#1\gdef\pdfwd{ width #1 }}
\def\imgysize#1{\epsfysize=#1\gdef\pdfht{ height #1 }}
\let\figureamount=\bigskipamount

\def\img#1#2{%
  \ifx\pdfimage\undefined%
    \setbox0=\hbox{\epsfbox{#1}}%
%    \message{width \the\wd0}%
%    \message{height \the\ht0}%
    \box0%
%    \epsfbox{#1}%
  \else%
    \setbox0=\hbox{\pdfimage\pdfwd\pdfht{#2}}%
    \box0%
%    \pdfimage\pdfwd\pdfht{#2}%
  \fi%
  \gdef\pdfwd{}\gdef\pdfht{}%
}

\newcount\figurenum
\let\figurecaption=\relax
\def\figurecap#1{\global\advance\figurenum by 1\gdef\figurecaption{#1}}

\def\placecaption{%
  \captionmode=1%
  \baselineskip=\smallbaselineskip%
  \noindent{\smallfonts Obr.~{\the\figurenum} --- \figurecaption}%
  \global\let\figurecaption=\relax%
  \smallskip%
  \baselineskip=\normalbaselineskip%
  \captionmode=0%
}

\def\figure#1{%
  \captionmode=1%
  \begingroup%
  \bigskip%
  \centerline{#1}%
  \ifx\figurecaption\relax%
  \else%
    \medskip%
    \leftskip=0pt\rightskip=0pt\parindent=0pt%
    \baselineskip=\smallbaselineskip%
    {\smallfonts Obr.~{\the\figurenum} --- \figurecaption}%
    \global\let\figurecaption=\relax%
  \fi%
  \bigskip%
  \endgroup%
  \captionmode=0%
}

\newdimen\framesep
\framesep=10pt
\def\frame#1{%
  \hbox{%
    \vrule%
    \vbox{%
      \hrule%
      \vskip\framesep%
      \hbox{%
        \kern\framesep%
        #1%
        \kern\framesep%
      }%
      \vskip\framesep%
      \hrule%
    }%
    \vrule%
  }%
}

\def\figureframe#1{%
  \bigskip%
  \centerline{%
    \frame{#1}%
  }%
  \bigskip%
}

\newbox\figparbox
\newdimen\figparwd
\newdimen\figparht
\def\figureleft#1#2{%
  \setbox\figparbox=\hbox{#1}%
  \figparwd=\wd\figparbox%
  \figparht=\ht\figparbox%
  \advance\figparwd by\framesep%
  \leavevmode\hangafter-#2\hangindent\figparwd%
  \advance\figparht by-10pt%
  \vadjust{\noindent\smash{\lower\figparht\hbox to 0pt{\box\figparbox\hss}}}%
  \ignorespaces%
}

\def\figureright#1#2{%
  \setbox\figparbox=\hbox{#1}%
  \figparwd=\wd\figparbox%
  \figparht=\ht\figparbox%
  \advance\figparwd by\framesep
  \leavevmode\hangafter-#2\hangindent-\figparwd%
  \advance\figparht by-10pt%
  \advance\figparwd by-\hsize%
  \advance\figparwd by-\framesep%
  \vadjust{\noindent\smash{\kern-\figparwd\lower\figparht\hbox to 0pt{\box\figparbox\hss}}}%
  \ignorespaces%
}

\newbox\capbx
\newdimen\capsep
\capsep=.3cm
\def\figurecaprt#1{%
  \captionmode=1%
  \begingroup%
  \bigskip%
  \setbox\capbx\hbox{#1}%
  \noindent\copy\capbx\kern\capsep%
  \ifx\figurecaption\relax%
  \else%
    \hbox{\vbox to\ht\capbx{\advance\hsize by -\wd\capbx\advance\hsize by -\capsep%
      \leftskip=0pt\rightskip=0pt\parindent=0pt%
      \baselineskip=\smallbaselineskip%
      {\smallfonts Obr.~{\the\figurenum} --- \figurecaption}%
      \global\let\figurecaption=\relax%
      \vfill%
    }}%
  \fi%
  \bigskip%
  \endgroup%
  \captionmode=0%
}

%% tables

\newcount\tablenum
\let\tablecaption=\relax
\def\tablecap#1{\advance\tablenum by 1\gdef\tablecaption{#1}}
\def\table#1{%
  \tabcaptionmode=1%
  \begingroup%
  \bigskip%
  \centerline{%
    \hbox{%
      \vbox{%
%        \hsize=0.80\hsize%
        #1%
      }%
    }%
  }%
  \ifx\tablecaption\relax%
  \else%
    \medskip%
    \leftskip=0pt\rightskip=0pt\parindent=0pt%
    \baselineskip=\smallbaselineskip%
    {\smallfonts Tab.~{\the\tablenum} --- \tablecaption}%
    \global\let\tablecaption=\relax%
  \fi%
  \bigskip%
  \endgroup%
  \tabcaptionmode=0%
}

%% articles, sections, subsections, paragraphs

\catcode`*=11
\newdimen\articlewd

\def\addpdfdestoutline#1{%
  \ifx\pdfimage\undefined\else%
    \global\advance \articlecnt by 1%
    \pdfdest num \the\articlecnt fitbh%
    \pdfoutline goto num \the\articlecnt count 0 {#1}%
  \fi%
}
% \addcontentline with hyperref's (without \article)
\def\addcontentline*#1#2#3{%
  \addpdfdestoutline{#1}%
  \addcontentline{#1}{#2}{#3}%
}

\def\article*#1#2{
  \setbox0=\hbox{\articlefnt #1}
  \setbox1=\hbox{#2}
  \articlewd=\wd0
  \advance\articlewd by \wd1
  \bigskip
  \addpdfdestoutline{#1}	% after the skip due to pagebreak
  \ifdim\articlewd<\hsize
    \vbox{
      \line{\box0\hfil\box1}
      \smallskip
      \hrule
    }
  \else
    \vbox{
      \box0\smallskip\hfill\box1
      \smallskip
      \hrule
    }
  \fi
  \smallskip
  \gdef\authorname{#2}
}

\newcount\articlecnt
\articlecnt=0
\def\article#1#2{
  \article*{#1}{#2}
  \addcontentline{#1}{#2}{\the\pageno}
}

%\def\endarticle{\medskip\line{\hfill\authorname}}
\def\endarticle{}

\def\section#1{\smallskip\noindent{\sectionfnt #1}\smallskip}

\def\pardot{.}
\def\paragraph#1{\smallskip\noindent{\paragraphfnt #1\pardot}}

%% footnotes

\newcount\footnotecnt
\footnotecnt=0
\newdimen\footnotedim
\def\efootnote#1#2{%
  \footnotemode=1%
  \begingroup%
  \baselineskip=\smallbaselineskip%
  \setbox\strutbox=\hbox{\vrule height7.083pt depth2.917pt width0pt}%
  \footnote{#1}{{\smallfonts #2}}%
  \endgroup%
  \footnotemode=0%
}
\def\myfootnote#1{\global\advance\footnotecnt by 1\efootnote{$^{\the\footnotecnt}$}{#1}}

%% header, footer

\def\footer#1#2#3{
  \leavevmode
  \vfill
  \hrule
  \medskip
  \begingroup
  \smallfonts
  \baselineskip=\smallbaselineskip
  \centerline{Povìtroò \povetronno/\povetronyear; Hradec Králové, \povetronyear.}
  \centerline{Vydala: {\bf Astronomická spoleènost v~Hradci Králové} (#1 na #2.~setkání ASHK)}
  \centerline{vydání
    1.,
    #3 stran,
    náklad ???~ks;
    dvoumìsíèník,
    MK~ÈR~E~13366, ISSN~1213--659X}
  \centerline{Redakce: Miroslav Bro¾, Martin Lehký, Martin Navrátil a Miroslav Ouhrabka}
  \centerline{Adresa: ASHK, Národních muèedníkù 256, Hradec Králové 8, 500\,08;
    IÈO: 64810828}
  \centerline{e--mail: \mail{ashk@email.cz}, web: \url{http://www.astrohk.cz/ashk/}}
%  \centerline{Tisk: ??? Tiskárna Aldis, Hradec Králové; náklad ??? výtiskù}
  \endgroup
  \footline{\hfil}
  \eject
}

%% title and last pages

\newdimen\titlevoff
\titlevoff=-5mm

\def\title#1#2#3{
  \def\povetronyear{#2}
  \def\povetronno{#3}
  \begingroup
%  \advance \hsize by 1cm
%  \advance\hoffset by -5mm
  \advance\voffset by \titlevoff
  \advance\vsize by -\titlevoff
  \line{\titlefnt P\hfil O\hfil V\hfil Ì\hfil T\hfil R\hfil O\hfil Ò}
  \bigskip
  \line{\subtitlefnt Obèasník Astronomické spoleènosti v Hradci Králové}
  \vskip1pt
  \line{\subtitlefnt #2/#3\hfill roèník #1}
  \vskip1pt
  \hrule
  \bigskip
}

\def\titlespec#1#2#3#4{
  \begingroup
  \gdef\titlespecial{#4}
%  \advance \hsize by 1cm
%  \advance\hoffset by -5mm
  \advance\voffset by \titlevoff
  \advance\vsize by -\titlevoff
  \line{\titlefnt P\hfil O\hfil V\hfil Ì\hfil T\hfil R\hfil O\hfil Ò}
  \bigskip
  \line{\subtitlefnt Obèasník Astronomické spoleènosti v Hradci Králové}
  \vskip1pt
  \line{\subtitlefnt SPECIÁL #2/#3\hfill roèník #1}
  \vskip1pt
  \hrule
  \bigskip
  \vfill
  \centerline{\specialfnt\titlespecial}
}

\def\titlefigure#1{\vfill\centerline{#1}}

\def\pagenumbers{%
  \footline{%
    \ifodd\pageno%
      {\hfil {\smallfonts {\sc Povìtroò} \povetronno/\povetronyear}\qquad {\tenbf\folio}}%
    \else%
      {{\tenbf\folio}\qquad {\smallfonts {\sc Povìtroò} \povetronno/\povetronyear}\hfil}%
    \fi%
  }%
}

\def\endtitle{
  \vfill
  \eject
  \endgroup
%  \pageno=1	%% even page left!
%  \pageno=2
%  \pagenumbers
}

\def\lastpage{
  \vfill\eject
  \nopagenumbers
}

%% abbreviations

\def\poznred#1{ (#1 --- pozn.$\!$ red.)}
\def\poznprekl#1{ (#1 --- pozn.$\!$ pøekl.)}

\def\notice#1{%
  \bigskip%
  {\noindent{\noticeitfnt Poznámka:} {\noticefnt #1}}%
}

\def\subfig#1{(#1)}
\def\vlevo{\subfig{a}}
\def\vpravo{\subfig{b}}

\def\pokracovani{\smallskip\line{\hfill{\scfnt Pokraèování}}}
\def\dokonceni{\smallskip\line{{\scfnt Dokonèení}\hfil}}
\def\dokonceniz#1#2{\smallskip\line{{\scfnt Dokonèení} z èísla #1/#2\hfil}}

\def\authors#1{%
  \begingroup%
  \smallskip%
  \baselineskip=\smallbaselineskip%
  {\smallfonts #1}%
  \smallskip%
  \endgroup%
}

\def\abstract#1{%
  \noindent{\scfnt Abstrakt:} #1%
  \medskip%
}

\def\introduction{\noindent {\scfnt Slovo úvodem.}\ }
\def\sign#1{\medskip\line{\hfil #1}}

\chardef\backsl=`\\
\chardef\tlde=`\~
\chardef\undrsc=`\_
\def\file#1{{\tt #1}}

% make urls and e-mails active in PDF (use \noexpand ~)

\def\urltxt#1#2{%
  \ifx\pdfimage\undefined%
    #1%
  \else%
    \pdfannotlink attr {/Border [0 0 0]} user{/Subtype /Link /A << /Type /Action /S /URI /URI (#2) >>}%
    \setcolor\cmykViolet #1\setcolor\cmykBlack\pdfendlink%
  \fi%
}

\def\url#1{\urltxt{{\web #1}}{#1}}
\def\mail#1{\urltxt{{\web #1}}{mailto:#1}}

\def\povrefurl#1#2#3#4{%
  \ifx\pdfimage\undefined%
     #1%
  \else%
    \pdfannotlink attr {/Border [0 0 0]} goto file{povetron-#2-#3.pdf} page #4 {/Fit}%
    \setcolor\cmykViolet #1\setcolor\cmykBlack\pdfendlink%
  \fi%
}

%% \end of povetron.tex

