Every once in a while I have to compile source .tex files into .ps files. (The reasons may differ: e.g., due to certain amount of pstricks-heavy legacy code, or issues of some old-printer–CUPS-filters that suddently do not process submitted PDFs properly, or an IEEE journal still requesting a Postscript file from me, etc.) These Postscript® files have a title comment which usually looks like follows:
%%Title: main.dvi
where "main" comes from my input file "main.tex". However, I usually wish to have something more meaningful there that the viewers such as gv
or evince
would parse and display properly in their window captions and when being asked about the file properties. Therefore, after running latex
+dvips
I postprocess the Postscript® file with a sed
script from the Makefile. This is done by a command such as
$(PSOBJECTS): \
%.ps: %.dvi Makefile
dvips -o $*.ps $<
sed -i 's/^%%Title: $<$$/%%Title: This is a very long title in one line without line breaks/' $@
chmod a+r $@
The downside of this approach is that now the title is present twice: inside the tex file and inside the Makefile. So, when you change the title at one place, you often forget to change the title at another place. I'm wondering whether it is possible to set the title for the Postscript® file from within the tex file (which will be then the only place then where the title will be set) by some clever command(s).
Example code to start with:
\RequirePackage{ifpdf}
\RequirePackage{ifxetex,ifluatex}
\newif\ifxetexorluatex
\ifxetex
\xetexorluatextrue
\else
\ifluatex
\xetexorluatextrue
\else
\xetexorluatexfalse
\fi
\fi
\documentclass{book}
\usepackage{relsize}
\newcommand{\bookTitleInOneLine}{This is a very long title in one line without line breaks}
\newcommand{\bookTitleWithLineBreaks}{This is a very long title\\occupying several lines\\with line breaks\\at meaningful positions}
\newcommand{\authorList}{John Doe, Sally Sixpack, Joe Bloggs, and John Smith}
\ifxetexorluatex
\usepackage[unicode,pdftitle={\bookTitleInOneLine},hidelinks,pdfauthor={\authorList}]{hyperref}%%% Setting basic meta data for the PDF
\else
\ifpdf
\usepackage[unicode,pdftitle={\bookTitleInOneLine},hidelinks,pdfauthor={\authorList}]{hyperref}%%% Setting basic meta data for the PDF
\else
\usepackage[unicode,hidelinks]{hyperref}
%%% Here, we'd ideally set the title for the dvi+postscript
\fi
\fi
\begin{document}
\title{\larger[1.999]\bookTitleWithLineBreaks}
\author{\authorList}
\maketitle
\end{document}
\usepackage[pdftitle=Title,pdfdisplaydoctitle=true]{hyperref}
?\usepackage[unicode,hidelinks]{hyperref}
, the title doesn't show up in the postscript file generated bylatex
+dvips
, and the viewergv
still shows "main.dvi" in the window caption when viewingmain.ps
.sed
in the makefile (so Linux) you may think to grep the\Title{....}
from the tex file, parse the line(s) and add that title inside the ps... all in the makefile...