I'm trying to compile a part of my thesis with tex4ht (to use LibreOffice grammar checker). It was working well few weeks ago but now it fails with the error:

! Undefined control sequence.
\H@refstepcounter #1->\sf@Hrefstepcounter 
                                      {#1}\@ifundefined {c@sub#1}{}{\if@...
l.42  \centering

It seems related to the subfig package.

I use TeXLive 2010 on Ubuntu 11.04.

Here is MWE with the way I load hyperref (the photo is the one from this wikipedia article):




 \subfloat[Who's that?]{\includegraphics[width=0.45\textwidth]{Einstein_1921_portrait2.jpg}}%
 \subfloat[Who's that?]{\includegraphics[width=0.45\textwidth]{Einstein_1921_portrait2.jpg}}
 \caption{A famous scientist and his twin brother.}

  • 1
    Welcome to TeX.sx! Please add a minimal working example (MWE) that illustrates your problem. The error might be caused by loading subfig after hyperref. With a few exceptions, hyperref has to be loaded last, subfig is not among the exceptions.
    – egreg
    Jul 28, 2011 at 10:26
  • Thanks but subig is loaded before hyperref. Jul 28, 2011 at 13:11
  • So a minimal working example is needed.
    – egreg
    Jul 28, 2011 at 13:12
  • I'm working on it :) Jul 28, 2011 at 13:42
  • If I Remove hyperref and hypcap the document compiles. Jul 28, 2011 at 14:06

2 Answers 2


As far as I can see there are more than one problem.

  1. As one can see in the log hyperref stopped early. This means that quite a lot commands are not defined. One of this now undefined commands is \H@refstepcounter and so the code of subfig


    fails. That's probably easy to go around this by using \makeatletter\let\H@refstepcounter\refstepcounter in the preamble.

  2. caption doesn't realize that hyperref has stopped early as it test for \hyper@makecurrent and the tex4ht style for hyperref (hyperref.4ht) defines it. So caption asume that commands exist (measuring@true) which are actually undefined.

I can't think about a sane way around this problem. In both cases I think that packages which use internal commands of other packages shouldn't assume they exist but actual test the existence - it is always possible that the names changes.

  • I agree with you. Jul 29, 2011 at 13:37
  • I'm open for ideas on a better test if hyperref has stopped early or not. However, I will extend this test in future versions of the caption package.
    – user2574
    Jul 29, 2011 at 18:45
  • @Axel: I would suggest that you ask Heiko to insert a clear marker, e.g. a switch `\hyp@stoppedearlytrue. Jul 30, 2011 at 9:23
  • I changed the algorithm to test if hyperref has stopped early in caption v3.2 which is available on CTAN now.
    – user2574
    Aug 16, 2011 at 6:18

It seems that subfig and hypcap are not compatible with TeX4ht. If I load subfigure instead (changing \subfloat into \subfigure) and delete the call to hypcap, the document compiles.

  • I did some trick like that (see my comments above) but in the end the document is unusable. I think I will give up. Thanks for your time. Jul 28, 2011 at 15:30
  • The subfig package usually loads the caption package. And if the caption package is loaded, the hypcap package isn't needed at all. (See caption package documentation for details.)
    – user2574
    Jul 29, 2011 at 6:34
  • @Axel The document doesn't compile also when hypcap is not loaded.
    – egreg
    Jul 29, 2011 at 7:55
  • Initially I started to use subfig because according to this page subfigure is obsolete but I have just realized that subfig is considered obsolete too. Jul 29, 2011 at 13:39

You must log in to answer this question.

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