TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
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 '11 at 10:26
Thanks but subig is loaded before hyperref. – Mathieu Dubois Jul 28 '11 at 13:11
So a minimal working example is needed. – egreg Jul 28 '11 at 13:12
I'm working on it :) – Mathieu Dubois Jul 28 '11 at 13:42
If I Remove hyperref and hypcap the document compiles. – Mathieu Dubois Jul 28 '11 at 14:06

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.

share|improve this answer
I agree with you. – Mathieu Dubois Jul 29 '11 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. – Axel Sommerfeldt Jul 29 '11 at 18:45
@Axel: I would suggest that you ask Heiko to insert a clear marker, e.g. a switch `\hyp@stoppedearlytrue. – Ulrike Fischer Jul 30 '11 at 9:23
I changed the algorithm to test if hyperref has stopped early in caption v3.2 which is available on CTAN now. – Axel Sommerfeldt Aug 16 '11 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.

share|improve this answer
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. – Mathieu Dubois Jul 28 '11 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.) – Axel Sommerfeldt Jul 29 '11 at 6:34
@Axel The document doesn't compile also when hypcap is not loaded. – egreg Jul 29 '11 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. – Mathieu Dubois Jul 29 '11 at 13:39

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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