Latex编译中中文问题

好的,谢谢。

能问一下,emacs中如何将texLive修改为XeLaTex吗?

确实不支持中文,能编译成功的也中文也显示。

月经贴。。。

话可以无用,但不可以无德。

我再网上找到的解决办法。 我用的环境是 ubuntu 16.04 + emacs 27.00 + texlive2018

主要是要加4句话: \usepackage{fontspec} \usepackage{xeCJK} \setmainfont{Times} ;; 英语用什么字体,前提是你的机器上有这个字体 \setCJKmainfont{BiauKai};;汉语用什么字体,要求同上,百度一下很多办法能导入字体。

上面的方法出处:http://moser-isi.ethz.ch/manuals.html 下面是一个完整例子。 \documentclass[a4paper,12pt]{article}

	\usepackage{fontspec}
	\usepackage{xeCJK}
	\setmainfont{Times}
	\setCJKmainfont{BiauKai}
	
	\begin{document}
	
	Simply type some Chinese text like 莫詩台方 and English text intermixed.
	
	\end{document}
2 个赞

我用的就是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 个赞