[Tex/LaTex] How to get rid of “c-cedilla” in math mode

errorsmacros

This code:

\documentclass{scrartcl}
\providecommand{\c}{\mathrm{c}}
\begin{document}
  Complement of $A$: $A^\c$.
\end{document}

Produces the following error:

! Missing { inserted.
<to be read again> 
                   \begingroup 
l.6   Complement of $A$: $A^\c
                              $.
!  ==> Fatal error occurred, no output PDF file produced!

The problem is that the command \c already exists (denotes a "c-cedilla"). However, I would rather like to use \c to denote set complements in math mode.

It seems that for some reason LaTeX cannot switch from text mode to math mode. How can I get rid of "c-cedilla" and get a normal 'c' in math mode?

Best Answer

This redefines it for math mode only, retaining its original use in text mode. EDITED , per egreg's recommendation, to use \DeclareRobustCommand in lieu of \def. The \expandafter in the definition allows the following \fi to be absorbed, so that the text version of \c can operate on the actual argument that follows.

\documentclass{book}
\let\svc\c
\DeclareRobustCommand\c{\ifmmode\mathrm{c}\else\expandafter\svc\fi}
\begin{document}
This is a \c complicated test.

Complement of $A$: $A^\c$.
\end{document}

enter image description here