<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">%% + ----- + ----- + ----- + ----- + ----- + ----- + ----- + ----- + ----- +
%% TP-PDF:  PDF generic macros for plain TeX
%% Author:  Tomasz Przechlewski &lt;ekotp@univ.gda.pl&gt;.
%% Date:    25.03.1997. *** version 0.6 *** postscript/distiller support ***
%% Changes: 16.03.2000. *** version 0.7 *** support for pdftex added ***
%%          02.12.2002. *** version 0.8 *** \PDFdestination fix ***
%%
%% This macros are described in detail in the article ,,Publikacje
%% elektroniczne: {\TeX} i PDF'' (GUST bulletin, number 8, 1997).
%%
%% The macros are based on the code from Sebastian Rahtz
%% and Yannis Halarambous |hyperref| package.
%%
%% Macros for sorting, inserting and `sanitizing' bookmarks
%% are prepared by Bogus{\l}aw Jackowski.
%%
%% + ----- + ----- + ----- + ----- + ----- + ----- + ----- + ----- + ----- +
%% WARNING: This file contains characters of codes &gt; 127, namely,
%% the Polish diacritical characters using ISO-8859-2 character set.
%% + ----- + ----- + ----- + ----- + ----- + ----- + ----- + ----- + ----- +
%%
%% User-defined commands:
%% + ---- + ------ + ----
%%
%% HYPERLINKS
%% ----------
%* \ref{&lt;label&gt;} -- cross-reference (link) to some place in the document
%%  associated with |label|. This command performs the following action:
%%  1. the appriopriate number of the referenced element (ie. table)
%%  is produced; 2. A rectangular area is defined (clicking on that area
%%  with mouse cause a jump to the referenced region of the document).
%%
%* \label{&lt;label&gt;} -- defines some place in a document (chapter/section
%%  heading, table title, quation etc) associated with &lt;label&gt;.
%%
%* \PDFdestination{&lt;destination&gt;} -- defines PDF destination page number,
%%  location on the page and a fit type (ie. which part of the page should
%%  be displayed). Usually &lt;destination&gt; is a label created automatically
%%  by TeX (see example at the end of this file).  The current value of
%%  |\PDFCurrentView| macro defines location and a fit type.
%%
%* \PDFview{&lt;view&gt;} -- set |\PDFCurrentView| to &lt;view&gt;. There are two
%%  &lt;view&gt; types defined: \FitHPDFView and \XYZPDFView (default).
%%  For more information see ``pdf Mark Reference Manual'', p.~23--24).
%%
%% BOOKMARKS
%% ---------
%* \writetorep{&lt;destination&gt;}{&lt;bookmark&gt;} -- writes text of the &lt;bookmark&gt;
%%  associated with &lt;destination&gt; to auxiliary file. Moreover the
%%  following declaration can be put before |\PDFbegin|:
%%
%*     \NoBookmarks -- suppress generation of bookmarks,
%*     \NoPLSanitize -- suppress ``sanitization'' of bookmarks.
%%
%%  As Acrobat Reader/Exchange displays bookmarks with built in font
%%  which lacks some Polish diacritic characters, they (the bookmarks)
%%  looks quite silly. To avoid this the `sanitization' of bookmarks
%%  is performed. Sanitization means conversion of Polish diacritics
%%  to the corresponding Latin glyphs.
%%
%%  ``Sanitization'' is encoding dependent process. As there are
%%  myriads of ``standards'' of encoding of Polish diacritics in use,
%%  the user have to adapt this code to his/her preferred encoding.
%%  The tp-pdf.tex package ``as it is'' uses ISO-8859-2 character set.
%%
%%  If one uses for example Mazovia one should change all the definitions
%%  of polish diacritics i.e from |\polisha| to |\polishZ| (compare the
%%  relevant fragment of the code below). If one knows AWK or Perl it is
%%  quite trivial task. For AWK users the recommended is using slim package
%%  available from ftp://ftp.GUST.org.pl/TeX/GUST/contrib/GUSTPROG/slim.zip
%%
%* \Xsanitize -- Should prohibit writing expandable tokens to |rep| file.
%%  The point is that the contents of |rep| file goes via specials,
%%  `as it is', to dvi file and then to PDF file.
%%  In order to achieve this the user SHOULD MODIFY \Xsanitize,
%%  according to his/her needs. The default value is: change |~| to space,
%%  and |\TeX|/|\LaTeX| to TeX/LaTeX (to get rid of |\|).
%%
%* \UseOutlines -- display bookmarks when opening PDF file.
%%
%% MISCELLANEA
%% -----------
%* \papersize{&lt;papersize&gt;} -- declare paper format (ie. A4, B5 etc).
%%  The following formats are defined: \aivpapersize (A4, default),
%%  \avpapersize (A5), \bvpapersize (B5), \aivlandscapepapersize
%%  (A4 landscape). Other formats may be defind with \papersize
%%  command called with appriopriate page width and height, ie:
%%  \papersize{176mm,250mm}.
%%
%* \DocInitZoom&lt;number&gt; -- Initial zoom when opening PDF file (default 1).
%%
%* \PDFbegin -- initialization, have to be put at the top of the document.
%%  Actually at present it only sets paper size, and document general
%%  information (author, title etc., see description of DOCINFO pdfmark
%%  for more information--``pdf Mark Reference Manual'', p.~18--19)
%%  but the user can extend it to do some other things.
%%  The following information can be provided by the user:
%%
%%     \PDFdoctitle{&lt;title&gt;} -- the document's author,
%%     \PDFdocauthor{&lt;author&gt;} -- the document's title,
%%     \PDFdocsubject{&lt;subject&gt;}  -- the document's subject,
%%     \PDFdockeywords{&lt;keywords&gt;} -- the document's keywords,
%%     \PDFdoccreator{&lt;creator&gt;} -- the document's creator (default: TeX).
%%
%%  To extend this list see description of DOCINFO pdfmark
%%  ``pdf Mark Reference Manual'', p.~18--19.
%%
%* \PDFbegin -- have to be put at the end of the document.
%%
%* \PDFnote{&lt;wd&gt;}{&lt;ht&gt;}{&lt;title&gt;}{&lt;text&gt;}{&lt;open&gt;} -- put PDF annotation.
%%  The annotation window width and height is &lt;wd&gt; and &lt;ht&gt; respectively;
%%  &lt;title&gt; is window title; text is annotation text;  &lt;open&gt; is a number,
%%  if positive annotation is open, otherwise is closed.
%%
%%  Note that, there is not full control of the appearance of the
%%  annotations, as the text is set with some screen font, unknown to TeX.
%%  Consequently, &lt;wd&gt; &lt;ht&gt; should be choosen by some rule of thumb or
%%  may be 0---it that case some standard dimension will be determined.
%%
%%  INDEX GENERATION
%%  ----------------
%% `hyperindex' macros should works with idxmac (or plidxmac) package,
%%  providing that every pages are marked with |page.&lt;pageno&gt;| label.
%%  To obtain this tp-pdf redefines |makeheadline| in the following style:
%%    \let\plainmakeheadline \makeheadline
%%    \def\makeheadline{\PDFdestination{page.\folio}\plainmakeheadline}
%%  It is up to user, not to spoil this.
%%
%% end of commands description
%% + ---- + ------ + ---- + --
%%
%% + ----- + ----- + ----- + ----- + ----- + ----- + ----- + ----- + ----- +
 \immediate\write16{&gt;&gt;TP-PDF macros (T. Przechlewski, ver. 0.8)&lt;&lt;}
 \input tp-crf.tex %% ---crf-macros---
 \makecrfile
%%
%% The |tp-crf| package should be slightly changed:
%% (tp-crf.tex is available from:
%% ftp://ftp.GUST.org.pl/TeX/GUST/contrib/GUSTLIB/)
%%
%% *** TeX or pdfTeX is running? ** march/2000
\newif\ifPDFTeXmode
\ifx\pdfoutput\undefined 
\else \global\PDFTeXmodetrue \fi
%%
\catcode`@=11
\def\@car#1#2#3{#1} \def\@cdr#1#2#3{#2} \def\@CDR#1#2#3{#3}
%
\def\defreference#1#2{\@nextdrf
\ifx\CurrentPDFLabel\nullPDFlabel \def\CurrentPDFLabel{#1}\else \fi%%
\edef\save{\string\newlabel{#1}{{#2}{\noexpand
\folio}{\CurrentPDFLabel}}}\write\crfile\expandafter{\save}%
\ignorespaces}
%
\def\CurrentPDFLabel{\nullPDFlabel} %%
\def\nullPDFlabel{nullPDFlabel}
\def\Warning#1{\write-1{&gt;&gt; PDF Warning: #1!}}
%%
%% + ----- + ----- + ----- + ----- + ----- + ----- + ----- + ----- + ----- +
%% The following code is copied from Sebastian Rahtz
%% and Yannis Halarambous |hyperref| package.
%%
\ifPDFTeXmode\else
\begingroup
  \catcode`P=12
  \catcode`T=12
  \lowercase{\endgroup
\gdef\rem@ptetc#1.#2PT#3!{#1\ifnum#2&gt;\z@.#2\fi}}
\def\strip@pt@and@otherjunk#1{\expandafter\rem@ptetc\the#1!}
\def\pdf@setheight{\literalps@out{%
  \strip@pt@and@otherjunk\baselineskip
  \space 2 sub dup
  /HyperBasePt exch def
  PDFToDvips /HyperBaseDvips exch def
  }%
}
%
\special{!
/DvipsToPDF { .01383701 div Resolution div } def
/PDFToDvips { .01383701 mul Resolution mul } def
% The rectangle around the links starts off
% |exactly| the size of the box;
% we will to make it slightly bigger, 1 point on all sides.
/HyperBorder  { 1 PDFToDvips } def
/TPHyperBorder  { 64 } def %% Margin correction --- TP ---
/HyperVoff {
   currentpoint exch pop vsize 72 sub exch DvipsToPDF sub
  /pdf@voff exch def
 } def
/HyperAutoVoff {
   currentpoint exch pop
    vsize 72 sub exch DvipsToPDF
    HyperBasePt sub % ---baseline skip---
    sub /pdf@voff exch def
 } def
/HyperStart {
   currentpoint
    HyperBorder add /pdf@lly exch def
    dup DvipsToPDF TPHyperBorder add /pdf@hoff exch def %% -- x --
    HyperBorder sub /pdf@llx exch def
} def
/HyperEnd  {
   currentpoint
    HyperBorder sub /pdf@ury exch def
    HyperBorder add /pdf@urx exch def
} def
/HyperAutoEnd  {
   currentpoint
    HyperBaseDvips sub /pdf@ury exch def
    /pdf@urx exch def
} def
systemdict
 /pdfmark known not
 {userdict /pdfmark systemdict /cleartomark get put} if
}
%%
%% + ----- + ----- + ----- + ----- + ----- + ----- + ----- + ----- + ----- +
%% Paper formats and similar stuff
%%
\def\aivpapersize{210mm,297mm}
\def\avpapersize{148mm,210mm}
\def\bvpapersize{176mm,250mm}
\def\aivlandscapepapersize{210mm,297mm}
\def\papersize#1{\gdef\PaperSize{#1}}
\def\SetPaperSize{\special{papersize=\PaperSize}}
\papersize{\aivpapersize}
\fi %% ** PDFTeXmode ***
\def\papersize#1{} %% *** temporary ****
\papersize{}  %% *** temporary ***
\def\SetPaperSize{}
%%
%% + ----- + ----- + ----- + ----- + ----- + ----- + ----- + ----- + ----- +
%%
\def\literalps@out#1{\special{ps:SDict begin #1 end}}%
\def\PDFTeXlinkattrs{} %% &lt;-- empty by default
%
\ifPDFTeXmode
%  \def\PDFanchorstart#1{\pdfannotlink \PDFTeXlinkattrs\space goto name {#1}}% SW
\def\PDFanchorstart#1{\pdfstartlink \PDFTeXlinkattrs\space goto name {#1}}% SW
  \def\PDFanchorend{\pdfendlink}%
\else
  \def\PDFanchorstart#1{\literalps@out{HyperStart}%
    \gdef\PDF@currentanchor{#1}}
  \def\PDFanchorend{\pdf@setheight
    \literalps@out{HyperAutoEnd HyperAutoVoff}%
    \literalps@out{[/Color \PDFLinkColor\space
     /Dest /\PDF@currentanchor\space
     /Rect [\pdf@bbox] \PDFLinkBorder
     /Subtype /Link
     /ANN pdfmark}%
    }
\fi
%
\def\pdf@bbox{pdf@llx pdf@lly pdf@urx pdf@ury}
\def\ColorRed{[1 0 0]}
\def\ColorWhite{[1 1 1]}
\def\ColorGreen{[0 1 0]}
\def\PDFLinkColor{\ColorRed} %% default color
\def\PDFLinkBorder{}
%%\def\PDFLinkBorder{/Border [0 0 0 0]} %% declares ,invisible' links
%%
%% + ----- + ----- + ----- + ----- + ----- + ----- + ----- + ----- + ----- +
%% Bookmark generation
%%
\newwrite\rep
%
\def\StartBookmarks{\immediate\openout\rep=\jobname.rep }
\def\bookmarkclosed{\def\BookStatusFlag{-}} %% now is closed
\def\bookmarkopen{\def\BookStatusFlag{}} %% now is open
\bookmarkopen
%
\def\writetorep#1#2{\begingroup
   \Xsanitize \edef\save{{#1}{#2}{\BookStatusFlag}}%
   \write\rep\expandafter{\save}%
   \endgroup
}
%
% |\Xsanitize|
\def\Xsanitize{\def\TeX{TeX}\def\LaTeX{LaTeX}\def~{ }}
%%
%% + ----- + ----- + ----- + ----- + ----- + ----- + ----- + ----- + ----- +
%% Cross-references
%%
\let\xref \ref
%
\def\ref#1{%
   \@ifundefined{#1}{\@markmissingcr
   \@crwrn{!WARNING: UNDEFINED REFERENCE \string#1}}%
   {\def\CurrPDFAnchor{\expandafter \expandafter\expandafter
      \@CDR \csname #1\endcsname }\PDFanchorstart{\CurrPDFAnchor}%
   \xref{#1}\PDFanchorend }%
}
%
\def\XYZPDFView{[ /XYZ pdf@hoff pdf@voff null ] }
\def\FitHPDFView{[ /FitH pdf@voff] }%%
\def\PDFview#1{\def\PDFCurrentView{#1}}
\PDFview{\XYZPDFView}
%
\ifPDFTeXmode
% \def\PDFdestination#1{\hbox to0pt{\raise\baselineskip
% \hbox to0pt{\pdfdest name {#1} xyz}}} %% 
% --- 2.12.2002
\def\PDFdestination#1{\setbox0 \hbox to0pt{\raise\baselineskip
  \hbox to0pt{\pdfdest name {#1} xyz}}%%
 \ht0=0pt\box0\relax } %% 
\else
\def\PDFdestination#1{% %%
  \literalps@out{HyperStart}\pdf@setheight %
  \literalps@out{HyperAutoEnd HyperAutoVoff}%
  \literalps@out{ [ /Dest /#1 /View \PDFCurrentView\space /DEST pdfmark }%
}
\fi
%%
%% + ----- + ----- + ----- + ----- + ----- + ----- + ----- + ----- + ----- +
%%
\def\PDFbegin{\SetPaperSize \DOCINFO \AddBookmarks}
\def\PDFend{\StopBookmarks}
\def\StopBookmarks{\write\rep{\string\endinput}\closeout\rep}
%
% Catalog entries **march/2000
\ifPDFTeXmode
   %% Catalog entry for ** pdftex **
   \def\UseOutlines{\pdfcatalog{/PageMode /UseOutlines} }
\else
   %% DOCView mark for ** ghostscript/distiller ***
   \def\UseOutlines{\special{ps: [ /PageMode
      /UseOutlines /View \DocInitView\space  /DOCVIEW pdfmark } }
\fi
%
% PDFinfo entries
\def\PDFdoctitle#1{\def\PDFDocTitle{#1}} \PDFdoctitle{}
\def\PDFdocauthor#1{\def\PDFDocAuthor{#1}}    \PDFdocauthor{}
\def\PDFdocsubject#1{\def\PDFDocSubject{#1}} \PDFdocsubject{}
\def\PDFdockeywords#1{\def\PDFDocKeywords{#1}} \PDFdockeywords{}
\def\PDFdoccreator#1{\def\PDFDocCreator{#1}}  \PDFdoccreator{TeX}
%
\ifPDFTeXmode
  \def\DOCINFO{\pdfinfo{%
     \ifx \PDFDocTitle \empty \else /Title (\PDFDocTitle) \fi
     \ifx \PDFDocAuthor \empty \else /Author (\PDFDocAuthor) \fi
     \ifx \PDFDocSubject \empty \else /Subject (\PDFDocSubject) \fi
     \ifx \PDFDocKeywords \empty \else /Keywords (\PDFDocKeywords) \fi
     \ifx \PDFDocCreator \empty \else /Creator (\PDFDocCreator) \fi
   }} 
\else
  \def\DOCINFO{\special{ps: [
     \ifx \PDFDocTitle \empty \else /Title (\PDFDocTitle) \fi
     \ifx \PDFDocAuthor \empty \else /Author (\PDFDocAuthor) \fi
     \ifx \PDFDocSubject \empty \else /Subject (\PDFDocSubject) \fi
     \ifx \PDFDocKeywords \empty \else /Keywords (\PDFDocKeywords) \fi
     \ifx \PDFDocCreator \empty \else /Creator (\PDFDocCreator) \fi
    /DOCINFO pdfmark } }
\fi
%
\def\DocInitView{[/XYZ null null \InitZoom] }
\def\DocInitZoom#1{\def\InitZoom{#1}}
\DocInitZoom{1}
%%
%% + ----- + ----- + ----- + ----- + ----- + ----- + ----- + ----- + ----- +
%  PDF note
\def\PDFnote#1#2#3#4#5{\def\@tempa{#3}%
%%
%% #1 width of the open note window (in points)
%% #2 height of the open note window (in points)
%% #3 the note's title (should be {} for notes without titles)
%% #4 the note's text (only plain text is allowed here!)
%% #5 number, if positive note is open, otherwise closed
%% see ``pdf Mark Reference Manual'', p.~6--8 for more details.
%%
\ifPDFTeXmode
\else
  \literalps@out{HyperStart}%
  %%\literalps@out{HyperEnd}%
  \literalps@out{currentpoint #2 PDFToDvips add /pdf@ury exch def
   #1 PDFToDvips add /pdf@urx exch def }
   \literalps@out{[/Rect [\pdf@bbox]
      \ifnum #5 &gt; 0 /Open true \fi
      \ifx\@tempa \empty \else /Title (#3) \fi
           /Contents (#4) /ANN pdfmark 
  } 
\fi
}
%
%% + ----- + ----- + ----- + ----- + ----- + ----- + ----- + ----- + ----- +
%% + ----- + ----- +     Hypertext index support   + ----- + ----- + ----- +
%%
%% (generated via |plmindex|/|makeidx| )
%% \@wrindex should be changed (very simple idea)
%%
\def\@wrindex#1#2{\def\@IndexFile{#1}\@@wrindex#2||\\}
\def\@@wrindex#1|#2|#3\\{\let\thepage\relax
 \ifx\\#2\\%
   \xdef\gtempa{\write\@IndexFile{\string
      \indexentry{#1|hyperpage}{\thepage}}}\endgroup\gtempa
   \if@nobreak \ifvmode\@nobreak\fi\fi\@esphack
 \else
   \xdef\gtempa{\write\@IndexFile{\string
      \indexentry{#1|#2}{\thepage}}}\endgroup\gtempa
   \if@nobreak \ifvmode\@nobreak\fi\fi\@esphack
 \fi
 %%\endgroup
 \@esphack
}
%
\def\hyperlink#1{\PDFanchorstart{page.#1}#1\PDFanchorend}
%
\def\hypmentry#1{$\underline{\hbox{\rm \hyperpage{#1}}}$}
\let\MENTRY\hypmentry
\def\boldindex#1{\index{#1|hypmentry}} %%
%
\def\@wrnextindex#1#2{\def\@IndexFile{#1}\@@wrindex#2||\\}
%
\def\hyperpage#1{\@hyperpage#1----\\}
\def\@hyperpage#1--#2--#3\\{%
 \ifx\\#2\\%
    \@commahyperpage{#1}%
 \else
  \hyperlink{#1}--\hyperlink{#2}%
 \fi
}
\def\@commahyperpage#1{\@@commahyperpage#1, ,\\}
\def\@@commahyperpage#1, #2,#3\\{%
 \ifx\\#2\\%
   \hyperlink{#1}%
 \else
   \hyperlink{#1}, \hyperlink{#2}%
 \fi
}
% Put PDF destination on every page
\let\plainmakeheadline \makeheadline
\def\makeheadline{\PDFdestination{page.\folio}\plainmakeheadline}
%
%%
%% + ----- + ----- + ----- + ----- + ----- + ----- + ----- + ----- + ----- +
%%
\catcode`@=12 % at signs are no longer letters ---
%
\def\label#1{\defreference{#1}{\CurrentCounter}}
%
%% + ----- + ----- + ----- + ----- + ----- + ----- + ----- + ----- + ----- +
%% + ----- + ----- + ----- +   Bookmarks   ----- + + ----- + ----- + ----- +
%%
% The following macros accomplish a (simple) task of converting the data
% in the form (supposedly written by TeX):
%
%    {sec.1}{Co to jest Acrobat?}{-}
%    {ssec.1.1}{Tworzenie dokumentów w formacie PDF}{}
%    {ssec.1.2}{Przegl±danie dokumentów zapisanych w formacie PDF}{}
%    {ssec.1.3}{Problemy z przeno¶no¶ci± PDF-a}{}
%    {ssec.1.3.1}{Problemy z przeno¶no¶ci± PDF-a}{}
%    {ssec.1.3.2}{Problemy z przeno¶no¶ci± PDF-a}{}
%    {ssec.1.3.3}{Problemy z przeno¶no¶ci± PDF-a}{}
%    {ssec.1.3.4}{Problemy z przeno¶no¶ci± PDF-a}{}
%    {ssec.1.3.5}{Problemy z przeno¶no¶ci± PDF-a}{}
%    {sec.2}{Tworzenie dokumentów w formacie PDF w systemie TeX}{}
%    {ssec.2.1}{Destylacja}{}
%    {ssec.2.2}{Problem fontów}{}
%    {sec.3}{Operatory pdfmark}{}
%    {ssec.3.1}{Odsy³acze hipertekstowe}{}
%    {ssec.3.2}{Zak³adki hipertekstowe}{}
%    {ssec.3.3}{Notka}{}
%    {ssec.3.4}{Inne operatory pdfmark}{}
%    {sec.4}{Pakiet tp-pdf}{}
%    {sec.5}{Podsumowanie}{}
%    {sec.6}{Literatura}{}
%
% to the following series of OUT pdfmarks:
%
%    [/Count -3 /Dest /sec.1 /Title (Co to jest Acrobat?) /OUT pdfmark
%    [/Dest /ssec.1.1 /Title (Tworzenie dokumentow w formacie PDF) /OUT pdfmark
%    [/Dest /ssec.1.2 /Title (Przegladanie dokumentow zapisanych w formacie PDF) /OUT pdfmark
%    [/Count 5 /Dest /ssec.1.3 /Title (Problemy z przenosnoscia PDF-a) /OUT pdfmark
%    [/Dest /ssec.1.3.1 /Title (Problemy z przenosnoscia PDF-a) /OUT pdfmark
%    [/Dest /ssec.1.3.2 /Title (Problemy z przenosnoscia PDF-a) /OUT pdfmark
%    [/Dest /ssec.1.3.3 /Title (Problemy z przenosnoscia PDF-a) /OUT pdfmark
%    [/Dest /ssec.1.3.4 /Title (Problemy z przenosnoscia PDF-a) /OUT pdfmark
%    [/Dest /ssec.1.3.5 /Title (Problemy z przenosnoscia PDF-a) /OUT pdfmark
%    [/Count -2 /Dest /sec.2 /Title (Tworzenie dokumentow w formacie PDF w systemie TeX) /OUT pdfmark
%    [/Dest /ssec.2.1 /Title (Destylacja) /OUT pdfmark
%    [/Dest /ssec.2.2 /Title (Problem fontow) /OUT pdfmark
%    [/Count -4 /Dest /sec.3 /Title (Operatory pdfmark) /OUT pdfmark
%    [/Dest /ssec.3.1 /Title (Odsylacze hipertekstowe) /OUT pdfmark
%    [/Dest /ssec.3.2 /Title (Zakladki hipertekstowe) /OUT pdfmark
%    [/Dest /ssec.3.3 /Title (Notka) /OUT pdfmark
%    [/Dest /ssec.3.4 /Title (Inne operatory pdfmark) /OUT pdfmark
%    [/Dest /sec.4 /Title (Pakiet tp-pdf) /OUT pdfmark
%    [/Dest /sec.5 /Title (Podsumowanie) /OUT pdfmark
%    [/Dest /sec.6 /Title (Literatura) /OUT pdfmark
%
% By default, the pdfmarks are written as DVIPS-oriented \special's (i.e.,
% having the form \special{ps: ...}), but it can be easily changed; see
% the definition of \flushoneitem.
%
% Another default is the maximal bookmark level (\maxitemlev) set to 6.
% The number can be changed, however, this may require an appropriate
% modification of the \initialiselevcount macro.
%
% Additionally, the macros perform a task of ``sanitizing'' of the titles
% of bookmarks, namely, Polish diacritical letters are converted to the
% corresponding Latin ones. Such sanitizing is obligatory, as PDF readers
% support only (hopefully temporarily) Adobe Standard encoding in bookmarks.
%
%    ±  (aogonek)     --&gt;   a
%    æ  (cacute)      --&gt;   c
%    ê  (eogonek)     --&gt;   e
%    ³  (lslash)      --&gt;   l
%    ñ  (nacute)      --&gt;   n
%    ó  (oacute)      --&gt;   o
%    ¶  (sacute)      --&gt;   s
%    ¼  (zacute)      --&gt;   z
%    ¿  (zdotaccent)  --&gt;   z
%    ¡  (Aogonek)     --&gt;   A
%    Æ  (Cacute)      --&gt;   C
%    Ê  (Eogonek)     --&gt;   E
%    £  (Lslash)      --&gt;   L
%    Ñ  (Nacute)      --&gt;   N
%    Ó  (Oacute)      --&gt;   O
%    ¦  (Sacute)      --&gt;   S
%    ¬  (Zacute)      --&gt;   Z
%    ¯  (Zdotaccent)  --&gt;   Z
%
% The macros responsible for the sanitizing can be either simply removed
% or, more advisably, adapted to another language.
%
% Please note that even if Adobe provides TPDF (truly portable document
% format, i.e., including bookmarks), the problem of sanitizing still
% remains, as the codes of characters appearing in DVI file differ, in
% general, from the input ones.
%
% ---
\newif\ifitemlistopen
\def\maybeopen#1{%
  \itemlistopentrue
  \immediate\openin\textitemlist #1\relax
  \ifeof\textitemlist
    \itemlistopenfalse
    \immediate\closein\textitemlist \let\NEXT\empty
    \immediate\write16{FILE #1 NOT FOUND}%
  \fi
}
% ---
\newread\textitemlist
% ---
\newcount\listitemno
\newcount\tempitemno
\newif\ifcontread
\gdef\splitlistitem#1#2#3#4#5#6{\def#4{#1}\def#5{#2}\def#6{#3}}%
{\obeyspaces\gdef\makespaceact{\obeyspaces\edef {\space}}}
% ---
\def\dotdot{.}
\def\relaxrelax{\relax}
\newcount\itemdotno
\def\fixdots#1{\itemdotno0\relax \expandafter\fixdotscont#1\relax}
\def\fixdotscont#1{%
  \def\paramtmp{#1}%
  \ifx\paramtmp\dotdot\advance\itemdotno1\relax\fi
  \ifx\paramtmp\relaxrelax\else \expandafter \fixdotscont \fi
}
% ---
\newtoks\listitemtok
% ---
% BEGIN OF OPTIONAL FRAGMENT (provided one knows what one is doing)
\def\polisha{±}
\def\polishc{æ}
\def\polishe{ê}
\def\polishl{³}
\def\polishn{ñ}
\def\polisho{ó}
\def\polishs{¶}
\def\polishx{¼}
\def\polishz{¿}
\def\polishA{¡}
\def\polishC{Æ}
\def\polishE{Ê}
\def\polishL{£}
\def\polishN{Ñ}
\def\polishO{Ó}
\def\polishS{¦}
\def\polishX{¬}
\def\polishZ{¯}
\def\acrosanit#1{\listitemtok{}\expandafter\acrosanitcont#1\relax}
\def\acrosanitcont#1{%
  \edef\paramtmp{#1}%
  \ifx\paramtmp\relaxrelax\else
    \ifx\paramtmp\polisha\def\paramtmp{a}\fi
    \ifx\paramtmp\polishc\def\paramtmp{c}\fi
    \ifx\paramtmp\polishe\def\paramtmp{e}\fi
    \ifx\paramtmp\polishl\def\paramtmp{l}\fi
    \ifx\paramtmp\polishn\def\paramtmp{n}\fi
    \ifx\paramtmp\polisho\def\paramtmp{o}\fi
    \ifx\paramtmp\polishs\def\paramtmp{s}\fi
    \ifx\paramtmp\polishx\def\paramtmp{z}\fi
    \ifx\paramtmp\polishz\def\paramtmp{z}\fi
    \ifx\paramtmp\polishA\def\paramtmp{A}\fi
    \ifx\paramtmp\polishC\def\paramtmp{C}\fi
    \ifx\paramtmp\polishE\def\paramtmp{E}\fi
    \ifx\paramtmp\polishL\def\paramtmp{L}\fi
    \ifx\paramtmp\polishN\def\paramtmp{N}\fi
    \ifx\paramtmp\polishO\def\paramtmp{O}\fi
    \ifx\paramtmp\polishS\def\paramtmp{S}\fi
    \ifx\paramtmp\polishX\def\paramtmp{Z}\fi
    \ifx\paramtmp\polishZ\def\paramtmp{Z}\fi
    \listitemtok\expandafter\expandafter\expandafter{\expandafter\the\expandafter\listitemtok\paramtmp}%
    \expandafter \acrosanitcont
  \fi
}
% END OF OPTIONAL PART
% ---
\def\readtmpitem{{\makespaceact\immediate\global\read\textitemlist to\tempitem}}
% ---
\def\parpar{\par}
\def\endinputendinput{\endinput}
\def\readitemlist#1{%
  \maybeopen{#1}%
  \def\tempitem{}%
  \contreadtrue
  \ifitemlistopen
    \loop
      \ifeof\textitemlist % sentinel
        \contreadfalse
        \itemlistopenfalse
        \immediate\write16{!WARNING: FILE \jobname.rep INCOMPLETE (IGNORED)}%
      \fi
      \ifcontread
        \readtmpitem
        \ifx\endinputendinput\tempitem \contreadfalse
        \else
          \advance\listitemno1
          \expandafter\expandafter\expandafter
          \def
          \expandafter\expandafter
          \csname listitem\number\listitemno \endcsname
          \expandafter
          {\tempitem}%
        \fi
    \repeat
    \immediate\closein\textitemlist %% &lt;&lt;TP&gt;&gt;
  \fi
}
% ---
\newcount\previtemlev
\newcount\itemlev
{\let\newcount\relax
\gdef\initialiselevcount{%
  \def\maxitemlev{6}% not too much?
  \expandafter\newcount\csname itemlev1\endcsname
  \expandafter\newcount\csname itemlev2\endcsname
  \expandafter\newcount\csname itemlev3\endcsname
  \expandafter\newcount\csname itemlev4\endcsname
  \expandafter\newcount\csname itemlev5\endcsname
  \expandafter\newcount\csname itemlev6\endcsname
}}
\def\inititemlevs{%
  \ifnum\itemlev&lt;\previtemlev
    \advance\itemlev1\relax \csname itemlev\number\itemlev\endcsname0\relax
    \expandafter \inititemlevs
  \fi
}
% ---
\def\processitemlist{%
  \ifitemlistopen
    \tempitemno\listitemno \previtemlev1
    \loop
      \expandafter\expandafter\expandafter % this expands the first argument
      \splitlistitem                       % of \splitlistitem to the form:
        \csname listitem\number\tempitemno\endcsname % {...}{...}{...}
        \itemlevinfo\itemtitle\itemopt % all three are local
      \fixdots\itemlevinfo
      \itemlev\itemdotno
      \advance\csname itemlev\number\itemlev\endcsname1\relax
      \def\countinfo{}%
      \ifnum\previtemlev&gt;\itemlev
        \advance\itemlev1\relax
        \edef\countinfo{\expandafter\the\csname itemlev\number\itemlev\endcsname}%
        \advance\itemlev-1\relax
        \inititemlevs
      \fi
      \previtemlev\itemdotno
      \ifSuppressPLSanit \listitemtok\expandafter{\itemtitle}\else
      \acrosanit\itemtitle \fi
      \expandafter\edef\csname listitem\number\tempitemno \endcsname{%
         \Ins@Bookmark }%
      \ifnum\tempitemno&gt;1\relax \advance\tempitemno-1\relax
    \repeat
  \fi
}
%%
\ifPDFTeXmode
  \def\Ins@Bookmark{%
     \ifx\countinfo\empty
      \pdfoutline goto name {\itemlevinfo} {\the\listitemtok}
     \else 
      \pdfoutline goto name {\itemlevinfo} count \itemopt\countinfo {\the\listitemtok}
     \fi 
  }
  \def\flushoneitem#1{#1} % configurable (driver-oriented)
\else
  \def\Ins@Bookmark{[ \ifx\countinfo\empty\else /Count \itemopt\countinfo \fi
     /Dest /\itemlevinfo
     /Title (\the\listitemtok)
     /OUT pdfmark }
  \def\flushoneitem#1{% configurable (driver-oriented)
    \special{ps:#1}%
    %%\immediate\write16{#1}% copy special content to stdo
  }
\fi
% ---
\newif\ifSuppressPLSanit
\def\NoPLSanitize{\SuppressPLSanittrue}
\def\YesPLSanitize{\SuppressPLSanitfalse}
\YesPLSanitize
% ---
% ---
\def\flushitemlist{%
  \ifitemlistopen
    \tempitemno1
    \loop
      \flushoneitem{\csname listitem\number\tempitemno \endcsname}%
      \ifnum\tempitemno&lt;\listitemno
      \advance\tempitemno1\relax
    \repeat
  \fi
}
% ---
\def\AddBookmarks{\initialiselevcount
  \readitemlist{\jobname.rep}%
  \StartBookmarks
  \processitemlist \flushitemlist}
\def\NoBookmarks{%
  \let\StopBookmarks\relax
  \def\AddBookmarks{\relax}\def\writetorep##1##2{\relax}
  \immediate\write16{BOOKMARKS SUPPRESSED}%
}
%% + ----- + ----- + ----- + ----- + ----- + ----- + ----- + ----- + ----- +
\endinput

</pre></body></html>