I'm trying to renew the math command \degso that it requires one argument. Right now, if I want to type the degree of a function f, I have to type \deg and manually add (x) behind it to get the desired result. However, I wanted to redefine the command \deg and add an argument to it so that next time, instead of typing \deg(x), I will only need to fill in an f between the brackets in \deg{}.
I have tried to something like \renewcommand{\deg}[1]{\deg(#1)} but clearly that didn't work. Is there any way I can make somehow redefine \deg?

  • 3
    Where's the advantage in typing \deg{f} rather than \deg(f)? – egreg Mar 1 at 18:24
  • @egreg idk... it doesn't really give me any advantage in this case I guess. But it might make some other commands more convenient. For example, when I want to type a superscript or a subscript more than one digit, it's very annoying to add the {} every single time when typing something like x_{12}. – Skorpion Mar 1 at 18:27
  • No, it's not annoying, particularly if your editor automatically adds the braces when you type _. – egreg Mar 1 at 18:41
  • @egreg That sounds interesting. I'm using TexStudio, it does automatically adds } whenever I type {. But I've never found the configuration where it would add {} when I type _ or ^. Could you tell me where it is if TexStudio has this feature and you happen to know it? Thanks... – Skorpion Mar 1 at 18:55
  • 3
    If you do decide to define commands for this (I would not) I would define new names rather than redefine standard commands. If you ever come to need to share your work and collaborate with other authors you will find it much easier to do so if your expressions are not using definitions that conflict with standard latex markup. you really don't need to call the command \deg when you could call it \dg or \Deg or anything else that is not already defined. – David Carlisle Mar 1 at 21:18

As David says, it is not recommended that you redefine existing commands in order to customise them -- the main reason is that doing this is very likely to confuse anyone who reads your TeX files, especially future collaborators.

Instead, you could use something like the code below to define a new command \Deg so that $\Deg f$ produces deg f(x). I have added an optional argument so that $\Deg[y]f$ yields deg f(y).

Here is a minimal working example:

\newcommand\Deg[2][x]{\deg #2(#1)}


  $\Deg f$, $\Deg[y]f$


This gives the promised output:

enter image description here

Note that that the \Deg macro, like \deg, needs to be used inside math-mode. Of course, you could use \ensuremath but I avoid this command because I think that it is better to be explicit about entering and leaving math-mode.

Finally, by using the \NewDocumentCommand command from the xparse package we can make the syntax for the optional argument more natural, so that $\Deg f$ produces deg f(x), as before, and now $\Deg f(y)$ produces deg f(y) (of course, $\deg f(y)$ does this too!). Here is the new code:

\NewDocumentCommand\Deg{ mD()x }{\deg #1(#2)}


  $\Deg f$, $\Deg f(y)$


The output is the same as before.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.