2

The following works perfectly:

\documentclass{memoir}

\usepackage{showkeys}
\usepackage{graphicx}
\newsubfloat{figure}

\begin{document}

\begin{figure}[htbp]
    \centering
    \subbottom[A\label{fig:A}]
    {\includegraphics[width = 0.4\textwidth]{example-image-a}}
    \hfill
    \subbottom[B\label{fig:B}]
    {\includegraphics[width = 0.4\textwidth]{example-image-b}}
\end{figure}

\end{document}

However, if I add the [final] option, the label is printed in the caption of each subfigure and I get errors saying that \sf@@memsub@label@hook is undefined. The class file memoir.cls includes the following snippet:

\@ifpackageloaded{showkeys}{%
    \renewcommand\sf@@memsub@label@hook[1]{%
        \SK@\SK@@label{#1}%
     }
}{}

Clearly, memoir makes some adaptions for the showkeys package, but these do not work with [final].

I found a thread concerning a conflict between showkeys, subfloats and bookmark, but the patches suggested there does not solve my problem.

1
  • 1
    Easiest fix: for showkeys final mode is the same as not being there at all, so just outcomment the showkeys package. A fix will be available in the next memoir release. Not sure when that will be. – daleif Feb 6 '20 at 12:57
1
+50

The final option for the showkeys package calls \endinput in the style file before it has read anything into it. Here is the top of showkeys.sty, with the line (*) in question marked:

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{showkeys}
          [1997/06/12 v3.12 Show cite and label keys (DPC)]
\DeclareOption{notref}{\let\SK@ref\@empty}
\DeclareOption{notcite}{\let\SK@cite\@empty}
\let\SK@refcolor\relax
\let\SK@labelcolor\relax
\DeclareOption{color}{\AtEndOfPackage{%
  \RequirePackage{color}%
  \definecolor{refkey}{gray}{.75}%
  \definecolor{labelkey}{gray}{.75}%
  \def\SK@refcolor{\color{refkey}}%
  \def\SK@labelcolor{\color{labelkey}}}}
\DeclareOption{final}{\endinput}   <--------------------- (*)
\DeclareOption{draft}{}
\ProcessOptions

Thus, loading showkeys with the final option suppresses all of the behaviour of showkeys. In effect, the package loads, but in a totally vacuous way. Then, memoir gets confused here:

\@ifpackageloaded{showkeys}{%
    \renewcommand\sf@@memsub@label@hook[1]{%
        \SK@\SK@@label{#1}%
     }
}{}

because \@ifpackageloaded{showkeys} is technically true, but showkeys didn't define anything.

The simple solution (other than either revising showkeys or adding a fix to memoir, which may happen in due course) is to comment out the line

\usepackage{showkeys}

from your TeX file when you don't want it any more. This will have literally the same effect on your file as using the final option, except that \@ifpackageloaded{showkeys} will now be false.

5
  • 1
    Easier in memoir: check if \SK@ is defined, it is defined after the \endinput. I just added that check to memoir. But I agree, I've never used the final option of that package, I've always outcomented in when I'm not using it. – daleif Feb 6 '20 at 13:05
  • @daleif thanks! I was assuming memoir wouldn't want to be changed just for this. It leads to an interesting question: where is the "bug", in memoir, or in showkeys?! – rbrignall Feb 6 '20 at 13:09
  • 1
    The bug is in memoir. Memoir is not using the normal \label macro for subfigures. So instead of asking the showkeys author to adapt to an odd choice in memoir, the solution being used here was added, it was quite easy. Just never noticed the final option in showkeys. – daleif Feb 6 '20 at 13:13
  • Very generous of you! I will edit my answer slightly... – rbrignall Feb 6 '20 at 13:27
  • 1
    I ended up making a package that loads showkeys unless [final] is used, so as to keep that functionality. – user44413 Feb 7 '20 at 8:44

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.