3

I'm trying to make a new command for something like this:

\operatorname{Re}\left\lbrace\num{1+2i}\right\rbrace

Because I'm using the mathtools package already I tried to do something like this: (And I have to undefine the previous \Re and \Im commands, because they are ugly and this command should be obviously called \Re and \Im.)

\let\Re\undefined
\let\Im\undefined
\DeclarePairedDelimiter\Re{\operatorname{Re}\lbrace}{\rbrace}
\DeclarePairedDelimiter\Im{\operatorname{Im}\lbrace}{\rbrace}

This will work, but will also spit put many errors. Like: Missing { inserted. \end{align} and so on.

Then I thought: Yes, this is probably, because the font can not scale (and shouldn't), like the \lbrace and \rbrace. And I tried something like this:

\let\Re\undefined
\let\Im\undefined
\DeclarePairedDelimiter\braces{\lbrace}{\rbrace}
\newcommand{\Re}{1}{\operatorname{Re}\braces*{#1}}
\newcommand{\Im}{1}{\operatorname{Im}\braces*{#1}}

But this will produce:

Missing $ inserted. \newcommand{\Re}{1}{\operatorname{Re}

Missing \begin{document}. \newcommand{\Re}{1}{\operatorname{Re}

Inserting \ensuremath or something like that doesn't help much.

Last try:

\let\Re\undefined
\let\Im\undefined
\newcommand{\Re}{1}{\operatorname{Re}\left\lbrace #1 \right\rbrace}
\newcommand{\Im}{1}{\operatorname{Im}\left\lbrace #1 \right\rbrace}

Missing $ inserted. \newcommand{\Re}{1}{\operatorname{Re}

Missing \begin{document}. \newcommand{\Re}{1}{\operatorname{Re}

You can't use `macro parameter character #' in math mode. ...nd{\Re}{1}{\operatorname{Re}\left\lbrace #

It can't be this hard to make something like this work, or can it? I really don't know what I should try next, or what am I even doing wrong.

1
  • why do you want \left and \right with 1+2i? you would get better spacing with (1+2i) than with \left(1+2i\right) Nov 28, 2018 at 22:04

2 Answers 2

6

You have the incorrect syntax for \newcommand.

\newcommand{\Re}{1}

should be

\newcommand{\Re}[1]
6

You can use the \DeclarePairedDelimiterXPPfrom mathtools. It will define \Reand \Im commands, which have a star version (adds a pair of implicit \left \right in front of the delimiters), but they also accept an optional argument among \big, \Big, \bigg and \Bigg, which adds a pair oof implicit \bigl \bigr, &c.

\documentclass[10pt]{article}
\usepackage{mathtools} %
\let\Re\undefined
\let\Im\undefined
 \DeclarePairedDelimiterXPP\Re[1]{\operatorname{Re}}{\lbrace}{\rbrace}{}{#1}
 \DeclarePairedDelimiterXPP\Im[1]{\operatorname{Im}}{\lbrace}{\rbrace}{}{#1}

\begin{document}

   \[ \Re*{\frac{z-1}{z + 1}}\qquad \Im[\Big]{\frac{z-1}{z + 1}} \]%

\end{document} 

enter image description here

2
  • Wouldn't operator name be better for Re and Im, then 2\Re looks right again. Re and Im are math operators after all
    – daleif
    Nov 29, 2018 at 8:32
  • 2
    @daleif: You're right. I didn't think of testing this. I've fixed the code. Thanks!
    – Bernard
    Nov 29, 2018 at 9:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .