Creating a new command for the Real Part of a Complex Number

amsmath

I have created the following command: \renewcommand{\Re}[1]{\operatorname{Re}{\left\{{#1}\right\}}}

So that I can write, for example: \Re{w+z} , and "Re {w+z}" is shown.

The problem is, that I would like to write: \Re^2{z} And I would like to get: "Re^2 {z}" just as it can be done with trigonometric functions.

For example: \sin^2{(x)} returns "sin^2 (x)" automatically.

The thing is, if I use \renewcommand{\Re}[2]{\operatorname{Re}^{#1}{\left\{{#2}\right\}}} ,

I will have to write, for example, \Re{}{z} every time I needed "Re {z}" to be shown, which is terrible.

I would like to write \Re{something} and get "Re {something}", and also \Re^p{something} and get "Re^p {something}" every time needed, for any p.

I am having the same problem with the imaginary part of the complex numbers, but it's just the same thing.

Does anyone know how can I solve this problem?

Best Answer

Here I defined a new operator name using \DeclareMathOperator{\myRe}{Re}. Then I used the new operator name in a new command \myReCommand that has an optional argument. Not sure if that helps.

\documentclass{article}

% For \DeclareMathOperator
\usepackage{amsmath}

% For better versions of \left and \right (\mleft and \mright)
% Thanks to user Mico for the hint.
\usepackage{mleftright}

\DeclareMathOperator{\myRe}{Re}
\newcommand{\myReCommand}[2][]{\ensuremath{\myRe^{#1}\mleft(#2\mright)}}

\begin{document}

\begin{equation}
    \myRe^2(x) + \myRe(x)^2
\end{equation}

\myReCommand{x} \myReCommand[2]{x}

\end{document}

enter image description here


Unrelated to LaTeX, I found this about the notation \sin^2(t). In addition, see here or here for more discussions.


enter image description here


enter image description here


enter image description here

Related Question