\documentclass[UTF8,a4paper,12pt]{ctexart}
\usepackage[fixed]{fontawesome5}
\begin{document}
\section*{prepaper}
\begin{itemize}
\item a
\end{itemize}
\section{\faIcon{cog}b}
\section{\faIcon{cogs}c}
\end{document}出现了错误:Package fontawesome5 Error: The requested icon COG was not found. end{document}
但是我使用下面这个,增加了几行就可以通过编译了。
\documentclass[UTF8,a4paper,12pt]{ctexart}
\usepackage[fixed]{fontawesome5}
\title{a}
\author{a}
\date{2021/03/16}
\begin{document}
\maketitle
\section*{prepaper}
\begin{itemize}
\item a
\end{itemize}
\section{\faIcon{cog}b}
\section{\faIcon{cogs}c}
\end{document}就可以编译
原先考虑问题不周到,删去答案重新回答。这应该是页眉引起的问题。应该是headings 这种页面样式中 \sectionmark 定义中的 \MakeUppercase 把 {cog} 给改成了大写,从而导致 \faIcon 不能识别参数 COG,因此,报错的信息为:Package fontawesome5 Error: The requested icon COG was not found. 注意 COG 是大写。
我原来以为是 ctex 的锅,因为我注意到基本文档类 article 并没有报错。实际上,这里我犯了一个错误,忽略了 ctexart 和 article 默认页面样式的差别。ctexart 默认的页面样式是 headings,而 article 默认的页面样式是 plain,article 文档类完美躲过了这个问题。
至于这个问题的解决办法,我水平有限,还没想好怎么解决 \MakeUppercase 的问题。重新设计页眉,避免使用 \MakeUppercase 肯定是可以的,或者在指定了页面样式 headings 后 利用 xpatch 包把 \sectionmark 定义中的 \MakeUppercase 替换掉。但这样一来,显然页眉里其他英文字符不能被大写了,下面这个例子就是这样的做法:
\documentclass{article}
\usepackage{fontawesome5,xpatch}
\pagestyle{headings}
\xpatchcmd{\sectionmark}{\MakeUppercase}{\relax}{}{}
\begin{document}
\section{\faCog b}
\MakeUppercase{capital}
\section{\faCogs c}
\end{document}嗯。。。 protect 居然就可以。。。好吧,我原来命令行
latexdef -p fontawesome5 \faCog显示的结果是:
\faCog:
\protected\long macro:->\faPreselectedIcon {cog}就没往 \protect 上去想,那么,这样就可以解决问题了:
\documentclass{ctexart}
\usepackage{fontawesome5}
\begin{document}
\section{\protect\faCog b}
\section{\protect\faCogs c}
\end{document}