2

Consider the MWE posted below (based on How does one type Chinese in LaTeX?) - you will need the simsun.ttc font in the same directory.

First, in the MWE below (call it test.tex) uncomment the \begin/\end{filecontents*} section, and compile with:

pdflatex test.tex && biber test && pdflatex test.tex

This will also generate the .bib - and everything should compile fine, and the Chinese text is selectable:

test.png

... and most importantly, the end of this compilation run reports this:

(./test.aux) ){/media/disk/texlive/2014/texmf-dist/fonts/enc/dvips/lm/lm-
ec.enc}<simsun.ttc><simsun.ttc><simsun.ttc><simsun.ttc></media/disk/texli
ve/2014/texmf-dist/fonts/type1/public/lm/lmbx12.pfb></media/disk/texlive/
2014/texmf-dist/fonts/type1/public/lm/lmr10.pfb></media/disk/texlive/2014
/texmf-dist/fonts/type1/public/lm/lmtt10.pfb>
Output written on test.pdf (1 page, 77939 bytes).
Transcript written on test.log.

That is - simsun.ttc font is read in, as expected.

Now, let's try this with precompiled format "header"; first, comment back the \begin/\end{filecontents*} section, so it is exactly the same as the MWE (we won't need the .bib file, as it is already generated - and we won't need to run the biber, as again the .bbl file has been generated in the previous run).

First, generate the precompiled format:

pdflatex -ini -jobname="test" "&test" mylatexformat.ltx "test.tex"

Note at this point, in the log there is:

$ grep 'zhw\|simsun\|uniso' test.log
(/media/disk/texlive/2014/texmf-dist/tex/generic/zhmetrics/zhwinfonts.tex

Then, let's use the precompiled format to compile the doc:

pdflatex "&test" test.tex

Now, the compilation ends like this:

] (./test.aux) ){/media/disk/texlive/2014/texmf-dist/fonts/enc/dvips/lm/lm-ec.enc}
kpathsea: Running mktexpk --mfmode / --bdpi 600 --mag 1+0/600 --dpi 600 unisongsl7a
mktexpk: Running ttf2pk -q unisongsl7a 600
mktexpk: ~/.texlive2014/texmf-var/fonts/pk/modeless/zhmetrics/unisong/unisongsl7a.600pk: successfully generated.
 <~/.texlive2014/texmf-var/fonts/pk/modeless/zhmetrics/unisong/unisongsl7a.600pk>
kpathsea: Running mktexpk --mfmode / --bdpi 600 --mag 1+0/600 --dpi 600 unisongsl65
^Ckpathsea: Appending font creation commands to missfont.log.

!pdfTeX error: pdflatex (file unisongsl65): Font unisongsl65 at 600 not found
 ==> Fatal error occurred, no output PDF file produced!

Now this is the thing: here I pressed Ctrl-C - but typically, pdflatex would fail as mktexpk would fail (I only got this to work after adding TEXFONTMAPS = .;$TEXMFDIST/source/fonts/zhmetrics;$TEXMF/fonts/map/{$progname,pdftex,dvips,}// to texmf-dist/web2c/texmf.cnf, and adding "Map ttfonts.map" to a new file $(kpsewhich --var-value=TEXMFLOCAL)/web2c/updmap.cfg, then texhash, then updmap-sys - then it fails again w/ "ambiguous entry for 'cyberb@Unicode@': font file present but not included, will be treated as font file not present"; then remove the "Map..." line from updmap.cfg, then again updmap-sys - and only then can the mktexpk generate bitmaps for unisong).

But the problem is - I do not want to use unisong (apparently, as it is a bitmap font, even if it can be generated, those glyphs are not selectable in the pdf); -- I want to use simsun.ttc, as I did when not using the precompiled header ?!

So my questions are - what could possibly have made this font usage change when using a precompiled format file; and how can I get simsun.ttc to be used also in the case of a precompiled format?

The MWE, test.tex:

\RequirePackage{filecontents}
% %% NOTE: filecontents cannot be active when -ini runs; must be commented!
% %% NOTE: cannot use just {{文章}}, must add a \relax inside!

% \begin{filecontents*}{\jobname.bib}
% @misc{baiduweb,
%   title = {{文章}\relax},
%   author = {Baidu},
%   url = {http://home.baidu.com/},
%   year = {2015},
% }
% \end{filecontents*}

\documentclass{article}
\usepackage[%
  style=ieee,
  isbn=true,
  doi=false,
  url=true,
  bibencoding=utf8,
  backend=biber
]{biblatex}
% \addbibresource{\jobname.bib}
\bibliography{\jobname}

\usepackage{lmodern}
\usepackage[utf8]{inputenc}
\usepackage[T2A, T1]{fontenc}
\usepackage[russian,greek,english]{babel}

\usepackage{CJKutf8}
% NOTE: this may require the font simsun.ttc in the same directory as this .tex file!

\AtBeginDvi{\input{zhwinfonts}} % MUST have! for \usepackage{CJKutf8}

% [http://lists.ffii.org/pipermail/cjk/2007-November/002045.html [Cjk] Problem with CJKchar]
\newcommand{\Chi}[2]{%
  \csname CJK*\endcsname{UTF8}{zhsong}%
    \CJKchar{#1}{#2}%
  \csname endCJK*\endcsname
}

% 文: 0x6587
\DeclareUnicodeCharacter{6587}{\Chi{"65}{"87}} % YES!
% 章: 0x7AE0
\DeclareUnicodeCharacter{7AE0}{\Chi{"7A}{"E0}} %


\begin{document}


% macro test:
\Chi{"65}{"87}\Chi{"7A}{"E0}    % ok

% direct unicode chars:
文章                             % ok

Just a testing of citation here: \cite{baiduweb} ...

% % seems this with the environment is not really needed?!

% \makeatletter
% \let\CJK@ignorespaces\relax % else the below breaks..
% \CJK@envStart{}{UTF8}{zhsong}
% \makeatother

\printbibliography[resetnumbers]

% \makeatletter
% \CJK@envEnd{}
% \makeatother

\end{document}
1

1 Answer 1

1

I think I got it: just use a \endofdump to indicate the end of the precompiled format slightly before \begin{document}; and then insert the \AtBeginDvi{\input{zhwinfonts}} line after it.

The preamble thus becomes:

\RequirePackage{filecontents}
% %% NOTE: filecontents cannot be active when -ini runs; must be commented!
% %% NOTE: cannot use just {{文章}}, must add a \relax inside!

% \begin{filecontents*}{\jobname.bib}
% @misc{baiduweb,
%   title = {{文章}\relax},
%   author = {Baidu},
%   url = {http://home.baidu.com/},
%   year = {2015},
% }
% \end{filecontents*}

\documentclass{article}
\usepackage[%
  style=ieee,
  isbn=true,
  doi=false,
  url=true,
  bibencoding=utf8,
  backend=biber
]{biblatex}
% \addbibresource{\jobname.bib}
\bibliography{\jobname}

\usepackage{lmodern}
\usepackage[utf8]{inputenc}
\usepackage[T2A, T1]{fontenc}
\usepackage[russian,greek,english]{babel}

\usepackage{CJKutf8}
% NOTE: this may require the font simsun.ttc in the same directory as this .tex file!

% [http://lists.ffii.org/pipermail/cjk/2007-November/002045.html [Cjk] Problem with CJKchar]
\newcommand{\Chi}[2]{%
  \csname CJK*\endcsname{UTF8}{zhsong}%
    \CJKchar{#1}{#2}%
  \csname endCJK*\endcsname
}

% 文: 0x6587
\DeclareUnicodeCharacter{6587}{\Chi{"65}{"87}} % YES!
% 章: 0x7AE0
\DeclareUnicodeCharacter{7AE0}{\Chi{"7A}{"E0}} %

\csname endofdump\endcsname% may \def to \relax; http://tex.stackexchange.com/questions/57398
\AtBeginDvi{\input{zhwinfonts}} % MUST have! for \usepackage{CJKutf8}

\begin{document}

... and the rest is the same. With this, now also with precompiled-format compilation, I can see simsun.ttc being loaded (and Chinese letters are selectable in the document, too).

1
  • If you are using pdflatex in its default mode (i.e. to PDF), surely \AtBeginDvi is strange?
    – cfr
    Jul 5, 2015 at 22:26

You must log in to answer this question.

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