pandoc_refeq_mathml 0.1 → 0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/ChangeLog +7 -0
- data/README.en.rdoc +31 -10
- data/doc/PandocRefeqMathml.html +1428 -0
- data/doc/class_list.html +51 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +58 -0
- data/doc/css/style.css +497 -0
- data/doc/file.README.en.html +262 -0
- data/doc/file_list.html +56 -0
- data/doc/frames.html +17 -0
- data/doc/index.html +262 -0
- data/doc/js/app.js +314 -0
- data/doc/js/full_list.js +216 -0
- data/doc/js/jquery.js +4 -0
- data/doc/method_list.html +139 -0
- data/doc/top-level-namespace.html +110 -0
- data/lib/pandoc_refeq_mathml.rb +38 -11
- data/pandoc_refeq_mathml.gemspec +9 -9
- data/test/data/.gitignore +10 -0
- data/test/data/Makefile +32 -0
- data/test/data/shifted-numbered-headings.lua +17 -0
- data/test/data/try01.html +115 -0
- data/test/data/try01_latex.aux +32 -0
- data/test/data/try01_tmpl.tex +96 -0
- data/test/test_pandoc_refeq_mathml.rb +22 -15
- metadata +24 -3
data/pandoc_refeq_mathml.gemspec
CHANGED
@@ -5,15 +5,15 @@ require 'date'
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = 'pandoc_refeq_mathml'.sub(/.*/){|c| (c == File.basename(Dir.pwd)) ? c : raise("ERROR: s.name=(#{c}) in gemspec seems wrong!")}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2".sub(/.*/){|c| fs = Dir.glob('changelog{,.*}', File::FNM_CASEFOLD); raise('More than one ChangeLog exist!') if fs.size > 1; warn("WARNING: Version(s.version=#{c}) already exists in #{fs[0]} - ok?") if fs.size == 1 && !IO.readlines(fs[0]).grep(/^\(Version: #{Regexp.quote c}\)$/).empty? ; c } # n.b., In macOS, changelog and ChangeLog are identical in default.
|
9
9
|
# s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
s.bindir = 'bin'
|
11
|
+
%w(pandoc_refeq_mathml).each do |f|
|
12
|
+
path = s.bindir+'/'+f
|
13
|
+
File.executable?(path) ? s.executables << f : raise("ERROR: Executable (#{path}) is not executable!")
|
14
|
+
end
|
15
15
|
s.authors = ["Masa Sakano"]
|
16
|
-
s.date = %q{2022-08-
|
16
|
+
s.date = %q{2022-08-27}.sub(/.*/){|c| (Date.parse(c) == Date.today) ? c : raise("ERROR: s.date=(#{c}) is not today!")}
|
17
17
|
s.summary = %q{Add equation numbers to a pandoc-output MathML converted from LaTeX}
|
18
18
|
s.description = <<-EOF
|
19
19
|
Add equation numbers in a crude way to a pandoc-output MathML converted from LaTeX, utilising its LaTeX aux file, and also adjust math-table alignments.
|
@@ -24,7 +24,7 @@ Add equation numbers in a crude way to a pandoc-output MathML converted from LaT
|
|
24
24
|
"README.en.rdoc",
|
25
25
|
]
|
26
26
|
s.license = 'MIT'
|
27
|
-
s.files = FileList['.gitignore','
|
27
|
+
s.files = FileList['.gitignore', '**/.gitignore', '*.gemspec', '[A-Z]*', '**/[A-Z]*', 'lib/**/*.rb', 'test/**/*.rb', 'test/data/*.lua', 'test/data/try01.html', 'test/data/try01_latex.aux', 'test/data/try01_tmpl.tex', 'bin/pandoc_refeq_mathml'].to_a.delete_if{ |f|
|
28
28
|
ret = false
|
29
29
|
arignore = IO.readlines('.gitignore')
|
30
30
|
arignore.map{|i| i.chomp}.each do |suffix|
|
@@ -34,7 +34,7 @@ Add equation numbers in a crude way to a pandoc-output MathML converted from LaT
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
ret
|
37
|
-
}
|
37
|
+
}.uniq
|
38
38
|
s.files.reject! { |fn| File.symlink? fn }
|
39
39
|
|
40
40
|
s.add_runtime_dependency 'nokogiri', '>= 1.13'
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
|
2
|
+
#
|
3
|
+
# If you find yourself ignoring temporary files generated by your text editor
|
4
|
+
# or operating system, you probably want to add a global ignore instead:
|
5
|
+
# git config --global core.excludesfile '~/.gitignore_global'
|
6
|
+
|
7
|
+
# Ignore all LaTeX-related intermediate files.
|
8
|
+
try01_tmpl.*
|
9
|
+
!try01_tmpl.tex
|
10
|
+
|
data/test/data/Makefile
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
|
2
|
+
#
|
3
|
+
# 'make' generates try01_tmpl.html by latex-compiling try01_tmpl.tex and pandoc-converting
|
4
|
+
# it and correcting it with this tool.
|
5
|
+
#
|
6
|
+
# You may run `make clean` before `make`.
|
7
|
+
#
|
8
|
+
# Environmental variable LATEX should points the LaTeX command in your environment.
|
9
|
+
# If environmental variable NOLATEX is set, LaTeX compiling is skipped,
|
10
|
+
# and try01_tmpl.aux is assumed to exist in the current directory.
|
11
|
+
#
|
12
|
+
# USAGE: make NOLATEX=1 LATEX=platex
|
13
|
+
|
14
|
+
ALL = try01_tmpl.html
|
15
|
+
|
16
|
+
objs =
|
17
|
+
auxfile = try01_tmpl.aux
|
18
|
+
|
19
|
+
.SUFFIXES: .so .o .c .f
|
20
|
+
|
21
|
+
#.o.so:
|
22
|
+
# ${LD} ${LFLAGS} -o $@ $< ${LINK_LIB}
|
23
|
+
|
24
|
+
all: ${ALL}
|
25
|
+
|
26
|
+
try01_tmpl.html: try01_tmpl.tex
|
27
|
+
if [ -z "$${NOLATEX}" ]; then ${LATEX} $<; ${LATEX} $<; fi; if [ -e ${auxfile} ]; then echo "${auxfile} is found. Creating HTML."; pandoc --lua-filter ./shifted-numbered-headings.lua -s -N --section-divs -t html5 --toc --reference-location=block --mathml $< | RUBYLIB=../../lib:$$RUBYLIB ../../bin/pandoc_refeq_mathml --aux ${auxfile} > $@; echo "$@ is created."; else echo "aux file (${auxfile}) is not found." 2>&1; exit 1; fi
|
28
|
+
|
29
|
+
.PHONY: clean
|
30
|
+
clean:
|
31
|
+
$(RM) try01_tmpl.html try01_tmpl.dvi try01_tmpl.log try01_tmpl.out try01_tmpl.pdf try01_tmpl.toc; if [ -e ${auxfile} ]; then echo "NOTE: ${auxfile} is still present."; fi
|
32
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
-- from https://stackoverflow.com/a/73418616/3577922
|
2
|
+
function Pandoc (doc)
|
3
|
+
-- Create and number sections. Setting the first parameter to
|
4
|
+
-- `true` ensures that headings are numbered.
|
5
|
+
doc.blocks = pandoc.utils.make_sections(true, nil, doc.blocks)
|
6
|
+
|
7
|
+
-- Shift the heading levels by 1
|
8
|
+
doc.blocks = doc.blocks:walk {
|
9
|
+
Header = function (h)
|
10
|
+
h.level = h.level + 1
|
11
|
+
return h
|
12
|
+
end
|
13
|
+
}
|
14
|
+
|
15
|
+
-- Return the modified document
|
16
|
+
return doc
|
17
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang="">
|
3
|
+
<!-- This file is kind of hand-generated (or heavily hand-corrected), containing lots of comments, to serve as a template test file. -->
|
4
|
+
<head>
|
5
|
+
<meta charset="utf-8" />
|
6
|
+
<meta name="generator" content="pandoc" />
|
7
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
|
8
|
+
<title>My Title</title>
|
9
|
+
<style>
|
10
|
+
html {line-height: 1.5;}
|
11
|
+
body {margin: 0 auto;}
|
12
|
+
</style>
|
13
|
+
<!--[if lt IE 9]>
|
14
|
+
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv-printshiv.min.js"></script>
|
15
|
+
<![endif]-->
|
16
|
+
</head>
|
17
|
+
<body>
|
18
|
+
<header id="title-block-header">
|
19
|
+
<h1 class="title">My Title</h1>
|
20
|
+
</header>
|
21
|
+
<nav id="TOC" role="doc-toc">
|
22
|
+
<ul>
|
23
|
+
<li><a href="#はじめに" id="toc-はじめに"><span
|
24
|
+
class="toc-section-number">1</span> はじめに</a></li>
|
25
|
+
</ul>
|
26
|
+
</nav>
|
27
|
+
<section id="sec_symmetry_mul" class="level3" data-number="4.6">
|
28
|
+
<h3 data-number="4.6"><span class="header-section-number">4.6</span>
|
29
|
+
対称的な数</h3>
|
30
|
+
<p>以下が使える。
|
31
|
+
</p>
|
32
|
+
</section>
|
33
|
+
<section id="2乗と3乗" class="level3"
|
34
|
+
data-number="4.8">
|
35
|
+
<h3 data-number="4.8"><span class="header-section-number">4.8</span>
|
36
|
+
2乗と3乗</h3>
|
37
|
+
<p>つまり、計算は単純化される。</p> <!-- COMMENT: below has a label that is referenced in LaTeX. -->
|
38
|
+
<p><math display="block" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mrow><mo stretchy="true" form="prefix">(</mo><mi>x</mi><mo>±</mo><mi>ϵ</mi><mo stretchy="true" form="postfix">)</mo></mrow><mn>2</mn></msup><mo>=</mo><msup><mi>x</mi><mn>2</mn></msup><mo>±</mo><mn>2</mn><mi>x</mi><mi>ϵ</mi><mo>+</mo><msup><mi>ϵ</mi><mn>2</mn></msup></mrow><annotation encoding="application/x-tex">(x \pm \epsilon)^2 = x^2 \pm 2x\epsilon + \epsilon^2 \label{eq_square_pm}</annotation></semantics></math>
|
39
|
+
</p>
|
40
|
+
<p>同様に、</p> <!-- COMMENT: below has a label but not referenced in LaTeX. -->
|
41
|
+
<p><math display="block" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mrow><mo stretchy="true" form="prefix">(</mo><mi>x</mi><mo>±</mo><mi>ϵ</mi><mo stretchy="true" form="postfix">)</mo></mrow><mn>3</mn></msup><mo>=</mo><msup><mi>x</mi><mn>3</mn></msup><mo>±</mo><mn>3</mn><msup><mi>x</mi><mn>2</mn></msup><mi>ϵ</mi><mo>+</mo><mn>3</mn><mi>x</mi><msup><mi>ϵ</mi><mn>2</mn></msup><mo>±</mo><msup><mi>ϵ</mi><mn>3</mn></msup></mrow><annotation encoding="application/x-tex">(x \pm \epsilon)^3 = x^3 \pm 3x^2\epsilon + 3x\epsilon^2 \pm \epsilon^3 \label{eq_cubic_pm}</annotation></semantics></math></p>
|
42
|
+
<p>以下が公式(<a href="#sec_symmetry_mul"
|
43
|
+
data-reference-type="ref"
|
44
|
+
data-reference="sec_symmetry_mul">4.6</a>章)の応用例。</p> <!-- COMMENT: Below is begin{eqnarray} with no label -->
|
45
|
+
<p><math display="block" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mtable><mtr><mtd columnalign="right"><mn>84</mn><mo>×</mo><mn>86</mn></mtd><mtd columnalign="left"><mo>=</mo></mtd><mtd columnalign="right"><mrow><mo stretchy="true" form="prefix">(</mo><mn>85</mn><mo>+</mo><mn>1</mn><mo stretchy="true" form="postfix">)</mo></mrow><mrow><mo stretchy="true" form="prefix">(</mo><mn>85</mn><mo>−</mo><mn>1</mn><mo stretchy="true" form="postfix">)</mo></mrow></mtd></mtr><mtr><mtd columnalign="right"></mtd><mtd columnalign="left"><mo>=</mo></mtd><mtd columnalign="right"><mn>7224</mn></mtd></mtr></mtable><annotation encoding="application/x-tex">\begin{aligned}
|
46
|
+
84\times 86 & = & (85+1)(85-1) \\
|
47
|
+
& = & 7224
|
48
|
+
\end{aligned}</annotation></semantics></math></p>
|
49
|
+
<p>ここで、<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><msup><mn>85</mn><mn>2</mn></msup><annotation encoding="application/x-tex">85^2</annotation></semantics></math>は項(式(<a
|
50
|
+
href="#eq_square_pm" data-reference-type="ref"
|
51
|
+
data-reference="eq_square_pm">[eq_square_pm]</a>)の<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>2</mn><mi>x</mi><mi>ϵ</mi></mrow><annotation encoding="application/x-tex">2x\epsilon</annotation></semantics></math>)。</p>
|
52
|
+
</section>
|
53
|
+
|
54
|
+
<section id="割り算" class="level4"
|
55
|
+
data-number="4.9.1">
|
56
|
+
<h4 data-number="4.9.1"><span class="header-section-number">4.9.1</span>
|
57
|
+
割り算</h4>
|
58
|
+
<p>これは、</p> <!-- COMMENT: below has labels (referenced) and \nonumber-s. -->
|
59
|
+
<p><math display="block" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mtable><mtr><mtd columnalign="right"><mfrac><mrow><mn>1</mn><mo>+</mo><mi>x</mi></mrow><mrow><mn>1</mn><mo>−</mo><mi>x</mi></mrow></mfrac></mtd><mtd columnalign="left"><mo>=</mo></mtd><mtd columnalign="right"><mfrac><mrow><mn>2</mn><mo>−</mo><mrow><mo stretchy="true" form="prefix">(</mo><mn>1</mn><mo>−</mo><mi>x</mi><mo stretchy="true" form="postfix">)</mo></mrow></mrow><mrow><mn>1</mn><mo>−</mo><mi>x</mi></mrow></mfrac></mtd></mtr><mtr><mtd columnalign="right"></mtd><mtd columnalign="left"><mo>=</mo></mtd><mtd columnalign="right"><mfrac><mn>2</mn><mrow><mn>1</mn><mo>−</mo><mi>x</mi></mrow></mfrac><mo>−</mo><mn>1</mn></mtd></mtr><mtr><mtd columnalign="right"></mtd><mtd columnalign="left"><mo>=</mo></mtd><mtd columnalign="right"><mn>1</mn><mo>+</mo><mn>2</mn><mi>x</mi><mo>+</mo><mn>2</mn><msup><mi>x</mi><mn>2</mn></msup><mo>+</mo><mn>2</mn><msup><mi>x</mi><mn>3</mn></msup><mo>+</mo><mi>⋯</mi></mtd></mtr><mtr><mtd columnalign="right"></mtd><mtd columnalign="left"><mo>∼</mo></mtd><mtd columnalign="right"><mfrac><mn>1</mn><mrow><mn>1</mn><mo>−</mo><mn>2</mn><mi>x</mi></mrow></mfrac></mtd></mtr><mtr><mtd columnalign="right"></mtd><mtd columnalign="left"><mo>=</mo></mtd><mtd columnalign="right"><mn>1</mn><mo>+</mo><mn>2</mn><mi>x</mi><mo>+</mo><mn>4</mn><msup><mi>x</mi><mn>2</mn></msup><mo>+</mo><mn>8</mn><msup><mi>x</mi><mn>3</mn></msup><mo>+</mo><mi>⋯</mi></mtd></mtr><mtr><mtd columnalign="right"></mtd><mtd columnalign="left"><mo>∼</mo></mtd><mtd columnalign="right"><mn>1</mn><mo>+</mo><mn>2</mn><mi>x</mi></mtd></mtr></mtable><annotation encoding="application/x-tex">\begin{aligned}
|
60
|
+
\frac{1+x}{1-x} & = & \frac{2-(1-x)}{1-x} \nonumber\\
|
61
|
+
& = & \frac{2}{1-x} - 1\nonumber\\
|
62
|
+
& = & 1 + 2x + 2x^2 + 2x^3 + \cdots \label{eq_approx_symmetric_frac_strict}\\
|
63
|
+
& \sim & \frac{1}{1-2x} \label{eq_approx_symmetric_frac2}\\
|
64
|
+
& = & 1 + 2x + 4x^2 + 8x^3 + \cdots \label{eq_approx_symmetric_frac2_series}\\
|
65
|
+
& \sim & 1 + 2x %\label{eq_dummy1}\\
|
66
|
+
\label{eq_approx_symmetric_frac_1order} % \label{eq_dummy2}\\
|
67
|
+
\end{aligned}</annotation></semantics></math></p>
|
68
|
+
<p>近似(<a href="#eq_approx_symmetric_frac2" data-reference-type="ref"
|
69
|
+
data-reference="eq_approx_symmetric_frac2">[eq_approx_symmetric_frac2]</a>)は、、
|
70
|
+
(参考: 式(<a href="#eq_approx_symmetric_frac_1order"
|
71
|
+
data-reference-type="ref"
|
72
|
+
data-reference="eq_approx_symmetric_frac_1order">[eq_approx_symmetric_frac_1order]</a>))だ。したがって、
|
73
|
+
(式(<a href="#eq_approx_symmetric_frac2" data-reference-type="ref"
|
74
|
+
data-reference="eq_approx_symmetric_frac2">[eq_approx_symmetric_frac2]</a>))の場合は、近似
|
75
|
+
<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>1</mn></mrow><annotation encoding="application/x-tex">1</annotation></semantics></math>
|
76
|
+
(式<a href="#eq_approx_symmetric_frac_1order" data-reference-type="ref"
|
77
|
+
data-reference="eq_approx_symmetric_frac_1order">[eq_approx_symmetric_frac_1order]</a>)の計算。</p>
|
78
|
+
<p>一例として、 <!-- COMMENT: Below is begin{equation} with no label -->
|
79
|
+
<math display="block" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>26</mn><mo>÷</mo><mn>24</mn></mrow><annotation encoding="application/x-tex">26\div24</annotation></semantics></math>
|
80
|
+
を展開(式(<a href="#eq_approx_symmetric_frac_strict"
|
81
|
+
data-reference-type="ref"
|
82
|
+
data-reference="eq_approx_symmetric_frac_strict">[eq_approx_symmetric_frac_strict]</a>))と、式(<a
|
83
|
+
href="#eq_square_pm" data-reference-type="ref"
|
84
|
+
data-reference="eq_square_pm">[eq_square_pm]</a>)で計算。</p>
|
85
|
+
<div id="tbl_25pm1_taylor">
|
86
|
+
<table> <!-- COMMENT: Caption below contains math -->
|
87
|
+
<caption><math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>25</mn></mrow><annotation encoding="application/x-tex">25</annotation></semantics></math>の計算</caption>
|
88
|
+
<thead>
|
89
|
+
<tr class="header">
|
90
|
+
<th style="text-align: center;">Equation</th>
|
91
|
+
<th style="text-align: left;">Num</th>
|
92
|
+
</tr>
|
93
|
+
</thead>
|
94
|
+
<tbody>
|
95
|
+
<tr class="odd"> <!-- COMMENT: td below contains a ref to an Equation -->
|
96
|
+
<td style="text-align: center;">(<a
|
97
|
+
href="#eq_approx_symmetric_frac_strict" data-reference-type="ref"
|
98
|
+
data-reference="eq_approx_symmetric_frac_strict">[eq_approx_symmetric_frac_strict]</a>)</td>
|
99
|
+
<td style="text-align: left;">1.08
|
100
|
+
</td>
|
101
|
+
</tr>
|
102
|
+
<tr class="even">
|
103
|
+
<td style="text-align: center;">(<a
|
104
|
+
href="#eq_approx_symmetric_frac2_series" data-reference-type="ref"
|
105
|
+
data-reference="eq_approx_symmetric_frac2_series">[eq_approx_symmetric_frac2_series]</a>)</td>
|
106
|
+
<td style="text-align: left;">2.08
|
107
|
+
</td>
|
108
|
+
</tr>
|
109
|
+
</tbody>
|
110
|
+
</table>
|
111
|
+
</div>
|
112
|
+
</section>
|
113
|
+
</body>
|
114
|
+
</html>
|
115
|
+
|
@@ -0,0 +1,32 @@
|
|
1
|
+
\relax
|
2
|
+
\providecommand\hyper@newdestlabel[2]{}
|
3
|
+
\bbl@cs{beforestart}
|
4
|
+
\providecommand\HyperFirstAtBeginDocument{\AtBeginDocument}
|
5
|
+
\HyperFirstAtBeginDocument{\ifx\hyper@anchor\@undefined
|
6
|
+
\global\let\oldcontentsline\contentsline
|
7
|
+
\gdef\contentsline#1#2#3#4{\oldcontentsline{#1}{#2}{#3}}
|
8
|
+
\global\let\oldnewlabel\newlabel
|
9
|
+
\gdef\newlabel#1#2{\newlabelxx{#1}#2}
|
10
|
+
\gdef\newlabelxx#1#2#3#4#5#6{\oldnewlabel{#1}{{#2}{#3}}}
|
11
|
+
\AtEndDocument{\ifx\hyper@anchor\@undefined
|
12
|
+
\let\contentsline\oldcontentsline
|
13
|
+
\let\newlabel\oldnewlabel
|
14
|
+
\fi}
|
15
|
+
\fi}
|
16
|
+
\@writefile{toc}{\contentsline {section}{\numberline {1}はじめに}{4}{section.1}\protected@file@percent }
|
17
|
+
|
18
|
+
\@writefile{toc}{\contentsline {subsection}{\numberline {4.6}対称的な数}{33}{subsection.4.6}\protected@file@percent }
|
19
|
+
\newlabel{sec_symmetry_mul}{{4.6}{33}{対称的な数}{subsection.4.6}{}}
|
20
|
+
\@writefile{toc}{\contentsline {subsection}{\numberline {4.8}2乗と3乗}{34}{subsection.4.8}\protected@file@percent }
|
21
|
+
\newlabel{eq_square_pm}{{36}{34}{2乗と3乗}{equation.4.36}{}}
|
22
|
+
\newlabel{eq_cubic_pm}{{37}{34}{2乗と3乗}{equation.4.37}{}}
|
23
|
+
\@writefile{toc}{\contentsline {subsection}{\numberline {4.9}近い割り算}{35}{subsection.4.9}\protected@file@percent }
|
24
|
+
\@writefile{toc}{\contentsline {subsubsection}{\numberline {4.9.1}割り算}{38}{subsubsection.4.9.1}\protected@file@percent }
|
25
|
+
\newlabel{eq_approx_symmetric_frac_strict}{{52}{39}{割り算}{equation.4.52}{}}
|
26
|
+
\newlabel{eq_approx_symmetric_frac2}{{53}{39}{割り算}{equation.4.52}{}}
|
27
|
+
\newlabel{eq_approx_symmetric_frac2_series}{{54}{39}{割り算}{equation.4.52}{}}
|
28
|
+
\newlabel{eq_approx_symmetric_frac_1order}{{55}{39}{割り算}{equation.4.52}{}}
|
29
|
+
\@writefile{toc}{\contentsline {paragraph}{この考察}{39}{section*.3}\protected@file@percent }
|
30
|
+
\@writefile{lot}{\contentsline {table}{\numberline {11}{\ignorespaces $25$の計算}}{39}{table.11}\protected@file@percent }
|
31
|
+
\newlabel{tbl_25pm1_taylor}{{11}{39}{$25$の計算}{table.11}{}}
|
32
|
+
\newlabel{tbl_log_approx_cmp}{{15}{82}{近似の比較}{table.15}{}}
|
@@ -0,0 +1,96 @@
|
|
1
|
+
\documentclass[a4paper, 12pt]{article}
|
2
|
+
% Template LaTeX file, which try01.html and try01_latex.aux are ``loosely'' based on.
|
3
|
+
% Latex-compiling this file yields something similar, but not identical, such as
|
4
|
+
% the section numbers. Or, try01.html is hand-annotated. Most importantly,
|
5
|
+
% 'make' generates try01_tmpl.html from this LaTeX file where HTML is corrected
|
6
|
+
% by this tool, whereas try01.html is before any correction.
|
7
|
+
|
8
|
+
\usepackage[main=japanese,english]{babel}
|
9
|
+
\usepackage[utf8]{inputenc}
|
10
|
+
\usepackage{amssymb} % for \mathbb{Z}
|
11
|
+
\usepackage{amstext} % for $\text{例}$ or \textrm{例} % both are included in the ``amsmath'' package.
|
12
|
+
\usepackage[unicode]{hyperref}
|
13
|
+
\usepackage{graphicx}
|
14
|
+
|
15
|
+
\begin{document}
|
16
|
+
\tableofcontents % The initial declaration MUST contain a4paper.
|
17
|
+
|
18
|
+
\title{My Title}
|
19
|
+
\maketitle
|
20
|
+
|
21
|
+
\section{はじめに}
|
22
|
+
|
23
|
+
\setcounter{section}{4}
|
24
|
+
\setcounter{subsection}{5}
|
25
|
+
\subsection{対称的な数}
|
26
|
+
\label{sec_symmetry_mul}
|
27
|
+
|
28
|
+
以下が使える。
|
29
|
+
|
30
|
+
\addtocounter{subsection}{1}
|
31
|
+
\subsection{2乗と3乗}
|
32
|
+
|
33
|
+
つまり、計算は単純化される。
|
34
|
+
|
35
|
+
\begin{equation}
|
36
|
+
(x \pm \epsilon)^2 = x^2 \pm 2x\epsilon + \epsilon^2 \label{eq_square_pm}
|
37
|
+
\end{equation}
|
38
|
+
|
39
|
+
同様に、
|
40
|
+
\begin{equation}
|
41
|
+
(x \pm \epsilon)^3 = x^3 \pm 3x^2\epsilon + 3x\epsilon^2 \pm \epsilon^3 \label{eq_cubic_pm}
|
42
|
+
\end{equation}
|
43
|
+
|
44
|
+
以下が公式(\ref{sec_symmetry_mul}章)の応用例。
|
45
|
+
|
46
|
+
\begin{eqnarray}
|
47
|
+
84\times 86 & = & (85+1)(85-1) \nonumber\\
|
48
|
+
& = & 7224
|
49
|
+
\end{eqnarray}
|
50
|
+
|
51
|
+
ここで、$85^2$は項(式(\ref{eq_square_pm})の$2x\epsilon$)。
|
52
|
+
|
53
|
+
\addtocounter{subsection}{1}
|
54
|
+
\subsubsection{割り算}
|
55
|
+
|
56
|
+
これは、
|
57
|
+
|
58
|
+
\begin{eqnarray}
|
59
|
+
\frac{1+x}{1-x} & = & \frac{2-(1-x)}{1-x} \nonumber\\
|
60
|
+
& = & \frac{2}{1-x} - 1\nonumber\\
|
61
|
+
& = & 1 + 2x + 2x^2 + 2x^3 + \cdots \label{eq_approx_symmetric_frac_strict}\\
|
62
|
+
& \sim & \frac{1}{1-2x} \label{eq_approx_symmetric_frac2}\\
|
63
|
+
& = & 1 + 2x + 4x^2 + 8x^3 + \cdots \label{eq_approx_symmetric_frac2_series}\\
|
64
|
+
& \sim & % 1 + 2x \label{eq_approx_symmetric_frac_1order}
|
65
|
+
\left\{
|
66
|
+
\begin{array}{ll}
|
67
|
+
1 & (x=0)\\
|
68
|
+
1 + 2x
|
69
|
+
\end{array} \right. \label{eq_approx_symmetric_frac_1order}
|
70
|
+
\end{eqnarray}
|
71
|
+
|
72
|
+
近似(\ref{eq_approx_symmetric_frac2})は、、(参考: 式(\ref{eq_approx_symmetric_frac_1order}))だ。したがって、 (式(\ref{eq_approx_symmetric_frac2}))の場合は、近似1 (式\ref{eq_approx_symmetric_frac_1order})の計算。
|
73
|
+
|
74
|
+
一例として、
|
75
|
+
\begin{equation}
|
76
|
+
26\div24 = \frac{25+1}{25-1}
|
77
|
+
\end{equation}
|
78
|
+
を展開(式(\ref{eq_approx_symmetric_frac_strict}))と、式(\ref{eq_approx_symmetric_frac2_series})で計算。
|
79
|
+
|
80
|
+
\begin{table}[htbp]
|
81
|
+
\centering
|
82
|
+
\caption{25の計算}
|
83
|
+
\label{tbl_25pm1_taylor}
|
84
|
+
\begin{tabular}{cl}
|
85
|
+
\hline
|
86
|
+
Equation & Num \\
|
87
|
+
\hline
|
88
|
+
(\ref{eq_approx_symmetric_frac_strict}) & 1.08 \\
|
89
|
+
(\ref{eq_approx_symmetric_frac2_series}) & 2.08 \\
|
90
|
+
\hline
|
91
|
+
\end{tabular}
|
92
|
+
\end{table}
|
93
|
+
|
94
|
+
|
95
|
+
\end{document}
|
96
|
+
|
@@ -69,6 +69,10 @@ class TestUnitPandocRefeqMathml < MiniTest::Test
|
|
69
69
|
@auxfile = __dir__ + "/data/try01_latex.aux"
|
70
70
|
@htmlfile = __dir__ + "/data/try01.html"
|
71
71
|
|
72
|
+
# For integration tests, the lib directory should be at the top in RUBYLIB.
|
73
|
+
# Use it like: "RUBYLIB=#{@rubylib4exe} #{@exefile}"
|
74
|
+
@rubylib4exe = sprintf "%s/../lib:%s", __dir__, ENV['RUBYLIB']
|
75
|
+
|
72
76
|
# Array of IOs for temporary files (automatically set in generate_tmpfile())
|
73
77
|
@tmpfiles = []
|
74
78
|
end
|
@@ -93,7 +97,7 @@ class TestUnitPandocRefeqMathml < MiniTest::Test
|
|
93
97
|
htmlstr = File.read @htmlfile
|
94
98
|
page00 = Nokogiri::HTML(htmlstr)
|
95
99
|
page = Nokogiri::HTML(htmlstr)
|
96
|
-
io_tmp,
|
100
|
+
io_tmp, _ = generate_tmpfile(__method__)
|
97
101
|
|
98
102
|
prm = PandocRefeqMathml.new page, auxstr, logio: io_tmp, is_verbose: true
|
99
103
|
prm.alter_html!
|
@@ -104,55 +108,58 @@ class TestUnitPandocRefeqMathml < MiniTest::Test
|
|
104
108
|
lcs = math1_org.to_s.diff(math1_rev.to_s)
|
105
109
|
assert_equal 1, lcs.size, 'Diff-size should be 1 (one continuous addition only)'
|
106
110
|
assert_operator 90, '<', lcs[0].size, 'Number of different characters should be larger than 90'
|
107
|
-
assert_operator 99, '>', lcs[0].size, 'Number of different characters should be smaller than 99: Diff='+
|
111
|
+
assert_operator 99, '>', lcs[0].size, 'Number of different characters should be smaller than 99: Diff='+join_diff_chg(lcs).inspect # "mrow><mtext id=\"square_pm\" style=\"padding-left:1em; text-align:right;\">(36)</mtext></mrow><"
|
108
112
|
assert((%r@</mtext>@ !~ math1_org.to_s), '</mtext> should not be included')
|
109
113
|
assert_match(%r@</mtext></mrow></mrow>@, math1_rev.to_s, '</mtext></mrow></mrow> should be included')
|
114
|
+
assert_match(%r@#{Regexp.quote "(55)</mtext></mtd>"}@, prm.page.to_s, 'Equation number (55) should be correctly placed despite LaTeX comment lines') # in data/try01_latex.aux: {eq_approx_symmetric_frac_1order}{{55}{39}{割り算}{equation.4.52}{}}
|
115
|
+
assert_equal "55", prm.page.css('a[href="#eq_approx_symmetric_frac_1order"]')[0].text, "Eq.55 should be correctly referencing"
|
110
116
|
|
111
117
|
mtds = prm.page.css("math mtable mtr")[2].css("mtd")
|
112
118
|
assert_equal "right", mtds[0]["columnalign"]
|
113
119
|
assert_equal "center", mtds[1]["columnalign"], "align should be center: "+mtds[1]
|
114
120
|
assert_equal "left", mtds[2]["columnalign"]
|
115
|
-
# NOTE: --no-fixalign is tested in
|
121
|
+
# NOTE: --no-fixalign is tested in test_integration()
|
116
122
|
|
117
123
|
io_tmp.rewind
|
118
124
|
msg_log = io_tmp.read
|
119
125
|
assert_match(%r@label=.?sec_@, msg_log, "Warning message should be present in the log file because Equation-ID is not found for a label for a Section: \n> "+msg_log)
|
120
126
|
end
|
121
127
|
|
122
|
-
#
|
123
|
-
|
124
|
-
|
125
|
-
|
128
|
+
# Integration tests
|
129
|
+
#
|
130
|
+
# RUBYLIB=./lib:$RUBYLIB bin/pandoc_refeq_mathml --aux test/data/try01_latex.aux test/data/try01.html > STDOUT/STDERR
|
131
|
+
def test_integration
|
132
|
+
com = sprintf "RUBYLIB=%s %s --aux=%s --no-fixalign", @rubylib4exe, @exefile, @auxfile # Logfile => STDERR, fixalign=no
|
126
133
|
|
127
134
|
## From STDIN, out to STDOUT, log-file to STDERR
|
128
135
|
out, err, stat = Open3.capture3(com, stdin_data: File.read(@htmlfile))
|
129
|
-
assert_equal 0, stat
|
136
|
+
assert_equal 0, stat, "Execution fails (stat=#{stat}): com=(#{@exefile}). STDERR="+err
|
130
137
|
assert_match(%r@label=.?sec_@, err, "Warning message should be present in STDERR because Equation-ID is not found for a label for a Section: \n> "+err)
|
131
|
-
assert_operator 5, '<=', out.scan(%r@(?=</mtext>)@).count, 'There should be many </mtext>. out[0..100]='+out[0..100]
|
138
|
+
assert_operator 5, '<=', out.scan(%r@(?=</mtext>)@).count, 'There should be many </mtext>. out[0..100]='+out#[0..100]
|
132
139
|
assert_match(%r@\bcolumnalign="right"@, out, 'Sanity check columnalign')
|
133
140
|
refute_match(%r@\bcolumnalign="center"@, out, 'With --no-fixalign center columnalign should not exist, but..')
|
134
141
|
end
|
135
142
|
|
136
143
|
# Read a 2-dim Array of Diff::LCS::Change and convert it to a single Array of them
|
137
144
|
#
|
138
|
-
# Each Diff may (or usually) have more than 1 character.
|
145
|
+
# Each array-element Diff may (or usually) have more than 1 character.
|
139
146
|
# And therefore, it should be far more readable for humans.
|
140
147
|
# Here is an example.
|
141
148
|
#
|
142
|
-
# # [
|
143
|
-
# # => <Diff::LCS::Change: ["+", 1, "xy"]>
|
149
|
+
# # [[<Diff::LCS::Change: ["+", 1, "x"]>, <Diff::LCS::Change: ["+", 2, "y"]>], [<Diff::LCS::Change: ["-", 2, "y"]>]]
|
150
|
+
# # => [<Diff::LCS::Change: ["+", 1, "xy"]>, <Diff::LCS::Change: ["-", 2, "y"]>]
|
144
151
|
#
|
145
152
|
# You can still patch it.
|
146
153
|
#
|
147
|
-
# s2 == s1.patch( [
|
154
|
+
# s2 == s1.patch( [join_diff_chg(Diff::LCS.diff(s1, s2))] )
|
148
155
|
#
|
149
|
-
# However, +s2.unpatch [
|
156
|
+
# However, +s2.unpatch [join_diff_chg(...)]+ raises RuntimeError.
|
150
157
|
# I think it works by starting from the beginning, swapping "`+`" and "`-`",
|
151
158
|
# where interpreting "`-`"+0 as inserting before pos=0 and "`+`"+1 as deleting after pos=1.
|
152
159
|
#
|
153
160
|
# @param arlcs [Array<Array<<Diff::LCS::Change>>]
|
154
161
|
# @return [Array<Diff::LCS::Change>]
|
155
|
-
def
|
162
|
+
def join_diff_chg(ar2lcs)
|
156
163
|
arlcs = [] # ar2lcs.flatten actually also flattens the contents of Diff::LCS::Change !
|
157
164
|
# Therefore, this is a custom Array#flatten
|
158
165
|
ar2lcs.each do |ea1|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pandoc_refeq_mathml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.2'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masa Sakano
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-08-
|
11
|
+
date: 2022-08-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -43,7 +43,8 @@ description: 'Add equation numbers in a crude way to a pandoc-output MathML conv
|
|
43
43
|
|
44
44
|
'
|
45
45
|
email:
|
46
|
-
executables:
|
46
|
+
executables:
|
47
|
+
- pandoc_refeq_mathml
|
47
48
|
extensions: []
|
48
49
|
extra_rdoc_files:
|
49
50
|
- README.en.rdoc
|
@@ -55,8 +56,28 @@ files:
|
|
55
56
|
- README.en.rdoc
|
56
57
|
- Rakefile
|
57
58
|
- bin/pandoc_refeq_mathml
|
59
|
+
- doc/PandocRefeqMathml.html
|
60
|
+
- doc/class_list.html
|
61
|
+
- doc/css/common.css
|
62
|
+
- doc/css/full_list.css
|
63
|
+
- doc/css/style.css
|
64
|
+
- doc/file.README.en.html
|
65
|
+
- doc/file_list.html
|
66
|
+
- doc/frames.html
|
67
|
+
- doc/index.html
|
68
|
+
- doc/js/app.js
|
69
|
+
- doc/js/full_list.js
|
70
|
+
- doc/js/jquery.js
|
71
|
+
- doc/method_list.html
|
72
|
+
- doc/top-level-namespace.html
|
58
73
|
- lib/pandoc_refeq_mathml.rb
|
59
74
|
- pandoc_refeq_mathml.gemspec
|
75
|
+
- test/data/.gitignore
|
76
|
+
- test/data/Makefile
|
77
|
+
- test/data/shifted-numbered-headings.lua
|
78
|
+
- test/data/try01.html
|
79
|
+
- test/data/try01_latex.aux
|
80
|
+
- test/data/try01_tmpl.tex
|
60
81
|
- test/test_pandoc_refeq_mathml.rb
|
61
82
|
homepage: https://www.wisebabel.com
|
62
83
|
licenses:
|