bugtex4ht - Bugs: bug #423, \left and \right inside caption...

Show feedback again

You are not allowed to post comments on this tracker with your current authentification level.

bug #423: \left and \right inside caption with label cause TeX capacity exceeded when used with hyperref

Submitted by:  Joel Croteau <tv4fun>
Submitted on:  Fri May 24 13:39:57 2019  
Category: NonePriority: 5 - Normal
Severity: 5 - NormalStatus: None
Privacy: PublicAssigned to: None
Open/Closed: Closed

(Jump to the original submission Jump to the original submission)

Thu Aug 25 11:23:38 2022, comment #6:

I think that I've fixed this issue finally. We need to make the problematic commands robust. So for the future reference, instead of


it is better to use the following code for the commands that can be used in captions or sectioning commands:


Michal Hoftich <michal_h21>
Project Member
Mon Aug 19 01:15:01 2019, comment #5:

sorry, didn't mean to close the \caption expansion quite yet.

Karl Berry <karl>
Project Administrator
Mon Aug 19 01:14:11 2019, comment #4:

I think one would never want any \caption contents expanded when writing it to a file? Can't quite imagine when ...

Karl Berry <karl>
Project Administrator
Wed May 29 07:31:44 2019, comment #3:

The problem is, you may want to expand some macros, while others not. It is possible to disable all expansion, but you cannot automatically detect which macros should be expanded and which not.

Michal Hoftich <michal_h21>
Project Member
Tue May 28 17:26:35 2019, comment #2:

Thank you, Michal. Will try the \protect thing. If that works, it may be worthwhile to try and add some logic to do that automatically. I'm actually using tex4ebook, but it uses tex4ht internally, and that's where I ran into this issue.

Joel Croteau <tv4fun>
Sun May 26 10:12:03 2019, comment #1:

Dear Joel,

this issue is caused by the nameref support, which is loaded automatically by hyperref. Each caption, section title and similar stuff is then saved to the auxilary file, in order to be available for the \nameref command. There can be expansion issues when the contents are written to the auxilary file, as in your case.

I don't know if we can fix that on the tex4ht level - we could use something like \detokenize command to write literal contents of the caption to the aux file, but in this case you wouldn't save the current value of macros, which you may want in some cases.

On the document level, you can use the \protect command to disable expansion of the command when it is written:


BTW, if you want to make an eBook, you may want to take a look at tex4ebook: https://ctan.org/pkg/tex4ebook?lang=en

Michal Hoftich <michal_h21>
Project Member
Fri May 24 13:39:57 2019, original submission:

Recently when trying to convert a scientific paper to an eBook using tex4ht, I ran into some confusing errors. I tracked it down to a macro that used \left and \right inside of the caption of a labeled figure, which only seems to be a problem with hyperref included. A simple example to reproduce this:

When compiled with `mk4ht htlatex main2.tex`, this gives:

Interestingly, a small change to \thefigure results in a completely different error:

Now gives:

This only seems to happen with the very specific combination of factors I have outlined above. Not including \left and \right, not having them inside a \caption, not having the \label, or not including \hyperref all seem to make this go away, and it compiles with regular LaTeX just fine. I'm afraid I don't know enough about the macros you're using to be able to debug this.

Joel Croteau <tv4fun>


No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -unavailable- added by karl (Posted a comment)
  • -unavailable- added by michal_h21 (Posted a comment)
  • -unavailable- added by tv4fun (Submitted the item)

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.


    Please enter the title of George Orwell's famous dystopian book (it's a date):



    3 latest changes follow.

    Date Changed By Updated Field Previous Value => Replaced By
    Thu Aug 25 11:23:38 2022michal_h21Open/ClosedOpen=>Closed
    Mon Aug 19 01:15:01 2019karlOpen/ClosedClosed=>Open
    Mon Aug 19 01:14:11 2019karlOpen/ClosedOpen=>Closed
    Show feedback again

    Back to the top

    Powered by Savane 3.1-cleanup+gray