数学年刊A辑与AC辑LaTeX模板使用踩坑记
微信上的来电
下午,友人编译 《数学年刊(A辑)》时遇到问题,在微信上向我告知
tex 文件运行不了,这个 bug 怎么解决
pdf 是好的,那个 rar 文件是在官网直接下载的,我看教程说用 WinEdt 7,但是我下了这个但是没有选项
尝试
中文乱码
我通过官网下载模板,得到压缩包,解压,在 vscode 中直接打开会中文乱码,因此我改变编码方式为 GBK 编码。
File `cctart.cls' not found
然后直接运行 AC_example. tex 文件,结果报错
[{
"resource": "/c:/Users/17286/Downloads/AC辑模版-2017-8修改版/AC辑模版-2017-8/AC_example.tex",
"owner": "LaTeX",
"severity": 8,
"message": "File `cctart.cls' not found.",
"source": "LaTeX",
"startLineNumber": 1,
"startColumn": 1,
"endLineNumber": 1,
"endColumn": 65536
}]
于是我上网找教程,然后我在根目录下运行 powershell, 运行以下命令
New-item cctart.cls
以在根目录下创建 cctart. cls 文件,然后双击该文件,用 vscode 编辑,写入以下代码
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{cctart}
\PassOptionsToClass{\CurrentOption}{ctexart}
\LoadClass[fontset=fandol]{ctexart}
\@namedef{ver@breakurl.sty}{9999/99/99}
\csname ctex_at_end_package:nn\endcsname
{hyperref}{\let\C\undefined}
\endinput
File `cchead.sty' not found
再次运行,结果接着报错
[{
"resource": "/c:/Users/17286/Downloads/AC辑模版-2017-8修改版/AC辑模版-2017-8/astyle.tex",
"owner": "LaTeX",
"severity": 8,
"message": "File `cchead.sty' not found.",
"source": "LaTeX",
"startLineNumber": 1,
"startColumn": 1,
"endLineNumber": 1,
"endColumn": 65536
}]
看来是因为缺失 cchead. sty 文件,于是我便接着上网找 cchead. sty 的下载方式,发现其代码如下
\edef\ccheadCatAt{\the\catcode`\@}
\edef\ccheadCatEx{\the\catcode`\!}
\catcode`\@=11
\catcode`\!=11
%
\ifx\DeclareRobustCommand\undefined
\let\!def\def
\else
\let\!def\DeclareRobustCommand
\fi
%
\let\ccfnta=\relax
\let\ccfntb=\relax
\let\ccfntc=\relax
\let\ccfntd=\relax
\let\ccfnte=\relax
\let\ccfntf=\relax
\let\ccfntg=\relax
\let\ccfnth=\relax
\let\ccfnti=\relax
\let\ccfntj=\relax
%
\newcount\!ZihaoNo % contains current zihao no.
\newdimen\ccwd % contains width+space of a CC
\newdimen\ccht % contains height of a CC
\newdimen\ccdp % contains depth of a CC
\newbox\!ccbox % used to get width,depth & height
\newskip\!ccbdskip % used to adjust spacing of some BiaoDians
%
\!def\CCA{\hskip\!ccbdskip } % Add glue after some biadians
\!def\CCAS{\!ccbdskips } % Add glue after some biadians
\!def\CCB{\hskip\!ccbdskip } % Add glue before some biadians
\!def\CCBS{\!ccbdskips } % Add glue before some biadians
\def\!CurrentZiJu{0.0600}
\def\!SetCCFont#1#2{\ifx#1\relax\font#1=#2 \hyphenchar#1 -1 \fi\let\DaXiao#1}
\def\!SetupDaXiao#1{\!ZihaoNo=#1
\ifnum\!ZihaoNo=0\!SetCCFont{\ccfnta}{ccfnta}\else
\ifnum\!ZihaoNo=1\!SetCCFont{\ccfntb}{ccfntb}\else
\ifnum\!ZihaoNo=2\!SetCCFont{\ccfntc}{ccfntc}\else
\ifnum\!ZihaoNo=3\!SetCCFont{\ccfntd}{ccfntd}\else
\ifnum\!ZihaoNo=4\!SetCCFont{\ccfnte}{ccfnte}\else
\ifnum\!ZihaoNo=-4\!SetCCFont{\ccfntf}{ccfntf}\else
\ifnum\!ZihaoNo=5\!SetCCFont{\ccfntg}{ccfntg}\else
\ifnum\!ZihaoNo=-5\!SetCCFont{\ccfnth}{ccfnth}\else
\ifnum\!ZihaoNo=6\!SetCCFont{\ccfnti}{ccfnti}\else
\ifnum\!ZihaoNo=7\!SetCCFont{\ccfntj}{ccfntj}\else
\errmessage{Invalid \string\zihao\space command ignored}\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
}
\def\!SetZiJu{\setbox\!ccbox\hbox{\DaXiao M}\relax % setup temp box
\ccwd=2\wd\!ccbox \ccht=\ht\!ccbox \ccdp=\dp\!ccbox % get width,height,depth
\fontdimen2\DaXiao=\!CurrentZiJu\ccwd % space
\fontdimen3\DaXiao=0.5\fontdimen2\DaXiao % stretch
\fontdimen4\DaXiao=0.3333333333\fontdimen2\DaXiao % shrink
\fontdimen6\DaXiao=\ccwd % quad
\advance\ccwd by\fontdimen2\DaXiao % adjust \ccwd
\!ccbdskip=0pt plus 0pt minus 0.5\ccwd %
\def\!ccbdskips{\leavevmode\vrule width -0.45\ccwd height0pt depth0pt}\relax
}
%
\def\!ziti#1{\def\!ZiTi{#1}\relax}
\!def\ziti{\!ziti}
%
\def\!zihao#1{\!SetupDaXiao{#1}\!SetZiJu\relax}
\!def\zihao{\!zihao}
%
\def\!ziju#1{\def\!CurrentZiJu{#1}\!SetZiJu\relax}
\!def\ziju{\!ziju}
%
\!def\songti{\ziti{A}\relax}
\!def\heiti{\ziti{B}\relax}
\!def\kaishu{\ziti{C}\relax}
\!def\fangsong{\ziti{D}\relax}
\!def\biaosong{\ziti{E}\relax}
\!def\YH{\ziti{\char64}\CC }
\!def\pushziti{{\ccdummy\char63}\relax}
\!def\popziti{{\ccdummy\char62}\relax}
%
\font\ccdummy=ccdummy at 10 true pt
\hyphenchar\ccdummy -1 %
\!def\CC{\!SetZiJu\catcode`\~=\active\def~{\penalty\@M \ }\ccdummy\!ZiTi\DaXiao\frenchspacing}
%
\songti\zihao{5}
\catcode`\@=\ccheadCatAt
\catcode`\!=\ccheadCatEx
\endinput
如法炮制,创建文件,写入代码。
I can't find file `astyle'
再次运行,结果报错
[{
"resource": "/c:/Users/17286/Downloads/A辑模版-2017-8/A辑模版-2017-8/A_example.tex",
"owner": "LaTeX",
"severity": 8,
"message": "I can't find file `astyle'.",
"source": "LaTeX",
"startLineNumber": 16,
"startColumn": 8,
"endLineNumber": 16,
"endColumn": 14
}]
而报错的一行为
\input astyle
看来是没有找到 astyle 文件,而 astyle 文件究竟是什么呢?我在网上四处搜索,至今还没得出准确的结论。忽而,眼睛左转,看到根目录下大写的 ASTYLE. CTX 文件,“莫非这就是我苦苦所寻的 astyle 文件?”
但是,这个. ctx 文件是什么类型的文件呢?为何它在 vscode 的图标与. tex 文件的图标相同呢?
我先尝试改大写字母为小写字母,毕竟可能对英文大小写敏感嘛。
结果报错,与之前一样。
不得其解,便上网搜寻。时间已过一小时,网页开了二三十个,firefox 开了四个窗口,内存占用 96%,但是收获为零。
中场休息
然后去吃晚饭。
CTeX?
吃完饭后,我继续上网搜寻,结果偶然间发现一篇文章如何编译通过《数学年刊》LaTeX 模板,其中有一个关键名词
似乎略有耳熟?这不就是在模板所在压缩包附带的图片中出现的吗?
此时我已经意识到这可能是 texlive 不兼容 ctex 的原因,但是我不想在已经安装 texlive 的基础上再安装 ctex,所以我便寻找在 texlive 上兼容 ctex 或者能运行改模板的方法。
但是,我,大败而归,仓皇而逃。
搜索到的教程,除毫无作用,平添改动外,就是过于复杂,需要在 texlive 上大动干戈。
有两篇看起来比较好的文章如下
不辞辛苦者可一试。
巧合的是,两者的博客都是 Hexo & NexT.Gemini 框架。
既然自己撞得头破血流,那么不妨试着走前人走过的路吧。因此,我又回到这篇文章如何编译通过《数学年刊》LaTeX 模板,开始下载 ctex 3.1
一开始我只下载CTeX_3.1.217.2_Full. exe,发现无法运行,又下载了CTeX_3.1.217.2_Full. nsisbin,然后运行. exe 文件方可顺利安装。
不出所料,ctex 文件夹的大小与 texlive 不相上下,笨重无比。
解决方法
之后便依循着如何编译通过《数学年刊》LaTeX 模板所给出的方法便可正常编译。
为存档起见,此作复述:
- 将中文文件夹名改为纯西文文件夹名
- 将
ASTYLE.CTX
改为astyle.tex
correction4.ps
改为correction4.eps
- 将
astyle.tex
第 166 行改为
\sbox{\mygraphic}{\includegraphics[scale=1.8]{\figno.eps}}
- 将
astyle.tex
第 9 行改为
\usepackage{graphicx,epstopdf}
实际上,第一步的文件名更改可以省略。
然后运行文件,结果报错...... 不对,是成功!
后记
由于 ctex 体积过大而电脑空间紧张,且期刊遥不可及,故卸载之。