Package fontawesome5 Error: The requested icon COG was not found

发布于 2021-03-16 21:12:01
\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}

就可以编译

查看更多

关注者
0
被浏览
1.2k
如果您有什么不同意见,您是对的,我是错的。
这家伙很懒,什么也没写!

因为 \section\MakeUppercase

\documentclass{ctexart}
\usepackage{fontawesome5}
\def\test{\faIcon{cog}}
\begin{document}
  \section{\protect\test}
\end{document}
2 个回答
拿了橘子跑啊
拿了橘子跑啊 2021-03-16
这家伙很懒,什么也没写!

原先考虑问题不周到,删去答案重新回答。这应该是页眉引起的问题。应该是headings 这种页面样式中 \sectionmark 定义中的 \MakeUppercase 把 {cog} 给改成了大写,从而导致 \faIcon 不能识别参数 COG,因此,报错的信息为:Package fontawesome5 Error: The requested icon COG was not found. 注意 COG 是大写。

我原来以为是 ctex 的锅,因为我注意到基本文档类 article 并没有报错。实际上,这里我犯了一个错误,忽略了 ctexartarticle 默认页面样式的差别。ctexart 默认的页面样式是 headings,而 article 默认的页面样式是 plainarticle 文档类完美躲过了这个问题。

至于这个问题的解决办法,我水平有限,还没想好怎么解决 \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}

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览