I am trying to write a script (that will be easy) to create a xkcd color set for the package xcolor. Look at this MWE:

\documentclass{article}
\usepackage{xcolor} %
\definecolorset{HTML}{xkcd}{}{%
    OneColor,fcc2d9;%
    LastColor,56ae57%
}
\begin{document}    
\textcolor{xkcdOneColor}{OneColor}
\textcolor{xkcdLastColor}{LastColor}
\end{document}

...this will fail with:

This is pdfTeX, Version 3.1415926-2.5-1.40.14 (TeX Live 2013/Debian)
[...]
! Missing number, treated as zero.
<to be read again> 
                   f
l.6 }

? 

If I change the first f in OneColor to a, for example:

\definecolorset{HTML}{xkcd}{}{%
    OneColor,acc2d9;%
    LastColor,56ae57%
}

...now it works ok.

I understand I can circumvent this easily (seems that uppercase F does not create any problem), but I am curious: is it a bug or a driver (/me) error?

  • 1
    BTW, done --- it's at rlog.rgtti.com/2015/10/23/xkcd-color-list-for-latex-users – Rmano Oct 23 '15 at 9:46
  • 1
    I made a bug report. – Johannes_B Oct 23 '15 at 11:52
  • @Johannes_B --- I also though about doing it --- where do you report bugs for LaTeX packages? Is there something centralized or is just a matter of emailing the author(s)? Thanks! – Rmano Oct 23 '15 at 12:33
  • 2
    I it is a package bug, the package maintainer should be pinged. Email addresses are usually in the documentation or package source. If it is a LaTeX bug (i.e. base package), you can report bug on the project webpage. If you are not sure about a bug, you can always ask in our chat room. There is always somebody around picking it up. – Johannes_B Oct 23 '15 at 14:53
up vote 15 down vote accepted

It's a bug in xcolor.sty, where we find

283 \def\@hex@@Hex#1%
284  {\if a#1A\else \if b#1B\else \if c#1C\else \if d#1D\else
285   \if e#1E\else \if f#1f\else #1\fi\fi\fi\fi\fi\fi \@hex@Hex}

and it's clear that it should be \if f#1F. So no f gets converted to F, which is expected when hexadecimal digits conforming to TeX's syntax are later needed (as arguments for \number").

Indeed the input

\documentclass{article}
\usepackage{xcolor}

\makeatletter
\def\@hex@@Hex#1%
 {\if a#1A\else \if b#1B\else \if c#1C\else \if d#1D\else
  \if e#1E\else \if f#1F\else #1\fi\fi\fi\fi\fi\fi \@hex@Hex}
\makeatother

\definecolor{xk}{HTML}{fcc2d9}
\definecolor{XK}{HTML}{FCC2D9}

\begin{document}

A \textcolor{xk}{BCD} E

A \textcolor{XK}{BCD} E

\end{document}

produces the expected

enter image description here

Of course, expressing the HTML numbers in uppercase will circumvent the bug, too.


A possibly better patch is using etoolbox, that might be used in packages or classes (with \RequirePackage{etoolbox} in this case).

\documentclass{article}
\usepackage{xcolor}
\usepackage{etoolbox}
\makeatletter
\patchcmd{\@hex@@Hex}{f\else}{F\else}{\typeout{Patching xcolor}}{}
\makeatother

\definecolor{DHBW-blue}{HTML}{026f93}

\begin{document}
Hello World
\end{document}
  • Version 2.12 of xcolor, released 2016-05-11, has the correct code. – egreg Aug 10 '17 at 19:20

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.