1

I'm including a MATLAB script as an appendix in a report I'm writing, I'm using mcode to import it, but some of the lines are longer than the width of my paper. In my master document I have:

\usepackage[numbered]{mcode}
\usepackage[titletoc]{appendix}
body
\begin{appendices}
\appendix
\onecolumn
\small
\input{appendices.tex}
\end{appendices}

My document is two column, but in the appendices.tex that I'm including I have the following:

\newpage
\section{MATLAB FBA Script, quoted verbatim}
\lstinputlisting{MY_FILE_PATH.m}
\label{FBAscript}

Unfortunately, some of the lines of my code have the ends missing, especially when I've defined long arrays.

Could you please advise me on how to force wrap the text, while maintaining the correct line numbering?

The part causing me the most trouble are these long matlab lists:

%biomassRxns = {'Biomass_BT_v2'};
%long including LTA/LPDC
%biomassRxns = {'EX_cpd00002(b)','EX_cpd00006(b)','EX_cpd00005(b)','EX_cpd00010(b)','EX_cpd00003(b)','EX_cpd00012(b)','EX_cpd00018(b)','EX_cpd00001(b)','EX_cpd00046(b)','EX_cpd00096(b)','EX_cpd00254(b)','EX_cpd00052(b)','EX_cpd00038(b)','EX_cpd00031(b)','EX_cpd11493(b)','EX_cpd00126(b)','EX_cpd10516(b)','EX_cpd00205(b)','EX_cpd11463(b)','EX_cpd15499(b)','EX_cpd00063(b)','EX_cpd11462(b)','EX_cpd11461(b)','EX_cpd15664(b)','EX_cpd00201(b)','LPDC_cpd15697(c)','LPDC_cpd15729(c)','LPDC_cpd15742(c)','LPDC_cpd15700(c)','LPDC_cpd15741(c)','LPDC_cpd15732(c)','LPDC_cpd15724(c)','LPDC_cpd15533(c)','LPDC_cpd15695(c)','LPDC_cpd15738(c)','LPDC_cpd15745(c)','LPDC_cpd15736(c)','LPDC_cpd15727(c)','LPDC_cpd15799(c)','LPDC_cpd15743(c)','LPDC_cpd15696(c)','LPDC_cpd15740(c)','LPDC_cpd15699(c)','LPDC_cpd15731(c)','LPDC_cpd15536(c)','LPDC_cpd15792(c)','LPDC_cpd15737(c)','LPDC_cpd15728(c)','LPDC_cpd15744(c)','LPDC_cpd15726(c)','LPDC_cpd15798(c)','LPDC_cpd15723(c)','LPDC_cpd15795(c)','LPDC_cpd15739(c)','LPDC_cpd15730(c)','LPDC_cpd15698(c)','LPDC_cpd15722(c)','LPDC_cpd15794(c)','LPDC_cpd15735(c)','LPDC_cpd15538(c)','LPDC_cpd15791(c)','LPDC_cpd15725(c)','LPDC_cpd15797(c)','LPDC_cpd15531(c)','LPDC_cpd15734(c)','LPDC_cpd15733(c)','LPDC_cpd15540(c)','LPDC_cpd15793(c)','LPDC_cpd15529(c)','LPDC_cpd15712(c)','LPDC_cpd15782(c)','LPDC_cpd15714(c)','LPDC_cpd15788(c)','LPDC_cpd15790(c)','LPDC_cpd15789(c)','LPDC_cpd15710(c)','LPDC_cpd15786(c)','LPDC_cpd15713(c)','LPDC_cpd15707(c)','LPDC_cpd15715(c)','LPDC_cpd15711(c)','LPDC_cpd15787(c)','LPDC_cpd15783(c)','LPDC_cpd15709(c)','LPDC_cpd15784(c)','LPDC_cpd15708(c)','LPDC_cpd15785(c)','LTA_cpd15747(c)','LTA_cpd15750(c)','LTA_cpd15753(c)','LTA_cpd15749(c)','LTA_cpd15754(c)','LTA_cpd15752(c)','LTA_cpd15748(c)','LTA_cpd15751(c)','LTA_cpd15746(c)','LTA_cpd15759(c)','LTA_cpd15775(c)','LTA_cpd15767(c)','LTA_cpd15768(c)','LTA_cpd15766(c)','LTA_cpd15758(c)','LTA_cpd15757(c)','LTA_cpd15777(c)','LTA_cpd15776(c)','LTA_cpd15769(c)','LTA_cpd15761(c)','LTA_cpd15762(c)','LTA_cpd15756(c)','LTA_cpd15755(c)','LTA_cpd15764(c)','LTA_cpd15771(c)','LTA_cpd15760(c)','LTA_cpd15779(c)','LTA_cpd15774(c)','LTA_cpd15781(c)','LTA_cpd15763(c)','LTA_cpd15772(c)','LTA_cpd15770(c)','LTA_cpd15765(c)','LTA_cpd15773(c)','LTA_cpd15780(c)','LTA_cpd15778(c)'};
%long reaction list
%biomassRxns = {'EX_cpd00002(b)','EX_cpd00006(b)','EX_cpd00005(b)','EX_cpd00010(b)','EX_cpd00003(b)','EX_cpd00012(b)','EX_cpd00018(b)','EX_cpd00001(b)','EX_cpd00046(b)','EX_cpd00096(b)','EX_cpd00254(b)','EX_cpd00052(b)','EX_cpd00038(b)','EX_cpd00031(b)','EX_cpd11493(b)','EX_cpd00126(b)','EX_cpd10516(b)','EX_cpd00205(b)','EX_cpd11463(b)','EX_cpd15499(b)','EX_cpd00063(b)','EX_cpd11462(b)','EX_cpd11461(b)','EX_cpd15664(b)','EX_cpd00201(b)','EX_cpd15800(b)','EX_cpd15670(b)'};
%long less teichoic acid composition
biomassRxns = {'EX_cpd00002(b)','EX_cpd00006(b)','EX_cpd00005(b)','EX_cpd00010(b)','EX_cpd00003(b)','EX_cpd00012(b)','EX_cpd00018(b)','EX_cpd00001(b)','EX_cpd00046(b)','EX_cpd00096(b)','EX_cpd00254(b)','EX_cpd00052(b)','EX_cpd00038(b)','EX_cpd00031(b)','EX_cpd11493(b)','EX_cpd00126(b)','EX_cpd10516(b)','EX_cpd00205(b)','EX_cpd11463(b)','EX_cpd15499(b)','EX_cpd00063(b)','EX_cpd11462(b)','EX_cpd11461(b)','EX_cpd15664(b)','EX_cpd00201(b)','EX_cpd15800(b)'};
%biomassRxns = {'rxnBSbiomass'};
%biomassRxns = {'rxnBSbiomass_f_2'} 
7
  • Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format.
    – Johannes_B
    Aug 29 '14 at 8:48
  • 3
    listings has an option for that: breaklines=true.
    – Johannes_B
    Aug 29 '14 at 8:48
  • 2
    You may also want to have a look to the package matlab-prettifier. Aug 29 '14 at 8:51
  • @Johannes_B This destroys all the colour formatting, which I'd like to keep and don't have time to reinstate using 'mycolor' type commands. Aug 29 '14 at 8:56
  • @HarishKumar - this doesn't break the long arrays, it now just has long_list = ... {'item1','item2','item3', etc until it reaches the end of the page and carries on, rather than splitting the array onto seperate lines! Aug 29 '14 at 8:57
2

\usepackage[numbered,breaklines=true]{mcode} splits the long arrays properly, and is the solution I was looking for.

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.