Skip to content

Instantly share code, notes, and snippets.

@davidwessman
Last active December 10, 2015 07:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidwessman/5f19d6dcdbb367db58d6 to your computer and use it in GitHub Desktop.
Save davidwessman/5f19d6dcdbb367db58d6 to your computer and use it in GitHub Desktop.
Import Matlab to LaTeX
% https://www.ctan.org/pkg/listings
\usepackage[procnames]{listings}
\usepackage{color} %red, green, blue, yellow, cyan, magenta, black, white
\definecolor{mygreen}{RGB}{28,172,0} % color values Red, Green, Blue
\definecolor{mylilas}{RGB}{170,55,241}
% Python style for highlighting
\newcommand\matlabstyle{\lstset{
language=Matlab
breaklines=true,%
morekeywords={matlab2tikz},
keywordstyle=\color{blue},%
morekeywords=[2]{1}, keywordstyle=[2]{\color{black}},
identifierstyle=\color{black},%
stringstyle=\color{mylilas},
commentstyle=\color{mygreen},%
showstringspaces=false,%without this there will be a symbol in the places where there is a space
numbers=left,%
numberstyle={\tiny \color{black}},% size of the numbers
numbersep=9pt, % this defines how far the numbers are from the text
emph=[1]{for,end,break},emphstyle=[1]\color{red}, %some words to emphasise
%emph=[2]{word1,word2}, emphstyle=[2]{style},
}}
% Matlab environment
\lstnewenvironment{matlab}[1][]
{
\matlabstyle
\lstset{
#1,literate={ö}{{\"o}}1
{ä}{{\"a}}1
{å}{{\aa}}1
{Å}{{\AA}}1
{Ä}{{\"A}}1
{Ö}{{\"O}}1
{~}{{\tilde}}1
{é}{{\´{e}}}1
{É}{{\´{E}}}1
}
}
{}
% Matlab for external files
\newcommand\matlabexternal[2][]{{
\matlabstyle
\lstinputlisting[#1]{#2}}}
% Matlab for inline
\newcommand\matlabinline[1]{{\matlabstyle\lstinline!#1!}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment