# encoding=utf-8 require 'spec_helper' describe Polytexnic::Pipeline do subject(:processed_text) { Polytexnic::Pipeline.new(polytex).to_html } describe "display and inline math" do let(:math) do <<-'EOS' \begin{bmatrix} 1 & \cdots & 0 \\ \vdots & \ddots & \vdots \\ 2 & \cdots & 0 \end{bmatrix} EOS end let(:result) do <<-'EOS' \begin{bmatrix} 1 & \cdots & 0 \\ \vdots & \ddots & \vdots \\ 2 & \cdots & 0 \end{bmatrix} EOS end context "TeX displaystyle" do let(:equation) { "$$ #{math} $$"} let(:polytex) { equation } let(:contents) { "\\[ #{result} \\]"} it { should resemble contents } end context "LaTeX displaystyle" do let(:equation) { "\\[ #{math} \\]"} let(:polytex) { equation } let(:contents) { "\\[ #{result} \\]"} it { should resemble contents } context "with surrounding text" do let(:polytex) { "lorem\n\\[ #{math} \\]\nipsum" } it { should resemble '
' } end end context "TeX inline" do let(:equation) { "$#{math}$"} let(:polytex) { equation } let(:contents) { "\\( #{result} \\)"} it { should resemble contents } end context "TeX inline with a dollar sign" do let(:equation) { "$#{math} \\mbox{\\$2 bill}$"} let(:polytex) { equation } let(:contents) { "\\( #{result} \\mbox{\\$2 bill} \\)"} it { should resemble contents } end context "LaTeX inline" do let(:equation) { "\\( #{math} \\)" } let(:polytex) { equation } let(:contents) { "\\( #{result} \\)" } it { should resemble contents } end context "with a space before a dollar sign" do let(:polytex) { "foo $x$ bar" } let(:contents) { "
foo \\( x \\) bar" }
it { should include contents }
end
context 'using \ensuremath' do
let(:math) { 'x^2 + y' }
let(:equation) { "\\ensuremath{#{math}}" }
let(:polytex) { equation }
let(:contents) { "\\( #{math} \\)" }
it { should include contents }
end
end
describe "multiple occurrences of inline math on one line" do
let(:polytex) { '$\Omega > 0$ and \( x^2 - 2 \equiv 0 \) should work.' }
it { should resemble '\Omega' }
it { should resemble '\equiv' }
it { should resemble '' }
it { should resemble '\(' }
end
describe "equation environments" do
shared_examples "an equation environment" do
it { should resemble contents }
it { should resemble ' lorem' }
it { should resemble ' ipsum' }
end
describe "align" do
let(:equation) do <<-'EOS'
\begin{align}
x^2 + y^2 & = 1 \\
y & = \sqrt{1 - x^2}.
\end{align}
EOS
end
let(:polytex) { equation }
let(:contents) do <<-'EOS'
\begin{align}
x^2 + y^2 & = 1 \\
y & = \sqrt{1 - x^2}.
\end{align}
EOS
end
it_behaves_like "an equation environment"
end
describe "align*" do
let(:equation) do <<-'EOS'
\begin{align*}
x^2 + y^2 & = 1 \\
y & = \sqrt{1 - x^2}.
\end{align*}
EOS
end
let(:polytex) { equation }
let(:contents) do <<-'EOS'
\begin{align*}
x^2 + y^2 & = 1 \\
y & = \sqrt{1 - x^2}.
\end{align*}
EOS
end
it_behaves_like "an equation environment"
end
describe "aligned" do
let(:equation) do <<-'EOS'
\begin{equation}
\begin{aligned}
\nabla \times \vec{\mathbf{B}} -\, \frac1c\,
\frac{\partial\vec{\mathbf{E}}}{\partial t} & =
\frac{4\pi}{c}\vec{\mathbf{j}} \\ \nabla \cdot \vec{\mathbf{E}} & =
4 \pi \rho \\
\nabla \times \vec{\mathbf{E}}\, +\, \frac1c\,
\frac{\partial\vec{\mathbf{B}}}{\partial t} & = \vec{\mathbf{0}} \\
\nabla \cdot \vec{\mathbf{B}} & = 0
\end{aligned}
\end{equation}
EOS
end
let(:polytex) { equation }
let(:contents) do <<-'EOS'
\begin{equation}
\begin{aligned}
\nabla \times \vec{\mathbf{B}} -\, \frac1c\,
\frac{\partial\vec{\mathbf{E}}}{\partial t} & =
\frac{4\pi}{c}\vec{\mathbf{j}} \\ \nabla \cdot \vec{\mathbf{E}} &
= 4 \pi \rho \\
\nabla \times \vec{\mathbf{E}}\, +\, \frac1c\,
\frac{\partial\vec{\mathbf{B}}}{\partial t} & = \vec{\mathbf{0}} \\
\nabla \cdot \vec{\mathbf{B}} & = 0
\end{aligned}
\end{equation}
EOS
end
it_behaves_like "an equation environment"
end
describe "equation*" do
let(:equation) do <<-'EOS'
\begin{equation*}
\left.\begin{aligned}
dE &= \rho \\
d*B &= J + \dot{E}
\end{aligned}
\right\}
\qquad \text{Maxwell}
\end{equation*}
EOS
end
let(:polytex) { equation }
let(:contents) do <<-'EOS'
\begin{equation*}
\left.\begin{aligned}
dE &= \rho \\
d*B &= J + \dot{E}
\end{aligned}
\right\}
\qquad \text{Maxwell}
\end{equation*}
EOS
end
it_behaves_like "an equation environment"
end
end
endChapter 1 Foo