I am using titlesec and would like to use a macro that has a star variant in the title of a paragraph:
\documentclass{article}
\RequirePackage{titlesec}
\makeatletter
\def\something{@ifstar{A}{B}}
\makeatother
\begin{document}
\paragraph{A \something\ title} Lipsum.
\end{document}
This however returns an error
mwe.tex:9: Argument of \ttl@assign@i has an extra }. [\paragraph{A \something\ title}]
mwe.tex:9: Paragraph ended before \ttl@assign@i was complete. [\paragraph{A \something\ title}]
Why is this happening and how can I fix it?
\@ifstarare fragile. So you need\protector should use\DeclareRobustCommandinstead of\def. Alternatively I would suggest to use\NewDocumentCommand\something{s}{\IfBooleanTF{#1}{A}{B}}. – cabohah Mar 16 '23 at 15:35\titlesec. Without you would still have an error—just another one. – cabohah Mar 16 '23 at 15:41\protectbut another mistake was masking the fix! Sorry for the duplicate – Bordaigorl Mar 16 '23 at 15:50