Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}}
%\addtocounter{mdfzrefhack}{1}
%}
%=======================================================

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

\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.

share|improve this question

2 Answers 2

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}}%
  \addtocounter{mdfzrefhack}{1}%
}

\begin{document}

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

\swcsafe

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

\end{document}

enter image description here

I'd probably say

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

so that additional listings options to insertcode can be set.

share|improve this answer
    
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
up vote 2 down vote accepted

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.

share|improve this answer
    
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 at 15:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.