I'm trying to write a macro to change the definitions of \thesection, \thechapter, and other commands for the sectioning prefixes. I want to redefine only one of the commands depending on the user's input to a command. I've tried something like this:
\documentclass{report}
\usepackage{etoolbox}
\usepackage{titlesec}
\newcommand{\changeprefix}[2]{
%\renewcommand\csname the#1\endcsname{#2} % ! Extra \endcsname.
%\renewcommand \the#1{#2} %! Argument of \rem@pt has an extra }.
%\def\headername{\csuse{the#1}}
%\renewcommand \headername {#2} % compiles but has no effect
%\renewcommand \csuse{the#1} {#2} % compiles but prints the value of #2
\makeatletter
\expandafter\renewcommand \@nameuse{the#1} {#2} % compiles but prints everything after \@
\makeatother
}
\begin{document}
\changeprefix{section}{test prefix - }
\section{Test section}
Some text...
\end{document}
My attempts don't quite work. For the two bottom ones (that actually compile) I get the following output:
I've taken my inspiration from this answer as well as this one, but I'm not quite there yet. Is it possible to make this work and get the following output for the \section{Test section}
call?
test prefix - Test section