From c59d2f9adfa5b191a9fbe38e70fe2bdc11ec5b70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20K=C3=BCster?= Date: Sun, 10 Mar 2019 14:16:23 +0100 Subject: [PATCH] basic CJK support added --- cjk/README.md | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++ cjk/cjk.tex | 54 +++++++++++++++++++++++++++++++++++++ 2 files changed, 129 insertions(+) create mode 100644 cjk/README.md create mode 100644 cjk/cjk.tex diff --git a/cjk/README.md b/cjk/README.md new file mode 100644 index 0000000..c7298fd --- /dev/null +++ b/cjk/README.md @@ -0,0 +1,75 @@ +# Chinese, Japanese, Korean (CJK) Language Support + +## Installation + +At first you need to have the CJK LaTeX packages to be installed on your system. + +The easiest way is to install install all packages for Chinese, Japanese and KoreaN (CJK) from the apt repositories (Ubuntu Linux): + + +```bash +sudo apt-get install latex-cjk-all +``` + +Or install language specific packages: + +Chinese only: + +```bash +sudo apt-get install texlive-lang-chinese +``` + +Japanese only: + +```bash +sudo apt-get install texlive-lang-japanese +``` + +Korean only: + +```bash +sudo apt-get install texlive-lang-korean +``` + +(Pull requests with installation instructions for other OS are much appreciated.) + +## Import and use the CJK environment + +Considering the structure of this repository you can include the `cjk.tex` using the `\input` command using a relative path. You also need to define a `\cjklang` variable, that defines the character set to use. + +``` +\documentclass[10pt,A4]{article} % just added to demonstrate where to put the \def and input +\usepackage[utf8]{inputenc} % just added to demonstrate where to put the \def and input +\def \cjklang {gbsn} % defines to use gbsn simplified Chinese for this document +\input{../cjk/cjk.tex} % includes the CJK setup script. +% ... +``` + +That's it. + +You can use for `\cjklang` one of the following options: + +* Simplified Chinese: `gbsn`or `gkai` +* Traditional Chinese: `bmsi` or `bkai` +* Japnese: `min` (Mincho), `goth` (Gothic) or `maru` (Maru Gothic) +* Korean: `mj` for MyongJu + +Note, that there is no need to place the CJK environment inside the document. It is automatically done when including the `cjk.tex` file. The `cjk.tex` script uses the `\AfterEndPreamble` and `\AtEndDocument` hooks to place the environment at the very beginning and end of the document. +If you need more granular environments (e.g. mixing two or more) you can deactivate these hooks and use the `\begin{cjkenv}` and `\end{cjkenv}` in a custom way. + +## Troubleshooting + +The `cjk.tex` includes the `CJKutf8` package in order to cross-support the typesetting with the UTF-8 based typesetting of the `main.tex` files of the templates. If there is trouble in displaying characters, this may be your first source for troubleshooting. + +If there are errors like + +``` +! PACKAGE INPUTENC ERROR: UNICODE CHAR Ņ� (U+5173) +(INPUTENC) NOT SET UP FOR USE WITH LATEX. + +SEE THE INPUTENC PACKAGE DOCUMENTATION FOR EXPLANATION. +Type H for immediate help. +``` + +it may be caused, due to the use of the environment inside a header defining command like `\section`. +For troubleshooting such issues see this post: https://tex.stackexchange.com/questions/478696/is-there-a-way-to-make-fancyhdr-with-pagestyle-fancy-to-be-compatible-with-chine diff --git a/cjk/cjk.tex b/cjk/cjk.tex new file mode 100644 index 0000000..45c2f64 --- /dev/null +++ b/cjk/cjk.tex @@ -0,0 +1,54 @@ +%-----------------------------------------------------------------------------------------------------------------------------------------------% +% The MIT License (MIT) +% +% Copyright (c) 2019 Jan Küster +% +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: +% +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +% THE SOFTWARE. +% +% +%-----------------------------------------------------------------------------------------------------------------------------------------------% + +%---------------------------------------------------------------------------------------- +% BASE PACKAGE FOR CHINESE, JAPANESE, KOREAN +%---------------------------------------------------------------------------------------- +\usepackage{CJKutf8} +\usepackage{etoolbox} + + + +\def \cjklang {cjklang is not set} + +% TYPESETTING DEFINITIONS +% Define the \cjklang inside your document using one of the following options: + +% CHINESE TYPESTTING +% use gbsn or gkai for simplified Chinese +% use bmsi or bkai for traditional Chinese + +% JAPANESE TYPESETTING +% use min Mincho +% use goth for Gothic +% use maru for Maru Gothic + +% KOREAN TYPESETTING +% use mj for MyongJu + +\newenvironment{cjkenv}[1]{\begin{CJK*}{UTF8}{\cjklang}}{\end{CJK*}} + + +% place environment inside document via hooks +\AfterEndPreamble{\begin{cjkenv}} +\AtEndDocument{\end{cjkenv}} \ No newline at end of file