# Relatives/absolute path for listing with subfiles

I have problem with path management. Let me explain you:

I work with subfiles that are arranged in this way:

REPORT
--Main.tex
--lab1
----Matlab
------CodeLab1.m
----Report
------Report_P1_1.tex
--lab2
----Matlab
------CodeLab2.m
----Report
------Report_P2_1.tex

I want to be able to include the code "CodeLab1.m" in the "Report_P1_1.tex" file and "CodeLab2.m" in the "Report_P2_1.tex" and to be able to compile them either separately or from the main (as I use subfile its possible). The trick I use is this:

Main.tex:

\documentclass[]{article}

\usepackage{xcolor, listings, subfiles}
\definecolor{grey}{rgb}{0.96,0.96,0.96}
\lstset{backgroundcolor=\color{grey}}

\newcommand{\myPathLstONE}[0]{
\ifx\mainCmp\undefined  \renewcommand{\myPathLstONE}{../Matlab}
\else                   \renewcommand{\myPathLstONE}{lab1/Matlab}
\fi}
\newcommand{\myPathLstTWO}[0]{
\ifx\mainCmp\undefined  \renewcommand{\myPathLstTWO}{../Matlab}
\else                   \renewcommand{\myPathLstTWO}{lab2/Matlab}
\fi}

\begin{document}
\def\mainCmp{}

\part{Labo 1}
\subfile{lab1/Report/Report_P1_1.tex}

\part{Labo 2}
\subfile{lab2/Report/Report_P2_1.tex}

\end{document}


Report_P1_1.tex:

\documentclass[../../Main.tex]{subfiles}
\begin{document}

\section{Part 1}

There's a listing:

\lstinputlisting[]{\myPathLstONE/CodeLab1.m}

\end{document}


Report_P2_1.tex:

\documentclass[../../Main.tex]{subfiles}
\begin{document}

\section{Part 2}

There's a listing:

\lstinputlisting[]{\myPathLstTWO/CodeLab2.m}

\end{document}


It works quite well, the only problem (exept that its not really practical to define every time these command) is that in the output I got, there is always the name of the code file as you can see. I didn't find a way to avoid this.

As its possible to define multiple path for graphics, the inclusion of listings is my only problem working with this architecture.

Can somebody help or propose an other way to do this?

Thanks a lot!