I want to number the lines in a mdframed
environment with the line numbers appearing on the left of the frame, outside of it.
\documentclass{article}
\usepackage[framemethod=latex]{mdframed}
\newdimen\linenumbersep
\newcommand{\linenumber}[1]{%
\linenumbersep 4pt%
\advance\linenumbersep\mdflength{innerleftmargin}%
\advance\linenumbersep\mdflength{innerlinewidth}%
\advance\linenumbersep\mdflength{middlelinewidth}%
\advance\linenumbersep\mdflength{outerlinewidth}%
\advance\linenumbersep\mdflength{linewidth}%
\makebox[0pt][r]{{\rmfamily\tiny#1}\hspace*{\linenumbersep}}}
\begin{document}
\ttfamily
\begin{mdframed}
\linenumber{1}(define fact\\
\linenumber{2} (lambda (n)\\
\linenumber{3} (if (= n 0)\\
\linenumber{4} 1\\
\linenumber{5} (* n (fact (- n 1))))))
\end{mdframed}
\end{document}
After typesetting this document, I get
as expected. But when the tikz
method is used for drawing the frame by changing the second line of the source document
\usepackage[framemethod=tikz]{mdframed}
the line numbers are not visible anymore, giving
Is it possible to make this example work with the tikz
method?
I want to use something like this in a package I am writing to typeset a program listing with the help of Pygments. The line numbers would be generated automatically.
Best Answer
mdframed clips the box at the frame. But I don't know if it intended or a bug.
Edit 2017:
The problem seems to have been resolved. The patch it no longer needed.