maruku 0.6.1 → 0.7.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/MIT-LICENSE.txt +20 -0
- data/bin/maruku +153 -152
- data/bin/marutex +2 -29
- data/data/entities.xml +261 -0
- data/docs/math.md +14 -18
- data/lib/maruku.rb +65 -77
- data/lib/maruku/attributes.rb +109 -214
- data/lib/maruku/defaults.rb +45 -67
- data/lib/maruku/document.rb +43 -0
- data/lib/maruku/element.rb +112 -0
- data/lib/maruku/errors.rb +71 -0
- data/lib/maruku/ext/div.rb +105 -113
- data/lib/maruku/ext/fenced_code.rb +97 -0
- data/lib/maruku/ext/math.rb +22 -26
- data/lib/maruku/ext/math/elements.rb +20 -26
- data/lib/maruku/ext/math/mathml_engines/blahtex.rb +92 -104
- data/lib/maruku/ext/math/mathml_engines/itex2mml.rb +33 -26
- data/lib/maruku/ext/math/mathml_engines/none.rb +11 -19
- data/lib/maruku/ext/math/mathml_engines/ritex.rb +2 -4
- data/lib/maruku/ext/math/parsing.rb +107 -113
- data/lib/maruku/ext/math/to_html.rb +184 -187
- data/lib/maruku/ext/math/to_latex.rb +30 -21
- data/lib/maruku/helpers.rb +158 -257
- data/lib/maruku/html.rb +254 -0
- data/lib/maruku/input/charsource.rb +272 -319
- data/lib/maruku/input/extensions.rb +62 -63
- data/lib/maruku/input/html_helper.rb +220 -189
- data/lib/maruku/input/linesource.rb +90 -110
- data/lib/maruku/input/mdline.rb +129 -0
- data/lib/maruku/input/parse_block.rb +618 -612
- data/lib/maruku/input/parse_doc.rb +145 -215
- data/lib/maruku/input/parse_span.rb +658 -0
- data/lib/maruku/input/rubypants.rb +200 -128
- data/lib/maruku/inspect_element.rb +60 -0
- data/lib/maruku/maruku.rb +10 -31
- data/lib/maruku/output/entity_table.rb +33 -0
- data/lib/maruku/output/s5/fancy.rb +462 -462
- data/lib/maruku/output/s5/to_s5.rb +115 -135
- data/lib/maruku/output/to_html.rb +898 -983
- data/lib/maruku/output/to_latex.rb +561 -560
- data/lib/maruku/output/to_markdown.rb +207 -162
- data/lib/maruku/output/to_s.rb +11 -52
- data/lib/maruku/string_utils.rb +129 -179
- data/lib/maruku/toc.rb +185 -196
- data/lib/maruku/version.rb +33 -38
- data/spec/block_docs/abbrev.md +776 -0
- data/{tests/unittest → spec/block_docs}/abbreviations.md +11 -20
- data/{tests/unittest → spec/block_docs}/alt.md +2 -14
- data/{tests/unittest/pending → spec/block_docs}/amps.md +1 -13
- data/{tests/unittest → spec/block_docs}/attributes/att2.md +0 -12
- data/{tests/unittest → spec/block_docs}/attributes/att3.md +2 -14
- data/{tests/unittest → spec/block_docs}/attributes/attributes.md +12 -16
- data/{tests/unittest → spec/block_docs}/attributes/circular.md +0 -12
- data/{tests/unittest → spec/block_docs}/attributes/default.md +1 -13
- data/{tests/unittest → spec/block_docs}/blank.md +0 -12
- data/{tests/unittest → spec/block_docs}/blanks_in_code.md +16 -15
- data/{tests/unittest/loss.md → spec/block_docs/bug_def.md} +6 -18
- data/{tests/unittest → spec/block_docs}/bug_table.md +3 -15
- data/{tests/unittest → spec/block_docs}/code.md +7 -14
- data/{tests/unittest → spec/block_docs}/code2.md +4 -14
- data/{tests/unittest → spec/block_docs}/code3.md +12 -16
- data/{tests/unittest → spec/block_docs}/data_loss.md +2 -14
- data/{tests/unittest → spec/block_docs}/divs/div1.md +0 -12
- data/{tests/unittest → spec/block_docs}/divs/div2.md +0 -12
- data/{tests/unittest → spec/block_docs}/divs/div3_nest.md +3 -15
- data/{tests/unittest → spec/block_docs}/easy.md +1 -13
- data/spec/block_docs/email.md +29 -0
- data/{tests/unittest/pending → spec/block_docs}/empty_cells.md +3 -15
- data/{tests/unittest → spec/block_docs}/encoding/iso-8859-1.md +1 -14
- data/{tests/unittest → spec/block_docs}/encoding/utf-8.md +0 -12
- data/{tests/unittest → spec/block_docs}/entities.md +27 -29
- data/{tests/unittest/notyet → spec/block_docs}/escape.md +2 -14
- data/{tests/unittest → spec/block_docs}/escaping.md +11 -22
- data/{tests/unittest → spec/block_docs}/extra_dl.md +2 -13
- data/{tests/unittest → spec/block_docs}/extra_header_id.md +14 -20
- data/{tests/unittest → spec/block_docs}/extra_table1.md +3 -15
- data/spec/block_docs/fenced_code_blocks.md +66 -0
- data/spec/block_docs/fenced_code_blocks_highlighted.md +18 -0
- data/{tests/unittest → spec/block_docs}/footnotes.md +12 -24
- data/spec/block_docs/footnotes2.md +78 -0
- data/spec/block_docs/hard.md +25 -0
- data/spec/block_docs/header_after_par.md +62 -0
- data/{tests/unittest → spec/block_docs}/headers.md +10 -18
- data/{tests/unittest → spec/block_docs}/hex_entities.md +7 -18
- data/{tests/unittest → spec/block_docs}/hrule.md +5 -12
- data/{tests/unittest → spec/block_docs}/html3.md +1 -13
- data/{tests/unittest → spec/block_docs}/html4.md +2 -14
- data/{tests/unittest → spec/block_docs}/html5.md +2 -14
- data/spec/block_docs/html_block_in_para.md +22 -0
- data/spec/block_docs/html_inline.md +25 -0
- data/spec/block_docs/html_trailing.md +31 -0
- data/spec/block_docs/ie.md +62 -0
- data/spec/block_docs/iframe.md +29 -0
- data/{tests/unittest → spec/block_docs}/images.md +22 -28
- data/{tests/unittest → spec/block_docs}/images2.md +7 -17
- data/{tests/unittest → spec/block_docs}/inline_html.md +37 -67
- data/{tests/unittest → spec/block_docs}/inline_html2.md +1 -13
- data/spec/block_docs/inline_html_beginning.md +10 -0
- data/spec/block_docs/issue20.md +9 -0
- data/spec/block_docs/issue26.md +22 -0
- data/spec/block_docs/issue29.md +9 -0
- data/spec/block_docs/issue30.md +30 -0
- data/spec/block_docs/issue31.md +25 -0
- data/spec/block_docs/issue40.md +40 -0
- data/spec/block_docs/issue64.md +55 -0
- data/spec/block_docs/issue67.md +19 -0
- data/spec/block_docs/issue70.md +11 -0
- data/spec/block_docs/issue72.md +17 -0
- data/spec/block_docs/issue74.md +38 -0
- data/spec/block_docs/issue79.md +15 -0
- data/spec/block_docs/issue83.md +13 -0
- data/spec/block_docs/issue85.md +25 -0
- data/spec/block_docs/issue88.md +19 -0
- data/spec/block_docs/issue89.md +12 -0
- data/spec/block_docs/issue90.md +38 -0
- data/{tests/unittest/pending → spec/block_docs}/link.md +21 -18
- data/{tests/unittest → spec/block_docs}/links.md +33 -32
- data/spec/block_docs/links2.md +21 -0
- data/{tests/unittest → spec/block_docs}/list1.md +0 -12
- data/{tests/unittest → spec/block_docs}/list12.md +2 -14
- data/{tests/unittest → spec/block_docs}/list2.md +2 -14
- data/spec/block_docs/list_multipara.md +42 -0
- data/{tests/unittest → spec/block_docs}/lists.md +28 -29
- data/{tests/unittest → spec/block_docs}/lists10.md +2 -14
- data/spec/block_docs/lists11.md +23 -0
- data/spec/block_docs/lists12.md +43 -0
- data/spec/block_docs/lists13.md +55 -0
- data/spec/block_docs/lists14.md +61 -0
- data/spec/block_docs/lists15.md +36 -0
- data/spec/block_docs/lists6.md +88 -0
- data/spec/block_docs/lists7b.md +58 -0
- data/spec/block_docs/lists9.md +53 -0
- data/{tests/unittest → spec/block_docs}/lists_after_paragraph.md +19 -25
- data/spec/block_docs/lists_blank.md +35 -0
- data/{tests/unittest/list3.md → spec/block_docs/lists_blockquote_code.md} +2 -14
- data/{tests/unittest/list4.md → spec/block_docs/lists_need_blank_line.md} +50 -21
- data/spec/block_docs/lists_nested.md +44 -0
- data/spec/block_docs/lists_nested_blankline.md +28 -0
- data/spec/block_docs/lists_nested_deep.md +43 -0
- data/{tests/unittest → spec/block_docs}/lists_ol.md +37 -54
- data/spec/block_docs/lists_paraindent.md +47 -0
- data/spec/block_docs/lists_tab.md +54 -0
- data/spec/block_docs/loss.md +17 -0
- data/spec/block_docs/math-blahtex/equations.md +30 -0
- data/spec/block_docs/math-blahtex/inline.md +48 -0
- data/spec/block_docs/math-blahtex/math2.md +45 -0
- data/spec/block_docs/math-blahtex/table.md +25 -0
- data/spec/block_docs/math/embedded_invalid_svg.md +79 -0
- data/spec/block_docs/math/embedded_svg.md +97 -0
- data/spec/block_docs/math/equations.md +44 -0
- data/{tests/unittest → spec/block_docs}/math/inline.md +7 -19
- data/spec/block_docs/math/math2.md +45 -0
- data/{tests/unittest → spec/block_docs}/math/notmath.md +0 -12
- data/spec/block_docs/math/raw_mathml.md +87 -0
- data/spec/block_docs/math/table.md +25 -0
- data/{tests/unittest → spec/block_docs}/math/table2.md +5 -17
- data/{tests/unittest → spec/block_docs}/misc_sw.md +181 -118
- data/{tests/unittest → spec/block_docs}/olist.md +6 -18
- data/{tests/unittest → spec/block_docs}/one.md +0 -12
- data/{tests/unittest → spec/block_docs}/paragraph.md +0 -12
- data/{tests/unittest → spec/block_docs}/paragraph_rules/dont_merge_ref.md +4 -12
- data/{tests/unittest → spec/block_docs}/paragraph_rules/tab_is_blank.md +0 -12
- data/{tests/unittest → spec/block_docs}/paragraphs.md +1 -13
- data/{tests/unittest → spec/block_docs}/recover/recover_links.md +4 -16
- data/{tests/unittest/pending/ref.md → spec/block_docs/ref_with_period.md} +7 -16
- data/spec/block_docs/ref_with_title.md +22 -0
- data/{tests/unittest → spec/block_docs}/references/long_example.md +16 -23
- data/{tests/unittest → spec/block_docs}/references/spaces_and_numbers.md +0 -12
- data/{tests/unittest → spec/block_docs}/smartypants.md +24 -31
- data/{tests/unittest → spec/block_docs}/syntax_hl.md +13 -17
- data/{tests/unittest → spec/block_docs}/table_attributes.md +2 -14
- data/spec/block_docs/tables.md +58 -0
- data/{tests/unittest → spec/block_docs}/test.md +1 -13
- data/{tests/unittest/notyet → spec/block_docs}/ticks.md +1 -13
- data/spec/block_docs/toc.md +87 -0
- data/{tests/unittest/notyet → spec/block_docs}/triggering.md +14 -25
- data/{tests/unittest → spec/block_docs}/underscore_in_words.md +0 -12
- data/{tests/unittest → spec/block_docs}/wrapping.md +4 -16
- data/spec/block_docs/xml.md +33 -0
- data/{tests/unittest → spec/block_docs}/xml2.md +0 -12
- data/spec/block_docs/xml3.md +24 -0
- data/{tests/unittest → spec/block_docs}/xml_instruction.md +9 -20
- data/spec/block_spec.rb +110 -0
- data/spec/cli_spec.rb +8 -0
- data/spec/span_spec.rb +256 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/to_html_utf8_spec.rb +13 -0
- metadata +205 -243
- metadata.gz.sig +3 -0
- data/Rakefile +0 -48
- data/bin/marudown +0 -29
- data/bin/marutest +0 -345
- data/docs/changelog.md +0 -334
- data/lib/maruku/errors_management.rb +0 -92
- data/lib/maruku/ext/math/latex_fix.rb +0 -12
- data/lib/maruku/input/parse_span_better.rb +0 -746
- data/lib/maruku/input/type_detection.rb +0 -147
- data/lib/maruku/output/to_latex_entities.rb +0 -367
- data/lib/maruku/output/to_latex_strings.rb +0 -64
- data/lib/maruku/structures.rb +0 -167
- data/lib/maruku/structures_inspect.rb +0 -87
- data/lib/maruku/structures_iterators.rb +0 -61
- data/lib/maruku/tests/benchmark.rb +0 -82
- data/lib/maruku/tests/new_parser.rb +0 -373
- data/lib/maruku/tests/tests.rb +0 -136
- data/lib/maruku/usage/example1.rb +0 -33
- data/tests/bugs/code_in_links.md +0 -101
- data/tests/bugs/complex_escaping.md +0 -38
- data/tests/math/syntax.md +0 -46
- data/tests/math_usage/document.md +0 -13
- data/tests/others/abbreviations.md +0 -11
- data/tests/others/blank.md +0 -4
- data/tests/others/code.md +0 -5
- data/tests/others/code2.md +0 -8
- data/tests/others/code3.md +0 -16
- data/tests/others/email.md +0 -4
- data/tests/others/entities.md +0 -19
- data/tests/others/escaping.md +0 -16
- data/tests/others/extra_dl.md +0 -101
- data/tests/others/extra_header_id.md +0 -13
- data/tests/others/extra_table1.md +0 -40
- data/tests/others/footnotes.md +0 -17
- data/tests/others/headers.md +0 -10
- data/tests/others/hrule.md +0 -10
- data/tests/others/images.md +0 -20
- data/tests/others/inline_html.md +0 -42
- data/tests/others/links.md +0 -38
- data/tests/others/list1.md +0 -4
- data/tests/others/list2.md +0 -5
- data/tests/others/list3.md +0 -8
- data/tests/others/lists.md +0 -32
- data/tests/others/lists_after_paragraph.md +0 -44
- data/tests/others/lists_ol.md +0 -39
- data/tests/others/misc_sw.md +0 -105
- data/tests/others/one.md +0 -1
- data/tests/others/paragraphs.md +0 -13
- data/tests/others/sss06.md +0 -352
- data/tests/others/test.md +0 -4
- data/tests/s5/s5profiling.md +0 -48
- data/tests/unittest/bug_def.md +0 -28
- data/tests/unittest/email.md +0 -32
- data/tests/unittest/html2.md +0 -34
- data/tests/unittest/ie.md +0 -61
- data/tests/unittest/links2.md +0 -34
- data/tests/unittest/lists11.md +0 -28
- data/tests/unittest/lists6.md +0 -53
- data/tests/unittest/lists9.md +0 -76
- data/tests/unittest/math/equations.md +0 -86
- data/tests/unittest/math/math2.md +0 -57
- data/tests/unittest/math/table.md +0 -37
- data/tests/unittest/notyet/header_after_par.md +0 -70
- data/tests/unittest/red_tests/abbrev.md +0 -1388
- data/tests/unittest/red_tests/lists7.md +0 -68
- data/tests/unittest/red_tests/lists7b.md +0 -128
- data/tests/unittest/red_tests/lists8.md +0 -76
- data/tests/unittest/red_tests/xml.md +0 -70
- data/tests/unittest/xml3.md +0 -38
- data/tests/utf8-files/simple.md +0 -1
- data/unit_test_block.sh +0 -5
- data/unit_test_span.sh +0 -3
@@ -1,121 +1,107 @@
|
|
1
|
-
|
2
|
-
# Copyright (C) 2006 Andrea Censi <andrea (at) rubyforge.org>
|
3
|
-
#
|
4
|
-
# This file is part of Maruku.
|
5
|
-
#
|
6
|
-
# Maruku is free software; you can redistribute it and/or modify
|
7
|
-
# it under the terms of the GNU General Public License as published by
|
8
|
-
# the Free Software Foundation; either version 2 of the License, or
|
9
|
-
# (at your option) any later version.
|
10
|
-
#
|
11
|
-
# Maruku is distributed in the hope that it will be useful,
|
12
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
-
# GNU General Public License for more details.
|
15
|
-
#
|
16
|
-
# You should have received a copy of the GNU General Public License
|
17
|
-
# along with Maruku; if not, write to the Free Software
|
18
|
-
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
19
|
-
#++
|
1
|
+
require 'set'
|
20
2
|
|
21
|
-
module MaRuKu
|
3
|
+
module MaRuKu::Out::Latex
|
4
|
+
module MDDocumentExtensions
|
5
|
+
# @return [Set<String>]
|
6
|
+
attr_accessor :latex_required_packages
|
7
|
+
|
8
|
+
def latex_require_package(p)
|
9
|
+
self.latex_required_packages << p
|
10
|
+
end
|
22
11
|
|
23
|
-
|
12
|
+
def initialize(*args)
|
13
|
+
self.latex_required_packages = Set.new
|
14
|
+
super
|
15
|
+
end
|
16
|
+
end
|
24
17
|
|
25
|
-
|
26
|
-
"\\usepackage[C40]{fontenc}
|
18
|
+
Latex_preamble_enc_cjk =
|
19
|
+
"\\usepackage[C40]{fontenc}
|
27
20
|
\\usepackage[cjkjis]{ucs}
|
28
21
|
\\usepackage[utf8x]{inputenc}"
|
29
22
|
|
30
|
-
|
31
|
-
"\\usepackage{ucs}
|
23
|
+
Latex_preamble_enc_utf8 =
|
24
|
+
"\\usepackage{ucs}
|
32
25
|
\\usepackage[utf8x]{inputenc}"
|
33
26
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
<?mrk
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
will
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
...
|
113
|
-
|
114
|
-
=end
|
115
|
-
user_preamble = (file = @doc.attributes[:latex_preamble]) ?
|
116
|
-
"\\input{#{file}}\n" : ""
|
117
|
-
|
118
|
-
"\\documentclass{article}
|
27
|
+
# Render as a LaTeX fragment
|
28
|
+
def to_latex
|
29
|
+
children_to_latex
|
30
|
+
end
|
31
|
+
|
32
|
+
#=begin maruku_doc
|
33
|
+
# Attribute: maruku_signature
|
34
|
+
# Scope: document
|
35
|
+
# Output: html, latex
|
36
|
+
# Summary: Enables Maruku's signature.
|
37
|
+
# Default: true
|
38
|
+
#
|
39
|
+
# If false, Maruku does not append a signature to the
|
40
|
+
# generated file.
|
41
|
+
#=end
|
42
|
+
|
43
|
+
# Render as a complete LaTeX document
|
44
|
+
def to_latex_document
|
45
|
+
body = to_latex
|
46
|
+
|
47
|
+
if get_setting(:maruku_signature)
|
48
|
+
body << render_latex_signature
|
49
|
+
end
|
50
|
+
|
51
|
+
required = self.latex_required_packages.map do |p|
|
52
|
+
"\\usepackage{#{p}}\n"
|
53
|
+
end.join
|
54
|
+
|
55
|
+
#=begin maruku_doc
|
56
|
+
# Attribute: latex_cjk
|
57
|
+
# Scope: document
|
58
|
+
# Output: latex
|
59
|
+
# Summary: Support for CJK characters.
|
60
|
+
#
|
61
|
+
# If the `latex_cjk` attribute is specified, then appropriate headers
|
62
|
+
# are added to the LaTeX preamble to support Japanese fonts.
|
63
|
+
# You have to have these fonts installed -- and this can be a pain.
|
64
|
+
#
|
65
|
+
# If `latex_cjk` is specified, this is added to the preamble:
|
66
|
+
#
|
67
|
+
# <?mrk puts "ciao" ?>
|
68
|
+
#
|
69
|
+
# <?mrk md_codeblock(Maruku::MDDocument::Latex_preamble_enc_cjk) ?>
|
70
|
+
#
|
71
|
+
#
|
72
|
+
# while the default is to add this:
|
73
|
+
#
|
74
|
+
# <?mrk md_codeblock(Maruku::MDDocument::Latex_preamble_enc_utf8) ?>
|
75
|
+
#
|
76
|
+
#=end
|
77
|
+
|
78
|
+
encoding = get_setting(:latex_cjk) ? Latex_preamble_enc_cjk : Latex_preamble_enc_utf8
|
79
|
+
|
80
|
+
#=begin maruku_doc
|
81
|
+
# Attribute: latex_preamble
|
82
|
+
# Scope: document
|
83
|
+
# Output: latex
|
84
|
+
# Summary: User-defined preamble.
|
85
|
+
#
|
86
|
+
# If the `latex_preamble` attribute is specified, then its value
|
87
|
+
# will be used as a custom preamble.
|
88
|
+
#
|
89
|
+
# For example:
|
90
|
+
#
|
91
|
+
# Title: My document
|
92
|
+
# Latex preamble: preamble.tex
|
93
|
+
#
|
94
|
+
# will produce:
|
95
|
+
#
|
96
|
+
# ...
|
97
|
+
# \input{preamble.tex}
|
98
|
+
# ...
|
99
|
+
#
|
100
|
+
#=end
|
101
|
+
|
102
|
+
user_preamble = (file = @doc.attributes[:latex_preamble]) ? "\\input{#{file}}\n" : ""
|
103
|
+
|
104
|
+
"\\documentclass{article}
|
119
105
|
|
120
106
|
% Packages required to support encoding
|
121
107
|
#{encoding}
|
@@ -131,460 +117,475 @@ will produce:
|
|
131
117
|
|
132
118
|
#{user_preamble}
|
133
119
|
|
134
|
-
\\begin{document}
|
120
|
+
\\begin{document}
|
135
121
|
#{body}
|
136
122
|
\\end{document}
|
137
|
-
"
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
"\\vfill
|
123
|
+
"
|
124
|
+
end
|
125
|
+
|
126
|
+
def render_latex_signature
|
127
|
+
"\\vfill
|
143
128
|
\\hrule
|
144
129
|
\\vspace{1.2mm}
|
145
130
|
\\begin{tiny}
|
146
|
-
Created by \\href{
|
131
|
+
Created by \\href{#{MaRuKu::MARUKU_URL}}{Maruku} #{self.nice_date}.
|
147
132
|
\\end{tiny}"
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
Title: Input format for colors
|
164
|
-
Output: latex, html
|
165
|
-
Related: code_background_color
|
166
|
-
|
167
|
-
Admissible formats:
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
=
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
"\\textbf{#{children_to_latex}}"
|
326
|
-
end
|
327
|
-
def to_latex_emphasis
|
328
|
-
"\\emph{#{children_to_latex}}"
|
329
|
-
end
|
330
|
-
|
331
|
-
def wrap_as_span(c)
|
332
|
-
"{#{c} #{children_to_latex}}"
|
333
|
-
end
|
334
|
-
|
335
|
-
def wrap_as_environment(name)
|
336
|
-
"\\begin{#{name}}%
|
133
|
+
end
|
134
|
+
|
135
|
+
def to_latex_hrule
|
136
|
+
"\n\\vspace{.5em} \\hrule \\vspace{.5em}\n"
|
137
|
+
end
|
138
|
+
|
139
|
+
def to_latex_linebreak
|
140
|
+
"\\newline "
|
141
|
+
end
|
142
|
+
|
143
|
+
def to_latex_paragraph
|
144
|
+
children_to_latex + "\n\n"
|
145
|
+
end
|
146
|
+
|
147
|
+
#=begin maruku_doc
|
148
|
+
# Title: Input format for colors
|
149
|
+
# Output: latex, html
|
150
|
+
# Related: code_background_color
|
151
|
+
#
|
152
|
+
# Admissible formats:
|
153
|
+
#
|
154
|
+
# green
|
155
|
+
# #abc
|
156
|
+
# #aabbcc
|
157
|
+
#=end
|
158
|
+
|
159
|
+
# \color{name}
|
160
|
+
# \color[rgb]{1,0.2,0.3}
|
161
|
+
def latex_color(s, command='color')
|
162
|
+
if s =~ /\A\#([1-9A-F]{1,2})([1-9A-F]{1,2})([1-9A-F]{1,2})\z/i
|
163
|
+
# convert from 0-255 or 0-15 to 0.0-1.0
|
164
|
+
r, g, b = [$1, $2, $3].map {|c| c.hex / (c.length == 1 ? 15.0 : 255.0) }
|
165
|
+
"\\#{command}[rgb]{%0.2f,%0.2f,%0.2f}" % [r, g, b]
|
166
|
+
else
|
167
|
+
"\\#{command}{#{s}}"
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
#=begin maruku_doc
|
172
|
+
# Attribute: code_show_spaces
|
173
|
+
# Scope: global, document, element
|
174
|
+
#
|
175
|
+
# If `true`, shows spaces and tabs in code blocks.
|
176
|
+
#
|
177
|
+
# Example:
|
178
|
+
#
|
179
|
+
# One space
|
180
|
+
# Two spaces
|
181
|
+
# Tab, space, tab
|
182
|
+
# Tab, tab, tab and all is green!
|
183
|
+
# {:code_show_spaces code_background_color=#ffeedd}
|
184
|
+
# {:markdown}
|
185
|
+
#
|
186
|
+
# That will produce:
|
187
|
+
#
|
188
|
+
# One space
|
189
|
+
# Two spaces
|
190
|
+
# Tab, space, tab
|
191
|
+
# Tab, tab, tab and all is green!
|
192
|
+
# {:code_show_spaces code_background_color=#ffeedd}
|
193
|
+
#
|
194
|
+
#=end
|
195
|
+
|
196
|
+
#=begin maruku_doc
|
197
|
+
# Attribute: latex_use_listings
|
198
|
+
# Scope: document
|
199
|
+
# Output: latex
|
200
|
+
# Summary: Support for `listings` package.
|
201
|
+
# Related: code_show_spaces, code_background_color, lang, code_lang
|
202
|
+
#
|
203
|
+
# If the `latex_use_listings` attribute is specified, then
|
204
|
+
# code block are rendered using the `listings` package.
|
205
|
+
# Otherwise, a standard `verbatim` environment is used.
|
206
|
+
#
|
207
|
+
# * If the `lang` attribute for the code block has been specified,
|
208
|
+
# it gets passed to the `listings` package using the `lstset` macro.
|
209
|
+
# The default lang for code blocks is specified through
|
210
|
+
# the `code_lang` attribute.
|
211
|
+
#
|
212
|
+
# \lstset{language=ruby}
|
213
|
+
#
|
214
|
+
# Please refer to the documentation of the `listings` package for
|
215
|
+
# supported languages.
|
216
|
+
#
|
217
|
+
# If a language is not supported, the `listings` package will emit
|
218
|
+
# a warning during the compilation. Just press enter and nothing
|
219
|
+
# wrong will happen.
|
220
|
+
#
|
221
|
+
# * If the `code_show_spaces` is specified, than spaces and tabs will
|
222
|
+
# be shown using the macro:
|
223
|
+
#
|
224
|
+
# \lstset{showspaces=true,showtabs=true}
|
225
|
+
#
|
226
|
+
# * The background color is given by `code_background_color`.
|
227
|
+
#
|
228
|
+
#=end
|
229
|
+
|
230
|
+
def to_latex_code
|
231
|
+
if get_setting(:latex_use_listings)
|
232
|
+
@doc.latex_require_package('listings')
|
233
|
+
|
234
|
+
s = "\\lstset{columns=fixed,frame=shadowbox}"
|
235
|
+
|
236
|
+
if get_setting(:code_show_spaces)
|
237
|
+
s << "\\lstset{showspaces=true,showtabs=true}\n"
|
238
|
+
else
|
239
|
+
s << "\\lstset{showspaces=false,showtabs=false}\n"
|
240
|
+
end
|
241
|
+
|
242
|
+
color = latex_color get_setting(:code_background_color)
|
243
|
+
|
244
|
+
s << "\\lstset{backgroundcolor=#{color}}\n"
|
245
|
+
|
246
|
+
s << "\\lstset{basicstyle=\\ttfamily\\footnotesize}\n"
|
247
|
+
|
248
|
+
|
249
|
+
lang = self.attributes[:lang] || @doc.attributes[:code_lang] || '{}'
|
250
|
+
s << "\\lstset{language=#{lang}}\n" if lang
|
251
|
+
|
252
|
+
"#{s}\n\\begin{lstlisting}\n#{self.raw_code}\n\\end{lstlisting}"
|
253
|
+
else
|
254
|
+
"\\begin{verbatim}#{self.raw_code}\\end{verbatim}\n"
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
def to_latex_header
|
259
|
+
header_levels = %w(section subsection subsubsection)
|
260
|
+
h = header_levels[self.level - 1] || 'paragraph'
|
261
|
+
|
262
|
+
title = children_to_latex
|
263
|
+
if number = section_number
|
264
|
+
title = number + title
|
265
|
+
end
|
266
|
+
|
267
|
+
if id = self.attributes[:id]
|
268
|
+
# drop '#' at the beginning
|
269
|
+
id = id[1..-1] if id.start_with? '#'
|
270
|
+
%{\\hypertarget{%s}{}\\%s*{{%s}}\\label{%s}\n\n} % [ id, h, title, id ]
|
271
|
+
else
|
272
|
+
%{\\%s*{%s}\n\n} % [ h, title]
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
def to_latex_ul
|
277
|
+
if self.attributes[:toc]
|
278
|
+
@doc.toc.to_latex
|
279
|
+
else
|
280
|
+
wrap_as_environment('itemize')
|
281
|
+
end
|
282
|
+
end
|
283
|
+
|
284
|
+
def to_latex_quote
|
285
|
+
wrap_as_environment('quote')
|
286
|
+
end
|
287
|
+
|
288
|
+
def to_latex_ol
|
289
|
+
wrap_as_environment('enumerate')
|
290
|
+
end
|
291
|
+
|
292
|
+
def to_latex_li
|
293
|
+
"\\item #{children_to_latex}\n"
|
294
|
+
end
|
295
|
+
|
296
|
+
def to_latex_strong
|
297
|
+
"\\textbf{#{children_to_latex}}"
|
298
|
+
end
|
299
|
+
|
300
|
+
def to_latex_emphasis
|
301
|
+
"\\emph{#{children_to_latex}}"
|
302
|
+
end
|
303
|
+
|
304
|
+
def wrap_as_span(c)
|
305
|
+
"{#{c} #{children_to_latex}}"
|
306
|
+
end
|
307
|
+
|
308
|
+
def wrap_as_environment(name)
|
309
|
+
"\\begin{#{name}}%
|
337
310
|
#{children_to_latex}
|
338
|
-
\\end{#{name}}\n"
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
311
|
+
\\end{#{name}}\n"
|
312
|
+
end
|
313
|
+
|
314
|
+
SAFE_CHARS = Set.new(('a'..'z').to_a + ('A'..'Z').to_a)
|
315
|
+
|
316
|
+
# the ultimate escaping
|
317
|
+
# (is much better than using \verb)
|
318
|
+
def latex_escape(source)
|
319
|
+
source.chars.inject('') do |s, b|
|
320
|
+
s << if b == '\\'
|
321
|
+
'~'
|
322
|
+
elsif SAFE_CHARS.include? b
|
323
|
+
b
|
324
|
+
else
|
325
|
+
"\\char%d" % b[0].ord
|
326
|
+
end
|
327
|
+
end
|
328
|
+
end
|
329
|
+
|
330
|
+
def to_latex_entity
|
331
|
+
entity_name = self.entity_name
|
332
|
+
|
333
|
+
entity = MaRuKu::Out::EntityTable.instance.entity(entity_name)
|
334
|
+
unless entity
|
335
|
+
maruku_error "I don't know how to translate entity '#{entity_name}' to LaTeX."
|
336
|
+
return ""
|
337
|
+
end
|
338
|
+
|
339
|
+
replace = entity.latex_string
|
340
|
+
@doc.latex_require_package entity.latex_package if entity.latex_package
|
341
|
+
|
342
|
+
if replace
|
343
|
+
if replace.start_with?("\\") && !replace.end_with?('$', '}')
|
344
|
+
replace + "{}"
|
345
|
+
else
|
346
|
+
replace
|
347
|
+
end
|
348
|
+
else
|
349
|
+
tell_user "Cannot translate entity #{entity_name.inspect} to LaTeX."
|
350
|
+
entity_name
|
351
|
+
end
|
352
|
+
end
|
353
|
+
|
354
|
+
def to_latex_inline_code
|
355
|
+
# Convert to printable latex chars
|
356
|
+
s = latex_escape(self.raw_code)
|
357
|
+
|
358
|
+
color = get_setting(:code_background_color)
|
359
|
+
colorspec = latex_color(color, 'colorbox')
|
360
|
+
|
361
|
+
"{#{colorspec}{\\tt #{s}}}"
|
362
|
+
end
|
363
|
+
|
364
|
+
def to_latex_immediate_link
|
365
|
+
url = self.url
|
366
|
+
text = url.gsub(/^mailto:/,'') # don't show mailto
|
367
|
+
text = latex_escape(text)
|
368
|
+
if url.start_with? '#'
|
369
|
+
url = url[1..-1]
|
370
|
+
"\\hyperlink{#{url}}{#{text}}"
|
371
|
+
else
|
372
|
+
"\\href{#{url}}{#{text}}"
|
373
|
+
end
|
374
|
+
end
|
375
|
+
|
376
|
+
def to_latex_im_link
|
377
|
+
url = self.url
|
378
|
+
|
379
|
+
if url.start_with? '#'
|
380
|
+
url = url[1..-1]
|
381
|
+
"\\hyperlink{#{url}}{#{children_to_latex}}"
|
382
|
+
else
|
383
|
+
"\\href{#{url}}{#{children_to_latex}}"
|
384
|
+
end
|
385
|
+
end
|
386
|
+
|
387
|
+
def to_latex_link
|
388
|
+
id = self.ref_id || children_to_s
|
389
|
+
ref = @doc.refs[sanitize_ref_id(id)] || @doc.refs[sanitize_ref_id(children_to_s)]
|
390
|
+
if ref
|
391
|
+
url = ref[:url]
|
392
|
+
|
393
|
+
if url.start_with? '#'
|
394
|
+
url = url[1..-1]
|
395
|
+
"\\hyperlink{#{url}}{#{children_to_latex}}"
|
396
|
+
else
|
397
|
+
"\\href{#{url}}{#{children_to_latex}}"
|
398
|
+
end
|
399
|
+
else
|
400
|
+
$stderr.puts "Could not find id = '#{id}'"
|
401
|
+
children_to_latex
|
402
|
+
end
|
403
|
+
end
|
404
|
+
|
405
|
+
def to_latex_email_address
|
406
|
+
"\\href{mailto:#{self.email}}{#{latex_escape(self.email)}}"
|
407
|
+
end
|
408
|
+
|
409
|
+
def to_latex_table
|
410
|
+
num_columns = self.align.size
|
411
|
+
|
412
|
+
head, *rows = @children.each_slice(num_columns).to_a
|
413
|
+
|
414
|
+
h = { :center => 'c' , :left => 'l' , :right => 'r'}
|
415
|
+
align_string = self.align.map {|a| h[a] }.join('|')
|
416
|
+
|
417
|
+
s = "\\begin{tabular}{#{align_string}}\n"
|
418
|
+
|
419
|
+
s << array_to_latex(head, '&') + "\\\\" + "\n"
|
420
|
+
|
421
|
+
s << "\\hline \n"
|
422
|
+
|
423
|
+
rows.each do |row|
|
424
|
+
s << array_to_latex(row, '&') + "\\\\" + "\n"
|
425
|
+
end
|
426
|
+
|
427
|
+
s << "\\end{tabular}"
|
428
|
+
|
429
|
+
# puts table in its own paragraph
|
430
|
+
s << "\n\n"
|
431
|
+
end
|
432
|
+
|
433
|
+
|
434
|
+
def to_latex_head_cell
|
435
|
+
children_to_latex
|
436
|
+
end
|
437
|
+
|
438
|
+
def to_latex_cell
|
439
|
+
children_to_latex
|
440
|
+
end
|
441
|
+
|
442
|
+
def to_latex_footnote_reference
|
443
|
+
id = self.footnote_id
|
444
|
+
if f = @doc.footnotes[id]
|
445
|
+
"\\footnote{#{f.children_to_latex.strip}} "
|
446
|
+
else
|
447
|
+
$stderr.puts "Could not find footnote '#{id}'"
|
448
|
+
end
|
449
|
+
end
|
450
|
+
|
451
|
+
def to_latex_raw_html
|
452
|
+
# Raw HTML removed in latex version
|
453
|
+
""
|
454
|
+
end
|
455
|
+
|
456
|
+
## Definition lists ###
|
457
|
+
def to_latex_definition_list
|
458
|
+
s = "\\begin{description}\n"
|
459
|
+
s << children_to_latex
|
460
|
+
s << "\\end{description}\n"
|
461
|
+
end
|
462
|
+
|
463
|
+
def to_latex_definition
|
464
|
+
s = ""
|
465
|
+
|
466
|
+
self.terms.each do |t|
|
467
|
+
s << "\n\\item[#{t.children_to_latex}] "
|
468
|
+
end
|
469
|
+
|
470
|
+
self.definitions.each do |d|
|
471
|
+
s << "#{d.children_to_latex} \n"
|
472
|
+
end
|
473
|
+
|
474
|
+
s
|
475
|
+
end
|
476
|
+
|
477
|
+
def to_latex_abbr
|
478
|
+
children_to_latex
|
479
|
+
end
|
480
|
+
|
481
|
+
def to_latex_image
|
482
|
+
id = self.ref_id
|
483
|
+
ref = @doc.refs[sanitize_ref_id(id)] || @doc.refs[sanitize_ref_id(children_to_s)]
|
484
|
+
if ref
|
485
|
+
url = ref[:url]
|
486
|
+
$stderr.puts "Images not supported yet (#{url})"
|
487
|
+
""
|
488
|
+
else
|
489
|
+
maruku_error "Could not find ref #{id.inspect} for image.\n"+
|
490
|
+
"Available are: #{@docs.refs.keys.inspect}"
|
491
|
+
""
|
492
|
+
end
|
493
|
+
end
|
494
|
+
|
495
|
+
def to_latex_div
|
496
|
+
type = self.attributes[:class]
|
497
|
+
id = self.attributes[:id]
|
498
|
+
case type
|
499
|
+
when /^un_(\w*)/
|
500
|
+
@children.shift
|
501
|
+
s = "\\begin{u#{$1}}\n"
|
502
|
+
s << children_to_latex
|
503
|
+
s << "\\end{u#{$1}}\n"
|
504
|
+
when /^num_(\w*)/
|
505
|
+
@children.delete_at(0)
|
506
|
+
s = "\\begin{#{$1}}"
|
507
|
+
s << "\n\\label{#{id}}\\hypertarget{#{id}}{}\n"
|
508
|
+
s << children_to_latex
|
509
|
+
s << "\\end{#{$1}}\n"
|
510
|
+
when /^proof/
|
511
|
+
@children.delete_at(0)
|
512
|
+
s = "\\begin{proof}\n"
|
513
|
+
s << children_to_latex
|
514
|
+
s << "\\end{proof}\n"
|
515
|
+
else
|
516
|
+
children_to_latex
|
517
|
+
end
|
518
|
+
end
|
519
|
+
|
520
|
+
# Convert each child to html
|
521
|
+
def children_to_latex
|
522
|
+
array_to_latex(@children)
|
523
|
+
end
|
524
|
+
|
525
|
+
def array_to_latex(array, join_char='')
|
526
|
+
e = []
|
527
|
+
array.each do |c|
|
528
|
+
if c.kind_of?(String)
|
529
|
+
e << string_to_latex(c)
|
530
|
+
else method = c.kind_of?(Maruku::MDElement) ? "to_latex_#{c.node_type}" : "to_latex"
|
531
|
+
next unless c.respond_to?(method)
|
532
|
+
|
533
|
+
h = c.send(method)
|
534
|
+
|
535
|
+
unless h
|
536
|
+
raise "Nil latex for #{c.inspect} created with method #{method}"
|
537
|
+
end
|
538
|
+
|
539
|
+
if h.kind_of? Array
|
540
|
+
e.concat h
|
541
|
+
else
|
542
|
+
e << h
|
543
|
+
end
|
544
|
+
end
|
545
|
+
end
|
546
|
+
e.join(join_char)
|
547
|
+
end
|
548
|
+
|
549
|
+
# These are TeX's special characters
|
550
|
+
LATEX_ADD_SLASH = %w({ } $ & # _ %)
|
551
|
+
|
552
|
+
# These, we transform to {\tt \char<ascii code>}
|
553
|
+
LATEX_TO_CHARCODE = %w(^ ~ > <)
|
554
|
+
|
555
|
+
# escapes special characters
|
556
|
+
def string_to_latex(s)
|
557
|
+
s = escape_to_latex(s)
|
558
|
+
OtherGoodies.each do |k, v|
|
559
|
+
s.gsub!(k, v)
|
560
|
+
end
|
561
|
+
s
|
562
|
+
end
|
563
|
+
|
564
|
+
# other things that are good on the eyes
|
565
|
+
OtherGoodies = {
|
566
|
+
/(\s)LaTeX/ => '\1\\LaTeX\\xspace ', # XXX not if already \LaTeX
|
567
|
+
}
|
568
|
+
|
569
|
+
private
|
570
|
+
|
571
|
+
def escape_to_latex(s)
|
572
|
+
s.chars.inject("") do |result, b|
|
573
|
+
if LATEX_TO_CHARCODE.include? b
|
574
|
+
result << "{\\tt \\symbol{#{b[0].ord}}}"
|
575
|
+
elsif LATEX_ADD_SLASH.include? b
|
576
|
+
result << '\\' << b
|
577
|
+
elsif b == '\\'
|
578
|
+
# there is no backslash in cmr10 fonts
|
579
|
+
result << "$\\backslash$"
|
580
|
+
else
|
581
|
+
result << b
|
582
|
+
end
|
583
|
+
end
|
584
|
+
end
|
585
|
+
end
|
586
|
+
|
587
|
+
module MaRuKu
|
588
|
+
class MDDocument
|
589
|
+
include MaRuKu::Out::Latex::MDDocumentExtensions
|
590
|
+
end
|
591
|
+
end
|