I'm just trying to build the formula shown below in Latex. My approach would be the following: prob[ \tilde{n}=n \mid \tilde{s}=s]
However, the first two n's are not displayed correctly. Does anyone know what is wrong about my approach? (absolute Latex beginner)
4 Answers
\documentclass{article}
\usepackage{amsmath}
\DeclareMathOperator\prob{prob}
\begin{document}
\(
\prob[\tilde{n}=n\mid\tilde{s}=n] =p > \frac{1}{2}
\)
\end{document}
- 1,121,712
- 237,551
-
-
9The OP is using the correct
\tilde{n}syntax; while\tilde nalso works it's worse markup. – egreg Apr 22 '18 at 21:47 -
1
-
1
-
@egreg I’m not sure what this is supposed to show me: at any rate,
\tilde\notinand\tilde{\notin}render identically, as expected. – Konrad Rudolph Apr 23 '18 at 12:07 -
1@KonradRudolph Try without
amsmath. It's just an example, though, which shows that something can go wrong with the sloppy syntax. – egreg Apr 23 '18 at 12:14 -
1@egreg So amsmath fixes a bug/bad API in the (
\mathaccent) command: The syntax isn’t sloppy, it’s well-defined through TeX’ rules (and the original\tildebreaks this expectation, and hence required fixing). – Konrad Rudolph Apr 23 '18 at 12:20 -
3@KonradRudolph
amsmathfixes no bug, it just reimplements all the math accents. Since the original\tlldecommand has no argument, the syntax\tilde xis not well defined. Look at page 291 of the TeXbook for the syntax of\mathaccentand page 289 for<math field>to discover why\tilde\notinfails. – egreg Apr 23 '18 at 12:24 -
3Why does this simple answer get 17 votes? Sometimes, I don't understand the psychology of this site...but I'm not complainin' – Steven B. Segletes Apr 23 '18 at 13:45
-
2@Steven: It's probably because the question showed up in the "Hot Network Questions" list for some reason, so it is getting a lot of traffic. – Apr 23 '18 at 18:28
-
@Rahul Thanks for pointing that out (in all my years here, my mind blanks out that part of the webpage...I'm not even aware it exists!) I'll remember that, next time I need to apply a thumb to the scales.
;^)– Steven B. Segletes Apr 23 '18 at 18:43
With a code adapted from an example in mathtools documentation. The \prob macro can make the size of the brackets and midrule fit the contents of the macro using the starred version \prob*. Alternatively one can use an optional argument: \big, \Big, \bigg,\Bigg, which inserts a pair of implicit \bigl ... \bigr before the delimiters:
\documentclass{article}
\usepackage{mathtools, nccmath}
\providecommand\given{}
\DeclarePairedDelimiterXPP\prob[1]{\mathrm{prob}}[]{}{
\renewcommand\given{\nonscript\:\delimsize\vert\nonscript\:\mathopen{}}
#1}
\begin{document} %
\[ \prob[\big]{\tilde{n} = n\given\tilde{s} = n} = p > \mfrac12\]%
\end{document}
- 271,350
An alternative that sizes the brackets and the vertical bar automatically to the content between them is to use \left, \middle and \right. This uses egreg’s trick for a vertical bar that grows.
\documentclass[preview,varwidth]{standalone}
\usepackage{amsmath}
\usepackage{unicode-math}
\DeclareMathOperator\prob{prob}
\ifdefined\Umiddle
\newcommand{\relmiddle}{\Umiddle class 5 }
\else
\newcommand{\relmiddle}[1]{\mathrel{}\middle#1\mathrel{}}
\fi
\begin{document}
\(
\prob \left[ \tilde{n} = \frac{n^{2^m}}{2} \relmiddle\vert \tilde{s} = n \right] = p > \frac{1}{2}
\)
\end{document}
This example will work with your font packages of choice, not just unicode-math. And you can still declare \prob with two arguments.
- 44,045
The following works for me very well even though Steven B. Segletes has a perfect answer. I have changed n to n/2 for better visibility on the height of the mid line.
\begin{equation}
\operatorname{prob} \left[\left. \tilde{n}=\frac{n}{2} \right| \tilde{s}=n\right] =p > \frac{1}{2}
\end{equation}
I have added \left. before the fraction to enforce the height of the mid line to be that of the height of the fraction.
- 1,964
-
2Please do never use
$$(see https://tex.stackexchange.com/questions/503/why-is-preferable-to). – TeXnician Apr 23 '18 at 09:04 -
-
iom the vertical bar and the
[...]should be the same size as they are part of a combined syntax – daleif Apr 23 '18 at 10:01




$\operatorname{prob}[\tilde{n} = n \mid \tilde{s} = n] = p > \frac{1}{2}$with packageamsmath(screenshot). – Henri Menke Apr 22 '18 at 21:32ns? The formula you've given is different than your attempt. Also, it's helpful if you give a complete minimal working example with your code, that starts with\documentclassand ends withend{document}. – Teepeemm Apr 23 '18 at 12:44