页面

2013年1月4日星期五

org-mode+beamer CJK解决方案

org-mode+beamer CJK解决方案

1 xetex

今天查了不少资料,终于弄出一个比较满意的方案了。一直回避用latex处理中日文,果然好麻烦啊,字体控制什么的,原理一点不懂,有时间再恶补一下。

此方案使用基于utf-8的xetex引擎处理中文。 为此要注意文件本身要用utf-8编码, 并用xelatex编译。

1.1 .emacs

1.1.1 把emacs的默认文件编码改为utf-8

(setq default-buffer-file-coding-system 'utf-8)

1.1.2 把org-mode的latex引擎改为xelatex

(setq org-latex-to-pdf-process
      '("xelatex -interaction=nonstopmode %f" "xelatex -interaction=nonstopmode %f"))

1.1.3 修改org-export-latex-default-packages-alist,去掉package inputenc,否则与xeCJK冲突

(add-hook 'org-mode-hook
          (lambda ()
            (setq org-export-latex-default-packages-alist
                  (delete '("AUTO" "inputenc" t) org-export-latex-default-packages-alist))
            ))

1.1.4 增加@表示alert的支持

(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(org-emphasis-alist
   (quote (("*" bold "<b>" "</b>")
           ("/" italic "<i>" "</i>")
           ("_" underline "<span style=\"text-decoration:underline;\">" "</span>")
           ("=" org-code "<code>" "</code>" verbatim)
           ("~" org-verbatim "<code>" "</code>" verbatim)
           ("+" (:strike-through t) "<del>" "</del>")
           ("@" org-warning "<b>" "</b>")
           )))
 '(org-export-latex-emphasis-alist
   (quote (("*" "\\textbf{%s}" nil)
           ("/" "\\emph{%s}" nil)
           ("_" "\\underline{%s}" nil)
           ("+" "\\st{%s}" nil)
           ("=" "\\protectedtexttt" t)
           ("~" "\\verb" t)
           ("@" "\\alert{%s}" nil)
           ))))
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 )

1.1.5 org-mode导出latex后与auctex的冲突

(setq-default TeX-master nil)

1.2 xeCJK

用xeCJK负责字体管理。注意与inputenc冲突。把这部分代码放在org文件中,由YASnippet自动生成。

1.2.1 全体

# -*- mode: snippet -*-
# name: cjkbeamer
# key: cjkbeamer
# --
# -*- coding: utf-8; -*-
#+TITLE: ${1:标题}
#+AUTHOR: ${2:作者}
#+DATE: ${3:}

#+OPTIONS:  H:3 num:t toc:nil \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t
#+OPTIONS:  TeX:t LaTeX:t skip:nil d:nil todo:t pri:nil tags:not-in-toc

#+STARTUP: beamer
#+STARTUP: showall
#+LaTeX_CLASS: beamer
#+LATEX_CLASS_OPTIONS: [xcolor=svgnames]
#+BEAMER_FRAME_LEVEL: 2
#+COLUMNS: %40ITEM %10BEAMER_env(Env) %10BEAMER_envargs(Env Args) %4BEAMER_col(Col) %8BEAMER_extra(Extra)

#+LATEX_HEADER: \usecolortheme[named=SeaGreen]{structure}
#+LATEX_HEADER: \usetheme{Antibes}
#+LATEX_HEADER: \setbeamertemplate{footline}[frame number]
#+LATEX_HEADER: \setbeamertemplate{navigation symbols}{}
#+LATEX_HEADER: \AtBeginSection {\begin{frame}{大纲} \tableofcontents[currentsection] \end{frame}}
#+LATEX_HEADER: \usepackage{xeCJK}
#+LATEX_HEADER: \setCJKmainfont{${4:SimSun}}
#+LATEX_HEADER: \setCJKsansfont{$4}
#+LATEX_HEADER: \setCJKmonofont{$4}

$0

1.2.2 UTF-8

告诉emacs本文件用UTF-8。 与.emacs中不同,只设置本文件。 emacs命令是add-file-local-variable-prop-line。

# -*- coding: utf-8; -*-

1.2.3 xeCJK

xetex直接查找系统的字体。 用fc-list确定可用的字体名。 一般article正文是mainfont, 但beamer里的多是sansfont。

#+LATEX_HEADER: \usepackage{xeCJK}
#+LATEX_HEADER: \setCJKmainfont{${4:MS Gothic}}
#+LATEX_HEADER: \setCJKsansfont{$4}
#+LATEX_HEADER: \setCJKmonofont{$4}

1.2.4 Beamer

其余部分是Beamer的习惯设定。

Date: 2013-01-04 19:26:16 東京 (標準時)

Author: jiongny

Org version 7.8.11 with Emacs version 24

Validate XHTML 1.0

没有评论: