LaTeX, CJK, and “Font C70/song/m/n/6/57=cyberb57 at 6.0pt not loadable: Metric (TFM) file not found.”

I started to use CJK in LaTeX recently, and I spend a lot of time trying to fix the following problem:

! Font C70/song/m/n/9/65=cyberb65 at 9.0pt not loadable:
                         Metric (TFM) file not found.
 
                   relax 
l.74 ^^e6^^97^^a0
                 \\par
? 

I searched Internet to find a fix. I'm not the only one who got such error, but the only recommendation was to correctly install CJK fonts. Unfortunately, it wasn't my case. My CJK fonts were installed and worked.

Finally, I've traced the source of the problem and fixed it.

I use background texts which are produced in \EveryShipout. The text should be displayed in Helvetica font, so the shipout code contains:

... \\fontfamily{phv}\\selectfont ...

Now let's trace TeX execution. It processes CJK text, and the current encoding is some "CXX". A page is full, so shipout procedure is activated. "Selectfont" tries to load "phv" for "CXX" encoding (font shape "CXX/phv/m/n"). It's undefined, so fallback is "CXX/song/m/n", which somehow is translated to "cyberbXX" (my CJK font), and for some reason it is not found (altough exists).

The fix is simple. The shipout code should also define the font encoding:

... \\fontfamily{phv}\\fontencoding{T1}\\selectfont ...

All this seems obvious now, but it wasn't easy to realize. TeX error message is very misleading: error context is the source code, not the shipout code.

14 September 2005, update

An example to reproduce the problem. Note that I really need to use "set@typeset@protect", therwise font changing commands doesn't work.

%
% Standard preamble for a CJK document
%
\\documentclass{article}
\\usepackage[encapsulated]{CJK}
\\usepackage{ucs}
\\usepackage[utf8x]{inputenc}
%
% Master page
%
\\usepackage{everyshi}
\\newcommand{\\MasterPage}{ %
% Ok
%\\fontsize{9pt}{11pt}\\fontfamily{phv}\\fontencoding{T1}\\selectfont
% Error
\\fontsize{9pt}{11pt}\\fontfamily{phv}\\selectfont
CJK Text}
\\makeatletter\\EveryShipout{\\set@typeset@protect\\MasterPage}\\makeatother
%
% Document itself
%
\\begin{document}
\\begin{CJK}{UTF8}{cyberbit}
^^e6^^97^^a0CJK Text\\par
^^e6^^97^^a0\\par
^^e6^^97^^a0\\par
... 100+ lines ...
^^e6^^97^^a0\\par
^^e6^^97^^a0\\par
\\clearpage
\\end{CJK}
\\end{document}
Categories: TeX

Updated: