2

I have a tex file like this:

\documentclass{standalone}
\usepackage[cmyk]{xcolor}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
    \fill[green] circle (3);
\end{tikzpicture}

\end{document}

I compile it with pdflatex and then turn into svg using pdf2svg, and I get a result like this:

pdf2svg

I'm now trying to achieve the same result using dvisvgm.

I have a tex file like this:

\documentclass[dvisvgm]{standalone}
\usepackage[cmyk]{xcolor}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
    \fill[green] circle (3);
\end{tikzpicture}

\end{document}

I compile it with latex test2.tex and then turn into svg using dvisvgm test2.dvi. However the result looks like this:

dvisvgm

It seems to me that the colors are treated as rgb when using the dvisvgm route even though I have specified cmyk when loading the xcolor package.

Is there a way that I could compile the file via the dvisvgm route and get colors that look similar to the pdf2svg version above?

1
  • 6
    SVG doesn't support CMYK colors. Therefore, dvisvgm just uses a common, simple formula to convert the color values to RGB. A proper conversion would require ICC color profiles which dvisvgm doesn't support. So, at the moment, it's not directly possible to get the same CMYK-based colors as in the PDF file.
    – Martin
    Commented Apr 2 at 16:31

1 Answer 1

5

Since SVG doesn't support CMYK colors natively, the program generating the SVG file has to convert them to RGB. This is usually done with a simple formula that roughly maps the colors to the RGB color space, e.g. green to green, red to red, yellow to yellow etc., but it doesn't take the actual tint, tone, shade etc. into account. Actually, this is a pretty complex topic and requires a color management system (CMS) and ICC color profiles to handle color mappings properly. So, at the moment, it's not directly possible to get the same colors from CMYK values as produced by PDF viewers or pdf2svg.
Edit: As of version 3.3, dvisvgm creates similar RGB colors from CMYK ones as Ghostscript.

dvisvgm doesn't use a CMS to convert between color spaces. I'm also reluctant to rely on one because it's a hard to maintain the dependency on another third-party library, like Little CMS. While Windows comes with a CMS built-in, other operating systems don't, so that a portable solution would be necessary.

However, there are still other ways to get more satisfying visual results when using CMYK colors. After playing around with several approaches, I got two techniques that are somewhat easy to implement and might be available in one of the next dvisvgm releases.

The first one is based on a formula, I found in this topic. It produces great results, the colors are just a bit darker than the ones created by Ghostscript or various PDF viewers.

Here's a comparison of the results created by Ghostscript (left), the mentioned formula (middle), and the current conversion used by dvisvgm:

Ghostscript Approximation default CMYK to RGB conversion

The second method is to use a table of RGB colors pre-computed for an amount of CMYK colors and interpolate all other values from them. According to my tests, 625 sample values, i.e. 5 samples per CMYK dimension, lead to results that are hard to distinguish from the results created by PDF viewers -- at least to my eyes.

Results created by Ghostscript (left) and linear interpolation:

Ghostscript Interpolation

While the first method is fast and very easy to implement, the second one creates better matching results. Comparing the results of both approaches, the difference between the perceived colors (using deltaE, CIEDE2000) lies between 2 and 10 which is not too bad. Here's a visualization of the differences for the above gradient example (darker colors denote greater differences):

deltaE

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .