I want to include parts of my Matlab code in my LaTeX document using mcode.sty. Here's a MWE:
\documentclass[b5paper, 10pt, twoside, openright, dvipsnames,cmyk]{report}
\usepackage{listings} % Is this package necessary?
\usepackage[framed,numbered,autolinebreaks]{mcode}
\begin{document}
Figure~\ref{fig:binarysearch} doesnt work!
\begin{figure}
\label{fig:binarysearch}
\lstinputlisting{pics/met/binarysearch.m}
\caption[Matlab code for the half-interval search method]
{Matlab code for the half-interval search method}
\end{figure}
\end{document}
Is there a way to define which line number I want to start on for each included code section? Let's say I want to start on line 6. How is this accomplished? The default is (naturally) 1.
I've placed the code in a figure environment, and I want to refer to it as a figure. However, referring in the text to the figure doesn't work. The compiled file writes ?? instead of the figure reference.
matlab-prettifierpackage; it improves uponmcodein many ways. See this answer, for instance. – jub0bs May 12 '15 at 12:29:pI refer you to section 2 of thematlab-prettifierdoc, in which you will find a point-by-point comparison of the alternatives (mcode,minted, etc.). Basically,matlab-prettifieraims to be easier to use and more consistent thanmcode. – jub0bs May 12 '15 at 16:07mcode, there seems to be less space per line in LaTeX compared to Matlab. I've fittet my code into one line in Matlab, but the text must be on two lines in my document. Is this the case formatlab-prettifiertoo? – ROLF Jun 07 '15 at 19:07mcodeormatlab-prettifier; rather, it depends on the font (family, size, etc.) and the text width you use; you can use thelistings' option calledlinewidthto tweak the latter to your liking. – jub0bs Jun 07 '15 at 21:04