Open tosti007 opened 2 years ago
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}
According to the documentation there is both a
endinnercode
andendcode
hook. Theendinnercode
works as expected and adds the given code right at the end inside the box. Theendcode
hook does not produce anything, it's simply ignored.I have tried it on Overleaf with both
Latex
andpdfLatex
compilers and with TeX Live versions2014
,2017
, and2021
.The document used (copied and modified from the example
tex
file: