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.

4
  • 3
    Provide a MWE please, otherwise we can't guess what's wrong with your code. Commented Dec 9, 2023 at 3:26
  • 1
    I don't suppose you just need to compile a second time so that \ref{X} is defined? (And \label is written to the aux file, but this hasn't changed for a long time, so changing to MikTeX 2.9 wouldn't have broken it.) Commented Dec 9, 2023 at 3:32
  • 2
    You should look at refcount. Possible duplicate: How to use \pageref{foo} as a number? Commented Dec 9, 2023 at 4:12
  • 2
    \label write into the aux file. The should be a \newlabel entry. If the aux file is not there, check if you have some clean option in your compilation. Commented Dec 9, 2023 at 7:51

1 Answer 1

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} 
2
  • Mico your method indeed work. But why could the same file be successful in previous installation? Commented Dec 9, 2023 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). Commented Dec 9, 2023 at 13:55

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.