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:




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


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

1 Answer 1


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


    Path: & #1\\
    Area: & \filename@area\\
    Base: & \filename@base\\
    Extension:  & \filename@ext\\
    Name: & \filename@base.\filename@ext\\



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.