6

I have a function which takes a filepath as an argument. How can I extract the basename (file.c in the example below) from the argument?

\mycommand{path/to/file.c}

...

\def\@mycommand#1{
  ...
  \section{\basename{#1})}
  ...
}
11

LaTeX includes a filepath parser (the exact syntax it parses depends on the system)

\makeatletter

\filename@parse{path/to/file.c}

\typeout{area: \filename@area}

\typeout{name: \filename@base}

\typeout{ext: \filename@ext}

\makeatother

Produces this on the terminal:

area: path/to/
name: file
ext: c
|improve this answer|||||

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.