4

Referring to my recent question, to which I would like to express my thanks, Symbol of the tennis ball, I'm having a difficult to compilate it. In my book, as in this MWE, I have an error.

How can I eliminate it?

Related questions:

  1. Decrease the height of the enumerate aligned with the text;
  2. Pretty enumerate: fontawesome

MWE:

\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}

ERROR:

This is pdfTeX, Version 3.14159265-2.6-1.40.20 (MiKTeX 2.9.7050) entering extended mode ("C:/Users/utente/Desktop/errore fonta5.tex" LaTeX2e <2018-12-01> ("C:\Program Files\MiKTeX 2.9\tex/latex/base\article.cls" Document Class: article 2018/09/03 v1.4i Standard LaTeX document class ("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-helpe r.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 Answer 1

6

\hbox is a TeX primitive and it requires braces, even if the argument is a single token.

The line:

\setbox\battery=\hbox\faBatteryFull

should be:

\setbox\battery=\hbox{\faBatteryFull}

That's why TeX reports a missing { on that line:

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

?

The error message accuses \tex_let:D of causing the error because \hbox expands tokens (\faBatteryFull) looking for to <dimen> or spread <dimen> or {, and \tex_let:D is the first non-expandable token which doesn't match any of the above options.

The version with fontawesome (not 5) works because \faBatteryFull expands to \faicon {battery-full} which, in turn, expands to {\csname faicon@battery-full\endcsname }. The { is then seen by \hbox which then will contain exactly \csname faicon@battery-full\endcsname. It works by chance, but it is wrong code nevertheless.


Fixed code:

\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}
10
  • Thank you very much. Your code works correctly, but when I use it into my preamble of my book I have this error: ("C:\Program Files\MiKTeX 2.9\tex/latex/newtx\t1ntxtlf.fd") ! No room for a new \count . \ch@ck ...\else \errmessage {No room for a new #3} \fi l.138 \alloc@0\count\countdef\insc@unt\pointcount@ ?
    – Sebastiano
    Jul 25, 2019 at 21:31
  • Wait. I try your 2nd edit. I see if this works. Thank you.
    – Sebastiano
    Jul 25, 2019 at 21:33
  • Your code (recently edited) is copied identically on my long preamble: but it gives the same error as before. ! No room for a new \count . \ch@ck ...\else \errmessage {No room for a new #3} \fi l.138 \alloc@0\count\countdef\insc@unt\pointcount@ ? Why doesn't it work if it's correct?
    – Sebastiano
    Jul 25, 2019 at 21:36
  • 1
    the fragment \alloc@0\count is from an old (pre 2015) latex and will only allow 256 \newcount, current latex allows 32000 counts so you should not run out. Jul 26, 2019 at 13:52
  • 1
    @Sebastiano eek \alloc@0\count\countdef\insc@unt\pointcount@ in mtpro really doesn't work in latex, shoudl be reported to the package maintainer Jul 26, 2019 at 23:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .