# Showkeys on subbottoms in memoir not showing while using the bookmark package

When running the following MWE:

\documentclass{memoir}
\usepackage{graphicx}
\newsubfloat{figure}
\usepackage[draft]{showkeys}
%\usepackage{bookmark}
\begin{document}
\begin{figure}[htb]
\centering
\subbottom[A\label{fig:examplea}]{\includegraphics[width=0.49\columnwidth]{example-image-a}}
\subbottom[B\label{fig:exampleb}]{\includegraphics[width=0.49\columnwidth]{example-image-b}}
\caption{Example A and B}
\label{fig:examples}
\end{figure}
\end{document}


I get:

However if i uncomment the bookmark package (as below):

\documentclass{memoir}
\usepackage{graphicx}
\newsubfloat{figure}
\usepackage[draft]{showkeys}
\usepackage{bookmark}
\begin{document}
\begin{figure}[htb]
\centering
\subbottom[A\label{fig:examplea}]{\includegraphics[width=0.49\columnwidth]{example-image-a}}
\subbottom[B\label{fig:exampleb}]{\includegraphics[width=0.49\columnwidth]{example-image-b}}
\caption{Example A and B}
\label{fig:examples}
\end{figure}
\end{document}


Is there a way to show the keys on the subbottom picture while also having the bookmarks picture?

If the way is to update from TeXlive 2016 to 2017 i'll do so in a few day's, but can't do it right now

• Is it an interaction between the \usepackage[draft]{showkeys} and the bookmarks package? – Peter Wilson Jun 10 '17 at 20:03
• @PeterWilson same result with and without the [draft] option, only the bookmark package seems to affect it – Thorbjørn E. K. Christensen Jun 10 '17 at 21:04
• bookmark loads hyperref, and when hyperref is active \label inside \subbottom behaves differently, they actually does not use \label at all, so the hook that showkeys adds inside \label never triggers. – daleif Jun 12 '17 at 8:20
• Hmm, more complicated than than. We just need to inject \SK@\SK@@label{#1}} after \@bsphack in the proper version of \sf@@memsub@label. But etoolbox cannot handle this because of the #1, trying other methods – daleif Jun 12 '17 at 8:40
• Shorter patch added – daleif Jun 12 '17 at 10:36

Until I find a way to make a short patch, here is something that seems to work

\makeatletter
\AtBeginDocument{
\renewcommand*{\sf@@memsub@label}[1]{%
\@bsphack
\protected@write\@auxout{}{%
\string\newlabel{#1}%
{{\@nameuse{p@sub\@captype}\@nameuse{@@thesub\@captype}}%
{\thepage}%
{\mem@currentlabelname\relax}%
{\@currentHref}{}}}%
\protected@write\@auxout{}{%
\string\newlabel{sub@#1}%
{{\@nameuse{@@thesub\@captype}}%
{\thepage}%
{\mem@currentlabelname\relax}%
{\@currentHref}{}}}%
\@esphack}
}{}
}{}
}
\makeatother


Update with a shorter patch

% experimental, may change
\usepackage{regexpatch}
\makeatletter
\AtBeginDocument{
\makeatletter
\regexpatchcmd{\sf@@memsub@label}{\c{@bsphack}}{%
\c{@bsphack}\c{SK@}\c{SK@@label}\cB\{\cP\#1\cE\}
}{ \typeout{success} }{ \typeout{failure} }
\makeatother
}
\makeatother