How would one implement Euclidean distance in LaTeX. Please some one help me. Here is the below link:
4 Answers
I am not sure what exactly do you want to write; does the following help?
\documentclass{article}
\usepackage{amsmath}
\DeclareMathOperator{\dis}{d}
\begin{document}
\[
\lVert \mathbf{p} \rVert = \dis(\mathbf{p},\mathbf{0}).
\]
\end{document}

- 505,128
Building on @GonzaloMedina's answer, I suggest you create a macro called \norm in the document's preamble, using either of the following two approaches:
auto-size the double-bar "fence" symbols:
\newcommand{\norm}[1]{\left\lVert #1 \right\rVert}This will place double vertical bars around the command's argument. Because of the use of the
\leftand\rightmodifiers, the double-bar fence symbols will "grow" automatically as may be necessary.preserve the option to assign explicit sizes to the "fence" symbols:
\usepackage{mathtools} \DeclarePairedDelimiter{\norm}{\lVert}{\rVert}With this setup,
\norm*{...}will produce automatically sized double-bar fence symbols around the macro's, whereas (say)\norm[\bigg]{...}will generate\biggdouble-bar symbols. There are four sizing modifiers:\big,\Big,\bigg, and\Bigg.
If need be, you can indicate whether the norm is supposed to be an $L_2$, $L_1$, or $L_p$ norm by adding a suffix $_2$, $_1$, $_p$, etc to the expression. E.g., you could write \norm{x}_{2} and \norm{y}_p.
- 506,678
-
The package
commathprovides the\normcommand with an optional argument for its size. – jofel Jun 23 '16 at 13:22
Here are some tips if you're looking for symbols:
Use DeTeXify.
Since you linked to Wikipedia, here is another suggestion:
View the source of LaTeXified math1 for viewing the TeX equivalent.
If you're strong, you may also search through this massive authentic database of extant symbols in the entire TeX universe.
1 In Internet Explorer, it roughly translates to right clicking on the image and clicking on "View Source". In Chrome, this translates to "Inspect Element" after the element. In chrome, it is much more pleasant too. In Firefox, go to the page you want to view and then press Ctrl+U. A new Window appears with the HTML code visible and colored appropriately.
(In Internet Explorer, you can press Alt+V to open the View menu, then press C to select the Source command. A Notepad window appears with the HTML code available for editing.)
- 757,742
- 4,545
PdfLaTeX offers \|, and it looks great. I had the same question as OP a year ago, followed the advice on this page, and stumbled onto \| only yesterday. Minimum working example:
\documentclass{article}
\usepackage{bm} %For bold math symbols.
\begin{document}
\[ \bm{a} \cdot \bm{b} = \| \bm{a} \| \| \bm{b} \| \cos \theta
\]
\[ \left\| \frac{a}{b} \right\|
\]
\[ \left\|
\Bigg\|
\bigg\|
\Big\|
\big\|
\|
\right\|
\]
\end{document}
- 381
-
3The
\|command isn’t available only in PdfLaTeX: it’s a LaTeX standard command (but it exists in plain TeX too) that produces a so-called Ord[inary] atom; in the context of your first equation, it is much better to use\lVertand\rVertinstead (e.g,\lVert\bm{b}\rVert\cos\theta), which produce an Open[ing] and a Close[ing] atom, respectively. You might also want to have a look to themathtoolspackage and to its\DeclarePairedDelimiterdeclaration (see themathtoolmanual, section 3.6); this remarks also applies to @Mico’s answer. – GuM Oct 09 '16 at 22:28 -
1
-
Side by side, I see no difference when I compare mathtools'
\lVertand\rVertto the standard\|, except that\|is briefer, ambidextrous, and doesn't require an extra package to work. Why would you recommend it? – LaTeX2enub1336 Oct 10 '16 at 18:19 -
2You haven’t read the reference I gave carefully enough! (;-) Compare the output of
\log \|-2\|versus\log\lVert-2\rVert; or of\|\bm{b}\|\cos\thetaversus\lVert\bm{b}\rVert\cos\theta. Note that themathtoolspackage has nothing to do with this: that package is only relevant in that it provides the\DeclarePairedDelimitercommand. – GuM Oct 10 '16 at 20:40 -
1What caught me up was that
\rVertand\lVertareamsmath.sty-dependent, so they wouldn't compile with the preamble I used above. Because they did withmathtools.sty, I assumed that was the package for them. And you're absolutely right: they're a big improvement in the example you gave. I didn't see your reference until after I replied. Looks like some very handy information there, so thank you for this and that both. – LaTeX2enub1336 Oct 10 '16 at 21:34

\documentclass{article}\begin{document}Euclidean Distance\end{document}? What exactly do you want to implement? – percusse Sep 04 '12 at 00:55Editlink on the right upper part on Wiki you can see the source code of the page. – percusse Sep 04 '12 at 00:56$\mathbf{\overline{pq}}$? – Sep 04 '12 at 00:56