I am trying to automatically add section label based on the file name. My structure is as such:
- main.tex
- 1.0.introduction.tex
- 1.1.0.foo.tex
- 1.1.1.bar.tex
I am using \currfilename from package currfile to get the filename {which removes the .tex} and xstring to remove everything before the last {.} up to three levels deep.
So my newcommand clearname is producing the expected result: from 1.0.introduction -> introduction. The problem occurs when trying to add my command to the label.
While \label{\currfilename} works and the label gets created, when doing \label{\clearname{\currfilename}} I get 6 different compilation errors which I am too of a novice to wrap my head around.
MWE:
main.tex
\documentclass{article}
\usepackage{xstring}
\usepackage{currfile}
\usepackage{showkeys}
\newcommand{\clearname}[1]{%
\StrCount{#1}{.}[\tmp]
\IfEqCase{\tmp}{%
{1}{\StrBehind{#1}{.}}%
{2}{\StrBehind{#1}{.}[\tmp2]\StrBehind{\tmp2}{.}}%
{3}{\StrBehind{#1}{.}[\tmp2]\StrBehind{\tmp2}{.}[\tmp3]\StrBehind{\tmp3}{.}}
}
}
\begin{document}
\input{1.0.introduction}
\end{document}
1.0.introduction.tex
\section{Introduction}
\currfilename
\label{\currfilename}
\clearname{\currfilename}
% \label{\clearname{\currfilename}}
As clearly seen in \ref{1.0.introduction}
So to summarize I need the label created to be introduction and not 1.0.introduction.
