DHQ: Digital Humanities Quarterly
Editorial
Math Encoding Sample
Revision Note
change made to this location The previous version of the article will remain available.
Abstract
Sample MathJax encoding
MathML
Sample 1 of MathML encoding:
V
=
4
3
π
r
3
Sample 2 of MathML encoding:
E
=
m
c
2
When
a
=
0
,
there are two solutions to
a
x
2
+
b
x
+
c
=
0
and they are
x
=
−
b
±
b
2
−
4
a
c
2
a
.
ASCIIMath
Samples of ASCIIMath encoding. When `a != 0`, there are two solutions to `ax^2 + bx
+ c = 0` and
they are
`x = (-b +- sqrt(b^2-4ac))/(2a) .`
TeX
Sample of TeX encoding:
When \(a \ne 0\), there are two solutions to \(ax^2 + bx + c = 0\), and they are $$x
= {-b \pm \sqrt{b^2-4ac} \over 2a}.$$. Furthermore, Einstein proved decisively that
the relationship between energy and mass involves the speed of light, following the
formula
\(E=mc^2\). I have no idea what these next examples prove, but I'm sure it's important:
$$ {1 \over 10} + {1 \over 100} + {1 \over 1000} + {1 \over 10,\!000} + \dots $$ I
also think we should not have periods following block-level formulae. This one seems
especially interesting:
$$\matrix{0 & 1\cr<0&>1}$$
Sample of TeX encoding with extra delimiters (for testing only, deprecated practice):
When \(\(a \ne 0\)\), there are two solutions to \(ax^2 + bx + c = 0\), and they are
$$x = {-b \pm \sqrt{b^2-4ac} \over 2a}.$$. Furthermore, Einstein proved decisively
that the relationship between energy and mass involves the speed of light, following
the formula
\(\(E=mc^2\)\). I have no idea what these next examples prove, but I'm sure it's important:
$$$$ {1 \over 10} + {1 \over 100} + {1 \over 1000} + {1 \over 10,\!000} + \dots $$$$
I also think we should not have periods following block-level formulae. This one seems
especially interesting:
$$$$\matrix{0 & 1\cr<0&>1}$$$$
Sample of TeX encoding with no delimiters (for testing only, deprecated practice):
When a \ne 0, there are two solutions to ax^2 + bx + c = 0, and they are $$x = {-b
\pm \sqrt{b^2-4ac} \over 2a}.$$. Furthermore, Einstein proved decisively that the
relationship between energy and mass involves the speed of light, following the formula
E=mc^2. I have no idea what these next examples prove, but I'm sure it's important:
{1 \over 10} + {1 \over 100} + {1 \over 1000} + {1 \over 10,\!000} + \dots I also
think we should not have periods following block-level formulae. This one seems especially
interesting:
\matrix{0 & 1\cr<0&>1}
Collapsed Gibbs Sampler of the AlterLDA Model [Samples of TeX encoding from 000576.xml, testing how to embed the code in our encoding]
[The first example embeds the entire block of code within <formula>, escaping the ampersands.]
The joint probability of the model is given
by
$$\begin{align*}
p(\mathbf{w}, c, z, \gamma, \beta, \theta~|~\alpha,\eta, \xi) =& p(c~|~z) \cdot
p(\mathbf{w}~|~z,\beta) \cdot p(\gamma~|~\xi) \cdot p(\beta~|~\eta)\cdot p(z~|~\theta)\cdot
p(\theta~|~\alpha)\\
=& \prod^{M,N}\text{cat}(c~|~c,\gamma) \times \prod^{M,N}\text{cat}(\textbf{w}~|~z,\beta)\times\prod^{M,N}\text{cat}(z~|~\theta)\\
&\times\prod^{M}\text{dir}(\theta~|~\alpha)\times\prod^{K}\text{dir}(\gamma~|~\xi)\times\prod^{K}\text{dir}(\beta~|~\eta)\\
\end{align*}$$
We introduce a counter variable c which can be indexed in four dimensions, the current
topic (k), the current document
(m), the current alteration mode (a) and the current token (w).
$$
c_{k,m,a,\mathbf{w}} = \sum_{n=1}^N \mathbf{I}(
z_{m,n}=k
\quad\&\quad w_{m,n} = \mathbf{w}
\quad\&\quad c_{m,n} = a )
$$
In this setting, the desired computation is the probability of
a topic assignment at a specific position given a current configuration of
all other topic assignments. This probability can be formalized by
$$\begin{align*}
p(z_{m,n}~|~z_{-_{(m,n)}},\mathbf{w},c,\alpha,\eta,\xi)&\propto~p(z_{m,n},z_{-_{(m,n)}},\mathbf{w},c~|~\alpha,\eta,\xi)
\end{align*}$$
Adopting Equation 16 from the Carpenter paper, this probability can be written by
marginalizing θ,β,γ and from the joint probability.
$$\begin{align*}
p(z_{m,n},z_{-_{(m,n)}},\mathbf{w},c~|~\alpha,\eta,\xi) = & \int\int\int~p(\mathbf{w},c,z,\gamma,\beta,
\theta~|~\alpha,\eta,\xi)d\theta~d\beta~d\gamma\\
= & \underbrace{\int~p(\theta~|~\alpha)\cdot~p(z~|~\theta)d\theta}_A\\
& \times \underbrace{\int~p(\mathbf{w}~|~z,\beta)\cdot~p(\beta~|~\eta)d\beta}_B\\
& \times \int~p(c~|~z,\gamma)\cdot~p(\gamma~|~\xi)d\gamma\\
= & \prod_{k=1}^K\int~p(\gamma_k~|~\xi)\prod_{m=1,n=1}^{M,N_m}p(c~|~\gamma_{\text{argmax}(z_{m,n})})d\gamma_k
\times A \times B
\end{align*}$$
A and B are substituted here because their derivation is
identical to the one in Carpenter et al. Analogue to Equation 27 of
Carpenter et al., after inserting the definitions of the Dirichlet
distribution the result is proportional to three factors.
$$\begin{align*}
\propto (\mathbf{c}^-_{z_{m,n},*,*,*}+\alpha_{z_{m,n}})\left(
\frac{
\mathbf{c}^-_{z_{m,n},*,*,\mathbf{w}_{m,n}}+\eta_{w_{m,n}}
}{
\mathbf{c}^-_{z_{m,n},*,*,*}+\sum_v^V\eta_{v}
}
\right)\left(
\frac{
\mathbf{c}^-_{z_{m,n},*,c_{m,n},*}+\xi_{w_{m,n}}
}{
\mathbf{c}^-_{z_{m,n},*,*,*}+\sum_i^2\xi_{i}
}
\right)
\end{align*}$$
Where .- denotes the counter disregarding the current position m, n.
2. Collapsed Gibbs Sampler of the AlterLDA Model [Samples of TeX encoding from 000576.xml, testing how to embed the code in our encoding]
[The second example embeds the entire block of code within <formula>, escaping the ampersands.]
The joint probability of the model is given
by
$$\begin{align*}
p(\mathbf{w}, c, z, \gamma, \beta, \theta~|~\alpha,\eta, \xi) =& p(c~|~z) \cdot p(\mathbf{w}~|~z,\beta)
\cdot p(\gamma~|~\xi) \cdot p(\beta~|~\eta)\cdot p(z~|~\theta)\cdot p(\theta~|~\alpha)\\
=& \prod^{M,N}\text{cat}(c~|~c,\gamma) \times \prod^{M,N}\text{cat}(\textbf{w}~|~z,\beta)\times\prod^{M,N}\text{cat}(z~|~\theta)\\
&\times\prod^{M}\text{dir}(\theta~|~\alpha)\times\prod^{K}\text{dir}(\gamma~|~\xi)\times\prod^{K}\text{dir}(\beta~|~\eta)\\
\end{align*}$$
We introduce a counter variable c which can be indexed in four dimensions, the current
topic (k), the current document
(m), the current alteration mode (a) and the current token (w).
$$\[
c_{k,m,a,\mathbf{w}} = \sum_{n=1}^N \mathbf{I}(
z_{m,n}=k
\quad\&\quad w_{m,n} = \mathbf{w}
\quad\&\quad c_{m,n} = a )
\]$$
In this setting, the desired computation is the probability of
a topic assignment at a specific position given a current configuration of
all other topic assignments. This probability can be formalized by
$$\begin{align*}
p(z_{m,n}~|~z_{-_{(m,n)}},\mathbf{w},c,\alpha,\eta,\xi)&\propto~p(z_{m,n},z_{-_{(m,n)}},\mathbf{w},c~|~\alpha,\eta,\xi)
\end{align*}$$
Adopting Equation 16 from the Carpenter paper, this probability can be written by
marginalizing θ,β,γ and from the joint probability.
$$\begin{align*}
p(z_{m,n},z_{-_{(m,n)}},\mathbf{w},c~|~\alpha,\eta,\xi) = & \int\int\int~p(\mathbf{w},c,z,\gamma,\beta,
\theta~|~\alpha,\eta,\xi)d\theta~d\beta~d\gamma\\
= & \underbrace{\int~p(\theta~|~\alpha)\cdot~p(z~|~\theta)d\theta}_A\\
& \times \underbrace{\int~p(\mathbf{w}~|~z,\beta)\cdot~p(\beta~|~\eta)d\beta}_B\\
& \times \int~p(c~|~z,\gamma)\cdot~p(\gamma~|~\xi)d\gamma\\
= & \prod_{k=1}^K\int~p(\gamma_k~|~\xi)\prod_{m=1,n=1}^{M,N_m}p(c~|~\gamma_{\text{argmax}(z_{m,n})})d\gamma_k
\times A \times B
\end{align*}$$
A and B are substituted here because their derivation is
identical to the one in Carpenter et al. Analogue to Equation 27 of
Carpenter et al., after inserting the definitions of the Dirichlet
distribution the result is proportional to three factors.
$$\begin{align*}
\propto (\mathbf{c}^-_{z_{m,n},*,*,*}+\alpha_{z_{m,n}})\left(
\frac{
\mathbf{c}^-_{z_{m,n},*,*,\mathbf{w}_{m,n}}+\eta_{w_{m,n}}
}{
\mathbf{c}^-_{z_{m,n},*,*,*}+\sum_v^V\eta_{v}
}
\right)\left(
\frac{
\mathbf{c}^-_{z_{m,n},*,c_{m,n},*}+\xi_{w_{m,n}}
}{
\mathbf{c}^-_{z_{m,n},*,*,*}+\sum_i^2\xi_{i}
}
\right)
\end{align*}$$
Where .- denotes the counter disregarding the current position m, n.
3. Collapsed Gibbs Sampler of the AlterLDA Model [Samples of TeX encoding from 000576.xml, testing how to embed the code in our encoding]
[The third example embeds the entire block of code within <formula>, escaping ampersands and removing the outer layer of code]
The joint probability of the model is given
by
$$
p(\mathbf{w}, c, z, \gamma, \beta, \theta~|~\alpha,\eta, \xi) =& p(c~|~z) \cdot p(\mathbf{w}~|~z,\beta)
\cdot p(\gamma~|~\xi) \cdot p(\beta~|~\eta)\cdot p(z~|~\theta)\cdot p(\theta~|~\alpha)\\
=& \prod^{M,N}\text{cat}(c~|~c,\gamma) \times \prod^{M,N}\text{cat}(\textbf{w}~|~z,\beta)\times\prod^{M,N}\text{cat}(z~|~\theta)\\
&\times\prod^{M}\text{dir}(\theta~|~\alpha)\times\prod^{K}\text{dir}(\gamma~|~\xi)\times\prod^{K}\text{dir}(\beta~|~\eta)\\
$$
We introduce a counter variable c which can be indexed in four dimensions, the current
topic (k), the current document
(m), the current alteration mode (a) and the current token (w).
$$\[
c_{k,m,a,\mathbf{w}} = \sum_{n=1}^N \mathbf{I}(
z_{m,n}=k
\quad\&\quad w_{m,n} = \mathbf{w}
\quad\&\quad c_{m,n} = a )
\]$$
In this setting, the desired computation is the probability of
a topic assignment at a specific position given a current configuration of
all other topic assignments. This probability can be formalized by
$$
p(z_{m,n}~|~z_{-_{(m,n)}},\mathbf{w},c,\alpha,\eta,\xi)&\propto~p(z_{m,n},z_{-_{(m,n)}},\mathbf{w},c~|~\alpha,\eta,\xi)
$$
Adopting Equation 16 from the Carpenter paper, this probability can be written by
marginalizing θ,β,γ and from the joint probability.
$$
p(z_{m,n},z_{-_{(m,n)}},\mathbf{w},c~|~\alpha,\eta,\xi) = & \int\int\int~p(\mathbf{w},c,z,\gamma,\beta,
\theta~|~\alpha,\eta,\xi)d\theta~d\beta~d\gamma\\
= & \underbrace{\int~p(\theta~|~\alpha)\cdot~p(z~|~\theta)d\theta}_A\\
& \times \underbrace{\int~p(\mathbf{w}~|~z,\beta)\cdot~p(\beta~|~\eta)d\beta}_B\\
& \times \int~p(c~|~z,\gamma)\cdot~p(\gamma~|~\xi)d\gamma\\
= & \prod_{k=1}^K\int~p(\gamma_k~|~\xi)\prod_{m=1,n=1}^{M,N_m}p(c~|~\gamma_{\text{argmax}(z_{m,n})})d\gamma_k
\times A \times B
$$
A and B are substituted here because their derivation is
identical to the one in Carpenter et al. Analogue to Equation 27 of
Carpenter et al., after inserting the definitions of the Dirichlet
distribution the result is proportional to three factors.
$$
\propto (\mathbf{c}^-_{z_{m,n},*,*,*}+\alpha_{z_{m,n}})\left(
\frac{
\mathbf{c}^-_{z_{m,n},*,*,\mathbf{w}_{m,n}}+\eta_{w_{m,n}}
}{
\mathbf{c}^-_{z_{m,n},*,*,*}+\sum_v^V\eta_{v}
}
\right)\left(
\frac{
\mathbf{c}^-_{z_{m,n},*,c_{m,n},*}+\xi_{w_{m,n}}
}{
\mathbf{c}^-_{z_{m,n},*,*,*}+\sum_i^2\xi_{i}
}
\right)
$$
Where .- denotes the counter disregarding the current position m, n.
3. Collapsed Gibbs Sampler of the AlterLDA Model [Samples of TeX encoding from 000576.xml, testing how to embed the code in our encoding]
[The third example embeds the entire block of code within <formula>, escaping ampersands and removing the outer layer of code]
The joint probability of the model is given
by
$$
p(\mathbf{w}, c, z, \gamma, \beta, \theta~|~\alpha,\eta, \xi) =& p(c~|~z) \cdot p(\mathbf{w}~|~z,\beta)
\cdot p(\gamma~|~\xi) \cdot p(\beta~|~\eta)\cdot p(z~|~\theta)\cdot p(\theta~|~\alpha)\\
=& \prod^{M,N}\text{cat}(c~|~c,\gamma) \times \prod^{M,N}\text{cat}(\textbf{w}~|~z,\beta)\times\prod^{M,N}\text{cat}(z~|~\theta)\\
&\times\prod^{M}\text{dir}(\theta~|~\alpha)\times\prod^{K}\text{dir}(\gamma~|~\xi)\times\prod^{K}\text{dir}(\beta~|~\eta)\\
$$
We introduce a counter variable c which can be indexed in four dimensions, the current
topic (k), the current document
(m), the current alteration mode (a) and the current token (w).
$$\[
c_{k,m,a,\mathbf{w}} = \sum_{n=1}^N \mathbf{I}(
z_{m,n}=k
\quad\&\quad w_{m,n} = \mathbf{w}
\quad\&\quad c_{m,n} = a )
\]$$
In this setting, the desired computation is the probability of
a topic assignment at a specific position given a current configuration of
all other topic assignments. This probability can be formalized by
$$
p(z_{m,n}~|~z_{-_{(m,n)}},\mathbf{w},c,\alpha,\eta,\xi)&\propto~p(z_{m,n},z_{-_{(m,n)}},\mathbf{w},c~|~\alpha,\eta,\xi)
$$
Adopting Equation 16 from the Carpenter paper, this probability can be written by
marginalizing θ,β,γ and from the joint probability.
p(z_{m,n},z_{-_{(m,n)}},\mathbf{w},c~|~\alpha,\eta,\xi) = & \int\int\int~p(\mathbf{w},c,z,\gamma,\beta,
\theta~|~\alpha,\eta,\xi)d\theta~d\beta~d\gamma\\
= & \underbrace{\int~p(\theta~|~\alpha)\cdot~p(z~|~\theta)d\theta}_A\\
& \times \underbrace{\int~p(\mathbf{w}~|~z,\beta)\cdot~p(\beta~|~\eta)d\beta}_B\\
& \times \int~p(c~|~z,\gamma)\cdot~p(\gamma~|~\xi)d\gamma\\
= & \prod_{k=1}^K\int~p(\gamma_k~|~\xi)\prod_{m=1,n=1}^{M,N_m}p(c~|~\gamma_{\text{argmax}(z_{m,n})})d\gamma_k
\times A \times B
A and B are substituted here because their derivation is
identical to the one in Carpenter et al. Analogue to Equation 27 of
Carpenter et al., after inserting the definitions of the Dirichlet
distribution the result is proportional to three factors.
\propto (\mathbf{c}^-_{z_{m,n},*,*,*}+\alpha_{z_{m,n}})\left(
\frac{
\mathbf{c}^-_{z_{m,n},*,*,\mathbf{w}_{m,n}}+\eta_{w_{m,n}}
}{
\mathbf{c}^-_{z_{m,n},*,*,*}+\sum_v^V\eta_{v}
}
\right)\left(
\frac{
\mathbf{c}^-_{z_{m,n},*,c_{m,n},*}+\xi_{w_{m,n}}
}{
\mathbf{c}^-_{z_{m,n},*,*,*}+\sum_i^2\xi_{i}
}
\right)
Where .- denotes the counter disregarding the current position m, n.
Works Cited
Flanders 1999 Flanders, Julia. “Scholarly Habits and Digital Resources: Observations from a User Survey”. Women Writers Project, 1999. http://www.wwp.brown.edu/about/rwo/rwo_initial_report.html.



