4

I would like to achieve the following ornament: For the university we have to convert code into a PDF. To make this easier I use the following macro:

\newcommand{\includecode}[2][code]{\lstinputlisting[escapechar=, style=code, title=#2]{#2} \bigskip}

However, the title displays the entire path of the file, not just the file name itself. How can I fix this?

Edit: This is the command I use for including files:

\includecode{Intelli/src/a19/a/Immobilie.java}

Regards

Andi

UPDATE: My final code. Maybe someone might like this solution in the future.

\makeatletter
\newcommand{\captcode}[1]{\filename@parse{#1}\filename@base.\filename@ext}
\makeatother

\newcommand{\includecode}[2][code]{\lstinputlisting[escapechar=, style=code, title=\captcode{#2}]{#2} \bigskip}
9

The LaTeX kernel has a file name parser that can be used to split the path into components:

\documentclass{article}

\makeatletter
\newcommand{\test}[1]{%
  \filename@parse{#1}%
  \begin{tabular}{ll}
    Path: & #1\\
    Area: & \filename@area\\
    Base: & \filename@base\\
    Extension:  & \filename@ext\\
    Name: & \filename@base.\filename@ext\\
  \end{tabular}%
}
\makeatother

\begin{document}
  \test{Intelli/src/a19/a/Immobilie.java}
\end{document}

Result

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.