CTeX-org / forum

A temporarily alternate forum of `bbs.ctex.org`
https://t.me/chinesetex
Apache License 2.0
210 stars 16 forks source link

Error: Undefined control sequence #275

Closed huiliu-overleaf closed 1 year ago

huiliu-overleaf commented 1 year ago

检查

编译环境

描述问题

## 最小工作示例(MWE)

这是一个中文版的学位论文的模本,里面的内容已经删减到可以复现该错误,为了方便大家查看错误,我上传到overleaf了,链接是https://www.overleaf.com/7347856442mjkrppbmczzn

(用 XeLaTeX 编译后)输出

\HyOrg@maketitle ... \arraystretch {1.3} {\fanggb \begin {tabular}{ll} \make... l.30 \makeenglishtitle % 生成英文封面 The control sequence at the end of the top line of your error message was never \def'ed. If you have misspelled it (e.g., \hobx'), typeI' and the correct spelling (e.g., `I\hbox'). Otherwise just continue, and I'll forget about whatever was undefined.

! Undefined control sequence. \uline #1->\CJKunderline {#1} l.30 \makeenglishtitle % 生成英文封面 ! ?



## 链接

<!-- 请在此处填写相关链接(如果有的话) -->

- Overleaf:https://www.overleaf.com/7347856442mjkrppbmczzn

## 我还做了这些尝试

<!-- 请详述 --> 查阅了很多网上的信息,花了几个小时检查代码,但是未能发现问题所在

## 附件

<!-- 较长的 tex 或者 log 文件请以附件形式上传,不要在这里直接加入过长的代码 -->
[cupb-phd-thesis-master.zip](https://github.com/CTeX-org/forum/files/10458365/cupb-phd-thesis-master.zip)
muzimuzhi commented 1 year ago

搜索 artratex.sty 知,\fanggb 仅在

\ifartx@pdftex
    \ifartx@windows%
        % ...
        \newCJKfontfamily\fanggb{FangSong_GB2312}[AutoFakeBold=true]

下有定义。overleaf 运行的不是 windows,\fanggb 自然得不到定义。

! Undefined control sequence.
\uline https://github.com/CTeX-org/forum/issues/1->\CJKunderline

试试加载 xeCJKfntef 包。

从 v4.8.3 2020-05-01 开始,xeCJK 不默认加载 xeCJKfntef,见提交 https://github.com/CTeX-org/ctex-kit/commit/b61b7e616508171ec89873900658d9576c0d33ec 。模板上次更新可能是在这个版本发布之前。

huiliu-overleaf commented 1 year ago

Update note: 经过Windows系统里的fangsong_GB2312字体安装(点击安装时需要选择”为所有用户安装"),目前已经可以在windows平台的texlive 2022 +texstudio上成功编译不报错了。

请问慕子:如果想要在overleaf上也能编译,是否可能有解决思路?

huiliu-overleaf commented 1 year ago

我查到论坛上以前也有人在overleaf上使用国科大学位模本因为字体原因无法编译的问题。我已经阅读完并做了尝试,将fontset=none,并下载了fangsong_GB2312.otf文件到新建的Font文件夹中,但是在overleaf上编译还是出现了“Package fontspec Error: The font "fangsong" cannot be found.”的错误。overleaf的源代码的链接地址是https://www.overleaf.com/7347856442mjkrppbmczzn

note286 commented 1 year ago

首先可以移除条件判断语句,仅保留你需要的语句即可。并尝试将\newCJKfontfamily\fanggb{FangSong_GB2312}[AutoFakeBold=true]中的FangSong_GB2312改为字体文件名,并将字体文件放在和.cls文件同一目录。

huiliu-overleaf commented 1 year ago

@note286 我尝试在artratex.sty文件中,删除了@windows@mac的条件判断语句,保留了@adobe(不知道我这样做对不对),后我手动下载了Adobe字体集和FangSong_GB2312.otf字体到与.cls文件同一目录,然后又在主文件Thesis.tex中的\documentclass[doublesided,draftversion,fontset=adobe]{Style/cupbthesis}设置了fonset=adobe,其实我还试了fonset=none,但是均报错,甚至整篇文章乱码。关于LaTeX调用字体这一块我实在搞不懂调用原理,不知道我这个模本文件咋样才能在overleaf上运行。新的上传了字体的模本文件overleaf地址是: 折腾好久了,还是无法解决,能不能帮忙看看,谢谢!

note286 commented 1 year ago

你给个论文模板的GitHub地址吧,你的需求就是Overleaf运行对吧,还有其他需求吗?

huiliu-overleaf commented 1 year ago

此外,我是在artratex.sty文件中的\newCJKfontfamily\fanggb{FangSong_GB2312}[AutoFakeBold=true]FangSong_GB2312改成了添加了文件后缀的FangSong_GB2312.otf其它字体都类似修改了。

huiliu-overleaf commented 1 year ago

你给个论文模板的GitHub地址吧,你的需求就是Overleaf运行对吧,还有其他需求吗?

是的,就是在overleaf上能正常运行没有错误(主要是希望用到overleaf的云存储和修改历史功能),这是模本的overleaf链接,打开就可以编辑:https://www.overleaf.com/2384846776rfqtryynxmdf

谢谢!

note286 commented 1 year ago

https://github.com/linyuantiaohe/cupb-phd-thesis 是这个模板吗?

huiliu-overleaf commented 1 year ago

https://github.com/linyuantiaohe/cupb-phd-thesis 是这个模板吗?

对的,是这个模本。这个模本还有一个错误是没有加载宏包xeCJKfntef

note286 commented 1 year ago

好的,我看一下。

huiliu-overleaf commented 1 year ago

好的,我看一下。

嗯嗯

note286 commented 1 year ago

我个人非常不建议使用Overleaf写学位论文,插图不方便,需要频繁上传文件,每次只能打开一个文件,等等缺点。至于同步和历史版本,你可以使用git或者坚果云等工具,本地也可以实现。


打开artratex.sty文件,在222行\ifartx@windows%这一行之前插入:

\setCJKmainfont[AutoFakeBold,ItalicFont=simkai.ttf]{simsun.ttc}%
\setCJKsansfont[AutoFakeBold]{simhei.ttf}%
\setCJKmonofont{simfang.ttf}%
\newCJKfontfamily\fanggb{FangSong_GB2312.ttf}[AutoFakeBold=true]

打开cupbthesis.cls文件,将122行

\renewcommand{\CJKunderlinecolor}{\color[rgb]{0,0,0}}

替换为

\RequirePackage{xeCJKfntef}
\newcommand{\CJKunderlinecolor}{\color[rgb]{0,0,0}}

最后将FangSong_GB2312.ttfsimfang.ttfsimhei.ttfsimkai.ttfsimsun.ttc字体文件放在和Thesis.tex同一目录下。

huiliu-overleaf commented 1 year ago

我个人非常不建议使用Overleaf写学位论文,插图不方便,需要频繁上传文件,每次只能打开一个文件,等等缺点。至于同步和历史版本,你可以使用git或者坚果云等工具,本地也可以实现。

打开artratex.sty文件,在222行\ifartx@windows%这一行之前插入:

\setCJKmainfont[AutoFakeBold,ItalicFont=simkai.ttf]{simsun.ttc}%
\setCJKsansfont[AutoFakeBold]{simhei.ttf}%
\setCJKmonofont{simfang.ttf}%
\newCJKfontfamily\fanggb{FangSong_GB2312.ttf}[AutoFakeBold=true]

打开cupbthesis.cls文件,将122行

\renewcommand{\CJKunderlinecolor}{\color[rgb]{0,0,0}}

替换为

\RequirePackage{xeCJKfntef}
\newcommand{\CJKunderlinecolor}{\color[rgb]{0,0,0}}

最后将FangSong_GB2312.ttfsimfang.ttfsimhei.ttfsimkai.ttfsimsun.ttc字体文件放在和Thesis.tex同一目录下。

非常感激你的帮助,按照你的方法,成功解决了问题,没有报错,但是我仔细和原来文件对比后发现,正文字体好像是有些差异。如下图所示,左边是编译没报错的字体,右边是初始版本编译后的字体。是不是我字体选择错了吗? Screenshot_20230119_112132

huiliu-overleaf commented 1 year ago

左边字体比较颜色好像比较浅,右边比较深一些。

note286 commented 1 year ago

我给你配置的是中易系列字体(也就是Windows内置的那一套),你可以自己更换adobe、华文、方正等其他系列的,一般学校不会对此有特殊要求。

huiliu-overleaf commented 1 year ago

我给你配置的是中易系列字体(也就是Windows内置的那一套),你可以自己更换adobe、华文、方正等其他系列的,一般学校不会对此有特殊要求。

我明白了,谢谢!!