Chinaunix

标题: TeXLive中英文混排的间隔处理 [打印本页]

作者: zhiyizhi    时间: 2009-12-26 20:22
标题: TeXLive中英文混排的间隔处理
1. 采用CJKspace包,用的时候,首先把.emacs里面的适当位置添加如下内容
;; You should put the following in your .emacs file (additionally to the
;; common AUCTeX adaptations):
;;
;;   (autoload 'CJK-insert-space "cjkspace"
;;     "Insert tildes appropriately in CJK document." t)
;;    (defun my-LaTeX-mode-hook ()
;;     "Key definitions for LaTeX mode."
;;     (define-key LaTeX-mode-map " " 'CJK-insert-space)
;;     )
;;   (add-hook 'LaTeX-mode-hook 'my-LaTeX-mode-hook)
;;; Code:
(provide 'cjkspace)
(defvar CJK-space "~")
(defvar CJK-space-after-space nil
  "*If non-nil, typing a space yields a space.  Typing two consecutive
spaces yields a tilde.  If nil the behaviour is reversed.")
(make-variable-buffer-local 'CJK-space-after-space)
;;;###autoload
(defun CJK-insert-space (arg)
  "Insert tilde characters instead of spaces for LaTeX CJK documents.
If `CJK-space-after-space' is non-nil, typing a space yields a space.
Typing two consecutive spaces yields a tilde.  If `CJK-space-after-space'
is nil, the behaviour is reversed.
With prefix argument, always inserts space characters."
  (interactive "*P")
  (if arg
      (self-insert-command (prefix-numeric-value arg))
    (TeX-update-style)
    (if CJK-space-after-space
        (insert (cond ((bobp)
                       ?\ )
                      ((not (= (preceding-char) ?\ ))
                       ?\ )
                      ((and (> (point) 2)
                          (save-excursion
                             (forward-char -2)
                             (looking-at (concat "[" CJK-space
                                                 (regexp-quote TeX-esc) "]"))))
                           ?\ )
                      (t
                       (delete-backward-char 1)
                       CJK-space)))
      (insert (cond ((bobp)
                     ?\ )
                    ((= (preceding-char) (string-to-char TeX-esc))
                     ?\ )
                    ((= (preceding-char) ?\ )
                     ?\ )
                    ((and (> (point) 2)
                        (save-excursion
                           (forward-char -2)
                           (looking-at (concat (regexp-quote TeX-esc)
                                               CJK-space))))
                         CJK-space)
                    ((= (preceding-char) (string-to-char CJK-space))
                     (delete-backward-char 1)
                     ?\ )
                    (t
                     CJK-space))))))
;;; EOF
2.   用法:
     实例:
\documentclass[11pt]{article}
\usepackage{CJK}\usepackage{CJKspace}
\begin{document}
\parindent 2em
\begin{CJK*}{UTF8}{gbsn}
这是 English 中文 \textit{Chinese} 中文 {\itshape Italic} 数学 $x=y$
  混排 \verb+anything+
这是English中文\textit{Chinese}中文{\itshape Italic}数学$x=y$
混排\verb+anything+
这是~English~中文~\textit{Chinese}~中文~{\itshape Italic}~数学~$x=y$~混排~\verb+anything+
  混排 \verb+anything+ 保持 \texttt{spaces} 空格 \LaTeX\ 间隔
  \mbox{boxes} 盒子 \hbox{hbox} 中文 123456 数字.
\end{CJK*}
\end{document}
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/74418/showart_2131646.html




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2