I have some formatted long text files looking like this:

f=50 k_max=420

 Iteration   Func-count     min f(x)         Procedure
     0            1      7.07212e-09         
     1            2      7.07212e-09         initial simplex
     2            4      7.06369e-09         reflect
     3            6      7.06369e-09         contract outside
     4            8      7.06369e-09         contract inside
     5           10      7.06367e-09         contract inside

Exiting: Maximum number of function evaluations has been exceeded
         - increase MaxFunEvals option.
         Current function value: 0.000000 

f=100 k_max=1009

 Iteration   Func-count     min f(x)         Procedure
     0            1      1.89961e-10         
     1            2      1.89961e-10         initial simplex
     2            4      1.33983e-10         expand
     3            6      8.33243e-11         expand
     4            8      7.98592e-11         contract outside
     5           10      7.98592e-11         contract inside

Exiting: Maximum number of function evaluations has been exceeded
         - increase MaxFunEvals option.
         Current function value: 0.000000 

These files are the command line of MATLAB which are saved using diary command.

Is there a way to import the source file and typeset it beautifully in LaTeX? I love to use minted package or something comparable with colors if possible here.

  • @dustin,Is there some option there for plain Text file
    – rowman
    May 17, 2013 at 18:10
  • Define beautiful. Here are some possibilities: font; verbatim or not verbatim; in a box; in a tabular... it is hard to see what you seek. May 17, 2013 at 18:13
  • @rowman I added a screen capture from how I used it last. Is the general idea? I used it for code but it doesn't have to be that way.
    – dustin
    May 17, 2013 at 18:17
  • You might be interested in the matlab-prettifier package; see this answer.
    – jub0bs
    Apr 28, 2014 at 15:41

2 Answers 2


With the minted package, you can use


Here's an example file code.tex using your sample file and saving it as Mat1.m:





The output, after processing with pdflatex --shell-escape code.tex:

enter image description here

With the listings package, you can use


A simple example, again with the previous settings






The output:

enter image description here

  • Is it possible to selectively set which words to be in color? Note that this is a text output so words like function or min should not be in color like MATLAB language.
    – rowman
    May 18, 2013 at 16:00
  • @rowman Sure! Using the listings package, you can define your own settings. The package documentation has the details. I am not familiar enough with the minted package, so I wouldn't know how hard would be to do the same. May 18, 2013 at 17:12

Here is a link to one of my questions that has the listing environment.

disregard the vbox warning stuff

Or you can use the verbatim package and it will look just like it is in-putted.

The listing environment is just a highspeed form of verbatim.

Here is what the code does but this is just an image of code formatting. Is this the general idea? You can always adjust colors.

enter image description here

Useful links:

This is python based but the ideas are the same:

how to highlight syntax

This one is more general:

code highlighting

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.