Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xeCJK: 以特定方式使用 tikz 时,整篇文档的中文都无法显示 #517

Closed
muzimuzhi opened this issue Jun 4, 2020 · 1 comment
Assignees

Comments

@muzimuzhi
Copy link
Contributor

一个 xeCJK 文档中,如果

  • tikzpicture 之前无中文输入,
  • 且在 tikzpicture 里使用了一个内部把中文存进盒子的 pgfkeys key,

那么整篇文档的中文都无法显示

\documentclass{article}
\usepackage{xeCJK}
\usepackage{tikz}

\makeatletter
\tikzset{
  x name/.code={\setbox\@tempboxa=\hbox{中文}}
}
\makeatother

\begin{document}
\begin{tikzpicture}
  \node[draw, x name=名字] {测试};
\end{tikzpicture}
abc测试
\end{document}
  • 预期效果:带框的文本「测试」 + 文本「abc测试」
  • 实际输出:一个空框 + 文本「abc」,同时 log 中包含 Missing Character 报错:
    Missing character: There is no 中 in font nullfont!
    Missing character: There is no 文 in font nullfont!
    Missing character: There is no 名 in font nullfont!
    Missing character: There is no 字 in font nullfont!
    Missing character: There is no 测 in font nullfont!
    Missing character: There is no 试 in font nullfont!

其他信息:

  • 把例子里的 中文 换成 中文w,会新增报错 Missing character: There is no w in font nullfont!! Missing } inserted.
  • 换用 luatex-ja,问题不复现

上述例子的来源:

  • <name><text> 相同时,定义一个新的 key 来简化形如 \node (<name>) {<text>}; 的输入
  • 新 key 可以定义为 \tikzset{x name/.style={name={#1}, node contents={#1}}},于是输入可简化为 \node[x name=<...>];
  • 有时候,希望 <text> 在较短时能两端对齐,于是新 key 的定义调整为
    \tikzset{
      x name/.code={%
        \pgfkeysalso{node contents={#1}}%
        \setbox\@tempboxa=\hbox{#1}%
        \ifdim\wd\@tempboxa>3\ccwd
          \pgfkeysalso{node contents={\usebox\@tempboxa}}%
        \else
          \pgfkeysalso{node contents={\makebox[3\ccwd][s]{#1}}}%
        \fi
      }
    }
@qinglee
Copy link
Member

qinglee commented Jun 4, 2020

  1. pgf 会在作图环境中将字体设置为 \nullfont , 见 https://github.com/pgf-tikz/pgf/blob/65bcaafffbd0b21974b085504b4853684d5ed8bc/tex/generic/pgf/basiclayer/pgfcorescopes.code.tex#L227-L247 如果在作图环境中输入文本或者使用 \setbox 等排版命令,会导致 xeCJK 错误地将字体缓存为 \nullfont ,导致整篇文档对应字体的中文都不显示
  2. 如果在作图环境中使用 \setbox 等排版命令,需要在其内部使用 pgfinterruptpicture 环境。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants