Latex编译中中文问题

我用的就是texilve2018,xelatex应该是texlive的一部分吧。我安装了texlive2018 就直接能用xelatex了,是要设置一下,告诉emacs用哪个编译器。具体怎么设置,网上很多教程的。我记不清了,现在。

也不是pdflatex一定不行,必须得用xelatex,只不过后者简单。如下,可以用pdflatex编译:

\documentclass{article}
\usepackage{CJKutf8}
\begin{document}
\begin{CJK*}{UTF8}{gbsn}
文章内容。
\end{CJK*}
\end{document}

可以看到它不好的地方,中文必须放到特定(CJK)的environment中。

“月经贴”怎么就无德了?

他思维很活跃吧 :joy:

安装texlive2018, 用xelatex。 不用pdflatex 参考一个带中文的ppt(和pdf一样)

1 个赞

这个可以这样设置:

  ;; 使用xelatex一步生成PDF,不是org-latex-to-pdf-process这个命令
  (setq org-latex-pdf-process
        '(
	  "xelatex -shell-escape -interaction nonstopmode -output-directory %o %f"
	  "xelatex -shell-escape -interaction nonstopmode -output-directory %o %f"
	  "xelatex -shell-escape -interaction nonstopmode -output-directory %o %f"
	  "rm -fr %b.out %b.log %b.tex auto"
	  ))
  ;; 设置默认后端为 `xelatex'
  (setq org-latex-compiler "xelatex")

如果在windows上,我估计装好对应软件,然后设置好xelatex就可以了。如果是在linux上,可能还会遇到字体的问题。我之前做了一个小的总结:

这里

1 个赞

xelatex 的缺点不是慢吗?我用 pdflatex 写中文文档挺好,编译速度可能稍快。

pdflatex是相对原始一点,xelatex新一点,支持Unicode,可以使用系统的字体。

问一下各位大佬,我安装的texlive2019(官网编译的),但是有个问题就是,我在windows下面,可以正常运行pdf test.tex命令生成pdf文件,test.tex内容如下:

\documentclass[UTF8]{ctexart} \begin{document}

文章内容。

\end{document}

但是为什么我的ubuntu18.04,运行同样的命令确会出现会出现:CTeX fontset `fandol’ is unavailable in current(ctex) mode. 这个错误是什么原因导致的呢?有大佬能解答一下吗。

ubuntu 下面默认用的 fandol 字体集。你机器上可能没有。

\usepackage[UTF8, fontset=ubuntu]{ctexart}

试试,这个会使用 ubuntu 下面的文泉驿相关字体。

具体可以使用

texdoc  ctex

找 ctex 的文档看关于字体的那节

为什么我下载了fandol字符集,依旧是报同样的错误呢?

解决了我的问题,感谢

https://tug.org/texlive/doc/texlive-en/texlive-en.html#x1-340003.4.4

非常感谢,按你的提示 org 可以导出为 PDF了,并且支持中文。

这里总结下在 Windows 和 macOS 平台下的配置,其他平台应该也差不多:

  1. 安装 texlive,安装时间会有点长,Windows下占用空间 7.91G

macOS 用户如果使用 macports 可以用下面的两个命令安装:

sudo port install texlive
sudo port install texlive-lang-chinese
  1. Emacs 中设置使用 xelatex
(use-package ox-latex
  :after org
  :custom
  (org-latex-compiler "xelatex")
  (org-latex-pdf-process
   '("xelatex -shell-escape -interaction nonstopmode -output-directory %o %f"
     "xelatex -shell-escape -interaction nonstopmode -output-directory %o %f"
     "xelatex -shell-escape -interaction nonstopmode -output-directory %o %f"
     "rm -fr %b.out %b.log %b.tex auto"))
  (org-latex-packages-alist
   '("\\usepackage{fontspec} \\usepackage{xeCJK} \\setmainfont{Times New Roman} \\setCJKmainfont{微软雅黑}")))

macOS 用户可以把 “微软雅黑” 改为其他 macOS 有的中文字体,比如 “PingFang SC”

注意,如果org 文档中有带下划线的英文字符,要在org文件头加入下面的设置:

#+OPTIONS: ^:nil

比如在 org 文件中是这样:

- *gauging_show_data_file:* 显示数据文档

在 PDF 中如果没加 #+OPTIONS: ^:nil 会显示成下面这样:

参考文档:https://orgmode.org/manual/Subscripts-and-Superscripts.html

2 个赞

这个相当有用!!

但这部分的设置有些疑问:

这个知乎讨论中提到了尽量避免使用xeCJK而是使用ctex作为替代

我也是刚开始用,我是参考了前面楼的设置。

刚试用了下ctex, 也好使。ctex 有什么优势吗?

\\usepackage{ctex}

其实只需要用ctexart class然后用xelatex编译就行了,其他什么都不用设置,header部分不用额外加东西。

至于一些细致的定制,去看一下ctex的包文档,中文的。

XeCJK 的标点,断行不符合中文排版习惯,只提供最基本的显示汉字的功能,ctex 类会在 XeCJK 上做封装并提供汉字相关的长度单位和字号大小,并对默认模版做了汉化。

当然,用 TeX 做对格式要求比较严谨的中文排版一般会去折腾 LuaTeX 或者 UpTeX,这方面其实还是日本人做的好用。

1 个赞

感谢大佬指点。看来这个几年前的信息果然过时了。

Emacs 中要怎么设置呢?定制这个 org-latex-classes

ctex的包文档能否给个链接?我是看看。

Ctex文档

http://mirrors.ctan.org/language/chinese/ctex/ctex.pdf

(setq org-latex-compiler "xelatex")
(setq org-latex-pdf-process
	    '("latexmk -f -pdf -xelatex -interaction=nonstopmode -output-directory=%o %f"))
(add-to-list 'org-latex-classes
		   '("ctexart"
		     "\\documentclass[UTF8, a4paper]{ctexart}
		[NO-DEFAULT-PACKAGES]
		[PACKAGES]
		[EXTRA]
"
		     ("\\section{%s}" . "\\section*{%s}")
		     ("\\subsection{%s}" . "\\subsection*{%s}")
		     ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
		     ("\\paragraph{%s}" . "\\paragraph*{%s}")
		     ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
      (setq org-latex-default-class "ctexart")


我用了latexmk,texlive里面都有。这样应该直接编译中文,org文件里什么都不配置都能导出成中文PDF。

2 个赞