Hallo, ich habe den Code etwas erweiteret, sodass er mir mehrere Verzeichnisse für verschiedene eigene Sprachen macht. Da viel selbst definiert wurde ist das Beispiel nicht mehr wirklich minimal.
\documentclass[a4paper]{scrartcl}
\usepackage{scrhack}% verbessert u.a. auch listings
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage[ngerman]{babel}
\usepackage{color} % für \definecolor
\usepackage{listings}
\usepackage{microtype} % Captions im Programmcode
\definecolor{red}{rgb}{1,0,0}
\definecolor{darkgreen}{rgb}{0,0.392,0}
\definecolor{darkblue}{rgb}{0,0,0.75}
\lstdefinestyle{MatlabStyle}
{language=Matlab,
morekeywords={break,case,catch,continue,else,elseif,end,for,function,
global,if,otherwise,persistent,return,switch,try,while,ones,zeros},
float=hbp,
basicstyle=\ttfamily\small,
identifierstyle=\color{colIdentifier},
keywordstyle=\color{blue},
commentstyle=\color{dkgreen},
stringstyle=\color{dkgreen},
columns=flexible,
tabsize=2,
frame=single,
numbers=left,
extendedchars=true,
showspaces=false,
numberstyle=\tiny\color{black},
stepnumber=1,
numbersep=10pt,
showspaces=false,
showstringspaces=false,
breakautoindent=true}
\makeatletter
% Hook into listings
\lst@AddToHook{OutputOther}{\ProcessOther@silmeth}
% helper macro
\newcommand\ProcessOther@silmeth
{%
\ifnum\lst@mode=\lst@Pmode% % If we're in `Processing' mode...
\def\lst@thestyle{\color{blue}}% % ... redefine the style locally
\fi%
}
\lstdefinelanguage{StructuredText}{
%alsoletter={ =, ., ], [, ^, ;, (, ), +, -, *, /, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, :, :=},
%moredelim = *[l][\processlcom@homebrew]{/},
% alsoletter=0123456789,
keywordstyle={[1]\color{blue}},
keywordstyle={[2]\color{red}},
morekeywords=[1]{FUNCTION, LREAL, END_VAR, VAR_INPUT, LN, SQRT, IF, THEN, ELSE,
PROGRAM, BOOL, OF, DINT, INT, TO, DO, END_IF, END_FOR, ARRAY,
ANY, FOR, VAR, FUNCTION_BLOCK, VAR_OUTPUT, SIN, COS, TAN, PI, PT1, ABS},
morekeywords=[2]{FALSE, TRUE},
morekeywords=[2]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
literate=*{0}{{\textcolor{red}{0}}}{1}
{1}{{\textcolor{red}{1}}}{1}
{2}{{\textcolor{red}{2}}}{1}
{3}{{\textcolor{red}{3}}}{1}
{4}{{\textcolor{red}{4}}}{1}
{5}{{\textcolor{red}{5}}}{1}
{6}{{\textcolor{red}{6}}}{1}
{7}{{\textcolor{red}{7}}}{1}
{8}{{\textcolor{red}{8}}}{1}
{9}{{\textcolor{red}{9}}}{1}
{PT1}{{\textcolor{blue}{PT1}}}{1}
{dL1}{{\textcolor{black}{dL1}}}{1}
{rho0}{{\textcolor{black}{rho0}}}{1}
{help1}{{\textcolor{black}{help1}}}{1}
{help2}{{\textcolor{black}{help2}}}{1}
{acosh1}{{\textcolor{black}{acosh1}}}{1}
{acosh2}{{\textcolor{black}{acosh2}}}{1},
%otherkeywords={ ], [, ^, ;, := },
morecomment=[l][\color{green}]{//},
morecomment=[s][\color{green}]{/*}{*/},
morecomment=[s][\color{green}]{(*}{*)},
%moredelim=[s][\color{blue}]{(}{)},
%moredelim=[s][\color{blue}]{[}{]},
sensitive=true,
morestring=[b]",
deletekeywords={'},
breaklines=true,
numbersep=10pt,
}
\lstdefinestyle{StructuredTextStyle}{language=StructuredText}
%*****************************
%* Captions der Codeumgebung *
%*****************************
\renewcommand{\lstlistingname}{Code} % Listingname heisst nun Code
\makeatletter
\AtBeginDocument{%
\renewcommand*{\thelstlisting}{\thechapter.\arabic{lstlisting}}% % Nummerierung: section.listing
\@addtoreset{lstlisting}{section}%
\let\c@Ccode\c@lstlisting
}%
\makeatother
% Ein zweites Verzeichnis für HTML-Code definieren (siehe Anleitung zu
% tocbasic im scrguide)
\addtotoclist[float]{loh}
\newcommand*{\listoflohname}{HTML-Code}% Titel des neuen Verzeichnisses
\newcommand*{\listofHTMLlistings}{\listoftoc{loh}}% Nur eine Abkürzung
% Jetzt brauchen wir noch einen eigenen Zähler für HTML-Code
\newcounter{HTMLcode}[section]
\renewcommand*{\theHTMLcode}{\thechapter.\arabic{HTMLcode}}
\addtotoclist[float]{lom}
\newcommand*{\listoflomname}{Matlab-Code}% Titel des neuen Verzeichnisses
\newcommand*{\listofMatlablistings}{\listoftoc{lom}}% Nur eine Abkürzung
% Jetzt brauchen wir noch einen eigenen Zähler für HTML-Code
\newcounter{Matlabcode}[section]
\renewcommand*{\theMatlabcode}{\thechapter.\arabic{Matlabcode}}
\addtotoclist[float]{los}
\newcommand*{\listoflosname}{Strukturierter Text}% Titel des neuen Verzeichnisses
\newcommand*{\listofStructuredTextlistings}{\listoftoc{los}}% Nur eine Abkürzung
% Jetzt brauchen wir noch einen eigenen Zähler für HTML-Code
\newcounter{StructuredTextcode}[section]
\renewcommand*{\theStructuredTextcode}{\thechapter.\arabic{StructuredTextcode}}%\thesection.{\arabic{StructuredTextcode}
%******************************
%* Umgebung fuer Programmcode *
%******************************
\newif\iflistingwasHTML
\lstloadlanguages{[ANSI]C}
\lstdefinestyle{Cstyle}{%
language=[ANSI]C,
basicstyle=\ttfamily,
basicstyle=\scriptsize,
keywordstyle=\color{darkblue},
commentstyle=\color{darkgreen},
stringstyle=\color{red},
showstringspaces=false,
captionpos=b,
frame=single,
numbers = left
}
\makeatletter
\newcommand*\inputClisting{% Achtung: alles bis \lstinputlistng wirkt global!
\microtypesetup{activate=false}%
\renewcommand*{\lstlistingname}{C-Code}%
\renewcommand\thelstlisting{\thechapter.\arabic{lstlisting}}%
\let\c@lstlisting\c@Ccode
\iflistingwasHTML
\renewcommand*\addtocontents{\HTML@saved@addtocontents}%
\fi
\listingwasHTMLfalse
\lstset{style=Cstyle}%
\lstinputlisting
}
\makeatother
\lstnewenvironment{CCode}[1][]{%
\microtypesetup{activate=false}%
\renewcommand*{\lstlistingname}{C-Code}%
\lstset{style=Cstyle,
#1}%
}
{}
%******************************
%* Umgebung fuer Programmcode *
%******************************
\makeatletter
\newcommand*\inputMatlablisting{% Achtung: alles bis \lstinputlistng wirkt global!
\microtypesetup{activate=false}%
\renewcommand*{\lstlistingname}{Matlab-Code}%
\let\thelstlisting\theMatlabcode
\let\c@lstlisting\c@Matlabcode
\let\Matlab@saved@addtocontents\addtocontents
\renewcommand*{\addtocontents}[1]{%
\ifstr{##1}{lol}{%
\Matlab@saved@addtocontents{lom}%
}{%
\Matlab@saved@addtocontents{##1}%
}%
}%
\lstset{MatlabStyle}%
\listingwasMatlabtrue
\lstinputlisting
}
\lstnewenvironment{MatlabCode}[1][]{%
\microtypesetup{activate=false}
\renewcommand*{\lstlistingname}{Matlab-Code}%
% Einige Zeilen Code, damit listings den Zähler HTMLcode verwendet
\let\thelstlisting\theMatlabcode
\let\c@lstlisting\c@Matlabcode
% Einige Zeilen Code, damit listings keinen Eintrag in lol, sondern einen in
% loh vornimmt.
\let\Matlab@saved@addtocontents\addtocontents
\renewcommand*{\addtocontents}[1]{%
\ifstr{##1}{lol}{%
\Matlab@saved@addtocontents{lom}%
}{%
\Matlab@saved@addtocontents{##1}%
}%
}%
\lstset{style=MatlabStyle, #1}%
}
{}
\makeatother
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\makeatletter
\newcommand*\inputStructuredTextlisting{% Achtung: alles bis \lstinputlistng wirkt global!
\microtypesetup{activate=false}%
\renewcommand*{\lstlistingname}{Strukturierter Text}%
\let\thelstlisting\theStructuredTextcode
\let\c@lstlisting\c@StructuredTextcode
\let\StructuredText@saved@addtocontents\addtocontents
\renewcommand*{\addtocontents}[1]{%
\ifstr{##1}{lol}{%
\StructuredText@saved@addtocontents{lom}%
}{%
\StructuredText@saved@addtocontents{##1}%
}%
}%
\lstset{StructuredTextStyle}%
\listingwasStructuredTexttrue
\lstinputlisting
}
\lstnewenvironment{StructuredTextCode}[1][]{%
\microtypesetup{activate=false}
\renewcommand*{\lstlistingname}{Strukturierter Text}%
% Einige Zeilen Code, damit listings den Zähler HTMLcode verwendet
\let\thelstlisting\theStructuredTextcode
\let\c@lstlisting\c@StructuredTextcode
% Einige Zeilen Code, damit listings keinen Eintrag in lol, sondern einen in
% loh vornimmt.
\let\StructuredText@saved@addtocontents\addtocontents
\renewcommand*{\addtocontents}[1]{%
\ifstr{##1}{lol}{%
\StructuredText@saved@addtocontents{los}%
}{%
\StructuredText@saved@addtocontents{##1}%
}%
}%
\lstset{style=StructuredTextStyle, #1}%
}
{}
\makeatother
\begin{filecontents*}{test-a.html}
<tilte>HTML-Test</title>
\end{filecontents*}
\begin{filecontents*}{test-b.c}
#include <stdio.h>
\end{filecontents*}
\begin{document}
\lstlistoflistings
\listofHTMLlistings
\section{Kapitel}
\begin{CCode}[caption={Beschriftung1}, label=code:c]
int i;
i = 2;
\end{CCode}
\begin{MatlabCode}[caption={Beschriftung2}, label=code:html]
break
\end{MatlabCode}
\begin{StructuredTextCode}[caption={Beschriftung1}, label=code:c2]
A := B;
\end{StructuredTextCode}
\begin{MatlabCode}[caption={Beschriftung2}, label=code:html2]
break
\end{MatlabCode}
%\inputHTMLlisting[caption={HTML Test}]{test-a.html}
%\inputClisting[caption={C Test}]{test-b.c}
\end{document}
Ich würde mich sehr über Verbesserungsvorschläge freuen, da ich nicht sehr viel Ahnung habe und momentan sehr viel probiere.