I have some not-so-old PostScript programs that create an animation using the copypage operator. See a simple example below [*].
They worked fine in macOS using Preview and pstopdf while Apple supported PostScript. Sadly, this is no longer the case and now I'm stuck with Ghostscript from MacTeX. Unfortunately, ps2pdf from Ghostscript and epstopdf from TeX use PostScript Level 3 and apparently the semantics of copypage have changed since PostScript Level 2.
How can I tell Ghostscript to use PostScript Level 2 semantics for copypage?
I've tried this but it did not work:
ps2pdf -dLanguageLevel=2 foo.ps
EDIT: Following the suggestions in the comments, I've tried this but it still did not work:
$ diff orig/gs_init.ps ./gs_init.ps
777c777
< dup { erasepage } if
---
> %dup { erasepage } if
$ gs -P -h
GPL Ghostscript 10.04.0 (2024-09-18)
[omitted]
Search path:
. : /usr/local/share/ghostscript/10.04.0/Resource/Init :
[omitted]
$ gs -P -sDEVICE=pdfwrite -o out.pdf copypage.ps
The first command shows the changes made to a local copy of gs_init.ps.
The second command shows that this local copy will be loaded, overriding the installed one.
All this is running on macOS 15.7.1 with MacTeX 2025, which installs Ghostscript 10.04.0.
[*] Here is a simple example of an animation using copypage. Page 2 should contain two lines, not one.
$ cat copypage.ps
%!PS-Adobe-2.0
100 100 moveto 200 200 lineto stroke
copypage
100 200 moveto 200 100 lineto stroke
showpage
To summarize the discussion in the comments (especially the input from @KenS):
It cannot be done with Ghostscript when the output is PDF. [*]
It does work when the output is an image:
gs -I. -sDEVICE=png16m -o out%d.png copypage.ps
You need a local copy of gs_init.ps, modified as in the question.
[*] Apparently, this is a limitation of the pdfwrite device, not an intrinsic limitation of PDF, because one can reuse PDF stream objects across pages.