6

Can fontspec be used to manage a document's fonts if the fonts need to use the CMYK color model? The fontspec documentation, section 6.1, says that fontspec uses RGB colors. My experimentation (MWE below) seems to confirm that fontspec will convert CMYK colors passed to it into noticeably different RGB equivalents.

PDF output of MWE (using XeLaTeX, fontspec, xcolor):

PDF output of MWE (using XeLaTeX); fontspec changes CMYK colors to approximate RGB equivalents

MWE:

\documentclass[a4paper]{article} 

\usepackage{fontspec}
\usepackage{xcolor}

\definecolor{mycyan}{cmyk}{1,0,0,0}
\definecolor{mymagenta}{cmyk}{0,1,0,0}
\definecolor{myyellow}{cmyk}{0,0,1,0}
\definecolor{myblack}{cmyk}{0,0,0,1}

\begin{document} 

Without fontspec:

\textcolor{mycyan}{\rule{10pt}{10pt}}
\textcolor{mycyan}{XXX Cyan text (CMYK 1,0,0,0)}

\textcolor{mymagenta}{\rule{10pt}{10pt}}
\textcolor{mymagenta}{XXX Magenta text (CMYK 0,1,0,0)}

\textcolor{myyellow}{\rule{10pt}{10pt}}
\textcolor{myyellow}{XXX Yellow text (CMYK 0,0,1,0)}

\textcolor{myblack}{\rule{10pt}{10pt}}
\textcolor{myblack}{XXX Black text (CMYK 0,0,0,1)}

With fontspec:

\textcolor{mycyan}{\rule{10pt}{10pt}}
\fontspec[Color=mycyan]{Arial} XXX Cyan text (CMYK 1,0,0,0)

\textcolor{mymagenta}{\rule{10pt}{10pt}}
\fontspec[Color=mymagenta]{Arial} XXX Magenta text (CMYK 0,1,0,0)

\textcolor{myyellow}{\rule{10pt}{10pt}}
\fontspec[Color=myyellow]{Arial} XXX Yellow text (CMYK 0,0,1,0)

\textcolor{myblack}{\rule{10pt}{10pt}}
\fontspec[Color=myblack]{Arial} XXX Black text (CMYK 0,0,0,1)

\end{document}
  • 1
    Why don't you want to use \textcolor? \textcolor{mycyan}{\fontspec{Arial} XXX Cyan text (CMYK 1,0,0,0)} is working fine. (Leaving aside, that it would be better to set the document font globally in the preamble, instead of switching adhoc inside of \textcolor) – DG' Nov 2 '18 at 23:02
  • Also: The issue is known for a long time now → github.com/wspr/fontspec/issues/129 – DG' Nov 2 '18 at 23:14
  • @DG' Your suggestion worked for me too! Thank you. It's a fine workaround that enables me to use fontspec in sync with CMYK text colors. If you write up your suggestion as an answer, I'll select it as correct. – Tim Stewart Nov 2 '18 at 23:33
  • 1
    Well, it seems that the considerations here (click) apply. – egreg Nov 3 '18 at 15:34
4

Fontspec can work with CMYK colors, if you use \textcolor instead of fontspec's Color option:

\documentclass{article}

\usepackage{xcolor}
\usepackage{fontspec}

\definecolor{mycyan}{cmyk}{1,0,0,0}

\begin{document}

Without fontspec:

\textcolor{mycyan}{\rule{10pt}{10pt}}
\textcolor{mycyan}{XXX Cyan text (CMYK 1,0,0,0)}

With fontspec:

\textcolor{mycyan}{\rule{10pt}{10pt}}
\textcolor{mycyan}{\fontspec{Arial} XXX Cyan text (CMYK 1,0,0,0)}

\end{document}

enter image description here

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.