1

I used the listingcode example from here What can I use to typeset MATLAB code in my document? to load a matlab code file directly into LaTeX, but I use different file directories as followed:

\documentclass[11pt,a4paper]{article}
\usepackage{listing}
\def\matlab{D:/Dokumente/MATLAB/model/}
\definecolor{MLgreen}{RGB}{28,172,0} % color values Red, Green, Blue
\definecolor{MLlilas}{RGB}{170,55,241}
\begin{document}
\import{./}{Appendix.tex}
\end{document}

% !TEX root = Mainfile.tex 
\appendix
\lstset{language=Matlab,%
    %basicstyle=\color{red},
    breaklines=true,%
    morekeywords={matlab2tikz},
    keywordstyle=\color{blue},%
    morekeywords=[2]{1}, keywordstyle=[2]{\color{black}},
    identifierstyle=\color{black},%
    stringstyle=\color{MLlilas},
    commentstyle=\color{MLgreen},%
    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},    
}
\lstinputlisting{{\matlab\myscript.m}}

But i can't get this code to run.

2
  • Please, could you add the error log and indicate the lines it highlights? Commented Feb 1, 2021 at 15:49
  • ! Undefined control sequence. <argument> \matlab \graphfunctresp l.25 \lstinputlisting{{\matlab\graphfunctresp}}
    – Riboswitch
    Commented Feb 1, 2021 at 15:51

1 Answer 1

0

I solved the issue myself. I use Tex-subfiles I include in my mainfile-document and it works as followed: Mainfile:

\providecommand{\pgfsyspdfmark}[3]{}
\documentclass[11pt,a4paper]{article}
\usepackage{listings}
\usepackage{color}
%define different working directory
\def\matlab{D:/Dokumente/MATLAB/model/}
\definecolor{MLgreen}{RGB}{28,172,0} % color values Red, Green, Blue
\definecolor{MLlilas}{RGB}{170,55,241}
\begin{document}
    \lstset{language=Matlab,%
    %basicstyle=\color{red},
    breaklines=true,%
    morekeywords={matlab2tikz},
    keywordstyle=\color{blue},%
    morekeywords=[2]{1}, keywordstyle=[2]{\color{black}},
    identifierstyle=\color{black},%
    stringstyle=\color{MLlilas},
    commentstyle=\color{MLgreen},%
    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},    
}

\import{./}{Appendix.tex}
\end{document}

Appendixfile:

% !TEX root = Mainfile.tex 
\appendix
\section{Appendix}
\lstinputlisting{\matlab/myfun.m}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .