# How to modify postscript file to use the same font as the main document

I have to include a Postscript picture in a latex document. The ps file is generated by another program. I would like to modify the font within the ps so that it correspond to the same main font of the document. ( modifying the font from inside the program that generated the ps file is not an option)

How could I achieve that for the following MWE (lualatex with opentype )? How would it work with standard latex font (such latin modern, as an example)?

MWE:

\documentclass[]{article}
\usepackage{graphicx}
%lualatex setup
\usepackage{fontspec}
\setmainfont{MinionPro}%Or whatever
\setsansfont{Iwona}
%\usepackage{lmodern} %if using pdflatex

\begin{document}
\begin{figure}
\includegraphics[width=\textwidth,angle=270]{test.eps}
\end{figure}

\end{document}


From my limited knowledge of PostScript only these lines are involved with the font choice in the file:

%!PS-Adobe-2.0 EPSF-2.0
%%BoundingBox: 18 72 594 720
%%HiResBoundingBox: 18.000000 72.000000 594.000000 720.000000
%%Creator: TECPLOT
%%DocumentFonts: Helvetica Helvetica-Bold Symbol Times-Roman Times-Bold Times-Italic Times-BoldItalic Courier Courier-Bold
%%EndComments
% EPSF created by ps2eps 1.68
%%BeginProlog
1 1 translate
save
countdictstack
mark
newpath
/showpage {} def
/setpagedevice {pop} def
%%EndProlog
%%Page 1 1
/tecplotdict 120 dict def
tecplotdict begin
/ed  {exch def} def
/ftl {findfont exch scalefont setfont} def
/ftr {/ISOLatin1-Times-Roman ftl} def
/ftb {/ISOLatin1-Times-Bold ftl} def
/fti {/ISOLatin1-Times-Italic ftl} def
/ftib {/ISOLatin1-Times-BoldItalic ftl} def
/fcr {/ISOLatin1-Courier ftl} def
/fcb {/ISOLatin1-Courier-Bold ftl} def
/fhn {/ISOLatin1-Helvetica ftl} def
/fhb {/ISOLatin1-Helvetica-Bold ftl} def


Link to complete postscript example: https://gist.github.com/anonymous/323645a6884adfc56ea9

For the record, I tried to use inkscape to convert the file, but in the translation newlines and some formatting is lost.

I expect that it is be necessary to convert the font to a postscript compatible format, but possibly latex might have something built in (or some font might just work out of the box,don't know.)

• The sentence, “I have to include a Postscript picture in a latex file, that is generated by another program,” is ambiguous and ungrammatical. Are you creating the EPS to target a LaTeX file, whose main font you know? Or is the EPS generated by another program, and you have to alter it? – Davislor Sep 3 '15 at 10:17
• The postscript file is created by another program. I have to include that file in a latex document – Pierpaolo Sep 3 '15 at 10:20
• Okay. You might be able to reconfigure that other program (TECplot) or get the image in another format (SVG). If not, you might be able to replace the names of the standard fonts in the PS file with the names of the Type 1 fonts you want to use instead. – Davislor Sep 3 '15 at 10:31
• Gnuplot has a standard template that it’s possible to edit for things like fonts and colors by hand, if you must. (sparky.rice.edu/ps_file.html) TECplot, I don’t know as much about, but that still might be useful. – Davislor Sep 3 '15 at 10:32
• And finally, if it is too hard to change the images you receive, but the fonts have to match, could you bring the mountain to Mohammed and change the font of the LaTeX stylesheet? – Davislor Sep 3 '15 at 10:36

## 2 Answers

Lorehead is right. You can change lines 297 and 298 of your PostScript file to:

/MinionPro-Regular getisofont /ISOLatin1-Helvetica       exch definefont pop
/MinionPro-Bold    getisofont /ISOLatin1-Helvetica-Bold  exch definefont pop


It seems to work with a variety of fonts installed on my system. You need to give the PostScript name of the font. otfinfo -i <filename> will return this.

Second answer: it looks as if lines 945–1198 or so of your PS file are the ones you’d want to change. These appear to apply the font definitions from lines 20–30 or so to characters; fhb is Helvetica Bold, fhn Helvetica, and so on. If you can copy the font definition from another PS file, you might be able to change those labels to use it.

• What do you mean with copying from another Ps file? It exactly those information - how to modify the file- that i would like to know, – Pierpaolo Sep 3 '15 at 11:13
• I suggest that you create a PS file of your own that uses the font you want (GnuPlot might be a good tool), see how it declares the font, and see if copying that declaration near line 30 works. If it declares as /foo, try search-replacing fhn (but not /fhn) with foo. Likewise fhb. – Davislor Sep 3 '15 at 11:19