Difference between revisions of "TeX Live and CJK"

From ArchWiki
Jump to: navigation, search
m (<tt>text</tt> -> {{Codeline|text}})
(4 intermediate revisions by 3 users not shown)
Line 1: Line 1:
[[Category:TeX (English)]]
+
[[Category:TeX]]
The below tutorial guides you through getting your Tex to work with the Cyberbit font. If you don't much care what font you use, just make sure you have the texlive-langcjk package installed, and add this to your preamble:
+
The below tutorial guides you through getting your Tex to work with the Cyberbit font. If you do not much care what font you use, just make sure you have the texlive-langcjk package installed, and add this to your preamble:
  
 
  \usepackage[encapsulated]{CJK}
 
  \usepackage[encapsulated]{CJK}
Line 14: Line 14:
  
 
== Goals ==
 
== Goals ==
This Tutorial is supposed to explain how to configure your TeXlive Installation to successfully include CJK (Chinese, Japanese and Korean) Characters in your compiled TeX-files. This tutorial is based on the  [http://kile.sourceforge.net/Documentation/html/cjk.html Kile-HowTo on CJK Support]. The problem with the kile-tutorial (which nevertheless is very good) is the loose definition of the file and folder structure (for it is, as I think, written to be used for any TeX-distribution). Long story short, using the kile-tutorial, it might take you a couple of hours to find the appropriate places to store and configure your CJK-installation (at least when using TeXlive). Hope this helps you to avoid this hassle.
+
This Tutorial is supposed to explain how to configure your [[TeX Live]] Installation to successfully include CJK (Chinese, Japanese and Korean) Characters in your compiled TeX-files. This tutorial is based on the  [http://kile.sourceforge.net/Documentation/html/cjk.html Kile-HowTo on CJK Support]. The problem with the kile-tutorial (which nevertheless is very good) is the loose definition of the file and folder structure (for it is, as I think, written to be used for any TeX-distribution). Long story short, using the kile-tutorial, it might take you a couple of hours to find the appropriate places to store and configure your CJK-installation (at least when using TeXlive). Hope this helps you to avoid this hassle.
  
 
== Prerequisites ==
 
== Prerequisites ==
First, you need a working [http://wiki.archlinux.org/index.php/Texlive TeXlive installation], including the texlive-langcjk package. (In case you haven't done so already, use pacman to install them) and [http://wiki.archlinux.org/index.php/Fonts appropriate fonts]. This are the prerequisites on the TeX-part. Needless to say, you should have chosen a character encoding for your system which can deal with complex characters (like UTF8) and some kind of input method for these, like [http://wiki.archlinux.org/index.php/Scim scim].
+
First, you need a working [[TeX Live|TeXlive installation]], including the {{pkg|texlive-langcjk}} package. (In case you haven't done so already, use [[pacman]] to install them) and [[Fonts| appropriate fonts]]. This are the prerequisites on the TeX-part. Needless to say, you should have chosen a character encoding for your system which can deal with complex characters (like UTF8) and some kind of input method for these, like [[Scim]].
  
 
== The steps ==
 
== The steps ==
# Download and configure a CJK Font for your TeXlive distribution. Like done in the kile-tutorial we use the Cyberbit font. Create an empty folder, download the [ftp://ftp.netscape.com/pub/communicator/extras/fonts/windows/Cyberbit.ZIP Zip-file] and unpack it into the folder. Then rename the file named {{Codeline|Cyberbit.ttf}} to {{Codeline|cyberbit.ttf}} and download [http://delloye.free.fr/Unicode.sfd this file] into the same folder. Using the command <br>{{Codeline|$ ttf2tfm cyberbit.ttf -w cyberbit@Unicode@}}<br> you create some dozens (if not hundreds) of *.tfm files and their corresponding *.enc files.
+
# Download and configure a CJK Font for your TeXlive distribution. Like done in the kile-tutorial we use the Cyberbit font. Create an empty folder, download the [ftp://ftp.netscape.com/pub/communicator/extras/fonts/windows/Cyberbit.ZIP Zip-file] and unpack it into the folder. Then rename the file named {{Ic|Cyberbit.ttf}} to {{Ic|cyberbit.ttf}} and download [http://delloye.free.fr/Unicode.sfd this file] into the same folder. Using the command <br>{{Ic|$ ttf2tfm cyberbit.ttf -w cyberbit@Unicode@}}<br> you create some dozens (if not hundreds) of *.tfm files and their corresponding *.enc files.
# Now, we need folders in the TeXlive-filetree to copy the *.tfm and the *.enc files to their right places. (in the following I presume you have superuser-rights and are in the folder containing the *.tfm and *.enc files.)<br>{{Codeline|$ mkdir /usr/share/texmf-dist/fonts/tfm/cyberbit <br>$ chmod 755 /usr/share/texmf-dist/fonts/tfm/cyberbit <br>$ cp *.tfm /usr/share/texmf-dist/fonts/tfm/cyberbit/ <br>$ chmod 644 /usr/share/texmf-dist/fonts/tfm/cyberbit/* <br>$ mkdir /usr/share/texmf-dist/fonts/enc/pdftex/cyberbit <br>$ chmod 755 /usr/share/texmf-dist/fonts/enc/pdftex/cyberbit <br>$ cp *.enc /usr/share/texmf-dist/fonts/enc/pdftex/cyberbit/ <br>$ chmod 644 /usr/share/texmf-dist/fonts/enc/pdftex/cyberbit/* }}
+
# Now, we need folders in the TeXlive-filetree to copy the *.tfm and the *.enc files to their right places. (in the following I presume you have superuser-rights and are in the folder containing the *.tfm and *.enc files.)<br>{{Ic|$ mkdir /usr/share/texmf-dist/fonts/tfm/cyberbit <br>$ chmod 755 /usr/share/texmf-dist/fonts/tfm/cyberbit <br>$ cp *.tfm /usr/share/texmf-dist/fonts/tfm/cyberbit/ <br>$ chmod 644 /usr/share/texmf-dist/fonts/tfm/cyberbit/* <br>$ mkdir /usr/share/texmf-dist/fonts/enc/pdftex/cyberbit <br>$ chmod 755 /usr/share/texmf-dist/fonts/enc/pdftex/cyberbit <br>$ cp *.enc /usr/share/texmf-dist/fonts/enc/pdftex/cyberbit/ <br>$ chmod 644 /usr/share/texmf-dist/fonts/enc/pdftex/cyberbit/*}}
 
# Next, we need to install a map file connecting the *.enc files to the font. Download [http://delloye.free.fr/cyberbit.map cyberbit.map].
 
# Next, we need to install a map file connecting the *.enc files to the font. Download [http://delloye.free.fr/cyberbit.map cyberbit.map].
## In case the folder {{Codeline|/usr/share/texmf-config/pdftex/config/}} does not exist, create it: <br>{{Codeline|$ mkdir /usr/share/texmf-config/pdftex <br>$ mkdir /usr/share/texmf-config/pdftex/config <br>$ chmod -R 755 /usr/share/texmf-config/pdftex }}
+
## In case the folder {{Ic|/usr/share/texmf-config/pdftex/config/}} does not exist, create it: <br>{{Ic|$ mkdir /usr/share/texmf-config/pdftex <br>$ mkdir /usr/share/texmf-config/pdftex/config <br>$ chmod -R 755 /usr/share/texmf-config/pdftex}}
## Then copy the .map file into that folder: <br>{{Codeline|$ cp cyberbit.map /usr/share/texmf-config/pdftex/config/ <br>$ chmod 644 /usr/share/texmf-config/pdftex/config/cyberbit.map }}
+
## Then copy the .map file into that folder: <br>{{Ic|$ cp cyberbit.map /usr/share/texmf-config/pdftex/config/ <br>$ chmod 644 /usr/share/texmf-config/pdftex/config/cyberbit.map}}
 
# Then we need a file named c70cyberbit.fd you can download [http://delloye.free.fr/c70cyberbit.fd here].
 
# Then we need a file named c70cyberbit.fd you can download [http://delloye.free.fr/c70cyberbit.fd here].
## Create an appropriate folder (again, if it does not exist):<br>{{Codeline|$ mkdir /usr/share/texmf-dist/tex/misc <br>$ chmod 755 /usr/share/texmf-dist/tex/misc }}
+
## Create an appropriate folder (again, if it does not exist):<br>{{Ic|$ mkdir /usr/share/texmf-dist/tex/misc <br>$ chmod 755 /usr/share/texmf-dist/tex/misc}}
## And copy the file into it:<br>{{Codeline|$ cp c70cyberbit.fd /usr/share/texmf-dist/tex/misc/ <br>$ chmod 644 /usr/share/texmf-dist/tex/misc/c70cyberbit.fd }}
+
## And copy the file into it:<br>{{Ic|$ cp c70cyberbit.fd /usr/share/texmf-dist/tex/misc/ <br>$ chmod 644 /usr/share/texmf-dist/tex/misc/c70cyberbit.fd}}
# The font itself is still missing in the TeX-distribution tree:<br>{{Codeline|$ cp cyberbit.ttf /usr/share/texmf-dist/fonts/truetype/ <br>$ chmod 644 /usr/share/texmf-dist/fonts/truetype/cyberbit.ttf }}
+
# The font itself is still missing in the TeX-distribution tree:<br>{{Ic|$ cp cyberbit.ttf /usr/share/texmf-dist/fonts/truetype/ <br>$ chmod 644 /usr/share/texmf-dist/fonts/truetype/cyberbit.ttf}}
# To make sure that TeX will find the font, we have to add the truetype-folder into the TeX-config. To do so, edit {{Codeline|/usr/share/texmf/web2c/texmf.cnf}} and look for an entry called "TTFONTS", which should look like this: <br>{{Codeline|1=TTFONTS = .;$TEXMF/fonts/truetype//;$OSFONTDIR/TTF//}}<br>Although maybe not very elegant, I added {{Codeline|/usr/share/texmf-dist/fonts/truetype//}} to the end of the line, so that TeX will find the font for sure:<br>{{Codeline|1= TTFONTS = .;$TEXMF/fonts/truetype//;$OSFONTDIR/TTF//;/usr/share/texmf-dist/fonts/truetype//}}
+
# To make sure that TeX will find the font, we have to add the truetype-folder into the TeX-config. To do so, edit {{Ic|/usr/share/texmf/web2c/texmf.cnf}} and look for an entry called "TTFONTS", which should look like this: <br>{{Ic|1=TTFONTS = .;$TEXMF/fonts/truetype//;$OSFONTDIR/TTF//}}<br>Although maybe not very elegant, I added {{Ic|/usr/share/texmf-dist/fonts/truetype//}} to the end of the line, so that TeX will find the font for sure:<br>{{Ic|1= TTFONTS = .;$TEXMF/fonts/truetype//;$OSFONTDIR/TTF//;/usr/share/texmf-dist/fonts/truetype//}}
# Although I am not sure we really need this, I created a file called "pdftex.cfg" in the folder {{Codeline|/usr/share/texmf-config/pdftex/config/}} and added a line saying:<br>{{Codeline|map +cyberbit.map}}
+
# Although I am not sure we really need this, I created a file called "pdftex.cfg" in the folder {{Ic|/usr/share/texmf-config/pdftex/config/}} and added a line saying:<br>{{Ic|map +cyberbit.map}}
# TeX still does not know that it should by now be able to handle CJK input, until we edit {{Codeline|/usr/share/texmf/fonts/map/ttf2pk/config/ttfonts.map}} to include the following lines (if they already exist, all you have to do is to uncomment them):<br>{{Codeline| cyberb@Unicode@ cyberbit.ttf<br>cyberbit@Unicode@ cyberbit.ttf}}
+
# TeX still does not know that it should by now be able to handle CJK input, until we edit {{Ic|/usr/share/texmf/fonts/map/ttf2pk/config/ttfonts.map}} to include the following lines (if they already exist, all you have to do is to uncomment them):<br>{{Ic| cyberb@Unicode@ cyberbit.ttf<br>cyberbit@Unicode@ cyberbit.ttf}}
# To finish the configuration, run <br>{{Codeline|$ texhash}} <br>
+
# To finish the configuration, run <br>{{Ic|$ texhash}} <br>
  
 
Hopefully this tutorial will spare you the hours of work I spent configuring CJK in TeX.
 
Hopefully this tutorial will spare you the hours of work I spent configuring CJK in TeX.

Revision as of 13:13, 13 June 2012

The below tutorial guides you through getting your Tex to work with the Cyberbit font. If you do not much care what font you use, just make sure you have the texlive-langcjk package installed, and add this to your preamble:

\usepackage[encapsulated]{CJK}
\usepackage{ucs}
\usepackage[utf8x]{inputenc}
% use one of bsmi(trad Chinese), gbsn(simp Chinese), min(Japanese), mj(Korean); see:
% /usr/share/texmf-dist/tex/latex/cjk/texinput/UTF8/*.fd
\newcommand{\cntext}[1]{\begin{CJK}{UTF8}{gbsn}#1\end{CJK}}

and then encapsulate your CJK in \cntext.

\cntext{我的中文寫得很好。}

Goals

This Tutorial is supposed to explain how to configure your TeX Live Installation to successfully include CJK (Chinese, Japanese and Korean) Characters in your compiled TeX-files. This tutorial is based on the Kile-HowTo on CJK Support. The problem with the kile-tutorial (which nevertheless is very good) is the loose definition of the file and folder structure (for it is, as I think, written to be used for any TeX-distribution). Long story short, using the kile-tutorial, it might take you a couple of hours to find the appropriate places to store and configure your CJK-installation (at least when using TeXlive). Hope this helps you to avoid this hassle.

Prerequisites

First, you need a working TeXlive installation, including the texlive-langcjk package. (In case you haven't done so already, use pacman to install them) and appropriate fonts. This are the prerequisites on the TeX-part. Needless to say, you should have chosen a character encoding for your system which can deal with complex characters (like UTF8) and some kind of input method for these, like Scim.

The steps

  1. Download and configure a CJK Font for your TeXlive distribution. Like done in the kile-tutorial we use the Cyberbit font. Create an empty folder, download the Zip-file and unpack it into the folder. Then rename the file named Cyberbit.ttf to cyberbit.ttf and download this file into the same folder. Using the command
    $ ttf2tfm cyberbit.ttf -w cyberbit@Unicode@
    you create some dozens (if not hundreds) of *.tfm files and their corresponding *.enc files.
  2. Now, we need folders in the TeXlive-filetree to copy the *.tfm and the *.enc files to their right places. (in the following I presume you have superuser-rights and are in the folder containing the *.tfm and *.enc files.)
    $ mkdir /usr/share/texmf-dist/fonts/tfm/cyberbit
    $ chmod 755 /usr/share/texmf-dist/fonts/tfm/cyberbit
    $ cp *.tfm /usr/share/texmf-dist/fonts/tfm/cyberbit/
    $ chmod 644 /usr/share/texmf-dist/fonts/tfm/cyberbit/*
    $ mkdir /usr/share/texmf-dist/fonts/enc/pdftex/cyberbit
    $ chmod 755 /usr/share/texmf-dist/fonts/enc/pdftex/cyberbit
    $ cp *.enc /usr/share/texmf-dist/fonts/enc/pdftex/cyberbit/
    $ chmod 644 /usr/share/texmf-dist/fonts/enc/pdftex/cyberbit/*
  3. Next, we need to install a map file connecting the *.enc files to the font. Download cyberbit.map.
    1. In case the folder /usr/share/texmf-config/pdftex/config/ does not exist, create it:
      $ mkdir /usr/share/texmf-config/pdftex
      $ mkdir /usr/share/texmf-config/pdftex/config
      $ chmod -R 755 /usr/share/texmf-config/pdftex
    2. Then copy the .map file into that folder:
      $ cp cyberbit.map /usr/share/texmf-config/pdftex/config/
      $ chmod 644 /usr/share/texmf-config/pdftex/config/cyberbit.map
  4. Then we need a file named c70cyberbit.fd you can download here.
    1. Create an appropriate folder (again, if it does not exist):
      $ mkdir /usr/share/texmf-dist/tex/misc
      $ chmod 755 /usr/share/texmf-dist/tex/misc
    2. And copy the file into it:
      $ cp c70cyberbit.fd /usr/share/texmf-dist/tex/misc/
      $ chmod 644 /usr/share/texmf-dist/tex/misc/c70cyberbit.fd
  5. The font itself is still missing in the TeX-distribution tree:
    $ cp cyberbit.ttf /usr/share/texmf-dist/fonts/truetype/
    $ chmod 644 /usr/share/texmf-dist/fonts/truetype/cyberbit.ttf
  6. To make sure that TeX will find the font, we have to add the truetype-folder into the TeX-config. To do so, edit /usr/share/texmf/web2c/texmf.cnf and look for an entry called "TTFONTS", which should look like this:
    TTFONTS = .;$TEXMF/fonts/truetype//;$OSFONTDIR/TTF//
    Although maybe not very elegant, I added /usr/share/texmf-dist/fonts/truetype// to the end of the line, so that TeX will find the font for sure:
    TTFONTS = .;$TEXMF/fonts/truetype//;$OSFONTDIR/TTF//;/usr/share/texmf-dist/fonts/truetype//
  7. Although I am not sure we really need this, I created a file called "pdftex.cfg" in the folder /usr/share/texmf-config/pdftex/config/ and added a line saying:
    map +cyberbit.map
  8. TeX still does not know that it should by now be able to handle CJK input, until we edit /usr/share/texmf/fonts/map/ttf2pk/config/ttfonts.map to include the following lines (if they already exist, all you have to do is to uncomment them):
    cyberb@Unicode@ cyberbit.ttf
    cyberbit@Unicode@ cyberbit.ttf
  9. To finish the configuration, run
    $ texhash

Hopefully this tutorial will spare you the hours of work I spent configuring CJK in TeX.

Remarks

This procedure was tested with the following packages:
extra/texlive-core 2008.11906-1
extra/texlive-langcjk 2008.10331-1
And simplified Chinese characters.