3

I'm writing a document in mixed English and Chinese (with the xeCJK package. I want to add some fake bold headlines using the font Kaiti SC. When I do this using the AutoFakeBold option, this makes it unable to copy the characters in the resulting PDF. How can I fix this?

It seems like xeCJK is loading fontspec behind the curtains, so the issue might be related to it.

Here's a MWE.

%!TEX TS-program = xelatex
%!TEX encoding = UTF-8 Unicode

\documentclass[12pt, a4paper]{article}

\usepackage{xeCJK}
\setCJKmainfont[Scale=1.2, AutoFakeBold=true]{Kaiti SC} % removing the bold makes the output copyable


\begin{document}

\textbf{你好}

宋代大{\color{red}文学家}苏东坡常常一个人出去旅行。他特别喜欢参观寺庙。

\end{document}
3

Malipivo provided a solution using \pdfliteral, and that technique works for XeTeX too. This technique is used in zhmCJK package. You can read the documented source code of zhmCJK if you are interested in it.

However, it is quite tricky to apply this technique properly in xeCJK:

% !TeX program = XeLaTeX
% !TeX encoding = UTF-8
\documentclass{article}
\usepackage{xeCJK}

\setCJKmainfont{SimSun}

% value > 0
\def\xeCJKembold{0.4}

% hack into xeCJK, you don't need to understand it
\def\saveCJKnode{\dimen255\lastkern}
\def\restoreCJKnode{\kern-\dimen255\kern\dimen255}

% save old definition of \CJKsymbol and \CJKpunctsymbol for CJK output
\let\CJKoldsymbol\CJKsymbol
\let\CJKoldpunctsymbol\CJKpunctsymbol

% apply pdf literal fake bold
\def\CJKfakeboldsymbol#1{%
  \special{pdf:literal direct 2 Tr \xeCJKembold\space w}%
  \CJKoldsymbol{#1}%
  \saveCJKnode
  \special{pdf:literal direct 0 Tr}%
  \restoreCJKnode}
\def\CJKfakeboldpunctsymbol#1{%
  \special{pdf:literal direct 2 Tr \xeCJKembold\space w}%
  \CJKoldpunctsymbol{#1}%
  \saveCJKnode
  \special{pdf:literal direct 0 Tr}%
  \restoreCJKnode}
\newcommand\CJKfakebold[1]{%
  \let\CJKsymbol\CJKfakeboldsymbol
  \let\CJKpunctsymbol\CJKfakeboldpunctsymbol
  #1%
  \let\CJKsymbol\CJKoldsymbol
  \let\CJKpunctsymbol\CJKoldpunctsymbol}

\begin{document}

正常汉字。\CJKfakebold{可复制“伪粗体”汉字。English unchanged. 粗体汉字。}正常汉字。

\end{document}

enter image description here

Note that the non-CJK characters are unchanged in \CJKfakebold command. This is a feature by design. You should use \textbf or \bfseries as usual for English.

And note that the code above is not at all complete for xeCJK, puctuation kerning is wrong for example. It should be implemented more carefully (maybe in a very different way) if we add this feature into the package.

| improve this answer | |
  • Interesting. I'm not making a professional document so the kerning is not so important. Is there a way to combine this with the AutoFakeBold setting or should I just adjust the \xeCJKembold value manually? – pg-robban May 26 '14 at 16:22
  • @pg-robban: Well, I think you can set it manually. – Leo Liu May 26 '14 at 17:06
  • Alright, I have one more question before I mark the question as answered: Suppose I have a macro which does something with bold text, currently I do this with \textbf{#1} on that part. Is there any way I can find out if the argument consists of only Chinese characters so that I can apply the correct bold function (\textbf vs \CJKfakebold) or do I need to make separate macros? – pg-robban May 26 '14 at 18:48
  • @pg-robban: \textbf does not change Chinese characters, if you don't set BoldFont feature. And maybe you didn't notice that \CJKfakebold does not change Latin characters, as is shown above. You can use \CJKfakebold{\textbf{正确的粗体 Bold}} safely. – Leo Liu May 27 '14 at 10:45
  • Aha, I got it now :) 麻烦您了,thank you so much. – pg-robban May 27 '14 at 13:51
1

This is a know XeTeX bug, I don’t think there is currently a way to fix it.

| improve this answer | |

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.