How would one implement Euclidean distance in LaTeX. Please some one help me. Here is the below link:


  • 6
    \documentclass{article}\begin{document}Euclidean Distance\end{document} ? What exactly do you want to implement? – percusse Sep 4 '12 at 0:55
  • 1
    do you mean $\mathbf{\overline{pq}}$? – user11232 Sep 4 '12 at 0:56
  • 1
    Also if you click on Edit link on the right upper part on Wiki you can see the source code of the page. – percusse Sep 4 '12 at 0:56
  • Do you mean perhaps how to write the norm of a vector? – Gonzalo Medina Sep 4 '12 at 1:00
  • 3
    if you look at the source code of the wikipedia page (CTRL-U), you can see the latex code for the formulae – prettygully Sep 4 '12 at 1:39

I am not sure what exactly do you want to write; does the following help?




\lVert \mathbf{p} \rVert = \dis(\mathbf{p},\mathbf{0}).


enter image description here

|improve this answer|||||

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 \left and \right modifiers, the double-bar fence symbols will "grow" automatically as may be necessary.

  • preserve the option to assign explicit sizes to the "fence" symbols:


    With this setup, \norm*{...} will produce automatically sized double-bar fence symbols around the macro's, whereas (say) \norm[\bigg]{...} will generate \bigg double-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.

|improve this answer|||||
  • The package commath provides the \norm command with an optional argument for its size. – jofel Jun 23 '16 at 13:22

Here are some tips if you're looking for symbols:

  1. Use DeTeXify.
  2. Since you linked to Wikipedia, here is another suggestion:

    View the source of LaTeXified math1 for viewing the TeX equivalent.

  3. 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.)

|improve this answer|||||

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:

\usepackage{bm} %For bold math symbols.


\[  \bm{a} \cdot \bm{b} = \| \bm{a} \| \| \bm{b} \| \cos \theta 
\[  \left\| \frac{a}{b} \right\|    
\[  \left\|


enter image description here

|improve this answer|||||
  • 2
    The \| 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 \lVert and \rVert instead (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 the mathtools package and to its \DeclarePairedDelimiter declaration (see the mathtool manual, section 3.6); this remarks also applies to @Mico’s answer. – GuM Oct 9 '16 at 22:28
  • 1
  • Side by side, I see no difference when I compare mathtools' \lVert and \rVert to 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
  • 1
    You 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\theta versus \lVert\bm{b}\rVert\cos\theta. Note that the mathtools package has nothing to do with this: that package is only relevant in that it provides the \DeclarePairedDelimiter command. – GuM Oct 10 '16 at 20:40
  • What caught me up was that \rVert and \lVert are amsmath.sty-dependent, so they wouldn't compile with the preamble I used above. Because they did with mathtools.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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.