PDF Stuff

Knuth’s TeX creates files in an output format called DVI (DeVice Independent file format). More recent implementations of TeX (pdfTeX, XeTeX, LuaTeX) produce their output in PDF format. If you use a graphical user interface such as TeXworks to work with .tex files you will probably never encounter a .dvi file, as TeXworks is targeted at the direct generation of PDF output.



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

To get outlines (bookmarks) in your document: use the Navigator package by Paul Isambert:

\input navigator

\outline{0}{Chapter 1 – XeTeX}

\outline{1}{Section 1 – Unicode Support}


The \outlines are placed before the text they refer to. The number between the first pair of braces determines where the bookmark comes in the hierarchy: the lower the number, the higher the level of the bookmark.

pdfTeX and LuaTeX require that the command \finishpdffile be given at the end of the file for the outline hierarchy to be built. See the file ‘cm.tex’ on the Fonts page for an example.

This code ensures that bookmarks will be visible by default when the document is opened in a PDF reader. For XeTeX:

\special{pdf: docview << /PageMode /UseOutlines >>}

For pdfTeX/LuaTeX:

\pdfcatalog{/PageMode /UseOutlines}

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

Mark up for PDF metadata (author, title etc). For XeTeX:

\special{pdf: docinfo <<
/Author (Herodotus)
/Title (Histories)
/Subject (Ancient History)
/Keywords (Greeks, Persians)
>>}

other keys, such as /Date, /Creator, /Producer seem to be set automatically by XeTeX. The metadata can be viewed by clicking File > Properties in Adobe Reader.

For pdfTeX/LuaTeX:

\pdfinfo {
/Title (example.pdf)
/Author (Tom and Jerry)
/Subject (Example)
/Keywords (mouse, cat)
}


(from page 24 (22) of the pdfTeX users manual:)

The pdfTeX code given on this page also works in LuaTeX prior to version 0.85. In LuaTeX v. 0.85 most commands of the form \pdf* have been replaced by calls to one of three new primitives, \pdffeedback, \pdfextension and \pdfvariable. These take keywords so for example \pdfinfo becomes \pdfextension info. Some other commands simply drop the \pdf prefix, e.g. \pdfprotrudechars and \pdfadjustspacing become \protrudechars, \adjustspacing.

The practical affect of these changes is that certain things that rely on the \pdf primitives, (e.g. Navigator, certain Eplain commands) no longer work in the newer versions of LuaTeX. See the file ‘luatex2017.tex’ on the Misc page for a way of getting round this.

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

PDF page labels (logical page numbers). For XeTeX:

\special{pdf:docview <</PageLabels<</Nums[0<</P(title)>>1<</S/r>>3<</S/D>>]>>>>}

For pdfTeX/LuaTeX:

\pdfcatalog{/PageLabels<</Nums[0<</P(title)>>1<</S/r>>3<</S/D>>]>>}


The mark up above, which I found here
http://tex.stackexchange.com/questions/74149/plain-xetex-page-labels
controls how page numbers appear in the page number field of the PDF reader. Say you have have a book with a half title, blank verso, full title page (recto), imprint page (verso), table of contents (two pages) and then page one of chapter one. That’s six pages of prelims before you get to chapter one, page one (‘page one’ is actually page seven). See the files for an example:

prelims.tex, prelims.pdf.

UPDATE. I originally used this markup:

\special{pdf:docview <</PageLabels<</Nums[0<</P(title)>>4<</S/r>>6<</S/D>>]>>>>}

to get lower case roman numerals to start on the first page of the contents. It seems that most books that use lower case roman numerals in the prelims start the numbering from the very first page – the half title in this example – even though no page numbers are printed on the title or imprint pages. I have moved \pageno=-1 from the contents page to the half title. This altered code changes the PDF PageLabels to match:

\special{pdf:docview <</PageLabels<</Nums[0<</P(title)>>0<</S/r>>6<</S/D>>]>>>>}

The PDF PageLabels code has no effect on the printed document; it just means that if you enter say ‘10’ in the page field of Adobe Reader, it will take you to the page with ‘10’ printed on it (which is actually the 16th page in this document). If you used arabic numerals from the first actual page instead of lower case roman numerals you would not need this code at all.

I put in some PDF bookmarks using the Navigator package. Also I used Eplain’s cross referencing macros () to hyperlink chapter pages to the contents page.

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

Sumatra PDF is a lightweight PDF reader that runs on MS Windows. It is designed for portable use, so it can be run from a USB stick if you wish. Unlike Adobe Reader it does not lock the PDF file, so you can leave it open when you edit a file in TeXworks and run TeX. (I like to view the document as a two page spread in the PDF reader.) You can open multiple instances of the same document. Also, if you click on a hyperlink in Sumatra PDF, pressing the Backspace key will take you back to where you were.