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 24 May 2019 04:39:57 PM EEST  
Category: NonePriority: 5 - Normal
Severity: 5 - NormalStatus: None
Privacy: PublicAssigned to: None
Open/Closed: Open

Mon 19 Aug 2019 04:15:01 AM EEST, comment #5:

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

Karl Berry <karl>
Project Administrator
Mon 19 Aug 2019 04:14:11 AM EEST, 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 29 May 2019 10:31:44 AM EEST, 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 28 May 2019 08:26:35 PM EEST, 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 26 May 2019 01:12:03 PM EEST, 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 24 May 2019 04:39:57 PM EEST, 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):



    2 latest changes follow.

    Date Changed By Updated Field Previous Value => Replaced By
    Mon 19 Aug 2019 04:15:01 AM EESTkarlOpen/ClosedClosed=>Open
    Mon 19 Aug 2019 04:14:11 AM EESTkarlOpen/ClosedOpen=>Closed
    Show feedback again

    Back to the top

    Powered by Savane 3.1-cleanup+gray