3

I am writing a document (more specifically, a lexicon) which mixes two languages: a European language, and Japanese.

I use XeLaTeX (UTF8 source file) with the xeCJK package to handle the Japanese. Some of you are probably going to say that this is not optimal, but I have tried several solutions and this is the most seamless. xeCJK may not be ideal for 100% CJK docs, but when it comes to handling CJK parts in an otherwise non-CJK text it seems the least bad to me (by far).

What I’d like to do is setting the text color for Japanese script document-wide. Non-Japanese characters should not be affected and remain black. xeCJK already allows to set a specific font for CJK parts document-wide, with the \setCJKmainfont command. I’m looking for something similar for text color.

I had a look at the xeCJK documentation but couldn’t find a way to achieve this (plus, it’s only available in Chinese which doesn’t help, to be 100% honnest).

EDIT: Here is a very short exemple.

\documentclass{article}

\usepackage{fontspec}
\usepackage{xeCJK}

% Setting a specific font for Japanese only.
\setCJKmainfont{Kozuka Gothic Pro}

% Anything similar for text color?
% ?

\begin{document}

Hello everyone! In this document, some sentences will be in Japanese.
これも読めたら日本語が分かりますね。

\end{document}
  • 2
    Can you please add a minimal example of code, just to play with? – egreg Mar 22 '17 at 11:26
4

It appears that the \setCJKmainfont command of the xeCJK package internally uses fontspec, so you can use fontspec's Colour (or Color) option. Read the fontspec documentation (section 14.1 Colour, as of the current version 2017/02/12 v2.6) for details and warnings. For example, you can use “a six-digit hex colour RRGGBB” (below I changed your font to one I have):

\documentclass{article}

\usepackage{fontspec}
\usepackage{xeCJK}

\setCJKmainfont[Colour=EE22AA]{Noto Sans CJK JP}

\begin{document}

Hello everyone! In this document, some sentences will be in Japanese.
これも読めたら日本語が分かりますね。

\end{document}

xecjk with colour

  • Perfect! I didn't expect the solution to be that simple. – user96829 Mar 22 '17 at 23:42

Your Answer

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