4

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?

Bakuriu
  • 2,218
Andrey Tyukin
  • 137
  • 1
  • 11
  • If you have to define over a command use \renewcommand, but in the words of egreg, never redefine a command you don't fully understand. Could you not define a command that doesn't already exist. Something like \myc. Another alternative, of course, is to get an editor with good autocomplete functions, so that you don't have to define lots of new short commands to save yourself the typing. This is generally better as you don't get these problems and others can use your code safely, without the risk that your new definitions will break something or clash – Au101 Jun 17 '15 at 00:13
  • I do understand the command: it appends a funny squiggle to 'c', and I'm pretty sure that I will never need it. It's less about typing, more about reading, I don't want to clutter up too much space by writing out \complement every time. And myc is just a very bad name for a command. If the "c-cedilla" is so fundamental to LaTeX that one cannot deactivate it, I guess I better switch to using just c without \mathrm. Thanks anyway. – Andrey Tyukin Jun 17 '15 at 00:19
  • The macro \c is already defined, as a macro that puts a cedilla below its argument. Hence, the instruction \providecommand{\c}{\mathrm{c}} won't do anything. You need \renewcommand instead of \providecommand. Of course, redefining \c will make it impossible to use the macro to insert cedillas elsewhere in your document. – Mico Jun 17 '15 at 00:22
  • Ouch... Thank you very much Mico, that explains everything... I've just mixed up \renewcommand and \providecommand (I somehow got the wrong idea that \providecommand either creates or overrides the previous definition). – Andrey Tyukin Jun 17 '15 at 00:32
  • 1
    I would use A^\complement and then may be redefine \complement (I usually use a \mathsf{c}) or even change the definition to \complement{A} so you can change the output completely at the end. – Manuel Jun 17 '15 at 10:16

2 Answers2

8

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

  • 1
    Please, use \DeclareRobustCommand\c{...} instead of \def\c{...}. – egreg Jun 17 '15 at 07:29
  • Steven, is this the correct way? I do something similar to add a “math definition” to the \d accent and I use \expandafter\let\expandafter\originald\csname\encodingdefault\string\d\endcsname and then \AtBeginDocument{\DeclareRobustCommand*\d{\ifmmode\mathop{}\!d\else\expandafter\originald\fi}} is this really necessary, or what you do is enough? – Manuel Jun 17 '15 at 10:25
  • @Manuel I am no expert on the potential pitfalls of the fix I offer. However, since we know that egreg has read the answer and not pointed out the added issue you raise, it gives some measure of confidence. – Steven B. Segletes Jun 17 '15 at 10:30
  • @egreg Is there an easy answer to Manuel's query? – Steven B. Segletes Jun 17 '15 at 10:32
  • StevenB.Segletes Same here, that's why I'm a bit confused. This works here, and I don't remember where did I get that code from, but I think it tries to emulate LetLtxMacro or something like that. Let's see if @egreg has something to say. – Manuel Jun 17 '15 at 10:32
  • I'd simply avoid redefining kernel commands such as \c and \d. – egreg Jun 17 '15 at 10:42
  • @egreg Well, fault is on the kernel for having such nice names taken, with no possibility to extend them to math mode. The easiest is \renewcommand but since I didn't want to alter it's meaning, I had to go the hard way to tweak it correctly, so now \d behaves like always, but inside math mode instead of an error, I get a differential \int f(x) \d x, and I like it. – Manuel Jun 17 '15 at 11:07
  • 1
    Thou shalt not eat of the tree of "redefining kernel commands", @Manuel. But if you do, you will be like egreg himself. Go ahead, take a bite. – Steven B. Segletes Jun 17 '15 at 11:21
  • The problem is that the global namespace is polluted by extremely short, yet almost useless commands. In Java or C#, they would have called it \org.groupname.internationalization.turkish.language.atuturkreformed.ccedilla{} instead of just \c{} in order to avoid unnecessary name clashes. – Andrey Tyukin Jun 17 '15 at 13:20
  • @AndreyTyukin Perhaps your comment was directed at Manuel, but to answer what is \d, it places a diacritical dot under the following argument. – Steven B. Segletes Jun 17 '15 at 13:26
  • Yes, thanks again Steven, I've found it myself after a while... I guess I better stop asking questions in the comment section. It already feels a bit as if I've accidentally unearthed an old source of an ongoing eternal online battle between people who like \d in integrals and people who don't like to override kernel commands. – Andrey Tyukin Jun 17 '15 at 13:32
  • @AndreyTyukin Questions are fine. Better asked than unasked. – Steven B. Segletes Jun 17 '15 at 13:33
5

As you have rightly observed you are having problems because \c is already provided. Its purpose is to provide the cedilla diacritic, which can actually be added to a number of letters. The letter it is to be added to should appear as an argument of \c, e.g. \c{c} produces ç.

Accordingly, if you want to define an alternative \c macro, you must issue \renewcommand like so:

\renewcommand{\c}{\mathrm{c}}

Your code will now work.

This, however, is not necessarily a very good idea. If you ever need to write about limaçons you may regret doing this. Steven B. Segletes provides a superb compromise for this case. All the same, conventional wisdom is to be very careful about redefining basic LaTeX commands, unless you're confident you know what you're doing with them. Otherwise you may end up breaking things. The weirdest error I ever got was when I thought I'd be very clever and write a little package called trig, to provide commands like \arccsc. Little did I know that there actually already exists a trig package, which is used for some definitions required in the pdflscape package. Oh I had fun when I tried to render a document with one landscape page.

Anyway, even if you don't need \c, by redefining basic commands, you make your code unlikely to work well for anybody else. This is fine if you're just doing your maths homework, but beware of getting too used to your definition of \c if you then collaborate with someone else. You may also find that some editors' syntax highlighting will go awry with some redefinitions.

A nicer alternative is to simply use a similar definition which isn't already defined.

I recommended

\newcommand{\myc}{\mathrm{c}}

Which will give you no such problems, but it doesn't matter if this isn't to your taste. Anything you fancy. But you will have fewer problems if you're cautious about overwriting LaTeX's definitions.

It's your code, though, just maybe add a comment to remind yourself if you do redefine \c?

An alternative that may help other people is to think about finding an editor with good autocomplete functionality, or which can input long commands if you find them too cumbersome. Have a look through this list and see what might work for you. I now know that you yourself are not so concerned about input but others may find this a better alternative.

Au101
  • 10,278
  • limacons... I think it's the first time ever that I see this symbol in mathematical context. That's actually somewhat surprising (at least to me): it seems that there aren't too many French mathematicians with this symbol in their surname, there are a few people whose name is " François", but that's about it. And I've never seen anyone using "ç" in a mathematical formula. – Andrey Tyukin Jun 17 '15 at 01:10
  • 1
    Indeed! And I doubt you'll use limaçons in the same document as you use complements, it was just an example. Just for the record, I don't mean to insist that you do not redefine \c - of course you can write your code however you want. But I wanted to put you on your guard and let you know of the potential problems you may run into if you follow the advice I gave and use \renewcommand. I think it'd be irresponsible for me to say "just use \renewcommand{\c}{...}" and not warn you that you might break something! – Au101 Jun 17 '15 at 01:13
  • @AndreyTyukin -- the cedilla can also be used on other letters, and can easily occur in a bibliographic reference without your noticing. if a manuscript with such a combination reaches the production department of a publisher, it will wreak havoc, and raise the cost of producing the publication. the diacritics were given "nice" definitions by knuth, creator of tex, because in his work he cites publications by authors from all around the world, and needed these symbols frequently. – barbara beeton Jun 17 '15 at 12:28