LaTeX forum ⇒ 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.
user49915
Posts: 35
Joined: Wed Apr 17, 2019 12:51 pm

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

Postby user49915 » Wed Apr 17, 2019 3:07 pm

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:

  1. %%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:

  1. \RequirePackage{ifpdf}
  2. \RequirePackage{ifxetex,ifluatex}
  3. \newif\ifxetexorluatex
  4. \ifxetex
  5. \xetexorluatextrue
  6. \else
  7. \ifluatex
  8. \xetexorluatextrue
  9. \else
  10. \xetexorluatexfalse
  11. \fi
  12. \fi
  13. \documentclass{book}
  14. \usepackage{relsize}
  15. \newcommand{\bookTitleInOneLine}{This is a very long title in one line without line breaks}
  16. \newcommand{\bookTitleWithLineBreaks}{This is a very long title\\occupying several lines\\with line breaks\\at meaningful positions}
  17. \newcommand{\authorList}{John Doe, Sally Sixpack, Joe Bloggs, and John Smith}
  18. \ifxetexorluatex
  19. \usepackage[unicode,pdftitle={\bookTitleInOneLine},hidelinks,pdfauthor={\authorList}]{hyperref}%%% Setting basic meta data for the PDF
  20. \else
  21. \ifpdf
  22. \usepackage[unicode,pdftitle={\bookTitleInOneLine},hidelinks,pdfauthor={\authorList}]{hyperref}%%% Setting basic meta data for the PDF
  23. \else
  24. \usepackage[unicode,hidelinks]{hyperref}
  25. %%% Here, we'd ideally set the title for the dvi+postscript. The option pdfdisplaydoctitle=true of hyperref doesn't help.
  26. \fi
  27. \fi
  28. \begin{document}
  29. \title{\larger[1.999]\bookTitleWithLineBreaks}
  30. \author{\authorList}
  31. \maketitle
  32. \end{document}


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

Postby user22741 » Thu Apr 18, 2019 3:18 pm

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:

  1. latex main.tex
  2. mv main.dvi leon.dvi
  3. dvips leon.dvi leon.ps

user49915
Posts: 35
Joined: Wed Apr 17, 2019 12:51 pm

Postby user49915 » Thu Apr 18, 2019 5:07 pm

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

Postby user22741 » Thu Apr 18, 2019 6:34 pm

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: 35
Joined: Wed Apr 17, 2019 12:51 pm

Postby user49915 » Thu Apr 18, 2019 7:58 pm

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.


Return to “General”

Who is online

Users browsing this forum: No registered users and 10 guests