8

EDIT3: Note - the below apparently demonstrates a bug with Ghostscript 9.02's tiffsep device (see comments); tested it with Ghostscript 9.16 and it doesn't display this problem (CMYK separations are OK, black plate only, in both cases). But see also the accepted answer, which fixes this with also with gs 9.02. Still, caveat emptor...


Consider this MWE, test.tex (this is on Texlive 2014, updated to frozen):

\documentclass[10pt,twoside,openright]{book}
\pdfcompresslevel=0 % edit: added

\usepackage[fixpdftex,cmyk,svgnames]{xcolor}
\makeatletter
\def\typecmyk#1{%
\typeout{XC@mod@cmyk #1: \XC@mod@cmyk} % is 'cmyk' when active
} \typecmyk{A}
\makeatother

\usepackage[
  paperwidth=15cm,
  paperheight=20cm,
  outer=2cm,
  inner=2cm,
  top=2cm,
  bottom=2cm
  ]{geometry}
\usepackage[a4,center]{crop}
\crop[cam,info] % info is default, noinfo has to be set; use [off] to turn off all marks

\begin{document}
\frontmatter
\pagestyle{empty} %disable headers and footers
\pagenumbering{roman} %use roman page numbering in the frontmatter

\section{Another one}

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

\end{document}

If we compile this as usual, and rename the output as test1.pdf:

pdflatex test.tex
mv test.pdf test1.pdf

... then we can output the CMYK separations using ghostscript:

gs -q -sDEVICE=tiffsep -dNOPAUSE -dBATCH -dSAFER -r72x72 \
 -sOutputFile=test1.tif -dFirstPage=1 -dLastPage=1 test1.pdf
montage \
 test1.Cyan.tif test1.Magenta.tif test1.Yellow.tif test1.Black.tif \
 -border 1 -bordercolor lime -geometry +2+2 -tile x1 \
 test1_cmyk.png

... and with ImageMagick's montage we can put all CMYK separations on one image, and the result is this (click for high-res):

test1_cmyk.png

The text is supposed to be black - and indeed, there is "ink" only on the K plate, as expected. So all is good in this case.

But now, let's try compile the same example with "precompiled" format files; and retrieve the separations:

pdflatex -ini -jobname="test" "&pdflatex" mylatexformat.ltx "test.tex" 
pdflatex --file-line-error --synctex=1 "&test" test.tex
mv test.pdf test2.pdf
gs -q -sDEVICE=tiffsep -dNOPAUSE -dBATCH -dSAFER -r72x72 \
 -sOutputFile=test2.tif -dFirstPage=1 -dLastPage=1 test2.pdf
montage \
 test2.Cyan.tif test2.Magenta.tif test2.Yellow.tif test2.Black.tif \
 -border 1 -bordercolor lime -geometry +2+2 -tile x1 \
 test2_cmyk.png

... but now, the separations are like this:

test2_cmyk.png

... and it is as if for the text color only, the color black is as if defined in RGB - and then transformed to CMYK in the plainest/"dumbest" form possible: with color on all plates (instead of only on the black one), which is going to cost me a lot more in the print shop.

The weird thing is - we can uncompress the resulting PDFs with pdftk EDIT: now with \pdfcompresslevel=0 there is no need to uncompress with pdftk, we can observe test1.pdf/test2.pdf directly as they are uncompressed.... EDIT2: now these files have been uploaded here:

... and while these unfortunately cannot be compared with meld, with less -L test1.pdf they can be inspected, and for the text part, the PDF output is somewhat different:

% test1.pdf
Q
0 g 0 G
0 0 0 1 k 0 0 0 1 K
0 g 0 G
0 0 0 1 k 0 0 0 1 K
BT
/F16 14.3462 Tf 141.732 637.754 Td [(0.1)-1125(Another)-375(one)]TJ/F8 9.9626 Tf
 0 -21.821 Td [(Lorem)-315(ipsum)-315(dolor)-316(sit)-315(amet,)-319(consectetur
)-315(adipiscing)-315(elit,)-319(sed)-315(do)-315(eiusmo)-28(d)]TJ 0 -11.955 Td 
...
rum.)]TJ
0 0 0 1 k 0 0 0 1 K
0 0 0 1 k 0 0 0 1 K
ET

% test2.pdf
Q
0 g 0 G
0 0 0 1 k 0 0 0 1 K
0 g 0 G
BT
/F28 14.3462 Tf 141.732 637.754 Td [(0.1)-1125(Another)-375(one)]TJ/F8 9.9626 Tf
 0 -21.821 Td [(Lorem)-315(ipsum)-315(dolor)-316(sit)-315(amet,)-319(consectetur
)-315(adipiscing)-315(elit,)-319(sed)-315(do)-315(eiusmo)-28(d)]TJ 0 -11.955 Td 
...
rum.)]TJ
0 0 0 1 k 0 0 0 1 K
0 g 0 G
ET

... but the weird thing is, CMYK color model seems to be used always (k or K) and there is no sign of RGB (i.e. rg and RG) - so I am completely puzzled on as to where this leakage of black to the other components comes from ?!

So my question is - why does this "color leakage" happen when using a precompiled format file; and how can I get the correct result also with a precompiled format file?

EDIT: Shameless plug: I discovered this thanks to my patch to pdfshuffler for showing CMYK separations, given in Linux GUI for quick browsing of CMYK separations of multi-page PDF? - Software Recommendations Stack Exchange

  • 1
    Maybe the pdftk does some color corrections. Try to do your color separations after pdftk or try to set \pdfcompresslevel=0 in order to avoid the usage of pdftk. – wipet May 7 '15 at 7:47
  • Thanks @wipet - the pdftk is in there just to show how I get to the uncompressed PDF literals; otherwise the color separations in the post above are all derived via pdflatex -> ghostscript (-> montage) directly. \pdfcompresslevel=0 is a good idea, though, then pdftk would indeed not be needed. Cheers! – sdaau May 7 '15 at 7:50
  • 1
    My idea was that the compressed PDF hides something like 1 1 1 1 k and pdftk does correction of this and prints 0 0 0 1 k. The parts of your PDF shows 0 0 0 1 k and this is impossible to separate this to the result you shown. I tried to experiment with 0 0 0 1 k settings and with the separation using gs (similar as you) and I have normal result: black part is only at the last plate. – wipet May 7 '15 at 9:07
  • 1
    what happens if you put \normalcolor after \begin{document} ? – David Carlisle May 7 '15 at 10:00
  • 1
    I started with your two PDFs test1 and test2 and I applied your separation process using gs. Of course, I was very care to distinguish between test1 and test2 (many occurrences on command lines), but the result is the same in both cases: CMY are empty and K includes typesetting. It means that all is right. I cannot reproduce problem. – wipet May 7 '15 at 11:47
5

In both cases, 0 g 0 G can be seen in the PDF files. This comes from the PDF color stack of pdfTeX that is not yet reassigned to CMYK values. This can be done by:

\makeatletter
\newcommand*{\InitColorStack}{%
  \chardef\main@pdfcolorstack=\pdfcolorstackinit{0 0 0 1 k 0 0 0 1 K}\relax
}
\InitColorStack
\everyjob\expandafter{\the\everyjob\InitColorStack}
\makeatother

The status of pdfTeX's color stacks are not saved in the format file, therefore they need to be set also with the own format file. This is done by the setting of the token register \everyjob.

Now, the color settings 0 g 0 G in the gray model are gone in both PDF files and the separation should be more successful.

  • Many thanks for that, @HeikoOberdiek: I added your snippet right after the \pdfcompresslevel=0 in the preamble in the OP - and now even when I compile with precompiled header, the separations are OK -- and even with ghostscript 9.02! Great with a fix for this - cheers! – sdaau May 7 '15 at 12:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.