# Naming a section with filename

I am making quite a big document that will be worked on by many paople. We have therefore decided to divide the project by importing every section by it self as shown below.

\import{Sections/}{Test}
\import{Sections/}{Test2}


In each file (and therefore section) I would like the section to be called the same as the file (without .tex).

Test.tex should contain the section Test. Test2.tex should contain the section Test2 etc. There should not be a problem to do this in a "manual" way. However, it would be a lot less work if it was dynamic. Some code to simply copy into a new file.

I have tried the following.

\section{\currfilename} % Output: Test.tex

\section{\StrDel{\currfilename}{.tex}} % This either outputs "Test.tex" or a compilation error.

\section{\StrBefore{\currfilename}{.}} % This does the same as \StrDel


I have also tried to define it as a variable first, and then use it for the section as shown below. However, this does not work either.

\def \filenametosection{\StrBefore{\currfilename}{.}}
\section{filenametosection}


My question is therefore if anyone knows how to set the section name (in the beginnning of each file) in a not to complicated manner to the files name (without .tex).

• Does \currfilebase do what you want? – Marijn Jul 31 '19 at 10:56

Laughing at myself I managed to solve this in a simpler manner :D

By making a new command for each new section I am able to make a section and import the file with the same name like this.

\newcommand\newsection[1]{\section{#1}\import{Sections/}{#1}}


When making a new section I simply make a new section..

\newsection{Test}
\newsection{Test2}


This fixed the problem and should be simple for more people to learn.

An important note is that this fix does not support spaces or underscores in section names.