[texworks] Embed fonts with ps2pdf - argument parsing problem

Reinhard Kotucha reinhard.kotucha at web.de
Wed Jul 25 02:55:57 CEST 2012

On 2012-07-24 at 12:49:04 -0700, Brandon Kuczenski wrote:

 > On 7/23/2012 12:35 AM, Siep Kroonenberg wrote:
 > > On Mon, Jul 23, 2012 at 07:50:26AM +0200, Stefan Löffler wrote:
 > >> Hi,
 > >>
 > >> On 2012-07-21 01:07, Brandon Kuczenski wrote:
 > >>> I know this question has been "answered" on this list before, namely here:
 > >>>
 > >>> http://tug.org/pipermail/texworks/2009q2/000822.html
 > >>>
 > >>> However, the solution included there does not embed fonts,
 > >>> which is clearly not acceptable.  Because of the byzantine
 > >>> argument parsing that happens between the batch file and Tw, I
 > >>> cannot for the life of me figure out how to pass the options
 > >>> "-dEmbedAllFonts=true -dPDFSETTINGS=/prepress
 > >>> -dCompatibilityLevel=1.4" to ps2pdf from within TexWorks.  > >>
 > >>> Assuming the batch file cited above works for you (I don't have
 > >>> Windows > >> w/ TeX available at the moment to test), you can
 > >>> modify it to
 > >>
 > >> @latex %1 && dvips "%~dpn1.dvi" && ps2pdf -dEmbedAllFonts=true -dPDFSETTINGS=/prepress -dCompatibilityLevel=1.4 "%~dpn1.ps"
 > >>
 > >>
 > >> to pass additional parameters to ps2pdf. Note that this has to be done
 > >> in the batch file, the TeXworks configuration is unchanged.
 > > Or replace '=' with '#'. I recall that that may be needed for
 > > Windows batchfiles when invoking Ghostscript.
 > >
 > Sorry, it does not work. 

I tested it on Gentoo Linux and it works.  I also tried ancient
gs-8.60 and it works there too.

 > Without quotes, with equal signs and not hashmarks, GS chokes with the
 > following:
 > MiKTeX GPL Ghostscript 8.60 (2007-08-01)
 > Copyright (C) 2007 Artifex Software, Inc. All rights reserved.
 > This software comes with NO WARRANTY: see the file PUBLIC for details.
 > Error: /undefinedfilename in (true)

The error message means that Ghostscript received the string "true"
where it expects a filename.  Note that PostScript uses braces as
delimiters for strings while most other programming languages are
using single or double quotes.  Obviously the equals sign in
-dEmbedAllFonts=true was replaced by a space character.  Ghostscript
treats all non-optional arguments as filenames.  Hence the behavior is

The Ghostscript manual sais:

  When passing options to ghostcript through a batch file wrapper such
  as ps2pdf.bat you need to substitute '#' for '=' as the separator
  between options and their arguments. For example:

  ps2pdf -sPAPERSIZE#a4 file.ps file.pdf

  Ghostscript treats '#' the same internally, and the '=' is mangled
  by the command shell.
 > Operand stack:
 > Execution stack:
 > %interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2
 > %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1
 > %stopped_push
 > Dictionary stack:
 > --dict:1146/1684(ro)(G)-- --dict:0/20(G)-- --dict:70/200(L)--
 > Current allocation mode is local
 > Last OS error: No such file or directory
 > MiKTeX GPL Ghostscript 8.60: Unrecoverable error, exit code 1
 > Making the entirely obvious and simple, not at all unconventional,
 > substitution of hash marks for equal signs, howver, also doesn't work. 
 > Strangely, the PS file is no longer correctly built (or maybe it gets
 > written over).  TW completes without errors, but I wind up with an
 > incorrect ps file (which has no content) and no PDF.  The DVI file
 > builds correctly.  If I remove the switches, then the ps and pdf do
 > build correctly, but fonts are not embedded.

Well, if ps2pdf is invoked with one filename, the name of the output
file is created automatically (.ps replaced by .pdf).  If two
filenames are given on the command line, the second one denotes the
name of output (PDF) file.

It seems that some fragment of the optional arguments is treated as an
input file and "%~dpn1.ps" is treated as the name of the output (PDF)
file.  The file "TW-test/TW-test.ps" in your attachment is indeed an
empty PDF file.

What you can try is to remove the options -dPDFSETTINGS#/prepress and
-dCompatibilityLevel#1.4 completely.  The latter is superfluous
because PDF-1.4 is the default anyway.  Then you could try
-dEmbedAllFonts without #true.  This option is accepted here without
an argument but I don't know whether it does the right thing then.
But since fonts are not embedded by default, it's quite likely that it

 > Quoting the command switches individually has no effect.

Quoting on Windows is a pain.  It's obviously not documented properly.
If you're in luck you'll probably find some hints in Microsoft
developer's blogs, but not everything is explained.  It seems that
equal signs are mangled before quotes are evaluated.  Such a braindead
behavior is unthinkable in the Unix world.

In order to avoid such problems, I replaced all the Ghostscript batch
files in TeX Live by texlua scripts.  Maybe I could try to convert
your .bat file to texlua too.  Since all TeX distributions provide
LuaTeX for years, texlua is ubiquitous.

But what is the name of MiKTeX's hidden Ghostscript executable?
mtgs.exe?  Is it in PATH?

On the other hand, I recommend to install an up-to-date version of
Ghostscript.  8.60 is quite old and especially color management has
been improved significantly meanwhile.

 > Minimal example attached with tex file, batch file, and resulting
 > ps file (batch file extension changed to bXt because gmail won't
 > let me email .bat)

If security is such an issue I'm wondering why mail servers transfer
emails at all.  Adobe Reader refuses to extract .zip, .tar.gz,...
attachments because they are so dangerous.  Perl scripts can be
extracted though.  Cool security concept.

When I run

  latex TW-test.tex
  dvips TW-test.dvi
  ps2pdf TW-test.ps

I get

  $ pdffonts TW-test.pdf
  name                          type         emb sub uni object ID
  ----------------------------- ------------ --- --- --- ---------
  AQAEUC+CMR10                  Type 1C      yes yes no      10  0
  GAXVVL+NimbusSanL-Regu        Type 1C      yes yes no       8  0

even with gs-8.60.  I'm wondering why you need -dEmbedAllFonts at all.

What's the output of pdffonts if *you* run pstopdf without the
-dEmbedAllFonts option?


Reinhard Kotucha                                      Phone: +49-511-3373112
Marschnerstr. 25
D-30167 Hannover                              mailto:reinhard.kotucha at web.de
Microsoft isn't the answer. Microsoft is the question, and the answer is NO.

More information about the texworks mailing list