# Splitting root symbol

How can the \sqrt command be modified to split root symbol into two or more lines automatically?

Example:

\documentclass{standalone}

\begin{document}
\begin{minipage}[t]{0.8\textwidth}
The \textbf{Euclidean distance} between two points $P=(x, y, z)$and $Q=(a, b, c)$
in space is defined as $d(P, Q)= \sqrt{(x - a)^{2} + (y - b)^{2} + (z - c)^{2}}$.
The distance between a point $P$ and a geometric object $S$ like a line or plane is
the minimal distance $d(P, Q)$ which is possible with $Q$ on $S$.
\end{minipage}
\end{document} And I want something like this (artificial example using \overline):

\documentclass{standalone}

\begin{document}
\begin{minipage}[t]{0.8\textwidth}
The \textbf{Euclidean distance} between two points $P=(x, y, z)$and $Q=(a, b, c)$
in space is defined as $d(P, Q)= \sqrt{(x - a)^{2} +}$ $\overline{(y - b)^{2} + (z - c)^{2}}$.
The distance between a point $P$ and a geometric object $S$ like a line or plane is
the minimal distance $d(P, Q)$ which is possible with $Q$ on $S$.
\end{minipage}
\end{document} • Can you not afford a display-math environment in your document? Your square root would be easier to parse in one. Apr 29 '13 at 13:34
• There is something strange with the space between the coordinates x,y,z of the point P. Apr 29 '13 at 13:35
• @Jubobs: That's intended to be an inline equation. Apr 29 '13 at 13:42
• You could have provided the codes for the two examples (MWEs), to save people trying to help you some time ;)
– yo'
Apr 29 '13 at 13:44

This version allows TeX to break the math automatically. In this version you can only do this once a full version would need a counter and generate new unique names for the points each time. \documentclass{article}

\makeatletter
\def\savepos#1{\leavevmode\pdfsavepos\write\@auxout{%
\gdef\string\save@#1{{\the\pdflastxpos sp }{\the\pdflastypos sp }}}}

\def\xx#1{\expandafter\expandafter\expandafter\@firstoftwo\csname save@#1\endcsname}
\def\yy#1{\expandafter\expandafter\expandafter\@secondoftwo\csname save@#1\endcsname}

\def\xsqrt#1{%
\sqrt{\vphantom{#1}}%
\ifx\save@L\@undefined
\else
\ifdim\yy{L}=\yy{R}%
\else
\rlap{$\overline{\vphantom{#1}\hskip\dimexpr\xx{b}-\xx{L}\relax}$}%
\fi
\fi
\savepos{L}#1\savepos{R}%
\ifx\save@L\@undefined
\else
\ifdim\yy{L}=\yy{R}%
\llap{$\overline{\hskip\dimexpr\xx{R}-\xx{L}\relax}$}%
\else
\llap{$\overline{\vphantom{#1}\hskip\dimexpr\xx{R}-\xx{a}\relax}$}%
\fi
\fi
}

\makeatother

\begin{document}

\savepos{a}\begin{minipage}[t]{0.8\textwidth}
The \textbf{Euclidean distance} between two points $P=(x, y, z)$ and $Q=(a, b, c)$
in space is defined as $d(P, Q)= \xsqrt{(x - a)^{2} +(y - b)^{2} + (z - c)^{2}}$.
The distance between a point $P$ and a geometric object $S$ like a line or plane is
the minimal distance $d(P, Q)$ which is possible with $Q$ on $S$.
\end{minipage}\savepos{b}
\end{document}

• You are a wizard? This is fantastic! Apr 29 '13 at 21:43
• You have a little bug in your code: when \yy{L}=\yy{R} then the \vphantom{} is missing in the code. And another problem: the \sqrt mark have discrete sizes, maybe it doesn't vertically fit with \overline (try to use \bigl( inside the formula). Better would be: \def\myoverline#1#2{\vbox{\hrule\kern-.4pt\hbox{$\vphantom{#1}\hskip#2$}}}. Apr 17 '15 at 16:50
• @wipet thanks yes probably, looks about right (once I'd remembered what this answer was doing at all:-) Apr 17 '15 at 16:55

In cases such as the one you've brought up, I believe it's both simpler (for you) and clearer (for your readers) if you don't use the "surd" symbolism at all. Instead, use [...]^{1/2}, as is done in the following modified form of your MWE. Alternatively, as others have already suggested as well, you could move the long term into a "displayed" equation, i.e., onto a line by itself.

Not only is [...]^{1/2} simpler for you (because you don't have concern yourself with where the line break may fall), it is also easier on the readers' eyes (i.e., less distracting and hence also clearer) since the interline spacing in the paragraph in question doesn't have to be adjusted to accommodate the "surd". \documentclass{standalone}
\begin{document}
\begin{minipage}{0.8\textwidth}
The \textbf{Euclidean distance} between two points $P=(x, y, z)$ and
$Q=(a, b, c)$ in space is defined as $d(P, Q)= [(x - a)^{2} +(y - b)^{2} + (z - c)^{2}]^{1/2}$. The distance between a point $P$ and a geometric
object $S$, such as a line or plane, is the minimal distance $d(P, Q)$
which is possible with $Q\in S$.
\end{minipage}
\end{document}

• Just a typo: 1/2. Apr 29 '13 at 14:13
• @Sigur - thanks, I've fixed the typo
– Mico
Apr 29 '13 at 14:16 \documentclass[preview,border=12pt]{standalone} % change it to your class!

\usepackage{mathtools}

\begin{document}
\begin{multline*}
A   = \sqrt{a+b+c} \\
\overline{\rule{0pt}{2.5ex}+d+e+f}\\
\overline{\rule{0pt}{2.5ex}+g+h+i}
\end{multline*}
\end{document}


## Just another example: \documentclass[preview,border=12pt]{standalone}% change it to your own document class!
\usepackage[a6paper,margin=1cm]{geometry}
\usepackage{mathtools}

\begin{document}
\begin{multline*}
d(x,y)
= \sqrt{(x-x_0)^2} \\
\overline{\rule{0pt}{2.5ex}{}+(y-y_0)^2}\\
\overline{\rule{0pt}{2.5ex}{}+(z-z_0)^2}
\end{multline*}
\end{document}

• It is not so easy to handle with \rule{0pt}{2.5ex}. Apr 29 '13 at 13:41
• It seems to me that this is the same manual tweak as what m0nhawk does in the question. The problem is how to make it automated.
– yo'
Apr 29 '13 at 13:43

Here is a simple solution. When you need, just use the new command and split the radical as you want.

\newcommand{\sqrtx}{\sqrt{#1}\\\overline{#2}}

here some text \dotfill$\sqrtx{x^2+y^2}{z^2+y^2}$ • Although, it would be better to have TeX decided where this break should take place. Apr 29 '13 at 14:09
• @SeanAllred but TeX's aesthetic judgement would say never break here, so leaving it for TeX to decide can't really work:-) Apr 29 '13 at 14:26
• @DavidCarlisle Points, you have good ones, but is it not possible to `trick' TeX? Apr 29 '13 at 14:29
• @SeanAllred anything is possible Apr 29 '13 at 14:31
• @SeanAllred see another answer:-) Apr 29 '13 at 21:30