5

In formulas involving square roots, I consider the overline rather irritating and would like to create an operator that turns \sqrt{x} into √[x], i.e. the argument is bracket-delimited instead of the usual overlining. How can this be achieved?

So far, I tried

\usepackage{letltxmacro}
\LetLtxMacro{\orgsqrt}{\sqrt}
\renewcommand{\sqrt}[2][]{\orgsqrt[#1]{}\left[#2\right]}

but the spacing is not very appealing:

√ [x]

Ideally, the end of the √-Symbol would directly connect to the ['s upper left corner.

8
  • 3
    Not an answer your question, but have you considered writing (x)^{1/2} instead? Feb 16, 2015 at 12:15
  • What about $\surd$?
    – user31729
    Feb 16, 2015 at 12:16
  • @NajibIdrissi Sure, but a √ is more distinctive to spot, and fractions in exponents don't look that nice either... Feb 16, 2015 at 12:16
  • @ChristianHupfer Good point, it does look better, though that unfortunately fails at the optional argument, i.e. cube roots and the like cannot be typeset that way Feb 16, 2015 at 12:19
  • 1
    @TobiasKienzler: Then use \LetLtxMacro too ;-)
    – user31729
    Feb 16, 2015 at 12:28

2 Answers 2

5

If you let the \sqrt grow large it might be hard to avoid a horizontal notch at the top, but...

enter image description here

\documentclass{article}
\usepackage{mathtools}
\begin{document}

\[
\sqrt{\frac{1}{\sqrt{\frac{1}{\sqrt{x}}}}}
\]

\newcommand\bsqrt[2][]{%
\sqrt[{#1}]{\vphantom{\left[#2\right]}}\left[#2\right]%
}


\[
\bsqrt{\frac{1}{\bsqrt{\frac{1}{\bsqrt{x}}}}}
\]

\newcommand\bbsqrt[2][]{%
\sqrt[{#1}]{\vphantom{\left[\vcenter{\hbox{$#2$}}\right]}}%
\left[\vcenter{\hbox{$#2$}}\right]%
}


\[
\bbsqrt{\frac{1}{\bbsqrt{\frac{1}{\bbsqrt{x}}}}}
\]

\end{document}
1
  • +1 hm, looking at the big √s makes me thing by adding a line to the lower right corner would already make it look like a [, so this question could basically be used to create a slightly different √ that is overlayed with a [... Feb 17, 2015 at 8:47
4

See EDIT at end of answer for support of sqrt index in \displaystyle.

\documentclass{article}
\usepackage{scalerel}
\def\sqrt#1{\stretchrel{\surd}{\left[#1\right]}}

\begin{document}
\[
\sqrt{x} \quad \sqrt{\frac{x}{y}} \quad
\sqrt{\frac{1}{\sqrt{\frac{1}{\sqrt{x}}}}}
\]
\end{document}

enter image description here

The macro \stretchrel takes an optional integer argument indicating the maximum percent stretch allowed. Any stretch beyond that value results in an increasing width, as well. Thus defining \sqrt as

\def\sqrt#1{\stretchrel[200]{\surd}{\left[#1\right]}}

would result in the following depiction, in which the most stretched \surd is also widened:

enter image description here

If the gap between the surd and the bracket is considered too large, a negative space could be added:

\def\sqrt#1{\stretchrel{\surd}{\!\left[#1\right]}}

yielding

enter image description here


EDIT to support index on sqrt (but only in displaystyle). The earlier solutions support math styles, as shown in the first two examples of this MWE. Here, I introduce \dsqrt in the third example below, which supports indices on the sqrt; however it only functions in \displaystyle.

\documentclass{article}
\usepackage{scalerel,stackengine}
\stackMath
\def\sqrt#1{\stretchrel{\surd}{\left[#1\right]}}
%%% THE FOLLOWING DISABLES MATH-MODE PRESERVATION OF scalerel, WHICH MAKES
%%% NESTED scalerel MACROS MUCH MORE EFFICIENT BY ELIMINATING NESTED \mathchoice
\makeatletter
\def\turnoffsavemode{%
  \edef\m@switch{T}\LMex=1ex\relax\LMpt=1pt\relax%
  \renewcommand\ThisStyle[1]{\ifmmode\def\@mmode{T}##1\else\def\@mmode{F}##1\fi}%
}
\makeatother
%%%
% \dsqrt only works in displaystyle, but supports sqrt index
\newcommand\dsqrt[2][]{\stackinset{l}{1.8pt}{c}{2.5pt}{\scriptscriptstyle#1}%
  {\turnoffsavemode\stretchrel{\surd}{\left[#2\right]}}}

\begin{document}
\[
\sqrt{x} \quad \sqrt{\frac{x}{y}} \quad
\sqrt{\frac{1}{\sqrt{\frac{1}{\sqrt{x}}}}}
\]
\[\scriptstyle
\sqrt{x} \quad \sqrt{\frac{x}{y}} \quad
\sqrt{\frac{1}{\sqrt{\frac{1}{\sqrt{x}}}}}
\]
\[
\dsqrt[3]{x} \quad \dsqrt[3]{\frac{x}{y}} \quad
\dsqrt[3]{\frac{1}{\dsqrt[3]{\frac{1}{\dsqrt[3]{x}}}}}
\]
\end{document}

enter image description here

3
  • +1, though it's too bad \surd cant do e.g. $\sqrt[3]{\ }$ Feb 17, 2015 at 8:47
  • @TobiasKienzler I have provided \displaystyle support for the feature. See edit at end of answer. Feb 17, 2015 at 11:54
  • NOTE TO READERS: The functionality of the \turnoffsavemode macro has been incorporated into the pre-existing scalerel macro named \ignoremathstyle as of version 1.7 of scalerel (FEBRUARY 2015). Jun 24, 2015 at 11:01

You must log in to answer this question.

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