1

I'm trying to convert a TeX document that uses the package awesomebox to HTML using htlatex. Although I did not expect this to work out of the box and probably requires me to configure some environments myself, the error that it currently gives me is something that surprises me:

! Undefined control sequence.
\n:@textcolor: ...e {\protect \a:textcolor \color
                                                  #1{#2}#3\protect \b:textco...
l.14 \notebox{test}

Based on this it seems that the \textcolor command is causing issues (or at least this seems to be the textcolor definition?)

But if I use \textcolor directly then all is well (i.e., comment out the \notebox line in the file below).

Minimal (Not-)Working Example:

\documentclass[a4paper,twoside,openright]{book}
\usepackage[greek,british]{babel}

\usepackage{xcolor}
\usepackage{awesomebox}
\setlength{\aweboxleftmargin}{9mm}
\setlength{\aweboxsignraise}{-5mm}

\makeatletter

\begin{document}

\textcolor{green}{hi}
\notebox{test} % Comment out this line and it works just fine, but with it you get an error for textcolor

\end{document}

Any ideas what I could do to fix this?

5
  • I get no error with htlatex file (tested in a current texlive). May 27, 2020 at 17:37
  • I don't get this error as well. But I don't get the icon.
    – michal.h21
    May 27, 2020 at 17:59
  • Ohw that is very curious... I'll look at my version tomorrow :)
    – MrHug
    May 27, 2020 at 18:01
  • You probably has old TeX distribution where TeX4ht and xcolor clashes. I will try to come with a solution for the icons.
    – michal.h21
    May 27, 2020 at 18:02
  • Awesome, thanks a ton!
    – MrHug
    May 27, 2020 at 18:45

1 Answer 1

2

I don't get this error with the current TeX Live 2020. It is probably some package clash that had been fixed in the past.

Anyway, there is no awesomebox support in TeX4ht, so this needs some work. I've came with the following solution. Save this as awesomebox.4ht:

\NewConfigure{awesomebox}{3}
\newcounter{awesomebox@cnt}
\RenewDocumentCommand \awesomebox { O{abvrulecolor} O{} o m m m +m }{%
  \stepcounter{awesomebox@cnt}
  \def\awesomebox@id{awesomebox-\arabic{awesomebox@cnt}}
  \extractcolorspec{#1}{\tsf@color}%
  \expandafter\convertcolorspec\tsf@color{HTML}\tsf@color%
\a:awesomebox
  \IfValueTF {#3}
      {  #3 \\ #2 \textcolor{#6}{\Huge#5}\b:awesomebox #7  #2}
      {         #2 \textcolor{#6}{\Huge#5}\b:awesomebox #7  #2}
\c:awesomebox
}

\Configure{awesomebox}{%
  \Css{\#\awesomebox@id\space .icon{border-right:4px solid \#\tsf@color;}}
  \ifvmode\IgnorePar\fi\EndP%
  \HCode{<div class="awesomebox" id="\awesomebox@id"><div class="icon">}%
  \Picture+{}%
}{\EndPicture%
  \HCode{</div><div class="boxcontent">}%
  \par%
}{%
  \ifvmode\IgnorePar\fi\EndP%
  \HCode{</div></div>}%
}

\Css{.awesomebox{display:grid; grid-template-columns: 90px auto;margin-top:1rem;margin-bottom:1rem;}}
\Css{.awesomebox .icon{padding-right:0.5rem;margin-right:0.5rem;text-align:center;}}
\Css{.awesomebox .boxcontent{vertical-align:top;}}

It redefines the \awesomebox command to insert HTML tags instead of the default code. The redefinition also generates unique ID for each box - we need this in order to be able to apply color rule to each box. The rule color is converted to RGB value usable in CSS and saved in \tsf@color macro. \a:awesomebox, \b:awesomebox and \c:awesomebox are macros used to insert the HTML code. They are declared using \Configure{awesomebox}.

\Css{\#\awesomebox@id\space .icon{border-right:4px solid \#\tsf@color;}}

This declares the colored bar.

\HCode{<div class="awesomebox" id="\awesomebox@id"><div class="icon">}%

This inserts the <div> element that contain the whole box. Icon and the text are both contained in another <div> elements, with icon and boxcontent classes.

\Picture+{} ... \EndPicture

This will convert all code that is contained to images. It will convert icons to images.

\Css{.awesomebox{display:grid; grid-template-columns: 90px auto;margin-top:1rem;margin-bottom:1rem;}}
\Css{.awesomebox .icon{padding-right:0.5rem;margin-right:0.5rem;text-align:center;}}
\Css{.awesomebox .boxcontent{vertical-align:top;}}

This styles the box. We use the CSS grid to display box as table. Icon is 90px wide, the text content is resized as necessary.

There is another small issue. There are no support files for Fontawesome fonts in TeX4ht. We need to provide some dummy files to suppress the error message. Save the following content to both fa5free1solid.htf and fa5free1solid.htf:

.lm-ec

This is an example where I've added some more sample boxes:

\documentclass[a4paper,twoside,openright]{book}
\usepackage[greek,british]{babel}

\usepackage{xcolor}
\usepackage{awesomebox}
\setlength{\aweboxleftmargin}{9mm}
\setlength{\aweboxsignraise}{-5mm}
\usepackage{lipsum}

\makeatletter

\begin{document}

\textcolor{green}{hi}
\notebox{test} % Comment out this line and it works just fine, but with it you get an error for textcolor

\tipbox{\lipsum[1-2]}

\warningbox{\lipsum[3]}

\end{document}

And this is the result:

enter image description here

6
  • 1
    You are absolutely amazing, going far beyond the answer I was looking for. Thanks a ton!
    – MrHug
    May 28, 2020 at 7:59
  • You proved you are the best...such a nice suggestions....
    – MadyYuvi
    May 28, 2020 at 8:30
  • 1
    @MrHug thanks for your kind words :)
    – michal.h21
    May 28, 2020 at 8:35
  • 1
    @MadyYuvi thank you :)
    – michal.h21
    May 28, 2020 at 8:35
  • Just one more question, you mention the same file name fa5free1solid.htf twice I think, was one of them a typo?
    – MrHug
    May 28, 2020 at 10:08

You must log in to answer this question.

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