0

I noticed that $$\exp(\frac12), \exp\{\frac12\}, \exp[\frac12]$$ are all (at least visually) equivalent to $$\exp\left(\frac12\right), \exp\left\{\frac12\right\}, \exp\left[\frac12\right]$$

The same is also true for \sin, \cos, \log and \ln. How do I declare my own math operators that follow this convention?

Here is a MWE

\documentclass{article}
\usepackage{physics}

\begin{document}
\[
\exp{\frac{-1}{2}} \quad \exp(\frac{-1}{2}) \quad \exp[\frac{-1}2]
\]
\end{document}

Commenting the import of the physics package reverts the behaviour back to normal.

Edit: This behavior happens when using the physics package.

13
  • How are these visually equivalent? The first versions have normal brackets, while the second versions have auto-scaled ones. And off-topic: you should really avoid $$...$$, but use \[...\] or other environments instead.
    – Gargantuar
    Commented Apr 18 at 18:43
  • @Gargantuar Oh I'm sorry I forgot to mention, this is using the physics package. Also yeah, I always use align* environment, it's just more natural to write $$ on stackexchange since I use math stack a lot haha
    – Anvit
    Commented Apr 18 at 18:56
  • 3
    I'd strongly advise against using physics. The syntax introduced by it is bewildering at best.
    – Skillmon
    Commented Apr 18 at 20:08
  • @Skillmon do you have any alternative solution? As in how can I achieve this behavior without physics package
    – Anvit
    Commented Apr 18 at 21:13
  • 1
    I'd remove physics and then use \left(...\right) if you want automatic sizing. The sizing isn't always perfect but it's OK and I don't see how physics is helping here. Or (better) declare paired delimiters using \DeclarePairedDelimiter from amsmath/mathtools Commented Apr 19 at 7:49

2 Answers 2

2

Looking at the style file of physics, you can do the following:

\documentclass{article}

\usepackage{physics}
\DeclareMathOperator{\hey}{hey}
\NewDocumentCommand{\h}{}{\trigbraces{\hey}}

\begin{document}

\[
    \sin(\frac{1}{2})
    \h(\frac{1}{2})
\]

\end{document}

enter image description here

3
  • Can't I do the same thing with physics2 as well? Something like \newcommand{\myexp}{\exp\ab}
    – Anvit
    Commented Apr 21 at 1:01
  • @Anvit Yeah, you can, but there are a multitude of caveats. 1. \myexp must be followed by one of (, [, \{, \langle, \lvert, \lVert and finished with the appropriate closing delimiter. 2. Hence, something like \myexp(() will throw an error. 3. Hence, \myexp \alpha is impossible. 4. Hence, $\myexp$ will throw an error. Note that all of this isn't a problem if you're fine with using two different commands for the exponential function.
    – Gargantuar
    Commented Apr 21 at 1:06
  • while I do see that the documentation says that is not allowed, surprisingly 3. and 4. do not throw any error in a very simply document. Maybe they will in a more complex document. Thanks for taking out the time to answer my questions, your kindness is appreciated.
    – Anvit
    Commented Apr 21 at 1:15
2

You might use \DeclarePairedDelimiters from mathtools. One of the examples in the manual is

\DeclarePairedDelimiter\abs{\lvert}{\rvert}

This creates the following commands:

  • A command like \abs{x}, which produces non-scaling vertical bars
  • A command like \abs*{\frac{a}{b}}, which automatically scales the delimiters with \left and \right
  • An optional size argument, such as \abs[Bigg]{\frac{a}{b}}, which chooses a specific size
1
  • I wanted the function to work with whatever brackets I choose, not just the specific one we declare in the definition.
    – Anvit
    Commented Apr 18 at 23:49

You must log in to answer this question.

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