I'm trying to create a command \placeDate to print something on the first call and then print nothing and generate an error if I call it once again.
The idea is to print the macro as usual and at the end call another macro (\inhibit) to redefine the macro and generate an error that could work for any macro. In the error message I'd like to see the name of the macro that we called several times (here placeDate).
So as I have to renew the command I have to send \placeDate to \inhibit as an argument. When the error is generated I need to remove the backslash to write the description message. \removebs is the command for that. The point is I'd like to save the string before renewing the so that we can call the string in the message.
\documentclass[a4paper,12pt]{report} \usepackage[english]{babel} \usepackage[utf8x]{inputenc} \usepackage[T1]{fontenc} \newcommand{\removebs}[1]{% {\catcode92=9 \endlinechar-1 \scantokens{#1}}% } \newcommand{\inhibit}[2] { \newcommand{\obj}{\removebs{#1}} \renewcommand#1[#2] { \GenericError{}{Error: multiple \obj instantiation}{Only one \obj possible.}{} } } \newcommand{\placeDate}[1] { \noindent #1, \today.\\\\ \inhibit{\placeDate}{1} } \begin{document} \placeDate{City} %ok \placeDate{City} %generates error \end{document} Obviously here it doesn't work because when \obj is called then \removebs{#1} becomes \removebs{\placeDate} and then I suspect that \placeDate is expanded before the process of \removebs. So I'd like some help to solve that problem.
Here is what we get in Overleaf :
Thank you in advance.
EDIT : In fact I have some similar macros in my code that i need to inhibit the same way. So each of these macros would inihibt themselves by calling a generic inhibit macro.
Example: \macroA
Result expected:
Error: multiple macroA instantiation. Only one macroA possible.

