asciidoctor-latex 1.5.0.dev

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.adoc +22 -0
  3. data/README.adoc +213 -0
  4. data/Rakefile +55 -0
  5. data/bin/asciidoctor-latex +22 -0
  6. data/data/asciidoc_tex_macros.tex +42 -0
  7. data/data/preamble_article.tex +45 -0
  8. data/data/preamble_book.tex +44 -0
  9. data/lib/asciidoctor-latex.rb +1 -0
  10. data/lib/asciidoctor/latex.rb +8 -0
  11. data/lib/asciidoctor/latex/chem.rb +24 -0
  12. data/lib/asciidoctor/latex/click_block.rb +121 -0
  13. data/lib/asciidoctor/latex/converter.rb +358 -0
  14. data/lib/asciidoctor/latex/core_ext/colored_string.rb +35 -0
  15. data/lib/asciidoctor/latex/dollar.rb +28 -0
  16. data/lib/asciidoctor/latex/ent_to_uni.rb +17 -0
  17. data/lib/asciidoctor/latex/environment_block.rb +190 -0
  18. data/lib/asciidoctor/latex/inject_html.rb +49 -0
  19. data/lib/asciidoctor/latex/inline_macros.rb +20 -0
  20. data/lib/asciidoctor/latex/macro_insert.rb +49 -0
  21. data/lib/asciidoctor/latex/node_processors.rb +695 -0
  22. data/lib/asciidoctor/latex/prepend_processor.rb +36 -0
  23. data/lib/asciidoctor/latex/preprocess.rb +37 -0
  24. data/lib/asciidoctor/latex/tex_block.rb +108 -0
  25. data/lib/asciidoctor/latex/tex_postprocessor.rb +44 -0
  26. data/lib/asciidoctor/latex/tex_preprocessor.rb +65 -0
  27. data/lib/asciidoctor/latex/version.rb +5 -0
  28. data/manual.adoc +285 -0
  29. data/rake/cacert.pem +3894 -0
  30. data/rake/jdk_helper.rb +105 -0
  31. data/rake/tar-licence +19 -0
  32. data/rake/tar.rb +38 -0
  33. data/rspec/README.adoc +45 -0
  34. data/rspec/a.rb +79 -0
  35. data/rspec/b.rb +111 -0
  36. data/rspec/c.rb +121 -0
  37. data/rspec/data/tex1 +65 -0
  38. data/rspec/data/tex2 +5 -0
  39. data/rspec/data/tex2.expect +5 -0
  40. data/rspec/transform.rb +36 -0
  41. data/spec/README.adoc +45 -0
  42. data/spec/a.rb +79 -0
  43. data/spec/b.rb +111 -0
  44. data/spec/c.rb +121 -0
  45. data/spec/data/foo +1 -0
  46. data/spec/data/lorem +1 -0
  47. data/spec/data/tex1 +65 -0
  48. data/spec/data/tex2 +5 -0
  49. data/spec/data/tex2.expect +5 -0
  50. data/spec/transform.rb +36 -0
  51. data/test/examples/adoc/env.adoc +16 -0
  52. data/test/examples/adoc/eq.adoc +12 -0
  53. data/test/examples/adoc/zero.adoc +3 -0
  54. data/test/examples/asciidoc-html/block_open.adoc +17 -0
  55. data/test/examples/tex/env.tex +132 -0
  56. data/test/examples/tex/eq.tex +132 -0
  57. data/test/examples/tex/zero.tex +121 -0
  58. data/test/html_test.rb +8 -0
  59. data/test/latex_test.rb +8 -0
  60. data/test/test_helper.rb +4 -0
  61. data/test_jc/admonition.adoc +4 -0
  62. data/test_jc/click.adoc +7 -0
  63. data/test_jc/env.adoc +31 -0
  64. data/test_jc/example.adoc +17 -0
  65. data/test_jc/floating_title.adoc +15 -0
  66. data/test_jc/image.adoc +84 -0
  67. data/test_jc/images/frog.jpg +0 -0
  68. data/test_jc/images/red_frog.jpeg +0 -0
  69. data/test_jc/images/yellow_frog.jpeg +0 -0
  70. data/test_jc/listing.adoc +9 -0
  71. data/test_jc/lists.adoc +20 -0
  72. data/test_jc/math.adoc +10 -0
  73. data/test_jc/preamble.adoc +14 -0
  74. data/test_jc/section-numbered.adoc +9 -0
  75. data/test_jc/section.adoc +7 -0
  76. data/test_jc/sidebar.adoc +61 -0
  77. data/test_jc/verse.adoc +15 -0
  78. data/try-out/README.adoc +348 -0
  79. data/try-out/click.adoc +108 -0
  80. data/try-out/code.adoc +122 -0
  81. data/try-out/env.adoc +139 -0
  82. data/try-out/eq-latex.adoc +37 -0
  83. data/try-out/eq-stem.adoc +41 -0
  84. data/try-out/eqno-latex.adoc +120 -0
  85. data/try-out/math_article.adoc +138 -0
  86. data/try-out/pyth-stem.adoc +52 -0
  87. data/try-out/theorem-latex.adoc +50 -0
  88. data/try-out/xref-equations.adoc +28 -0
  89. metadata +210 -0
@@ -0,0 +1,36 @@
1
+ require 'asciidoctor'
2
+ require 'asciidoctor/extensions'
3
+
4
+ module Asciidoctor::LaTeX
5
+
6
+ # THIS CLASS IS NO LONGER USED
7
+ # Prepend lines to a document
8
+
9
+ class ClickStyleInsert < Asciidoctor::Extensions::Preprocessor
10
+
11
+ def putline line
12
+ @@line_array += [line, ""]
13
+ end
14
+
15
+ def process document, reader
16
+
17
+ warn "Entering ClickStyleInsert".magenta
18
+
19
+ @@line_array = []
20
+
21
+ return reader if reader.eof?
22
+
23
+ putline '++++'
24
+ putline '<style>'
25
+ putline '.click .title { color: blue; }'
26
+ putline '</style>'
27
+ putline '++++'
28
+
29
+ reader.unshift_lines @@line_array
30
+ reader
31
+ end
32
+
33
+ end
34
+
35
+
36
+ end
@@ -0,0 +1,37 @@
1
+ # DEFUNCT CODE?
2
+ #
3
+ # I think this is defunct code -- will investigate
4
+ #
5
+
6
+ # For trying things out
7
+ # Call the input file foo.in
8
+ # Then execute
9
+ #
10
+ # $ ruby preprocess foo
11
+ #
12
+ # Currently output is directed to the
13
+ # console. Uncomment the last line
14
+ # to direct output to foo.out
15
+
16
+ require 'asciidoctor/latex/tex_block'
17
+
18
+
19
+ base_name = ARGV[0]
20
+ input_file = base_name + ".in"
21
+ output_file = base_name + "out"
22
+
23
+ input = File.open(input_file, 'r') { |f| f.read }
24
+
25
+ puts "input:"
26
+ puts "-----------------"
27
+ puts input
28
+ puts "-----------------\n\n"
29
+
30
+ output = Asciidoctor::LaTeX::TeXBlock.process_environments input
31
+
32
+ puts "output:"
33
+ puts "-----------------"
34
+ puts output
35
+ puts "-----------------\n\n"
36
+
37
+ # File.open(output_file, 'w') {|f| f.write(output) }
@@ -0,0 +1,108 @@
1
+ # This is for the latex backend
2
+ # I have to review what the f the function
3
+ # of this code is -- still used??
4
+ #
5
+ # I believe the point here is that
6
+ # usage of [env.equation] etc
7
+ # obviates the need for this code.
8
+ #
9
+ # To be continued @jxxcarlson
10
+
11
+
12
+ #
13
+ # The purpose of the module TeXBlock is to
14
+ # transform structures of the form
15
+ # \[ ... \], either by passing them on unchanged
16
+ # or by stripping away the escaped braces.
17
+ #
18
+ # When ... is an environment such as
19
+ #
20
+ # \begin{equation} ### \end{equation}
21
+ #
22
+ # the escaped braces must be stripped.
23
+ # All other cases, as far as I know now (not far:-),
24
+ # the braces remain.
25
+ #
26
+ # For the moment the solution is to strip when
27
+ # the contents ... contain no string of the form
28
+ # \begin{XXX} except for the cases in which XXX is
29
+ #
30
+ # - array
31
+ # - matrix
32
+ #
33
+ # I believe that the list of these keywords is small,
34
+ # whereas the number of other environments is large
35
+ # and essentially unbounded, since users can define
36
+ # their own environments.
37
+ #
38
+ module Asciidoctor::LaTeX
39
+ module TeXBlock
40
+
41
+ # Find blocks delmited by \[ ... \]
42
+ def self.get_tex_blocks str
43
+ rx_tex_block = /(\\\[)(.*?)(\\\])/m
44
+ str.scan rx_tex_block
45
+ end
46
+
47
+
48
+ # Return the environment type of a tex block.
49
+ # Thus, if str = \[\begin{foo} ho ho ho \end{foo}\],
50
+ # the string "foo" is returned.
51
+ def self.environment_type str
52
+ rx_env_block = /\\begin\{(.*?)\}/
53
+ m = str.match rx_env_block
54
+ if m
55
+ env_type = m[1]
56
+ else
57
+ env_type = 'none'
58
+ end
59
+ env_type
60
+ end
61
+
62
+ # Return the environment type from an
63
+ # element of the array produced by
64
+ # get_tex_blocks -- each element is a
65
+ # three-element array with the tex block
66
+ # as the middle element.
67
+ def self.environmemt_type_of_match m
68
+ environment_type m[1]
69
+ end
70
+
71
+ # Return the block as-is -- do not
72
+ # strip delimiters.
73
+ def self.restore_match_data m
74
+ m.join()
75
+ end
76
+
77
+ # Return the block sans delimiters
78
+ def self.strip_match_data m
79
+ m[1]
80
+ end
81
+
82
+ # Transform the input string for a given block m
83
+ def self.process_tex_block m, str
84
+ block_type = environmemt_type_of_match m
85
+ if INNER_TYPES.include? block_type
86
+ output = str
87
+ else
88
+ output = str.gsub restore_match_data(m), strip_match_data(m)
89
+ end
90
+ output
91
+ end
92
+
93
+ # Transform the input string by stripping or
94
+ # passing each tex block as required
95
+ def self.process_environments str
96
+ tbs = get_tex_blocks str
97
+ tbs.each do |tb|
98
+ str = process_tex_block tb, str
99
+ end
100
+ str
101
+ end
102
+
103
+ # The list of "inner environments" whose enclosing
104
+ # escaped braces are not to be stripped.
105
+ INNER_TYPES = ["array", "matrix", "none"]
106
+
107
+ end
108
+ end
@@ -0,0 +1,44 @@
1
+ require 'asciidoctor'
2
+ require 'asciidoctor/extensions'
3
+
4
+ # a postprocessor to map the nonsense
5
+ # string 'DOLLOD' back to '$'
6
+ #
7
+ # This is used in for the LaTeX backend
8
+ # in conjunction with the code
9
+ # in 'tex_preprocessor' which maps '\$' to
10
+ # 'DOLLOD'
11
+ #
12
+ # There should be a better solution to the
13
+ # vexing proble of dealing with both $ ... $
14
+ # for mathematics and '\$' for currency. But
15
+ # this works and wil have to do for now.
16
+ #
17
+ # @jirutka: Advice?
18
+ #
19
+ module Asciidoctor::LaTeX
20
+ # Map @@DOLLAR: to \$
21
+ class TexPostprocessor < Asciidoctor::Extensions::Postprocessor
22
+
23
+ def process document, output
24
+ output = output.gsub('DOLLOD', '\$')
25
+ output = output.gsub('CHEMRIGHTARROW','->').gsub('CHEMLEFTARROW','<-').gsub('CHEMLEFTRIGHTARROW','<-->')
26
+ output.gsub('!!!BACKSLASH', '\\')
27
+ end
28
+
29
+ end
30
+
31
+ class HTMLPostprocessor < Asciidoctor::Extensions::Postprocessor
32
+
33
+ def process document, output
34
+ output = output.gsub('\DOLLOD', '\$')
35
+ # match_data = output.match /%%(.*)%%/
36
+ # if match_data
37
+ # output = output.gsub(match_data[0], match_data[1])
38
+ # end
39
+ output = output.gsub('DOLLOD', '$')
40
+ output.gsub('!!!BACKSLASH', '\\')
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,65 @@
1
+ require 'asciidoctor'
2
+ require 'asciidoctor/extensions'
3
+
4
+ # Map $ ... $ to \(..\) before
5
+ # running Asciidoctor, and map
6
+ # '\$' to 'DOLLOD'. The latter
7
+ # will be mapped back to '$'
8
+ # for the HTML backend by the
9
+ # postprocessor in 'dollar.rb' and
10
+ # to '\$' by the postprocessor
11
+ # in 'escape_dollar.rb'
12
+ #
13
+ # The remaining substitutions will
14
+ # be eliminated when I edit the
15
+ # relevant source files on noteshare.
16
+
17
+ module Asciidoctor::LaTeX
18
+ class TeXPreprocessor < Asciidoctor::Extensions::Preprocessor
19
+
20
+ # Map $...$ to stem:[...]
21
+ # TEX_DOLLAR_RX = /(^|\s|\()\$(.*?)\$($|\s|\)|,|\.)/
22
+ # TEX_DOLLAR_SUB = '\1latexmath:[\2]\3'
23
+ # TEX_DOLLAR_SUB = '\1\\\(\2\\\)\3'
24
+
25
+ TEX_DOLLAR_RX = /\$(.*?)\$/
26
+ TEX_DOLLAR_SUB = '\\\(\1\\\)'
27
+ TEX_DOLLAR_SUB2 = '+\\\(\1\\\)+'
28
+
29
+
30
+ def process document, reader
31
+ return reader if reader.eof?
32
+ replacement_lines = reader.read_lines.map do |line|
33
+ # (line.include? '$') ? (line.gsub TEX_DOLLAR_RX, TEX_DOLLAR_SUB) : line
34
+ if line.include? '<-->' and document.basebackend? 'tex'
35
+ line = line.gsub('<-->', 'CHEMLEFTRIGHTARROW')
36
+ end
37
+ if line.include? '->' and document.basebackend? 'tex'
38
+ line = line.gsub('->', 'CHEMRIGHTARROW')
39
+ end
40
+ if line.include? '<-' and document.basebackend? 'tex'
41
+ line = line.gsub('<-', 'CHEMLEFTARROW')
42
+ end
43
+ if line.include? '\$' and document.basebackend? 'html'
44
+ line = line.gsub '\$', 'DOLLOD'
45
+ end
46
+ if line.include? '%' and document.basebackend? 'tex'
47
+ line = line.gsub '%', '\%'
48
+ end
49
+ if line.include? '$'
50
+ line = line.gsub TEX_DOLLAR_RX, TEX_DOLLAR_SUB2
51
+ end
52
+ if line.include? '\\['
53
+ line = line.gsub '\\[', '+\\['
54
+ end
55
+ if line.include? '\\]'
56
+ line = line.gsub '\\]', '\\]+'
57
+ end
58
+ line
59
+ end
60
+ reader.unshift_lines replacement_lines
61
+ reader
62
+ end
63
+
64
+ end
65
+ end
@@ -0,0 +1,5 @@
1
+ module Asciidoctor
2
+ module LaTeX
3
+ VERSION = '1.5.0.dev'
4
+ end
5
+ end
data/manual.adoc ADDED
@@ -0,0 +1,285 @@
1
+ = LaTeX Converter Manual
2
+ James Carlson
3
+ :toc2:
4
+ :numbered:
5
+ :stem: latexmath
6
+
7
+ == Introduction
8
+
9
+ TexConverter translates a file written
10
+ in a subset of Asciidoc to LaTeX. The
11
+ subset is described below. While not
12
+ complete, it is adequate for the preparation
13
+ of a wide range of mathematical documents,
14
+ from one-page handouts to articles to entire books.
15
+
16
+ As a demonstration of the current state of this
17
+ project, the file you are looking at, `manual.adoc`,
18
+ can be rendered into HTML by
19
+ ----
20
+ $ asciidoctor manual.adoc
21
+ ----
22
+ or can be rendered as a LaTeX file via
23
+ ----
24
+ $ asciidoctor-latex manual.adoc
25
+ # => manual.tex
26
+ ----
27
+ The `.tex` file can in turn be rendred into pdf via
28
+ `pdflatex`.
29
+
30
+
31
+ Mathematical text in Asciidoc can be written as
32
+ one usually does in LaTeX if one invokes the
33
+ latex option.footnote:[This option exists but has not yet been released. To use
34
+ the option at http://noteshare.io[noteshare.io], include the code `:latex:` in
35
+ your document]. You do this via `asciidoctor -latex foo.adoc`.
36
+ Thus for the Pythagorean
37
+ theorem $a^2 + b^2 = c^2$, one writes
38
+
39
+ ----
40
+ $ a^2 + b^2 = c^2 $
41
+ ----
42
+
43
+ For the famous formula of Euler,
44
+ \[
45
+ e^{2\pi \sqrt{-1}} = 1
46
+ \]
47
+ one writes
48
+
49
+ ----
50
+ \[
51
+ e^{2\pi \sqrt{-1}} = 1
52
+ \]
53
+ ----
54
+
55
+
56
+ == The Asciidoc-LaTeX subset
57
+
58
+
59
+
60
+ === Sections, levels 1 through 5
61
+
62
+
63
+ === Ordered and unordered lists
64
+
65
+ In Asciidoc, an unordered list like
66
+
67
+ * Pay Bills
68
+ * Get Groceries
69
+ ** Milk
70
+ ** Bread
71
+ ** Orange Juice
72
+ * Change Oil Filter on Car
73
+
74
+ is written like this
75
+
76
+ ----
77
+ * Pay Bills
78
+ * Get Groceries
79
+ ** Milk
80
+ ** Bread
81
+ ** Orange Juice
82
+ * Change Oil Filter on Car
83
+ ----
84
+
85
+ Its translation into LaTeX is
86
+
87
+ ----
88
+ \begin{itemize}
89
+ \item Pay Bills
90
+ \item Get Groceries
91
+ \begin{itemize}
92
+ \item Milk
93
+ \item Bread
94
+ \item Orange Juice
95
+ \end{itemize}
96
+ \item Change Oil Filter on Car
97
+ \end{itemize}
98
+ ----
99
+
100
+ The corresponding ordered list,
101
+
102
+ . Pay Bills
103
+ . Get Groceries
104
+ .. Milk
105
+ .. Bread
106
+ .. Orange Juice
107
+ . Change Oil Filter on Car
108
+
109
+ is written as
110
+
111
+ ----
112
+ . Pay Bills
113
+ . Get Groceries
114
+ .. Milk
115
+ .. Bread
116
+ .. Orange Juice
117
+ . Change Oil Filter on Car
118
+ ----
119
+
120
+ with the following source in LaTex:
121
+
122
+ ----
123
+ \begin{enumerate}
124
+ \item Pay Bills
125
+ \item Get Groceries
126
+ \begin{enumerate}
127
+ \item Milk
128
+ \item Bread
129
+ \item Orange Juice
130
+ \end{enumerate}
131
+ \item Change Oil Filter on Car
132
+ \end{enumerate}
133
+ ----
134
+
135
+ === Bold, italic, and monospaced text
136
+
137
+ The text "She said _potatoes_ but he said *potaatoes*", written
138
+ in Asciidoc as
139
+
140
+ ----
141
+ She said _potatoes_ but he said *potaatoes*
142
+ ----
143
+ is mapped to
144
+
145
+ ----
146
+ She said \emph{potatoes} but he said \textbf{potaatoes}
147
+ ----
148
+
149
+ The text
150
+
151
+ ----
152
+ `monospaced`
153
+ ----
154
+
155
+ is mapped to
156
+
157
+ ----
158
+ {\tt monospaced}
159
+ ----
160
+
161
+
162
+ === Quotations
163
+
164
+ The text
165
+
166
+ ----
167
+ [quote, Abraham Lincoln, Soldiers' National Cemetery Dedication]
168
+ ____
169
+ Four score and seven years ago our fathers brought forth
170
+ on this continent a new nation
171
+ ____
172
+ ----
173
+ is mapped to
174
+
175
+ ----
176
+ \begin{quote}
177
+ Four score and seven years ago our fathers brought forth
178
+ on this continent a new nation
179
+ \end{quote}
180
+ ----
181
+
182
+ === Footnotes
183
+
184
+ Text like this
185
+ ----
186
+ Ho hum.footnote:[An epression of boredem]
187
+ ----
188
+ is mapped to
189
+
190
+ ----
191
+ Ho hum\footnote{An epression of boredem}
192
+ ----
193
+
194
+ === References and labels
195
+
196
+ The label
197
+
198
+ ----
199
+ Ho hum[[foo]]
200
+ ----
201
+
202
+ is mapped to
203
+
204
+ ----
205
+ Ho hum\label{foo}
206
+ ----
207
+
208
+ The cross-reference
209
+
210
+ ----
211
+ Please see <<foo>>
212
+ ----
213
+
214
+ is mapped to
215
+
216
+ ----
217
+ Please see \ref{foo}
218
+ ----
219
+
220
+
221
+
222
+ === Hyperlinks
223
+
224
+ The hyperlink
225
+
226
+ ----
227
+ http://nytimes.com[All the news that is fit to print]
228
+ ----
229
+
230
+ is mapped to
231
+
232
+ ----
233
+ \href{http://nytimes.com}{All the news that is fit to print}
234
+ ----
235
+
236
+ === Line breaks `+`
237
+
238
+ === Listing
239
+
240
+ === Open blocks
241
+
242
+ === Literal
243
+
244
+ === Page break
245
+
246
+ === Pass
247
+
248
+ ////
249
+ INLINE_TYPES = %w( inline_quoted)
250
+ BLOCK_TYPES = %w(admonition listing literal page_break paragraph stem pass open quote)
251
+ ////
252
+
253
+
254
+ == Mathematical text
255
+
256
+ We distinguish between _inner text_ amd _outer text_. the first
257
+ appears between math delimiters, while the second does not.
258
+
259
+ === Inner text
260
+
261
+ As noted in the introduction, mathematical text is enclosed in the
262
+ standard delimiters and is written in the normal way. Environments
263
+ supported in display math mode are
264
+
265
+ * matrix
266
+ * equation, including the label macro
267
+
268
+
269
+ === Outer text
270
+
271
+ To write a theorem, do this:
272
+
273
+ ----
274
+ .Theorem {counter:theorem}
275
+ --
276
+ For all $a$, $b$, $c$, the relation $a(b+c) = ab + ac$ holds.
277
+ --
278
+ ----
279
+
280
+ This will render in Asciidoc as
281
+
282
+ .Theorem {counter:theorem}
283
+ --
284
+ _For all $a$, $b$, $c$, the relation $a(b+c) = ab + ac$ holds._
285
+ --