I recently asked this question: Independent caption and numbers on different lstlisting language script
And the answer for my need was to use \lstnewenvironment. Problem is that I'm still working on the codes, so I need the codes to be imported. I was previously using \lstinputlisting, and it seems to be incompatible with \lstnewenvironment.
Is there a way to give the input document to the \lstnewenvironment as it is done with \lstinputlisting?
I tried this with no luck:
\documentclass{extarticle}
\usepackage{listings}
\newcounter{pythoncode}
\lstnewenvironment{pythoncode}[3]{
\renewcommand\lstlistingname{Python Code}
\setcounter{lstlisting}{\value{pythoncode}}
\lstset{
frame=single,
language=python,
rulecolor=\color{black},
commentstyle=\color{mGreen},
keywordstyle=\color{mOrange},
caption={[#1]{#1}},
label={#2},
inputpath={#3}
}
} {\addtocounter{pythoncode}{1}}
\begin{document}
\begin{pythoncode}{someCaption}{someLabel}{patronesOptimos.py}
\end{pythoncode}
\end{document}
Output is this (and of course it's not an empty Python file):
I also tried this, but it produces a timeout:
\documentclass{extarticle}
\usepackage{listings}
\lstdefinestyle{mypy}{
frame=single,
language=python,
rulecolor=\color{black},
commentstyle=\color{mGreen},
keywordstyle=\color{mOrange},
}
\newcounter{pythoncode}
\lstnewenvironment{pythoncode}[3]{
\renewcommand\lstlistingname{Python Code}
\setcounter{lstlisting}{\value{pythoncode}}
\lstset{
escapeinside={(*@}{@*)},
caption={[#1]{#1}},
label={#2}
}
} {\addtocounter{pythoncode}{1}}
\begin{document}
\begin{pythoncode}{someCaption}{someLabel}
(*@
\lstinputlisting[style = mypy]{Codigos/patronesOptimos.py}
@*)
\end{pythoncode}
\end{document}


