I am using the package xpinyin for displaying pinyin, a Chinese phonetic script above Chinese characters. This seems to work well, but I want to change the font of the phonetic script. I found some code in the package documentation, although that one is Chinese only:

\xpinyinsetup{ratio=0.5, vsep=1em, multiple={\color{red}}, font=Liberation Sans}

The Chinese in the documentation is still too high level for me, so I simply guess this is what it does:

  1. make the pinyin hal the size of the main font
  2. vertical separation of 1em, pinyin is separated by 1em from the Chinese character below
  3. if there are multiple pinyins for one character (多音字) then the pinyin will be the most likely one and colored red
  4. use the font Liberation Sans

However, I don't know if you can simply leave a space between Liberation and Sans. The main problem is the following result:

vocals missing

(In this picture I used Arial because it's a short enough name to be readable.) So I thought: "This must be a font issue." I tried using the Liberation Sans font in Libre Office, to check whether it could display the missing vocals with tones. There it was able to display it without indicating a change of font, but I don't know if it hides this information and maybe the font really cannot dislay those vocals.

Also notice how somehow the font name was added into the phonetic script. This might be intentional, although it rather seems like a bug. I don't understand the documentation though.

How can I make xpinyin display correctly without having the font name in the phonetic script of the first character?

Here some example code:

\documentclass[10pt, a4paper, parskip=full]{article} % twoside can be added if two sided margin layout is desired
\usepackage[a4paper,vmargin={30mm, 20mm},hmargin={30mm, 25mm},includeheadfoot]{geometry}

\xpinyinsetup{ratio=0.5, vsep=1em, multiple={\color{red}}, font=Liberation Sans}

\setCJKmainfont[]{WenQuanYi Micro Hei}

\defaultfontfeatures{Mapping=tex-text, Scale=MatchLowercase} % what does this do? -- influences how quotes are rendered
\setmainfont[Scale=1]{Open Sans}
\setmonofont{Liberation Mono}

\usepackage[english, ngerman]{babel}




1 Answer 1


I found a workaround and maybe this can be seen as a solution:

\xpinyinsetup{ratio={.7}, hsep={.5em plus .1em}, vsep={1.1em}, multiple={\color{red}}}

% redefine the pinyinscope environment, so that it uses a font which can display all pinyin syllables and vocals with diacritics
{\setmainfont{DejaVu Sans}\begin{pinyinscope}}%
{\end{pinyinscope}\setmainfont{Open Sans}}

This changes the font to a font, which can display all the diacritics of pinyin, whenever the environment pinyinscopeboxed begins and changes it back to another font, whenever the environment ends. The specific font one would have to configure as desired and it could probably be improved by somehow using a variable to contain the main font before changing it and then use that variable to switch back, but I don't know how to do that yet. I'd be grateful for suggestions on how to do that, or how to improve the solution in general.

This also avoids the buggy behavior, which causes the font name to be displayed in the rubies, because it doesn't use the font option of xpinyin.


Qing Lee told me about a proper way of doing this.

Don't renew the environment, but instead you can do the following, if you use the fontspec package:

\newfontfamily{\DVS}{DejaVu Sans}
\xpinyinsetup{ratio={.7}, hsep={.5em plus .1em}, vsep={1.1em}, multiple={\color{red}}, pysep={.2em}, font=\DVS}

(Other values than the font= are just for giving an example.)

You must log in to answer this question.

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