# Beautifully format text of an external document

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

m=3.775
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 '13 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. – Steven B. Segletes May 17 '13 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 '13 at 18:17
• You might be interested in the matlab-prettifier package; see this answer. – jub0bs Apr 28 '14 at 15:41

With the minted package, you can use

\inputminted[<options>]{<language>}{<file>}


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

\documentclass{article}
\usepackage{xcolor}
\usepackage{minted}

\begin{document}

\inputminted[bgcolor=gray!10]{matlab}{Mat1.m}

\end{document}


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

With the listings package, you can use

\lstinputlisting[<options>]{<file>}


A simple example, again with the previous settings

\documentclass{article}
\usepackage{xcolor}
\usepackage{listings}

\lstset{
basicstyle=\ttfamily,
backgroundcolor=\color{gray!10},
keywordstyle=\color{green!40!black},
columns=flexible
}

\begin{document}

\lstinputlisting[language=matlab]{Mat1.m}

\end{document}


The output:

• 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 '13 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. – Gonzalo Medina May 18 '13 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.