7

I'm not familiar with chinese characters and fonts. But I have to type some characters into a document. XeLaTeX may be an option, but I'm looking for a solution with pdflatex. Here is my MWE, which I created with the help of other questions and answers:

\documentclass{article}
\usepackage{CJKutf8}
\begin{document}
\begin{CJK*}{UTF8}{gbsn}
中華人民共和國

ABC-1234
\begin{verbatim}
中華人民共和國
ABC-1234
\end{verbatim}
\end{CJK*}
\end{document}

I have two questions:

  1. Is there a monospace font for chinese characters available for using in verbatim environments with same size than latin characters (I'm using MacTeX/TeXLive 2012)?
  2. Why are not all 7 chinese symbols in the resulted pdf?

result of pdflatex

  • with the help of tex.stackexchange.com/questions/94293/… I changed gbsn to maru or bkai. With these fonts, all 7 chinese symbold are in the generated pdf. So, I'm only looking for a fixed font, too. – Micha Apr 15 '13 at 22:13
  • Fixed font means monospaced font, right. As far as I know all Chinese fonts are monospaced... Of course, the character width of is different from an A. So you want A and to have the same width? – e-birk Apr 15 '13 at 22:20
  • yes, I've edited my posts – Micha Apr 15 '13 at 22:22
  • 1
    If you change to the bsmi family (instead of gbsn), you'll get all the characters. – Gonzalo Medina Apr 16 '13 at 0:20
  • 1
    For CJK scripts, monospaced usually means that a fullwidth character (e.g. ) is twice as wide as a halfwidth character (e.g. A). In fact it is more difficult to obtain this monospaced feature. – Leo Liu Apr 20 '13 at 11:57
7

output of MWE

  1. The ASCII characters ABC... are usually typeset as halfwidth characters while Chinese characters (汉字, ABC...) are typeset as fullwidth characters. See also Halfwidth and fullwidth forms.

    Hence, a solution is to convert the ASCII characters to fullwidth ones in Unicode. You might write your own converter or use a website like http://kiserai.net/hwfw.pl

  2. There are two writing systems for Chinese characters: the traditional and the simplified system. The characters and belong to the traditional characters, while the others can be used in both systems. Unfortunately, there is no one-to-one mapping between traditional characters and simplified ones. Several traditional characters can be mapped to one simplified one.

    Hence, when using a CJK environment you also need to decide which writing system, i.e., which font to use: gbsn and gkai are fonts with simplified characters, while bsmi and bkai are fonts with traditional characters. See also Problems of traditional and simplified Chinese characters and CJK environment and Chinese

Here is the code of the above picture:

\documentclass{article}
\usepackage{CJKutf8}
\begin{document}
\begin{CJK}{UTF8}{bsmi}
中華人民共和國

ABC-1234
\begin{verbatim}
中華人民共和國
ABC-123
4
\end{verbatim}
\end{CJK}
\end{document}
  • Yes I wondered about mentioning the possibility of changing the input, This is probably the "right" thing to do. – David Carlisle Apr 16 '13 at 12:39
  • @DavidCarlisle It is probably also possible to map A (U+0041) to (U+FF21), B to , and so on just within the "verbatim" environment. Hence, no external conversion is needed. (But not sure how to do that...) – e-birk Apr 16 '13 at 12:52
3

This makes all the ascii characters twice their normal width, I thought that would make them exactly line up but it seems to be drifting slightly, an alternative would be 2o replace 2\noexpand\width by a fixed with pre-calculated to be the width of the CJK characters in the verbatim font. It doesn't work as written if there are accented characters or other half width characters out of the ASCII range.

enter image description here

\documentclass{article}
\usepackage{CJKutf8}
\usepackage{verbatim}
\makeatletter
\def\verbatim@processline{%
\edef\tmp{\expandafter\cjkpad\the\verbatim@line\relax}
\tmp}

\def\cjkpad#1{%
\ifx\relax#1\par
\else
\ifnum\expandafter`\noexpand#1<128 %
\noexpand\makebox[2\noexpand\width]{\noexpand#1}%
\else
\noexpand#1%
\fi
\expandafter\cjkpad
\fi}
\makeatother
\begin{document}
\begin{CJK*}{UTF8}{bsmi}

\makeatletter

中華人民共和國

ABC-1234


\begin{verbatim}
中華人民共和國
ABC-1234
\end{verbatim}
\end{CJK*}
\end{document}
  • it works fine, but with a value 1.9 instead of 2 it looks better for me. – Micha Apr 16 '13 at 17:47
1
% UTF-8 encoding
% Compile with XeLaTeX
\documentclass{article}

\usepackage{xeCJK}

% Specify a Chinese font that contains all characters you need.
\setCJKmainfont{SimSun}

\begin{document}
中華人民共和國

ABC-1234

A fullwidth character is twice as wide as a halfwidth character:
\begin{verbatim}
|中華人民共和國|
|ABC-1234......|
\end{verbatim}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.