What is wrong with my system setup?

I bought a new computer with windows10, which I installed MikTeX2.9. The previous LaTeX file failed to compile in this new system. The follwing is a min. example:

\documentclass{book}
\usepackage{fontspec}
\usepackage[BoldFont,SlantFont,CheckSingle=true]{xeCJK}
\usepackage{CJKnumb}
\setmainfont{Times New Roman}
\setCJKmainfont{DFT_HZ5.TTC}
\begin{document}

\end{document}


You do not need to use DFT_HZ5.TTC any other Chinese font is the same. The following is the log file:

....
....
Font)                  TU/TimesNewRoman(0)/m/n --> TU/TimesNewRoman(0)/b/n on
input line 7.
LaTeX Font Info:    Overwriting math alphabet \mathit' in version bold'
(Font)                  OT1/cmr/bx/it --> TU/TimesNewRoman(0)/b/it on input lin
e 7.
LaTeX Font Info:    Overwriting math alphabet \mathsf' in version bold'
(Font)                  OT1/cmss/bx/n --> TU/lmss/b/n on input line 7.
LaTeX Font Info:    Overwriting math alphabet \mathtt' in version bold'
(Font)                  OT1/cmtt/m/n --> TU/lmtt/b/n on input line 7.

! Missing number, treated as zero.
\protect
l.8 隢?


It is not peculiar, because what is inside \CJKnumber is undefined. The program should popup and ask me, and I simple need to hit a return But it did not popup. The program simply break here.

However, if I remove the other Chinese character, the program become

\documentclass{book}
\usepackage{fontspec}
\usepackage[BoldFont,SlantFont,CheckSingle=true]{xeCJK}
\usepackage{CJKnumb}
\setmainfont{Times New Roman}
\setCJKmainfont{DFT_HZ5.TTC}
\begin{document}
\CJKnumber{\ref{coding}}
\end{document}


It is fine. What is wrong with my system setup?

• Could you please add code the code where you set \label{coding}? – egreg Jun 17 at 23:14

Similar to this answer, the error is caused by the fact that \ref{<label>} is not fully expandable (mainly because the \null in \@setref). Instead, you can use the fully expandable command \getrefnumber{<label>} from refcount package.

Full example:

\documentclass{book}
\usepackage[BoldFont,SlantFont,CheckSingle=true]{xeCJK}
\usepackage{CJKnumb}
\usepackage{refcount}

\begin{document}
\chapter{title}\label{coding}

\end{document}


Alternatively, to have consistent counter output format, it is recommended to (re)define \the<counter> command.

\documentclass{book}
\usepackage[BoldFont,SlantFont,CheckSingle=true]{xeCJK}
\usepackage{CJKnumb}

\renewcommand{\thechapter}{\CJKnumber{\arabic{chapter}}}

\begin{document}

\chapter{title}\label{coding}

\end{document}


Note that \CJKnumber accepts a number, not counter name, so we firstly use \arabic{chapter} to get the number.

This usage is more common.

• How about 第\CJKnumber{\thechapter}章 \hfill} Which command should I replace for \thechapter? This issue can be fixed using "chcp 65001" under command mode, at the cost of conflict at other software. It is a issue about UTF-8 coding. – ophage Jun 18 at 7:15
• @ophage I edited my answer to add a redefining \thechapter resolution. – muzimuzhi Z Jun 18 at 8:21