1

I have an appendix with a full Matlab script, quoted verbatim, numbered and coloured as I want.

However, I want to quote about 10 lines of it as a figure in the body of my report, and since I will not quote any specific line numbers, they do not need to be included (the numbers also look nasty next to a table with a wrapped caption, where you get the 1 essentially sitting on the hyphen!)

At the moment, I have numbered turned on in the package options, and cannot seem to turn it off for the extract.

Alternatively, I could take the numbered out of the package options and then tell it to number the appendix.

    \documentclass{article}
\usepackage[numbered,breaklines=true]{mcode}

\begin{document}

some body
\begin{figure}[h]    
        \begin{lstlisting}[language=Matlab,breaklines=true]
    % loop over different monosaccharide in minimal media
    offset = 2;
    for j = 1:length(carbonSourceList)
    disp(['Current carbon source in media is: ', carbonSourceList{j}]);
    %fprintf('\n');
    lbColumn = (j - 1) * offset + 2;
    %ubColumn = (j - 1) * offset + 3;
    ubColumn = lbColumn + 1;
    currentFBAsettings = allFBAsettings(:, [1 lbColumn:ubColumn]);
    tempModel = batch_modify_flux_bounds(currentFBAsettings, origModel);
    \end{lstlisting}
    \label{Extract}  
    \caption{Extract from FBA Matlab script showing looping over different carbon sources} 
\end{figure} 
more body
\newpage
\appendix
\onecolumn
\small
\newpage
\section{MATLAB FBA Script, quoted verbatim}
%\lstinputlisting[language=Matlab,breaklines=true]{ATCC29149_FBA_all_v4_3.m}
\begin{lstlisting}[language=Matlab,breaklines=true]
    % loop over different monosaccharide in minimal media
    offset = 2;
    for j = 1:length(carbonSourceList)
    disp(['Current carbon source in media is: ', carbonSourceList{j}]);
    %fprintf('\n');
    lbColumn = (j - 1) * offset + 2;
    %ubColumn = (j - 1) * offset + 3;
    ubColumn = lbColumn + 1;
    currentFBAsettings = allFBAsettings(:, [1 lbColumn:ubColumn]);
    tempModel = batch_modify_flux_bounds(currentFBAsettings, origModel);
    \end{lstlisting}
\label{FBAscript}
\end{document}

This produces both with numbers. When I tried putting numbered=False as a parameter, it started throwing up error messages about breaklines, which works when a 'numbered' parameter is not included in the \lstinputlisting options.

3
  • Hi. You should add some m code so that people can try to compile your code. In your code you need external files which are not available. Aug 29 '14 at 12:35
  • @ManuelKuehner Done. If you compile this (providing you have mcode.sty installed) you will get two pages. One which has on it a captioned figure with numbers, one with an appendix with the code numbered. I would like the figure to contain no numbers, but the appendix to have line numbers. Aug 29 '14 at 12:57
  • @ACrazyChemist You should have a look at the matlab-prettifier package; it improves upon mcode in many ways. See this answer, for instance.
    – jub0bs
    Sep 7 '14 at 13:14
1

Ok, I figured it out. I set up mcode without numbered selected. I then found the set of commands that having numbered in the option ran and it looked like this:

\lstset{%
    numbersep=3mm, numbers=left, numberstyle=\tiny, % number style
}

So I then just added this inside the \section within the appendix and the numbers were included.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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