1

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?

Bordaigorl
  • 15,135
  • 2
    Macros using \@ifstar are fragile. So you need \protect or should use \DeclareRobustCommand instead of \def. Alternatively I would suggest to use \NewDocumentCommand\something{s}{\IfBooleanTF{#1}{A}{B}}. – cabohah Mar 16 '23 at 15:35
  • 1
    BTW: The problem has (almost) nothing to do with using \titlesec. Without you would still have an error—just another one. – cabohah Mar 16 '23 at 15:41
  • Related: https://tex.stackexchange.com/questions/4736 – cabohah Mar 16 '23 at 15:44
  • @cabohah oh thanks! I did try to use \protect but another mistake was masking the fix! Sorry for the duplicate – Bordaigorl Mar 16 '23 at 15:50

0 Answers0