1

Sorry this is a basic question. I do not know where does \label write the data to?

In my previous installation of MikTex 2.9 I can use \CJKnumber{\ref{X}} to reference a previously defined number X and \CJKnumber will change this number into Chinese character. But the present installation cannot. It said the number \ref{X} is undefined. Therefore I want to check whether does \ref{X} really exists.

Mico
  • 506,678
nana
  • 23

1 Answers1

4

The reason why \CJKnumber{\ref{X}} cannot work is as follows. While \CJKnumber expects its argument to be a number, the \ref macro isn't expandable; therefore, \CJKnumber is not receiving a number to work on. (Jargon-Alert: "expandability" and "expansion" of macros is at the very core of the TeX programming language.)

What's the remedy? I suggest you employ the refcount package and its \getrefnumber macro; in contrast to \ref{<some_label>}, \getrefnumber{<some_label>} is expandable. The upshot is that \CJKnumber{\getrefnumber{<some_label>}} works as expected.

enter image description here

% !TEX TS-program = xelatex
\documentclass{article} % or some other suitable document class
\usepackage{xeCJK,CJKnumb}
\setCJKmainfont{SimSun}
\usepackage{refcount} % for \getrefnumber macro

\begin{document} \addtocounter{equation}{554} % just for this example \refstepcounter{equation}\label{eq:something}

\ref{eq:something} \CJKnumber{\getrefnumber{eq:something}}

\end{document}

Mico
  • 506,678
  • Mico your method indeed work. But why could the same file be successful in previous installation? – nana Dec 09 '23 at 13:38
  • @nana - Regarding your follow-up question: Not having any connections to the maintainer of the CJKnumb package, I'm afraid I have no answer. I do know that the non-expandability of the\ref macro has been a constant feature for many years (and, more likely, decades). – Mico Dec 09 '23 at 13:55