特定序言中的错误 fontawesome5

特定序言中的错误 fontawesome5

关于我最近的问题,我想对此表示感谢,网球的象征,我很难编译它。在我的书中,就像在这个 MWE 中一样,我有一个错误。

我怎样才能消除它?

相关问题:

  1. 减少与文本对齐的枚举的高度
  2. 漂亮列举:fontawesome

梅威瑟:

\documentclass[12pt]{article}
\usepackage{lipsum,xcolor}
\usepackage{fontawesome5}
\usepackage{enumitem} 
\setlist{nolistsep} 
\newcount\cnt
\cnt=1

\newbox\battery
\setbox\battery=\hbox\faBatteryFull

\def\numberlabel{%
  \ifnum\the\cnt>4\relax
  \else {\bfseries\small\sffamily[\the\cnt]}%
  \fi
}

\def\Item{%
  \item[%
    \smash{\raisebox{-0.85em}{%
    \vbox{\baselineskip=10pt
      \hbox to \the\wd\battery{\hss\numberlabel\hss}
      \hbox{%
        \ifnum\the\cnt=1{\color{green}\faBatteryFull}
        \else
          \ifnum\the\cnt=2{\color{orange}\faBatteryThreeQuarters}
          \else
            \ifnum\the\cnt=3{\color{yellow}\faBatteryHalf}
            \else
              \ifnum\the\cnt=4{\color{red}\faBatteryQuarter}
              \else{\sffamily\color{magenta}{\faBatteryEmpty}}
              \fi
            \fi
          \fi
        \fi}%
    }}}%
  ]%
  \advance\cnt by 1
}
\begin{document}
\begin{enumerate}
\Item \lipsum[1]
\Item \lipsum[2]
\Item \lipsum[3]
\Item \lipsum[4]
\Item \lipsum[5]
\end{enumerate}
\end{document}

错误:

这是 pdfTeX,版本 3.14159265-2.6-1.40.20(MiKTeX 2.9.7050)进入扩展模式(“C:/Users/utente/Desktop/errore fonta5.tex” LaTeX2e <2018-12-01>(“C:\Program Files\MiKTeX 2.9\tex/latex/base\article.cls” 文档类:article 2018/09/03 v1.4i 标准 LaTeX 文档类(“C:\Program Files\MiKTeX 2.9\tex/latex/base\size12.clo”)(“C:\Program Files\MiKTeX 2.9\tex/latex/lipsum\lipsum.sty”(“C:\Program Files\MiKTeX 2.9\tex/latex/l3kernel\expl3.sty”(“C:\Program Files\MiKTeX 2.9\tex/latex/l3kernel\expl3-code.tex”)(“C:\Program Files\MiKTeX 2.9\tex/latex/l3backend\l3backend-pdfmode.def”)(“C:\Program Files\MiKTeX 2.9\tex/latex/l3packages/xparse\xparse.sty”)(“C:\Program Files\MiKTeX 2.9\tex/latex/lipsum\lipsum.ltd.tex”)(“C:\Program Files\MiKTeX 2.9\tex/latex/xcolor\xcolor.sty”(“C:\Program Files\MiKTeX 2.9\tex/latex/graphics-cfg\color.cfg”)(“C:\Program Files\MiKTeX 2.9\tex/latex/graphics-def\pdftex.def”)(“C:\Program Files\MiKTeX 2.9\tex/latex/fontawesome5\fontawesome5.sty”(“C:\Program Files\MiKTeX 2.9\tex/latex/l3packages/l3keys2e\l3keys2e.sty”)(“C:\Program Files\MiKTeX 2.9\tex/latex/fontawesome5\fontawesome5-generic-helper.sty”(“C:\Program Files\MiKTeX 2.9\tex/latex/fontawesome5\fontawesome5-mapping.def”))(“C:\Program Files\MiKTeX 2.9\tex/latex/enumitem\enumitem.sty”)

! Missing { inserted.
<to be read again> 
                   \tex_let:D 
l.10 \setbox\battery=\hbox\faBatteryFull                                        
? 

答案1

\hbox是 TeX 原语并且需要括号,即使参数是单个标记。

以下行:

\setbox\battery=\hbox\faBatteryFull

应该:

\setbox\battery=\hbox{\faBatteryFull}

这就是为什么 TeX 会报告{该行缺失的原因:

! Missing { inserted.
<to be read again>
                   \tex_let:D
l.10 \setbox\battery=\hbox\faBatteryFull

?

错误消息指责\tex_let:D导致错误的原因是\hbox扩展标记(\faBatteryFull)寻找to <dimen>spread <dimen>{,并且\tex_let:D是第一个与上述任何选项都不匹配的不可扩展标记。

带有(不是 5)的版本fontawesome有效,因为\faBatteryFull扩展为\faicon {battery-full},而后者又扩展为{\csname faicon@battery-full\endcsname }{然后可以看到,\hbox这将恰好包含\csname faicon@battery-full\endcsname。它作品偶然,但无论如何它都是错误的代码。


固定代码:

\documentclass[12pt]{article}
\usepackage{lipsum,xcolor}
\usepackage{fontawesome5}
\usepackage{enumitem} 
\setlist{nolistsep} 
\newcount\cnt
\cnt=1

\newbox\battery
\setbox\battery=\hbox{\faBatteryFull}

\def\numberlabel{%
  \ifnum\the\cnt>4\relax
  \else {\bfseries\small\sffamily[\the\cnt]}%
  \fi
}

\def\Item{%
  \item[%
    \smash{\raisebox{-0.85em}{%
    \vbox{\baselineskip=10pt
      \hbox to \the\wd\battery{\hss\numberlabel\hss}
      \hbox{%
        \ifnum\the\cnt=1{\color{green}\faBatteryFull}
        \else
          \ifnum\the\cnt=2{\color{orange}\faBatteryThreeQuarters}
          \else
            \ifnum\the\cnt=3{\color{yellow}\faBatteryHalf}
            \else
              \ifnum\the\cnt=4{\color{red}\faBatteryQuarter}
              \else{\sffamily\color{magenta}{\faBatteryEmpty}}
              \fi
            \fi
          \fi
        \fi}%
    }}}%
  ]%
  \advance\cnt by 1
}
\begin{document}
\begin{enumerate}
\Item \lipsum[1]
\Item \lipsum[2]
\Item \lipsum[3]
\Item \lipsum[4]
\Item \lipsum[5]
\end{enumerate}
\end{document}

相关内容