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.

2 Answers2

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}
David Carlisle
  • 757,742
  • +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 [... – Tobias Kienzler Feb 17 '15 at 08: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