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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

While using mcode.sty, I recognized that at linebreaks with long comments parts of the surrounding frame got colored green or were even left white at using mathematical formulas, e.g. in the following example:


% load package with ``framed'' and ``numbered'' option.

% something NOT relevant to the usage of the package.

\item The following demo block shows the problems:
for i = 1:3
    if i >= 5                    % literate programming replacement
        disp('cool');           % comment with some §\mcommentfont\LaTeX in it: $\mcommentfont\pi x^2$§
    really really long really really long really really long really really long really really long line % blaaaaaaaa

How can uniformly black colored frames be achieved?

share|improve this question
I have removed my previous comment, I misinterpreted your question. – Dennis Jaheruddin Feb 13 '13 at 13:33
You forgot to include a list-environment (e.g. itemize) in your code. The problem only seems to occur in a list, if you remove the \item from your code everything works fine. – Torbjørn T. Feb 13 '13 at 19:53
@TorbjørnT.: Thank you for your comment - that environment enabled me to see the bug (because of the smaller textwidth)! – strpeter Feb 15 '13 at 8:12
I hope now people can see the remaining problem/conflict of the frame with math code inside the lstlisting-environment. – strpeter Feb 15 '13 at 8:17
You might want to use the matlab-prettifier package; see this answer. – Jubobs Mar 18 '14 at 0:25

The first problem can be solved (I think it is a bug in the package mcode.sty) quite simply by adding a few lines of code just after including \usepackage[framed,numbered,autolinebreaks,useliterate]{mcode}:


The problem at using mathematical formulas still remains.

share|improve this answer
Please consider accepting your own answer, so that it be removed from the pile of "unanswered" questions. – Jubobs Mar 18 '14 at 0:24

Your Answer


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.