Mathpix / mathpix-markdown-it

Markdown rendering + Latex extras (equations, tables, ...), with conversion features, for the scientific community
MIT License
501 stars 44 forks source link

PR into master from dev/olga/Fix-spacing-before-footnotetext #277

Closed OlgaRedozubova closed 11 months ago

OlgaRedozubova commented 1 year ago

branch: dev/olga/Fix-spacing-before-footnotetext

Why:

Fixes [mmd] The \footnotetext{} command in the middle of the text should not cause a line break #5794 For the issue [ocr-api] PDF OCR issues: quotes and footnotes #5782

What's being changed:

  1. Changes have been made to prevent block rules for footnotetext and foornone from breaking paragraphs. If there is no empty line before \footnotetext.

1.1. There are no empty line before and after \footnotetext. Content should not be divided into paragraphs.

mmd:

Note that the weights depend on the particular point \(x\) at which we're trying to evaluate \(x\). Moreover, if \(\left|x^{(i)}-x\right|\) is small, then \(w^{(i)}\) is close to 1 ; and if \(\left|x^{(i)}-x\right|\) is large, then \(w^{(i)}\) is small. Hence, \(\theta\) is chosen giving a much higher "weight" to the (errors on) training examples close to the query point \(x\). (Note also that while the formula for the weights takes a form that is cosmetically similar to the density of a Gaussian distribution, the \(w^{(i)}\) 's do not directly have anything to do with Gaussians, and in particular the \(w^{(i)}\) are not random variables, normally distributed or otherwise.) The parameter
\footnotetext{
\({ }^{4}\) If \(x\) is vector-valued, this is generalized to be \(w^{(i)}=\exp \left(-\left(x^{(i)}-x\right)^{T}\left(x^{(i)}-x\right) /\left(2 \tau^{2}\right)\right)\), or \(w^{(i)}=\exp \left(-\left(x^{(i)}-x\right)^{T} \Sigma^{-1}\left(x^{(i)}-x\right) / 2\right)\), for an appropriate choice of \(\tau\) or \(\Sigma\).
} \(\tau\) controls how quickly the weight of a training example falls off with distance of its \(x^{(i)}\) from the query point \(x ; \tau\) is called the bandwidth parameter, and is also something that you'll get to experiment with in your homework.

Before :

Screen Shot 2023-10-18 at 13 01 00

After:

Screen Shot 2023-10-18 at 12 59 45

1.2. Content should be broken into paragraphs if there is a blank line before or after \footnotetext. In this case, the rule of breaking into paragraphs is fulfilled.

Empty line before \footnotetext. mmd:

We now show that the Bernoulli and the Gaussian distributions are examples of exponential family distributions. The Bernoulli distribution with mean \(\phi\), written Bernoulli \((\phi)\), specifies a distribution over \(y \in\{0,1\}\), so that \(p(y=1 ; \phi)=\phi ; p(y=0 ; \phi)=1-\phi\). As we vary \(\phi\), we obtain Bernoulli distributions with different means. We now show that this class of Bernoulli distributions, ones obtained by varying \(\phi\), is in the exponential family; i.e., that there is a choice of \(T, a\) and \(b\) so that Equation (3) becomes exactly the class of Bernoulli distributions.

\footnotetext{
\({ }^{5}\) The presentation of the material in this section takes inspiration from Michael I. Jordan, Learning in graphical models (unpublished book draft), and also McCullagh and Nelder, Generalized Linear Models (2nd ed.).
} We write the Bernoulli distribution as:

$$
\begin{aligned}
p(y ; \phi) & =\phi^{y}(1-\phi)^{1-y} \\
& =\exp (y \log \phi+(1-y) \log (1-\phi)) \\
& =\exp \left(\left(\log \left(\frac{\phi}{1-\phi}\right)\right) y+\log (1-\phi)\right)
\end{aligned}
$$
Screen Shot 2023-10-18 at 13 16 40

Empty line after \footnotetext. mmd:

We now show that the Bernoulli and the Gaussian distributions are examples of exponential family distributions. The Bernoulli distribution with mean \(\phi\), written Bernoulli \((\phi)\), specifies a distribution over \(y \in\{0,1\}\), so that \(p(y=1 ; \phi)=\phi ; p(y=0 ; \phi)=1-\phi\). As we vary \(\phi\), we obtain Bernoulli distributions with different means. We now show that this class of Bernoulli distributions, ones obtained by varying \(\phi\), is in the exponential family; i.e., that there is a choice of \(T, a\) and \(b\) so that Equation (3) becomes exactly the class of Bernoulli distributions.
\footnotetext{
\({ }^{5}\) The presentation of the material in this section takes inspiration from Michael I. Jordan, Learning in graphical models (unpublished book draft), and also McCullagh and Nelder, Generalized Linear Models (2nd ed.).
} 

We write the Bernoulli distribution as:

$$
\begin{aligned}
p(y ; \phi) & =\phi^{y}(1-\phi)^{1-y} \\
& =\exp (y \log \phi+(1-y) \log (1-\phi)) \\
& =\exp \left(\left(\log \left(\frac{\phi}{1-\phi}\right)\right) y+\log (1-\phi)\right)
\end{aligned}
$$
Screen Shot 2023-10-18 at 13 19 29
iammosespaulr commented 11 months ago

@dlrac are these changes consistent with what's being emitted right now?

dlrac commented 11 months ago

@OlgaRedozubova Behavior looks good to me - it gives us control over how paragraphs are formed/broken. I did not audit the code itself.

@iammosespaulr For footnotes text there is an issue which I need to attend to. So we'll change new line behavior around footnotetext to be better. Current code does not handle it correctly.