# mdframed label multiply defined (with listings and paracol)

I use three packages (in a latex "book" document) to display source files (not only tex and sometimes loaded from external files) and their outputs (sometimes loaded from external files) side by side.

• listings for the syntax highlighting
• paracol to display side-by-side
• mdframed to customize appearance

My problem is, that this causes warnings of multiply defined labels (somewhere inside mdframed I think):

WARNING: Label 'mdf@pagelabel-1' multiply defined
WARNING: There were multiply defined labels


I hacked my way through, but I'm not satisfied with my solution... is there a better way?

Here is my minimal "working with warnings" example. My hacks are commented out (to use them toggle comment on the \switchcolumn command to).

\documentclass[]{book}

\usepackage{listings}
\usepackage{mdframed}
\usepackage{paracol}

\lstnewenvironment{insertcode}{\mdframed}{\endmdframed}

%-------------------------------------------------------
%\newcounter{mdfzrefhack}
%\setcounter{mdfzrefhack}{1}
%\newcommand{\swcsafe}{
%\switchcolumn
%\setcounter{mdf@zref@counter}{\value{mdfzrefhack}}
%}
%=======================================================

%-------------------------------------------------------

\begin{document}

\begin{paracol}{2}
\begin{insertcode}
x
\end{insertcode}

%-------------------------------------------------------
%\swcsafe
%=======================================================
\switchcolumn
%-------------------------------------------------------

\begin{insertcode}
y
\end{insertcode}
\end{paracol}

\end{document}


Each of the modifications below (magically in some cases) make the warnings go away:

• not using mdframed
• changing the document type from book to minimal (for ex.)
• shifting one of the listings a bit lower by placing some text above it in the column

Edited: made the example simpler, deleted PS (thanks to egreg)

UPDATE: I've just submitted this on the github of mdframed.

-

You have to use the “internal” commands in \lstnewenvironment, instead of \begin{mdframed} and \end{mdframed}. This seems to work:

\documentclass[]{book}

\usepackage{listings}
\usepackage{mdframed}
\usepackage{paracol}

\lstnewenvironment{insertcode}{\mdframed}{\endmdframed}

\newcounter{mdfzrefhack}
\setcounter{mdfzrefhack}{1}
\newcommand{\swcsafe}{\switchcolumn
\setcounter{mdf@zref@counter}{\value{mdfzrefhack}}%
}

\begin{document}

\begin{paracol}{2}
\begin{insertcode}
x
\end{insertcode}

\swcsafe

\begin{insertcode}
y
\end{insertcode}
\end{paracol}

\end{document}


I'd probably say

\lstnewenvironment{insertcode}[1][]
{\lstset{#1}\mdframed}
{\endmdframed}


so that additional listings options to insertcode can be set.

-
Thanks, but this only answers my "PS", not the original question. Still it was a helpful info, but the problem stays. I'll edit my code according to your suggestion to leave out \Before... commands. And of course, I use a more complicated logic inside insertcode, but It was a minimal example so... –  masu Sep 26 '13 at 10:17

Official answer from the mdframed package author and maintainer:

In your question you pointed out the correct issue. I think the simplest way is to use the option usetwoside=false:

\lstnewenvironment{insertcode}{\mdframed[usetwoside=false]}{\endmdframed}

In this case no check is done.

-
Did it help? ... –  Marco Daniel Dec 11 '13 at 14:33
@MarcoDaniel It seems to help. –  masu Dec 11 '13 at 17:22
This also worked to fix "undefined reference" warnings that were also caused by the mdframed package. –  gablin Feb 26 '14 at 15:24