mdframed icon indicating copy to clipboard operation
mdframed copied to clipboard

Bug: argument "endcode" not working

Open tosti007 opened this issue 4 years ago • 1 comments

According to the documentation there is both a endinnercode and endcode hook. The endinnercode works as expected and adds the given code right at the end inside the box. The endcode hook does not produce anything, it's simply ignored.

I have tried it on Overleaf with both Latex and pdfLatex compilers and with TeX Live versions 2014, 2017, and 2021.

The document used (copied and modified from the example tex file:

% arara: pdflatex
\documentclass{article}
\usepackage[tikz]{mdframed}
\usepackage{lipsum}

\begin{document}
\begin{mdframed}[%
  endinnercode={This is the endinnercode!},
  endcode={Here is the endcode!}]
 \lipsum 
\end{mdframed}
\lipsum

\end{document}

tosti007 avatar Jan 13 '22 13:01 tosti007

In the released mdframed.sty v1.9b (2013/07/01), an mdframed environment does

\color@begingroup
  \mdfsetup{userdefinedwidth=\linewidth,<mdf options>}%
  \mdf@startcode
  % ...
\color@endgroup
\mdf@endcode

One can see \mdf@endcode, the macro that holds the value of endcode, is set inside the color group, but is used outside that group. The combined effect is, the endcode passed to the optional argument of mdframed is never used.

Try this patch:

\documentclass{article}
\usepackage[tikz]{mdframed}
\usepackage{lipsum}

\usepackage{xpatch}
\makeatletter
% expand \mdf@endcode before the group ends
\xpatchcmd\endmdframed
  {\color@endgroup\mdf@endcode}
  {\expandafter\color@endgroup\mdf@endcode}
  {}{\PatchFailed}
\makeatother

\begin{document}
\begin{mdframed}[
  startinnercode={This is the startinnercode!},
  endinnercode={This is the endinnercode!},
  startcode={This is the startcode!},
  endcode={This is the endcode!}
]
 \lipsum[1][1-3]\par
\end{mdframed}

\end{document}

image

muzimuzhi avatar Jan 14 '22 05:01 muzimuzhi