4

This answer states that the caption package is not compatible with revtex4-1.

Another answer provides a workaround to make caption compatible with revtex4-1 by using the ragged2e package.

It seems to me that the \caption command provided by revtex4-1 is responsible for this. Can this incompatibility be fixed easily?

5

The caption package needs to patch the commands \caption, \@caption, and \@makecaption, the first ones are defined by the LaTeX kernel (but sometimes overwritten by document classes like revtex4-1), and the latter one is defined by the document class.

Unfortunately there are no guidelines on how to patch internal LaTeX commands, and the concept "LaTeX packages" is only designed for packages which extends LaTeX without patching internal LaTeX code. So packages like caption cannot be implemented in a clean and compatible way, it's simply an impossible task.

Basically there are four different methods on how to patch existing commands anyway:

  1. Save the old definition, and make the new definition use the old one, too.
  2. Patch the command with \patchcmd (or a different command) offered by the etoolbox package.
  3. Redefine the definition without saving and using the old one. But try to build-in as many definitions offered by document classes and/or other packages as possible.
  4. Simply redefine the definition without saving and using the old one.

The method chosen deeply affects how compatible is your definition with other packages which either redefines the command, too, or rely on a specific behavior of that command. That's one of the many reasons why there are so many incompatibilities between different LaTeX packages resp. LaTeX document classes and packages.

The caption package used to use the method 1 until version 3.0. But since so many document classes and packages re-define \caption and \@caption itself this method has lead to a way which was not maintainable. So starting with version 3.1 the caption package uses method 3. And to make sure it does not overwrite any functionality it checks if \caption, \@caption, and \@makecaption are known before the redefinition takes place. If it finds an unknown definition it refuses to redefine \caption and \@caption, making sure that the caption package either works as expected or drops an incompatible message to the user, falling back to an "compatibility mode" offering only functionality which was already offered by version 1.0 of the package which did not patched \caption. (And since the subcaption package relies on the patched versions of \caption and \@caption it refuses to work at all.)

BTW: Luckily most LaTeX packages the caption package is adapted to are dead/unmaintained, otherwise it would take very much time to keep track of internal changes within these packages. Which basically means packages like caption could only be realized because most of the other LaTeX packages are already dead!

As consequence any document class (or package which redefines \caption or \@caption) is considered as "incompatible" as long as the caption package isn't adapted to it.

Now back to your questions:

Why the revtex4-1 class is incompatible with the subcaption package? Because the caption package isn't adapted to the revtex4-1 document class yet.

Can this incompatibility be fixed easily? I don't know. For answering this I had to take a closer look at the sources of revtex4-1.

However, currently adapting the caption package to a document class means enhancing the caption package itself. This will change with the upcoming version 3.4 of the caption package which will offer a documented interface for these adaptions, so more people (or the author of the document class herself/himself) can offer these adaptions.

  • Great answer! BTW, IMHO, it is not lucky but your continuous maintenance that make the caption package realized. Thank you. – Eli4ph Jun 11 '18 at 5:51
  • 1
    @Eli4ph I just took a first look at revtex4-1 and it seems the adaption to the caption package is not too difficult, maybe I'll try it on one of the next week-ends. But there is a challenge: revtex4-1 is patching the caption stuff from longtable, too, I have to take a closer look if and how I can manage that... – user2574 Jun 11 '18 at 7:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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