GeneralHow to set the title of the generated Postscript® file from within the source LaTeX file?

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
user49915
Posts: 81
Joined: Wed Apr 17, 2019 12:51 pm

How to set the title of the generated Postscript® file from within the source LaTeX file?

Post by user49915 »

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 as 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 usually postprocess the Postscript® file with a `sed` script from the Makefile. 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:

Code: Select all

\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. The option pdfdisplaydoctitle=true of hyperref doesn't help.
  \fi
\fi
\begin{document}
\title{\larger[1.999]\bookTitleWithLineBreaks}
\author{\authorList}
\maketitle
\end{document}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

user22741
Posts: 35
Joined: Fri Nov 09, 2018 12:03 pm

How to set the title of the generated Postscript® file from within the source LaTeX file?

Post by user22741 »

The name shown in the `.ps` comments is utterly unrelated to the tex document. It get added from `dvips`. If you want to change it, rename the `.dvi` before converting it to `.ps`

Example:

Code: Select all

latex main.tex
mv main.dvi leon.dvi
dvips leon.dvi leon.ps
user49915
Posts: 81
Joined: Wed Apr 17, 2019 12:51 pm

How to set the title of the generated Postscript® file from within the source LaTeX file?

Post by user49915 »

user22741 wrote:The name shown in the `.ps` comments is utterly unrelated to the tex document. It get added from `dvips`. If you want to change it, rename the `.dvi` before converting it to `.ps`
This approach has the same drawback: the title is present at two different places (in the tex file and in the file system). Unfortunately, it is even worse than postprocessing with `sed`, since file systems typically restrict the character set that can be used in the file names.
user22741
Posts: 35
Joined: Fri Nov 09, 2018 12:03 pm

How to set the title of the generated Postscript® file from within the source LaTeX file?

Post by user22741 »

Use a reasonable name for your tex file (no crazy letters that your systems disallows for a good reason), set the title in the hyperref options to the same with `pdftitle={\jobname}` and the comment in the ps file will be correct automatically


If you insist on a jobname different from your file name, compile with `latex --jobname=foo main`
user49915
Posts: 81
Joined: Wed Apr 17, 2019 12:51 pm

How to set the title of the generated Postscript® file from within the source LaTeX file?

Post by user49915 »

user22741 wrote:Use a reasonable name for your tex file (no crazy letters that your systems disallows for a good reason)
Of course.
Paper titles such as "The wildcards * and ? are considered harmful: a saga on input/output" would lead to file names such as "The wildcards * and ? are considered harmful: a saga on input/output.tex" which I believe to be illegal on (ex)FAT or NTFS.
Post Reply