mizuho 0.9.10 → 0.9.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. data/README.markdown +18 -2
  2. data/asciidoc/BUGS +3 -6
  3. data/asciidoc/BUGS.txt +0 -3
  4. data/asciidoc/CHANGELOG +660 -397
  5. data/asciidoc/CHANGELOG.txt +237 -2
  6. data/asciidoc/INSTALL +14 -14
  7. data/asciidoc/MANIFEST +2 -0
  8. data/asciidoc/Makefile.in +9 -1
  9. data/asciidoc/README +2 -2
  10. data/asciidoc/a2x.py +101 -43
  11. data/asciidoc/asciidoc.conf +18 -11
  12. data/asciidoc/asciidoc.py +615 -260
  13. data/asciidoc/common.aap +2 -2
  14. data/asciidoc/configure +9 -9
  15. data/asciidoc/configure.ac +1 -1
  16. data/asciidoc/doc/a2x.1 +34 -4
  17. data/asciidoc/doc/a2x.1.txt +12 -0
  18. data/asciidoc/doc/article.pdf +0 -0
  19. data/asciidoc/doc/asciidoc.1 +73 -29
  20. data/asciidoc/doc/asciidoc.1.txt +56 -30
  21. data/asciidoc/doc/asciidoc.dict +23 -2
  22. data/asciidoc/doc/asciidoc.txt +468 -327
  23. data/asciidoc/doc/book.epub +0 -0
  24. data/asciidoc/doc/faq.txt +201 -25
  25. data/asciidoc/doc/latex-filter.pdf +0 -0
  26. data/asciidoc/doc/music-filter.pdf +0 -0
  27. data/asciidoc/doc/publishing-ebooks-with-asciidoc.txt +1 -1
  28. data/asciidoc/doc/source-highlight-filter.pdf +0 -0
  29. data/asciidoc/doc/source-highlight-filter.txt +48 -37
  30. data/asciidoc/docbook45.conf +4 -4
  31. data/asciidoc/examples/website/ASCIIMathML.js +938 -0
  32. data/asciidoc/examples/website/CHANGELOG.txt +3056 -0
  33. data/asciidoc/examples/website/INSTALL.txt +227 -0
  34. data/asciidoc/examples/website/LaTeXMathML.js +1223 -0
  35. data/asciidoc/examples/website/README-website.txt +29 -0
  36. data/asciidoc/examples/website/README.txt +35 -0
  37. data/asciidoc/examples/website/a2x.1.txt +358 -0
  38. data/asciidoc/examples/website/asciidoc-docbook-xsl.txt +65 -0
  39. data/asciidoc/examples/website/asciidoc-graphviz-sample.txt +170 -0
  40. data/asciidoc/examples/website/asciidoc.css +533 -0
  41. data/asciidoc/examples/website/asciidoc.js +189 -0
  42. data/asciidoc/examples/website/asciidocapi.txt +189 -0
  43. data/asciidoc/examples/website/asciimathml.txt +61 -0
  44. data/asciidoc/examples/website/build-website.sh +25 -0
  45. data/asciidoc/examples/website/customers.csv +18 -0
  46. data/asciidoc/examples/website/epub-notes.txt +210 -0
  47. data/asciidoc/examples/website/faq.txt +1298 -0
  48. data/asciidoc/examples/website/index.txt +502 -0
  49. data/asciidoc/examples/website/latex-backend.txt +192 -0
  50. data/asciidoc/examples/website/latex-bugs.txt +134 -0
  51. data/asciidoc/examples/website/latex-filter.txt +196 -0
  52. data/asciidoc/examples/website/latexmathml.txt +41 -0
  53. data/asciidoc/examples/website/layout1.conf +153 -0
  54. data/asciidoc/examples/website/layout1.css +65 -0
  55. data/asciidoc/examples/website/layout2.conf +153 -0
  56. data/asciidoc/examples/website/layout2.css +83 -0
  57. data/asciidoc/examples/website/main.aap +159 -0
  58. data/asciidoc/examples/website/manpage.txt +197 -0
  59. data/asciidoc/examples/website/music-filter.txt +148 -0
  60. data/asciidoc/examples/website/newlists.txt +40 -0
  61. data/asciidoc/examples/website/newtables.txt +743 -0
  62. data/asciidoc/examples/website/plugins.txt +91 -0
  63. data/asciidoc/examples/website/publishing-ebooks-with-asciidoc.txt +398 -0
  64. data/asciidoc/examples/website/slidy-example.txt +167 -0
  65. data/asciidoc/examples/website/slidy.txt +113 -0
  66. data/asciidoc/examples/website/source-highlight-filter.txt +239 -0
  67. data/asciidoc/examples/website/support.txt +5 -0
  68. data/asciidoc/examples/website/testasciidoc.txt +231 -0
  69. data/asciidoc/examples/website/userguide.txt +5991 -0
  70. data/asciidoc/examples/website/version83.txt +37 -0
  71. data/asciidoc/examples/website/xhtml11-quirks.css +43 -0
  72. data/asciidoc/filters/latex/latex2png.py +28 -12
  73. data/asciidoc/filters/music/music2png.py +22 -6
  74. data/asciidoc/filters/source/source-highlight-filter.conf +7 -5
  75. data/asciidoc/help.conf +147 -131
  76. data/asciidoc/html4.conf +1 -0
  77. data/asciidoc/html5.conf +37 -39
  78. data/asciidoc/javascripts/asciidoc.js +3 -3
  79. data/asciidoc/lang-de.conf +4 -0
  80. data/asciidoc/lang-es.conf +2 -0
  81. data/asciidoc/lang-fr.conf +1 -1
  82. data/asciidoc/lang-hu.conf +2 -0
  83. data/asciidoc/lang-it.conf +2 -0
  84. data/asciidoc/lang-nl.conf +5 -0
  85. data/asciidoc/lang-pt-BR.conf +2 -0
  86. data/asciidoc/lang-ru.conf +2 -3
  87. data/asciidoc/latex.conf +2 -2
  88. data/asciidoc/slidy.conf +4 -2
  89. data/asciidoc/stylesheets/asciidoc.css +29 -4
  90. data/asciidoc/stylesheets/docbook-xsl.css +12 -5
  91. data/asciidoc/stylesheets/toc2.css +1 -0
  92. data/asciidoc/stylesheets/xhtml11-quirks.css +1 -1
  93. data/asciidoc/tests/data/lang-de-man-test.txt +21 -0
  94. data/asciidoc/tests/data/lang-en-man-test.txt +21 -0
  95. data/asciidoc/tests/data/lang-es-man-test.txt +21 -0
  96. data/asciidoc/tests/data/lang-fr-man-test.txt +21 -0
  97. data/asciidoc/tests/data/lang-hu-man-test.txt +21 -0
  98. data/asciidoc/tests/data/lang-it-man-test.txt +21 -0
  99. data/asciidoc/tests/data/lang-it-test.txt +106 -0
  100. data/asciidoc/tests/data/lang-nl-man-test.txt +21 -0
  101. data/asciidoc/tests/data/lang-pt-BR-man-test.txt +21 -0
  102. data/asciidoc/tests/data/lang-ru-man-test.txt +21 -0
  103. data/asciidoc/tests/data/lang-uk-man-test.txt +21 -0
  104. data/asciidoc/tests/data/testcases.conf +10 -0
  105. data/asciidoc/tests/data/testcases.txt +40 -0
  106. data/asciidoc/tests/testasciidoc.conf +143 -17
  107. data/asciidoc/tests/testasciidoc.py +11 -2
  108. data/asciidoc/{stylesheets → themes/flask}/flask.css +0 -0
  109. data/asciidoc/{stylesheets → themes/volnitsky}/volnitsky.css +1 -1
  110. data/asciidoc/vim/ftdetect/asciidoc_filetype.vim +1 -1
  111. data/asciidoc/vim/syntax/asciidoc.vim +1 -1
  112. data/asciidoc/xhtml11-quirks.conf +2 -2
  113. data/asciidoc/xhtml11.conf +35 -37
  114. data/lib/mizuho.rb +1 -1
  115. data/lib/mizuho/generator.rb +3 -1
  116. data/source-highlight/darwin/source-highlight +0 -0
  117. data/templates/juvia.js +30 -5
  118. metadata +58 -9
  119. data/asciidoc/stylesheets/asciidoc-manpage.css +0 -18
  120. data/asciidoc/stylesheets/flask-manpage.css +0 -1
  121. data/asciidoc/stylesheets/volnitsky-manpage.css +0 -1
Binary file
data/asciidoc/doc/faq.txt CHANGED
@@ -2,15 +2,84 @@ AsciiDoc Frequently Asked Questions
2
2
  ===================================
3
3
 
4
4
 
5
- [NOTE]
6
- ======
7
- - New FAQs are normally added at the top of this document.
8
- - The FAQ may be updated between AsciiDoc releases so some of the
9
- newer FAQs may apply to the trunk and not the current release.
10
- ======
5
+ NOTE: New FAQs are appended to the bottom of this document.
6
+
7
+ /////////////////////////////////////////////////////////////////
8
+ ADD NEW FAQS TO THE BOTTOM OF THIS DOCUMENT TO MAINTAIN NUMBERING
9
+ /////////////////////////////////////////////////////////////////
10
+
11
+ == How do you handle spaces in included file names?
12
+ Spaces are not allowed in macro targets so this include macro will not
13
+ be processed:
14
+
15
+ include::my document.txt[]
16
+
17
+ The work-around is to replace the spaces with the `{sp}` (space
18
+ character) attribute, for example:
19
+
20
+ include::my{sp}document.txt[]
21
+
22
+
23
+ == How do I number all paragraphs?
24
+ Some documents such as specifications and legalese require all
25
+ paragraphs to be sequentially numbered through the document, and to be
26
+ able to reference these numbers.
27
+
28
+ This can be achieved by using the DocBook toolchain but numbering the
29
+ paragraphs with AsciiDoc using a custom config file containing the
30
+ following (see http://www.methods.co.nz/asciidoc/userguide.html#X27
31
+ for ways to include such a file):
32
+
33
+ ---------------------------------------------------------------------
34
+ [paragraph]
35
+ <formalpara{id? id="{id}"}{role? role="{role}"}{id? xreflabel="{paracounter}"}><title>{title}</title><para>
36
+ {title%}<simpara{id? id="{id}"}{role? role="{role}"}{id? xreflabel="{paracounter}"}>
37
+ {paracounter} |
38
+ {title%}</simpara>
39
+ {title#}</para></formalpara>
40
+ {counter2:paracounter}
41
+ {empty}
42
+ ---------------------------------------------------------------------
43
+
44
+ References to the paragraphs operate in the normal way, you label the
45
+ paragraph:
46
+
47
+ -----------------------------
48
+ [[some_label_you_understand]]
49
+ paragraph contents
50
+ -----------------------------
51
+
52
+ and reference it in the normal manner:
53
+
54
+ -----------------------------
55
+ <<some_label_you_understand>>
56
+ -----------------------------
57
+
58
+ The text of the reference will be the paragraph number.
59
+
60
+ For this to work for HTML you have to generate it via the DocBook
61
+ toolchain.
62
+
63
+
64
+ == Sources of information on configuring DocBook toolchains
65
+ DocBook is a content and structure markup language, therefore
66
+ AsciiDoc generated DocBook markup is also limited to content and
67
+ structure. Layout and formatting definition is specific to the
68
+ DocBook toolchain.
69
+
70
+ The dblatex toolchain can be configured by setting parameters defined
71
+ at http://dblatex.sourceforge.net/doc/manual/sec-params.html or for
72
+ more complex styling by custom Latex stylesheets described at
73
+ http://dblatex.sourceforge.net/doc/manual/sec-custom-latex.html.
74
+
75
+ Similarly FOP can be configured by parameters described at
76
+ http://sagehill.net/docbookxsl/OptionsPart.html and with custom xsl
77
+ stylesheets generating formatting objects as described at
78
+ http://sagehill.net/docbookxsl/CustomizingPart.html.
79
+
11
80
 
12
81
  [[X5]]
13
- == How can I include embedded fonts in an EPUB document
82
+ == How can I include embedded fonts in an EPUB document?
14
83
  This is a two step process:
15
84
 
16
85
  1. Declare the font files and their use in your document's CSS
@@ -30,7 +99,7 @@ body {
30
99
  }
31
100
  .........................................
32
101
 
33
- 2. Declare the the font file as resource when you use `a2x(1)` to
102
+ 2. Declare the font file as resource when you use `a2x(1)` to
34
103
  compile the EPUB. For example:
35
104
 
36
105
  a2x -f epub -d book --epubcheck --stylesheet epubtest.css --resource .ttf=application/x-font-ttf --resource LiberationSerif-Regular.ttf epubtest.txt
@@ -48,11 +117,11 @@ body {
48
117
  accordingly (see the 'RESOURCES' section in the `a2x(1)` man page
49
118
  for details).
50
119
  - The URL value of the CSS 'src' property is set to the destination
51
- font file relative the the CSS file.
120
+ font file relative to the CSS file.
52
121
  - The `--resource` option allows you to inject any file (not just font
53
122
  files) into the EPUB output document.
54
123
  - Using the CSS '@font-face' rule is a complex subject and is outside
55
- the scope of the FAQ.
124
+ the scope of this FAQ.
56
125
  - Many EPUB readers do not process embedded fonts.
57
126
  ======
58
127
 
@@ -312,7 +381,7 @@ http://dblatex.sourceforge.net/doc/sec-custom.html[doc.lot.show XSL
312
381
  parameter] -- you can set it using the dblatex `--param` command-line
313
382
  option, for example:
314
383
 
315
- $ a2x --dblatex-opts="--param=doc.lot.show=figure,table" doc/article.txt
384
+ a2x --dblatex-opts="--param=doc.lot.show=figure,table" doc/article.txt
316
385
 
317
386
 
318
387
  == How can I stop the document title being displayed?
@@ -408,7 +477,7 @@ CSS stylesheet. For example the following command will generate a
408
477
  single `article.html` file containing embedded images, admonition
409
478
  icons and the CSS stylesheet:
410
479
 
411
- $ asciidoc -a data-uri -a icons article.txt
480
+ asciidoc -a data-uri -a icons article.txt
412
481
 
413
482
 
414
483
  == Are there any tools to help me understand what's going on inside AsciiDoc?
@@ -874,20 +943,55 @@ http://live.gnome.org/Yelp[Yelp], the GNOME help viewer, does a
874
943
  creditable job of displaying DocBook XML files directly.
875
944
 
876
945
 
877
- == Can you create ODF documents using AsciiDoc?
946
+ == Can you create ODF and PDF files using LibreOffice?
878
947
 
879
- The easiest and highest fidelity method I've seen is to generate
880
- HTML from AsciiDoc then paste it from your browser (we use Firefox)
881
- into OpenOffice Writer.
948
+ https://www.libreoffice.org/[LibreOffice] can convert HTML produced by
949
+ AsciiDoc to ODF text format and PDF format (I used LibreOffice 3.5 at
950
+ the time of writing, the fidelity is very good but it's not perfect):
882
951
 
883
- - I found that that there is better fidelity pasting HTML generated by
884
- the 'html4' backend instead of the default 'xhtml11' backend.
885
- - Don't paste AsciiDoc tables of contents, OpenOffice Writer (I was
886
- using version 2.3) hangs when saving. This may be something to do
887
- with the embedded JavaScript but I haven't looked closely at it, I
888
- may even be wrong about this.
952
+ . Create the HTML file using AsciiDoc, for example:
953
+
954
+ asciidoc -a icons -a numbered -a disable-javascript article.txt
955
+ +
956
+ JavaScript is disabled because LibreOffice does not execute
957
+ JavaScript, this means that AsciiDoc table of contents and footnotes
958
+ will not be rendered into ODF (if you want the table of contents and
959
+ footnotes you could manually cut and paste them from a Web browser).
889
960
 
890
- This tip was contributed by Bernard Amade.
961
+ . Convert the HTML file to an ODF text file using LibreOffice:
962
+
963
+ lowriter --invisible --convert-to odt article.html
964
+ +
965
+ --
966
+ The images imported from an HTML file will be linked, if your document
967
+ contains images you should convert them to embedded images:
968
+
969
+ [lowerroman]
970
+ . Open the document in LibreOffice Writer.
971
+ . Run the 'Edit->Links...' menu command.
972
+ . Select all links and press the 'Break Link' button.
973
+
974
+ Some images may also have been resized. To restore an image to its
975
+ original size:
976
+
977
+ [lowerroman]
978
+ . Right-click on the image and select the 'Picture...' menu item.
979
+ . Click on the 'Crop' tab.
980
+ . Press the 'Original Size' button.
981
+
982
+ --
983
+
984
+ . Convert the ODF file to an PDF text file using LibreOffice:
985
+
986
+ lowriter --invisible --convert-to pdf article.odt
987
+ +
988
+ A PDF index is automatically created using the section headings.
989
+
990
+ Alternatively you could manually copy-and-paste the entire document
991
+ from a Web browser into a blank ODF document in LibreOffice -- this
992
+ technique will bring through the table of contents and footnotes.
993
+
994
+ This tip was originally contributed by Bernard Amade.
891
995
 
892
996
 
893
997
  == How can I suppress cell separators in included table data files?
@@ -948,7 +1052,7 @@ characters. If you need spaces encode them as `%20`. For example:
948
1052
  Set the AsciiDoc 'lang' attribute to the appropriate language code.
949
1053
  For example:
950
1054
 
951
- $ a2x -a lang=es doc/article.txt
1055
+ a2x -a lang=es doc/article.txt
952
1056
 
953
1057
  This will ensure that downstream DocBook processing will generate the
954
1058
  correct language specific document headings (things like table of
@@ -1021,7 +1125,7 @@ The default format for the `{localdate}` attribute is the ISO 8601
1021
1125
  the `{localdate}` attribute. For example by setting it using the
1022
1126
  asciidoc(1) `-a` command-line option:
1023
1127
 
1024
- $ asciidoc -a localdate=`date +%d-%m-%Y` mydoc.txt
1128
+ asciidoc -a localdate=`date +%d-%m-%Y` mydoc.txt
1025
1129
 
1026
1130
  You could also set it by adding an Attribute Entry to your source
1027
1131
  document, for example:
@@ -1120,3 +1224,75 @@ If quoting were omitted the equals character (separating the
1120
1224
  entry name `x` from the value `y`) would be escaped.
1121
1225
 
1122
1226
 
1227
+ == How can I control page breaks when printing HTML outputs?
1228
+ Here are some techniques you can use to control page breaks in HTML
1229
+ outputs produced by the 'xhtml11' and 'html5' backends:
1230
+
1231
+ - You can generate a page break with the '<<<' block macro. The
1232
+ following example prints the 'Rats and Mice' section on a new page:
1233
+ +
1234
+ ----------------
1235
+ <<<
1236
+ == Rats and Mice
1237
+ Lorum ipsum ...
1238
+ ----------------
1239
+
1240
+ - You can use the 'unbreakable' option to instruct the browser not to
1241
+ break a block element. The following image and it's caption will be
1242
+ kept together the printed page:
1243
+ +
1244
+ ------------------------------------
1245
+ [options="unbreakable"]
1246
+ .Tiger block image
1247
+ image::images/tiger.png[Tiger image]
1248
+ ------------------------------------
1249
+
1250
+ - You can apply the 'unbreakable' option globally to all block
1251
+ elements by defining the 'unbreakable-option' attribute in your
1252
+ document header.
1253
+
1254
+ - Finally, the most powerful technique is to create custom CSS
1255
+ containing paged media properties. For example this asciidoc(1)
1256
+ command:
1257
+ +
1258
+ --
1259
+
1260
+ asciidoc --attribute stylesheet=article.css article.txt
1261
+
1262
+ Will include the following `article.css` file in the output document:
1263
+
1264
+ -------------------------------------------------
1265
+ div#toc, div.sect1 { page-break-before: always; }
1266
+ -------------------------------------------------
1267
+
1268
+ Which will ensure the table of contents and all top level sections
1269
+ start on a new printed page.
1270
+ --
1271
+
1272
+
1273
+ == Is it possible to reposition the Table of Contents in HTML outputs?
1274
+ By default the 'xhtml11' and 'html5' backends auto-position the TOC
1275
+ after the header. You can manually position the header by setting the
1276
+ 'toc-placement' attribute value to 'manual' and then inserting the
1277
+ `toc::[]` block macro where you want the TOC to appear. For example,
1278
+ put this in the document header:
1279
+
1280
+ ----------------------
1281
+ :toc-placement: manual
1282
+ ----------------------
1283
+
1284
+ and this where you want the TOC to appear:
1285
+
1286
+ -------
1287
+ toc::[]
1288
+ -------
1289
+
1290
+
1291
+ == HTML generated by AsciiDoc fills the width of the browser, how can I limit it to a more readable book width?
1292
+ You can set the maximum with for outputs generated by 'html5',
1293
+ 'xhtml11' and 'slidy' backends by assigning the
1294
+ link:userguide.html#X103[max-width] attribute (either from the
1295
+ command-line or with an attribute entry in the document header). For
1296
+ example:
1297
+
1298
+ asciidoc -a max-width=55em article.txt
Binary file
Binary file
@@ -13,7 +13,7 @@ ifdef::blogpost[]
13
13
  :blogpost-posttype: post
14
14
  :blogpost-categories: AsciiDoc,eBook,EPUB,DocBook
15
15
 
16
- *Published*: 2010-08-23
16
+ *Published*: 2010-08-23 +
17
17
  *Updated*: 2010-05-08
18
18
  endif::blogpost[]
19
19
 
@@ -12,11 +12,10 @@ source-highlight] to highlight 'html4' and 'xhtml11' outputs. You also
12
12
  have the option of using the http://pygments.org/[Pygments] syntax
13
13
  highlighter for 'xhtml11' outputs.
14
14
 
15
- To use Pygments you need to define an AsciiDoc attribute named
16
- 'pygments' (either from the command-line or in the global
17
- `asciidoc.conf` configuration file) and you will also need to have
18
- Pygments installed and the 'pygmentize' command in your PATH.
19
-
15
+ - The filter command must reside in the shell search 'PATH'.
16
+ 'pygmentize' command in your 'PATH'.
17
+ - To use Pygments you need to define an AsciiDoc attribute named
18
+ 'pygments'.
20
19
  - You can customize Pygments CSS styles by editing
21
20
  `./stylesheets/pygments.css`.
22
21
  - To make Pygments your default highlighter put the following line
@@ -30,8 +29,50 @@ Pygments installed and the 'pygmentize' command in your PATH.
30
29
 
31
30
  DocBook Outputs
32
31
  ---------------
33
- DocBook outputs are highlighted by toolchains that have
34
- `programlisting` element highlight support, for example 'dblatex'.
32
+ AsciiDoc encloses the source code in a DocBook 'programlisting'
33
+ element and leaves source code highlighting to the DocBook toolchain
34
+ (dblatex has a particularly nice programlisting highlighter). The
35
+ DocBook programlisting element is assigned two attributes:
36
+
37
+ . The 'language' attribute is set to the AsciiDoc 'language'
38
+ attribute.
39
+ . The 'linenumbering' attribute is set to the AsciiDoc 'src_numbered'
40
+ attribute ('numbered' or 'unnumbered').
41
+
42
+
43
+ Block attributes
44
+ ----------------
45
+ The following attributes can be included in source code block
46
+ attribute lists.
47
+
48
+ - 'style' and 'language' are mandatory.
49
+ - 'style', 'language' and 'src_numbered' are the first three
50
+ positional attributes in that order.
51
+ - The 'args' attribute allows the inclusion of arbitrary (highlighter
52
+ dependent) command options.
53
+
54
+ //
55
+
56
+ style::
57
+ Set to 'source'.
58
+ language::
59
+ The source code language name.
60
+ src_numbered::
61
+ Set to 'numbered' to include line numbers.
62
+ src_tab::
63
+ Set tab size (GNU source-highlight only).
64
+ args::
65
+ Include this attribute value in the highlighter command-line (GNU
66
+ source-highlight and pygmentize) or in the `programlisting` element
67
+ (DocBook).
68
+
69
+
70
+ Testing
71
+ -------
72
+ Test the filter by converting the test file to HTML with AsciiDoc:
73
+
74
+ $ asciidoc -v ./filters/source/source-highlight-filter-test.txt
75
+ $ firefox ./filters/source/source-highlight-filter-test.html &
35
76
 
36
77
 
37
78
  Examples
@@ -196,33 +237,3 @@ end
196
237
  - You may need to place callout markers inside source code comments to
197
238
  ensure they are not misinterpreted and mangled by the highlighter.
198
239
  =====
199
-
200
-
201
- Installation
202
- ------------
203
- HTML
204
- ~~~~
205
- If you want to syntax highlight AsciiDoc HTML outputs (`html4` and
206
- `xhtml11` backends) you need to install
207
- http://www.gnu.org/software/src-highlite/[GNU source-highlight] or
208
- http://pygments.org/[Pygments] (most distributions have these
209
- packages).
210
-
211
- DocBook
212
- ~~~~~~~
213
- AsciiDoc encloses the source code in a DocBook 'programlisting'
214
- element and leaves source code highlighting to the DocBook toolchain
215
- (dblatex has a particularly nice programlisting highlighter). The
216
- DocBook programlisting element is assigned two attributes:
217
-
218
- . The 'language' attribute is set to the AsciiDoc 'language'
219
- attribute.
220
- . The 'linenumbering' attribute is set to the AsciiDoc 'src_numbered'
221
- attribute ('numbered' or 'unnumbered').
222
-
223
- Testing
224
- ~~~~~~~
225
- Test the filter by converting the test file to HTML with AsciiDoc:
226
-
227
- $ asciidoc -v ./filters/source/source-highlight-filter-test.txt
228
- $ firefox ./filters/source/source-highlight-filter-test.html &
@@ -42,7 +42,7 @@ endif::asciidoc7compatible[]
42
42
  <simpara><?asciidoc-pagebreak?></simpara>
43
43
 
44
44
  [blockdef-pass]
45
- latexmath-style=template="latexmathblock",subs=[]
45
+ latexmath-style=template="latexmathblock",subs=()
46
46
 
47
47
  [macros]
48
48
  # math macros.
@@ -138,12 +138,12 @@ latexmath-style=template="latexmathblock",subs=[]
138
138
 
139
139
  # List tags.
140
140
  [listtags-bulleted]
141
- list=<itemizedlist{id? id="{id}"}{role? role="{role}"}{reftext? xreflabel="{reftext}"}{compact-option? spacing="compact"}>{unbreakable-option? <?dbfo keep-together="{unbreakable-option#always}"?>}{title?<title>{title}</title>}|</itemizedlist>
141
+ list=<itemizedlist{id? id="{id}"}{role? role="{role}"}{reftext? xreflabel="{reftext}"}{compact-option? spacing="compact"}>{unbreakable-option? <?dbfo keep-together="always"?>}{title?<title>{title}</title>}|</itemizedlist>
142
142
  item=<listitem>|</listitem>
143
143
  text=<simpara>|</simpara>
144
144
 
145
145
  [listtags-numbered]
146
- list=<orderedlist{id? id="{id}"}{role? role="{role}"}{reftext? xreflabel="{reftext}"} numeration="{style}"{compact-option? spacing="compact"}>{unbreakable-option? <?dbfo keep-together="{unbreakable-option#always}"?>}{title?<title>{title}</title>}{start?<?dbfo start="{start}"?><?dbhtml start="{start}"?>}|</orderedlist>
146
+ list=<orderedlist{id? id="{id}"}{role? role="{role}"}{reftext? xreflabel="{reftext}"} numeration="{style}"{compact-option? spacing="compact"}>{unbreakable-option? <?dbfo keep-together="always"?>}{title?<title>{title}</title>}{start?<?dbfo start="{start}"?><?dbhtml start="{start}"?>}|</orderedlist>
147
147
  item=<listitem>|</listitem>
148
148
  text=<simpara>|</simpara>
149
149
 
@@ -497,7 +497,7 @@ rowsep="{grid@none|cols:0:1}" colsep="{grid@none|rows:0:1}"
497
497
  {toc#}<?asciidoc-toc?>
498
498
  {numbered#}<?asciidoc-numbered?>
499
499
 
500
- [docinfo]
500
+ [+docinfo]
501
501
  {notitle%} <title>{doctitle}</title>
502
502
  <date>{revdate}</date>
503
503
  # To ensure valid articleinfo/bookinfo when there is no AsciiDoc header.
@@ -0,0 +1,938 @@
1
+ /*
2
+ ASCIIMathML.js
3
+ ==============
4
+ This file contains JavaScript functions to convert ASCII math notation
5
+ to Presentation MathML. The conversion is done while the (X)HTML page
6
+ loads, and should work with Firefox/Mozilla/Netscape 7+ and Internet
7
+ Explorer 6+MathPlayer (http://www.dessci.com/en/products/mathplayer/).
8
+ Just add the next line to your (X)HTML page with this file in the same folder:
9
+ This is a convenient and inexpensive solution for authoring MathML.
10
+
11
+ Version 1.4.7 Dec 15, 2005, (c) Peter Jipsen http://www.chapman.edu/~jipsen
12
+ Latest version at http://www.chapman.edu/~jipsen/mathml/ASCIIMathML.js
13
+ For changes see http://www.chapman.edu/~jipsen/mathml/asciimathchanges.txt
14
+ If you use it on a webpage, please send the URL to jipsen@chapman.edu
15
+
16
+ This program is free software; you can redistribute it and/or modify
17
+ it under the terms of the GNU General Public License as published by
18
+ the Free Software Foundation; either version 2 of the License, or (at
19
+ your option) any later version.
20
+
21
+ This program is distributed in the hope that it will be useful,
22
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
23
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24
+ General Public License (at http://www.gnu.org/copyleft/gpl.html)
25
+ for more details.
26
+ */
27
+
28
+ var checkForMathML = true; // check if browser can display MathML
29
+ var notifyIfNoMathML = true; // display note if no MathML capability
30
+ var alertIfNoMathML = false; // show alert box if no MathML capability
31
+ var mathcolor = ""; // change it to "" (to inherit) or any other color
32
+ var mathfontfamily = "serif"; // change to "" to inherit (works in IE)
33
+ // or another family (e.g. "arial")
34
+ var displaystyle = true; // puts limits above and below large operators
35
+ var showasciiformulaonhover = true; // helps students learn ASCIIMath
36
+ var decimalsign = "."; // change to "," if you like, beware of `(1,2)`!
37
+ var AMdelimiter1 = "`", AMescape1 = "\\\\`"; // can use other characters
38
+ var AMdelimiter2 = "$", AMescape2 = "\\\\\\$", AMdelimiter2regexp = "\\$";
39
+ var doubleblankmathdelimiter = false; // if true, x+1 is equal to `x+1`
40
+ // for IE this works only in <!-- -->
41
+ //var separatetokens;// has been removed (email me if this is a problem)
42
+ var isIE = document.createElementNS==null;
43
+
44
+ if (document.getElementById==null)
45
+ alert("This webpage requires a recent browser such as\
46
+ \nMozilla/Netscape 7+ or Internet Explorer 6+MathPlayer")
47
+
48
+ // all further global variables start with "AM"
49
+
50
+ function AMcreateElementXHTML(t) {
51
+ if (isIE) return document.createElement(t);
52
+ else return document.createElementNS("http://www.w3.org/1999/xhtml",t);
53
+ }
54
+
55
+ function AMnoMathMLNote() {
56
+ var nd = AMcreateElementXHTML("h3");
57
+ nd.setAttribute("align","center")
58
+ nd.appendChild(AMcreateElementXHTML("p"));
59
+ nd.appendChild(document.createTextNode("To view the "));
60
+ var an = AMcreateElementXHTML("a");
61
+ an.appendChild(document.createTextNode("ASCIIMathML"));
62
+ an.setAttribute("href","http://www.chapman.edu/~jipsen/asciimath.html");
63
+ nd.appendChild(an);
64
+ nd.appendChild(document.createTextNode(" notation use Internet Explorer 6+"));
65
+ an = AMcreateElementXHTML("a");
66
+ an.appendChild(document.createTextNode("MathPlayer"));
67
+ an.setAttribute("href","http://www.dessci.com/en/products/mathplayer/download.htm");
68
+ nd.appendChild(an);
69
+ nd.appendChild(document.createTextNode(" or Netscape/Mozilla/Firefox"));
70
+ nd.appendChild(AMcreateElementXHTML("p"));
71
+ return nd;
72
+ }
73
+
74
+ function AMisMathMLavailable() {
75
+ if (navigator.appName.slice(0,8)=="Netscape")
76
+ if (navigator.appVersion.slice(0,1)>="5") return null;
77
+ else return AMnoMathMLNote();
78
+ else if (navigator.appName.slice(0,9)=="Microsoft")
79
+ try {
80
+ var ActiveX = new ActiveXObject("MathPlayer.Factory.1");
81
+ return null;
82
+ } catch (e) {
83
+ return AMnoMathMLNote();
84
+ }
85
+ else return AMnoMathMLNote();
86
+ }
87
+
88
+ // character lists for Mozilla/Netscape fonts
89
+ var AMcal = [0xEF35,0x212C,0xEF36,0xEF37,0x2130,0x2131,0xEF38,0x210B,0x2110,0xEF39,0xEF3A,0x2112,0x2133,0xEF3B,0xEF3C,0xEF3D,0xEF3E,0x211B,0xEF3F,0xEF40,0xEF41,0xEF42,0xEF43,0xEF44,0xEF45,0xEF46];
90
+ var AMfrk = [0xEF5D,0xEF5E,0x212D,0xEF5F,0xEF60,0xEF61,0xEF62,0x210C,0x2111,0xEF63,0xEF64,0xEF65,0xEF66,0xEF67,0xEF68,0xEF69,0xEF6A,0x211C,0xEF6B,0xEF6C,0xEF6D,0xEF6E,0xEF6F,0xEF70,0xEF71,0x2128];
91
+ var AMbbb = [0xEF8C,0xEF8D,0x2102,0xEF8E,0xEF8F,0xEF90,0xEF91,0x210D,0xEF92,0xEF93,0xEF94,0xEF95,0xEF96,0x2115,0xEF97,0x2119,0x211A,0x211D,0xEF98,0xEF99,0xEF9A,0xEF9B,0xEF9C,0xEF9D,0xEF9E,0x2124];
92
+
93
+ var CONST = 0, UNARY = 1, BINARY = 2, INFIX = 3, LEFTBRACKET = 4,
94
+ RIGHTBRACKET = 5, SPACE = 6, UNDEROVER = 7, DEFINITION = 8,
95
+ LEFTRIGHT = 9, TEXT = 10; // token types
96
+
97
+ var AMsqrt = {input:"sqrt", tag:"msqrt", output:"sqrt", tex:null, ttype:UNARY},
98
+ AMroot = {input:"root", tag:"mroot", output:"root", tex:null, ttype:BINARY},
99
+ AMfrac = {input:"frac", tag:"mfrac", output:"/", tex:null, ttype:BINARY},
100
+ AMdiv = {input:"/", tag:"mfrac", output:"/", tex:null, ttype:INFIX},
101
+ AMover = {input:"stackrel", tag:"mover", output:"stackrel", tex:null, ttype:BINARY},
102
+ AMsub = {input:"_", tag:"msub", output:"_", tex:null, ttype:INFIX},
103
+ AMsup = {input:"^", tag:"msup", output:"^", tex:null, ttype:INFIX},
104
+ AMtext = {input:"text", tag:"mtext", output:"text", tex:null, ttype:TEXT},
105
+ AMmbox = {input:"mbox", tag:"mtext", output:"mbox", tex:null, ttype:TEXT},
106
+ AMquote = {input:"\"", tag:"mtext", output:"mbox", tex:null, ttype:TEXT};
107
+
108
+ var AMsymbols = [
109
+ //some greek symbols
110
+ {input:"alpha", tag:"mi", output:"\u03B1", tex:null, ttype:CONST},
111
+ {input:"beta", tag:"mi", output:"\u03B2", tex:null, ttype:CONST},
112
+ {input:"chi", tag:"mi", output:"\u03C7", tex:null, ttype:CONST},
113
+ {input:"delta", tag:"mi", output:"\u03B4", tex:null, ttype:CONST},
114
+ {input:"Delta", tag:"mo", output:"\u0394", tex:null, ttype:CONST},
115
+ {input:"epsi", tag:"mi", output:"\u03B5", tex:"epsilon", ttype:CONST},
116
+ {input:"varepsilon", tag:"mi", output:"\u025B", tex:null, ttype:CONST},
117
+ {input:"eta", tag:"mi", output:"\u03B7", tex:null, ttype:CONST},
118
+ {input:"gamma", tag:"mi", output:"\u03B3", tex:null, ttype:CONST},
119
+ {input:"Gamma", tag:"mo", output:"\u0393", tex:null, ttype:CONST},
120
+ {input:"iota", tag:"mi", output:"\u03B9", tex:null, ttype:CONST},
121
+ {input:"kappa", tag:"mi", output:"\u03BA", tex:null, ttype:CONST},
122
+ {input:"lambda", tag:"mi", output:"\u03BB", tex:null, ttype:CONST},
123
+ {input:"Lambda", tag:"mo", output:"\u039B", tex:null, ttype:CONST},
124
+ {input:"mu", tag:"mi", output:"\u03BC", tex:null, ttype:CONST},
125
+ {input:"nu", tag:"mi", output:"\u03BD", tex:null, ttype:CONST},
126
+ {input:"omega", tag:"mi", output:"\u03C9", tex:null, ttype:CONST},
127
+ {input:"Omega", tag:"mo", output:"\u03A9", tex:null, ttype:CONST},
128
+ {input:"phi", tag:"mi", output:"\u03C6", tex:null, ttype:CONST},
129
+ {input:"varphi", tag:"mi", output:"\u03D5", tex:null, ttype:CONST},
130
+ {input:"Phi", tag:"mo", output:"\u03A6", tex:null, ttype:CONST},
131
+ {input:"pi", tag:"mi", output:"\u03C0", tex:null, ttype:CONST},
132
+ {input:"Pi", tag:"mo", output:"\u03A0", tex:null, ttype:CONST},
133
+ {input:"psi", tag:"mi", output:"\u03C8", tex:null, ttype:CONST},
134
+ {input:"Psi", tag:"mi", output:"\u03A8", tex:null, ttype:CONST},
135
+ {input:"rho", tag:"mi", output:"\u03C1", tex:null, ttype:CONST},
136
+ {input:"sigma", tag:"mi", output:"\u03C3", tex:null, ttype:CONST},
137
+ {input:"Sigma", tag:"mo", output:"\u03A3", tex:null, ttype:CONST},
138
+ {input:"tau", tag:"mi", output:"\u03C4", tex:null, ttype:CONST},
139
+ {input:"theta", tag:"mi", output:"\u03B8", tex:null, ttype:CONST},
140
+ {input:"vartheta", tag:"mi", output:"\u03D1", tex:null, ttype:CONST},
141
+ {input:"Theta", tag:"mo", output:"\u0398", tex:null, ttype:CONST},
142
+ {input:"upsilon", tag:"mi", output:"\u03C5", tex:null, ttype:CONST},
143
+ {input:"xi", tag:"mi", output:"\u03BE", tex:null, ttype:CONST},
144
+ {input:"Xi", tag:"mo", output:"\u039E", tex:null, ttype:CONST},
145
+ {input:"zeta", tag:"mi", output:"\u03B6", tex:null, ttype:CONST},
146
+
147
+ //binary operation symbols
148
+ {input:"*", tag:"mo", output:"\u22C5", tex:"cdot", ttype:CONST},
149
+ {input:"**", tag:"mo", output:"\u22C6", tex:"star", ttype:CONST},
150
+ {input:"//", tag:"mo", output:"/", tex:null, ttype:CONST},
151
+ {input:"\\\\", tag:"mo", output:"\\", tex:"backslash", ttype:CONST},
152
+ {input:"setminus", tag:"mo", output:"\\", tex:null, ttype:CONST},
153
+ {input:"xx", tag:"mo", output:"\u00D7", tex:"times", ttype:CONST},
154
+ {input:"-:", tag:"mo", output:"\u00F7", tex:"divide", ttype:CONST},
155
+ {input:"@", tag:"mo", output:"\u2218", tex:"circ", ttype:CONST},
156
+ {input:"o+", tag:"mo", output:"\u2295", tex:"oplus", ttype:CONST},
157
+ {input:"ox", tag:"mo", output:"\u2297", tex:"otimes", ttype:CONST},
158
+ {input:"o.", tag:"mo", output:"\u2299", tex:"odot", ttype:CONST},
159
+ {input:"sum", tag:"mo", output:"\u2211", tex:null, ttype:UNDEROVER},
160
+ {input:"prod", tag:"mo", output:"\u220F", tex:null, ttype:UNDEROVER},
161
+ {input:"^^", tag:"mo", output:"\u2227", tex:"wedge", ttype:CONST},
162
+ {input:"^^^", tag:"mo", output:"\u22C0", tex:"bigwedge", ttype:UNDEROVER},
163
+ {input:"vv", tag:"mo", output:"\u2228", tex:"vee", ttype:CONST},
164
+ {input:"vvv", tag:"mo", output:"\u22C1", tex:"bigvee", ttype:UNDEROVER},
165
+ {input:"nn", tag:"mo", output:"\u2229", tex:"cap", ttype:CONST},
166
+ {input:"nnn", tag:"mo", output:"\u22C2", tex:"bigcap", ttype:UNDEROVER},
167
+ {input:"uu", tag:"mo", output:"\u222A", tex:"cup", ttype:CONST},
168
+ {input:"uuu", tag:"mo", output:"\u22C3", tex:"bigcup", ttype:UNDEROVER},
169
+
170
+ //binary relation symbols
171
+ {input:"!=", tag:"mo", output:"\u2260", tex:"ne", ttype:CONST},
172
+ {input:":=", tag:"mo", output:":=", tex:null, ttype:CONST},
173
+ {input:"lt", tag:"mo", output:"<", tex:null, ttype:CONST},
174
+ {input:"<=", tag:"mo", output:"\u2264", tex:"le", ttype:CONST},
175
+ {input:"lt=", tag:"mo", output:"\u2264", tex:"leq", ttype:CONST},
176
+ {input:">=", tag:"mo", output:"\u2265", tex:"ge", ttype:CONST},
177
+ {input:"geq", tag:"mo", output:"\u2265", tex:null, ttype:CONST},
178
+ {input:"-<", tag:"mo", output:"\u227A", tex:"prec", ttype:CONST},
179
+ {input:"-lt", tag:"mo", output:"\u227A", tex:null, ttype:CONST},
180
+ {input:">-", tag:"mo", output:"\u227B", tex:"succ", ttype:CONST},
181
+ {input:"-<=", tag:"mo", output:"\u2AAF", tex:"preceq", ttype:CONST},
182
+ {input:">-=", tag:"mo", output:"\u2AB0", tex:"succeq", ttype:CONST},
183
+ {input:"in", tag:"mo", output:"\u2208", tex:null, ttype:CONST},
184
+ {input:"!in", tag:"mo", output:"\u2209", tex:"notin", ttype:CONST},
185
+ {input:"sub", tag:"mo", output:"\u2282", tex:"subset", ttype:CONST},
186
+ {input:"sup", tag:"mo", output:"\u2283", tex:"supset", ttype:CONST},
187
+ {input:"sube", tag:"mo", output:"\u2286", tex:"subseteq", ttype:CONST},
188
+ {input:"supe", tag:"mo", output:"\u2287", tex:"supseteq", ttype:CONST},
189
+ {input:"-=", tag:"mo", output:"\u2261", tex:"equiv", ttype:CONST},
190
+ {input:"~=", tag:"mo", output:"\u2245", tex:"cong", ttype:CONST},
191
+ {input:"~~", tag:"mo", output:"\u2248", tex:"approx", ttype:CONST},
192
+ {input:"prop", tag:"mo", output:"\u221D", tex:"propto", ttype:CONST},
193
+
194
+ //logical symbols
195
+ {input:"and", tag:"mtext", output:"and", tex:null, ttype:SPACE},
196
+ {input:"or", tag:"mtext", output:"or", tex:null, ttype:SPACE},
197
+ {input:"not", tag:"mo", output:"\u00AC", tex:"neg", ttype:CONST},
198
+ {input:"=>", tag:"mo", output:"\u21D2", tex:"implies", ttype:CONST},
199
+ {input:"if", tag:"mo", output:"if", tex:null, ttype:SPACE},
200
+ {input:"<=>", tag:"mo", output:"\u21D4", tex:"iff", ttype:CONST},
201
+ {input:"AA", tag:"mo", output:"\u2200", tex:"forall", ttype:CONST},
202
+ {input:"EE", tag:"mo", output:"\u2203", tex:"exists", ttype:CONST},
203
+ {input:"_|_", tag:"mo", output:"\u22A5", tex:"bot", ttype:CONST},
204
+ {input:"TT", tag:"mo", output:"\u22A4", tex:"top", ttype:CONST},
205
+ {input:"|--", tag:"mo", output:"\u22A2", tex:"vdash", ttype:CONST},
206
+ {input:"|==", tag:"mo", output:"\u22A8", tex:"models", ttype:CONST},
207
+
208
+ //grouping brackets
209
+ {input:"(", tag:"mo", output:"(", tex:null, ttype:LEFTBRACKET},
210
+ {input:")", tag:"mo", output:")", tex:null, ttype:RIGHTBRACKET},
211
+ {input:"[", tag:"mo", output:"[", tex:null, ttype:LEFTBRACKET},
212
+ {input:"]", tag:"mo", output:"]", tex:null, ttype:RIGHTBRACKET},
213
+ {input:"{", tag:"mo", output:"{", tex:null, ttype:LEFTBRACKET},
214
+ {input:"}", tag:"mo", output:"}", tex:null, ttype:RIGHTBRACKET},
215
+ {input:"|", tag:"mo", output:"|", tex:null, ttype:LEFTRIGHT},
216
+ //{input:"||", tag:"mo", output:"||", tex:null, ttype:LEFTRIGHT},
217
+ {input:"(:", tag:"mo", output:"\u2329", tex:"langle", ttype:LEFTBRACKET},
218
+ {input:":)", tag:"mo", output:"\u232A", tex:"rangle", ttype:RIGHTBRACKET},
219
+ {input:"<<", tag:"mo", output:"\u2329", tex:null, ttype:LEFTBRACKET},
220
+ {input:">>", tag:"mo", output:"\u232A", tex:null, ttype:RIGHTBRACKET},
221
+ {input:"{:", tag:"mo", output:"{:", tex:null, ttype:LEFTBRACKET, invisible:true},
222
+ {input:":}", tag:"mo", output:":}", tex:null, ttype:RIGHTBRACKET, invisible:true},
223
+
224
+ //miscellaneous symbols
225
+ {input:"int", tag:"mo", output:"\u222B", tex:null, ttype:CONST},
226
+ {input:"dx", tag:"mi", output:"{:d x:}", tex:null, ttype:DEFINITION},
227
+ {input:"dy", tag:"mi", output:"{:d y:}", tex:null, ttype:DEFINITION},
228
+ {input:"dz", tag:"mi", output:"{:d z:}", tex:null, ttype:DEFINITION},
229
+ {input:"dt", tag:"mi", output:"{:d t:}", tex:null, ttype:DEFINITION},
230
+ {input:"oint", tag:"mo", output:"\u222E", tex:null, ttype:CONST},
231
+ {input:"del", tag:"mo", output:"\u2202", tex:"partial", ttype:CONST},
232
+ {input:"grad", tag:"mo", output:"\u2207", tex:"nabla", ttype:CONST},
233
+ {input:"+-", tag:"mo", output:"\u00B1", tex:"pm", ttype:CONST},
234
+ {input:"O/", tag:"mo", output:"\u2205", tex:"emptyset", ttype:CONST},
235
+ {input:"oo", tag:"mo", output:"\u221E", tex:"infty", ttype:CONST},
236
+ {input:"aleph", tag:"mo", output:"\u2135", tex:null, ttype:CONST},
237
+ {input:"...", tag:"mo", output:"...", tex:"ldots", ttype:CONST},
238
+ {input:":.", tag:"mo", output:"\u2234", tex:"therefore", ttype:CONST},
239
+ {input:"/_", tag:"mo", output:"\u2220", tex:"angle", ttype:CONST},
240
+ {input:"\\ ", tag:"mo", output:"\u00A0", tex:null, ttype:CONST},
241
+ {input:"quad", tag:"mo", output:"\u00A0\u00A0", tex:null, ttype:CONST},
242
+ {input:"qquad", tag:"mo", output:"\u00A0\u00A0\u00A0\u00A0", tex:null, ttype:CONST},
243
+ {input:"cdots", tag:"mo", output:"\u22EF", tex:null, ttype:CONST},
244
+ {input:"vdots", tag:"mo", output:"\u22EE", tex:null, ttype:CONST},
245
+ {input:"ddots", tag:"mo", output:"\u22F1", tex:null, ttype:CONST},
246
+ {input:"diamond", tag:"mo", output:"\u22C4", tex:null, ttype:CONST},
247
+ {input:"square", tag:"mo", output:"\u25A1", tex:null, ttype:CONST},
248
+ {input:"|__", tag:"mo", output:"\u230A", tex:"lfloor", ttype:CONST},
249
+ {input:"__|", tag:"mo", output:"\u230B", tex:"rfloor", ttype:CONST},
250
+ {input:"|~", tag:"mo", output:"\u2308", tex:"lceiling", ttype:CONST},
251
+ {input:"~|", tag:"mo", output:"\u2309", tex:"rceiling", ttype:CONST},
252
+ {input:"CC", tag:"mo", output:"\u2102", tex:null, ttype:CONST},
253
+ {input:"NN", tag:"mo", output:"\u2115", tex:null, ttype:CONST},
254
+ {input:"QQ", tag:"mo", output:"\u211A", tex:null, ttype:CONST},
255
+ {input:"RR", tag:"mo", output:"\u211D", tex:null, ttype:CONST},
256
+ {input:"ZZ", tag:"mo", output:"\u2124", tex:null, ttype:CONST},
257
+ {input:"f", tag:"mi", output:"f", tex:null, ttype:UNARY, func:true},
258
+ {input:"g", tag:"mi", output:"g", tex:null, ttype:UNARY, func:true},
259
+
260
+ //standard functions
261
+ {input:"lim", tag:"mo", output:"lim", tex:null, ttype:UNDEROVER},
262
+ {input:"Lim", tag:"mo", output:"Lim", tex:null, ttype:UNDEROVER},
263
+ {input:"sin", tag:"mo", output:"sin", tex:null, ttype:UNARY, func:true},
264
+ {input:"cos", tag:"mo", output:"cos", tex:null, ttype:UNARY, func:true},
265
+ {input:"tan", tag:"mo", output:"tan", tex:null, ttype:UNARY, func:true},
266
+ {input:"sinh", tag:"mo", output:"sinh", tex:null, ttype:UNARY, func:true},
267
+ {input:"cosh", tag:"mo", output:"cosh", tex:null, ttype:UNARY, func:true},
268
+ {input:"tanh", tag:"mo", output:"tanh", tex:null, ttype:UNARY, func:true},
269
+ {input:"cot", tag:"mo", output:"cot", tex:null, ttype:UNARY, func:true},
270
+ {input:"sec", tag:"mo", output:"sec", tex:null, ttype:UNARY, func:true},
271
+ {input:"csc", tag:"mo", output:"csc", tex:null, ttype:UNARY, func:true},
272
+ {input:"log", tag:"mo", output:"log", tex:null, ttype:UNARY, func:true},
273
+ {input:"ln", tag:"mo", output:"ln", tex:null, ttype:UNARY, func:true},
274
+ {input:"det", tag:"mo", output:"det", tex:null, ttype:UNARY, func:true},
275
+ {input:"dim", tag:"mo", output:"dim", tex:null, ttype:CONST},
276
+ {input:"mod", tag:"mo", output:"mod", tex:null, ttype:CONST},
277
+ {input:"gcd", tag:"mo", output:"gcd", tex:null, ttype:UNARY, func:true},
278
+ {input:"lcm", tag:"mo", output:"lcm", tex:null, ttype:UNARY, func:true},
279
+ {input:"lub", tag:"mo", output:"lub", tex:null, ttype:CONST},
280
+ {input:"glb", tag:"mo", output:"glb", tex:null, ttype:CONST},
281
+ {input:"min", tag:"mo", output:"min", tex:null, ttype:UNDEROVER},
282
+ {input:"max", tag:"mo", output:"max", tex:null, ttype:UNDEROVER},
283
+
284
+ //arrows
285
+ {input:"uarr", tag:"mo", output:"\u2191", tex:"uparrow", ttype:CONST},
286
+ {input:"darr", tag:"mo", output:"\u2193", tex:"downarrow", ttype:CONST},
287
+ {input:"rarr", tag:"mo", output:"\u2192", tex:"rightarrow", ttype:CONST},
288
+ {input:"->", tag:"mo", output:"\u2192", tex:"to", ttype:CONST},
289
+ {input:"|->", tag:"mo", output:"\u21A6", tex:"mapsto", ttype:CONST},
290
+ {input:"larr", tag:"mo", output:"\u2190", tex:"leftarrow", ttype:CONST},
291
+ {input:"harr", tag:"mo", output:"\u2194", tex:"leftrightarrow", ttype:CONST},
292
+ {input:"rArr", tag:"mo", output:"\u21D2", tex:"Rightarrow", ttype:CONST},
293
+ {input:"lArr", tag:"mo", output:"\u21D0", tex:"Leftarrow", ttype:CONST},
294
+ {input:"hArr", tag:"mo", output:"\u21D4", tex:"Leftrightarrow", ttype:CONST},
295
+
296
+ //commands with argument
297
+ AMsqrt, AMroot, AMfrac, AMdiv, AMover, AMsub, AMsup,
298
+ {input:"hat", tag:"mover", output:"\u005E", tex:null, ttype:UNARY, acc:true},
299
+ {input:"bar", tag:"mover", output:"\u00AF", tex:"overline", ttype:UNARY, acc:true},
300
+ {input:"vec", tag:"mover", output:"\u2192", tex:null, ttype:UNARY, acc:true},
301
+ {input:"dot", tag:"mover", output:".", tex:null, ttype:UNARY, acc:true},
302
+ {input:"ddot", tag:"mover", output:"..", tex:null, ttype:UNARY, acc:true},
303
+ {input:"ul", tag:"munder", output:"\u0332", tex:"underline", ttype:UNARY, acc:true},
304
+ AMtext, AMmbox, AMquote,
305
+ {input:"bb", tag:"mstyle", atname:"fontweight", atval:"bold", output:"bb", tex:null, ttype:UNARY},
306
+ {input:"mathbf", tag:"mstyle", atname:"fontweight", atval:"bold", output:"mathbf", tex:null, ttype:UNARY},
307
+ {input:"sf", tag:"mstyle", atname:"fontfamily", atval:"sans-serif", output:"sf", tex:null, ttype:UNARY},
308
+ {input:"mathsf", tag:"mstyle", atname:"fontfamily", atval:"sans-serif", output:"mathsf", tex:null, ttype:UNARY},
309
+ {input:"bbb", tag:"mstyle", atname:"mathvariant", atval:"double-struck", output:"bbb", tex:null, ttype:UNARY, codes:AMbbb},
310
+ {input:"mathbb", tag:"mstyle", atname:"mathvariant", atval:"double-struck", output:"mathbb", tex:null, ttype:UNARY, codes:AMbbb},
311
+ {input:"cc", tag:"mstyle", atname:"mathvariant", atval:"script", output:"cc", tex:null, ttype:UNARY, codes:AMcal},
312
+ {input:"mathcal", tag:"mstyle", atname:"mathvariant", atval:"script", output:"mathcal", tex:null, ttype:UNARY, codes:AMcal},
313
+ {input:"tt", tag:"mstyle", atname:"fontfamily", atval:"monospace", output:"tt", tex:null, ttype:UNARY},
314
+ {input:"mathtt", tag:"mstyle", atname:"fontfamily", atval:"monospace", output:"mathtt", tex:null, ttype:UNARY},
315
+ {input:"fr", tag:"mstyle", atname:"mathvariant", atval:"fraktur", output:"fr", tex:null, ttype:UNARY, codes:AMfrk},
316
+ {input:"mathfrak", tag:"mstyle", atname:"mathvariant", atval:"fraktur", output:"mathfrak", tex:null, ttype:UNARY, codes:AMfrk}
317
+ ];
318
+
319
+ function compareNames(s1,s2) {
320
+ if (s1.input > s2.input) return 1
321
+ else return -1;
322
+ }
323
+
324
+ var AMnames = []; //list of input symbols
325
+
326
+ function AMinitSymbols() {
327
+ var texsymbols = [], i;
328
+ for (i=0; i<AMsymbols.length; i++)
329
+ if (AMsymbols[i].tex)
330
+ texsymbols[texsymbols.length] = {input:AMsymbols[i].tex,
331
+ tag:AMsymbols[i].tag, output:AMsymbols[i].output, ttype:AMsymbols[i].ttype};
332
+ AMsymbols = AMsymbols.concat(texsymbols);
333
+ AMsymbols.sort(compareNames);
334
+ for (i=0; i<AMsymbols.length; i++) AMnames[i] = AMsymbols[i].input;
335
+ }
336
+
337
+ var AMmathml = "http://www.w3.org/1998/Math/MathML";
338
+
339
+ function AMcreateElementMathML(t) {
340
+ if (isIE) return document.createElement("m:"+t);
341
+ else return document.createElementNS(AMmathml,t);
342
+ }
343
+
344
+ function AMcreateMmlNode(t,frag) {
345
+ // var node = AMcreateElementMathML(name);
346
+ if (isIE) var node = document.createElement("m:"+t);
347
+ else var node = document.createElementNS(AMmathml,t);
348
+ node.appendChild(frag);
349
+ return node;
350
+ }
351
+
352
+ function newcommand(oldstr,newstr) {
353
+ AMsymbols = AMsymbols.concat([{input:oldstr, tag:"mo", output:newstr,
354
+ tex:null, ttype:DEFINITION}]);
355
+ }
356
+
357
+ function AMremoveCharsAndBlanks(str,n) {
358
+ //remove n characters and any following blanks
359
+ var st;
360
+ if (str.charAt(n)=="\\" && str.charAt(n+1)!="\\" && str.charAt(n+1)!=" ")
361
+ st = str.slice(n+1);
362
+ else st = str.slice(n);
363
+ for (var i=0; i<st.length && st.charCodeAt(i)<=32; i=i+1);
364
+ return st.slice(i);
365
+ }
366
+
367
+ function AMposition(arr, str, n) {
368
+ // return position >=n where str appears or would be inserted
369
+ // assumes arr is sorted
370
+ if (n==0) {
371
+ var h,m;
372
+ n = -1;
373
+ h = arr.length;
374
+ while (n+1<h) {
375
+ m = (n+h) >> 1;
376
+ if (arr[m]<str) n = m; else h = m;
377
+ }
378
+ return h;
379
+ } else
380
+ for (var i=n; i<arr.length && arr[i]<str; i++);
381
+ return i; // i=arr.length || arr[i]>=str
382
+ }
383
+
384
+ function AMgetSymbol(str) {
385
+ //return maximal initial substring of str that appears in names
386
+ //return null if there is none
387
+ var k = 0; //new pos
388
+ var j = 0; //old pos
389
+ var mk; //match pos
390
+ var st;
391
+ var tagst;
392
+ var match = "";
393
+ var more = true;
394
+ for (var i=1; i<=str.length && more; i++) {
395
+ st = str.slice(0,i); //initial substring of length i
396
+ j = k;
397
+ k = AMposition(AMnames, st, j);
398
+ if (k<AMnames.length && str.slice(0,AMnames[k].length)==AMnames[k]){
399
+ match = AMnames[k];
400
+ mk = k;
401
+ i = match.length;
402
+ }
403
+ more = k<AMnames.length && str.slice(0,AMnames[k].length)>=AMnames[k];
404
+ }
405
+ AMpreviousSymbol=AMcurrentSymbol;
406
+ if (match!=""){
407
+ AMcurrentSymbol=AMsymbols[mk].ttype;
408
+ return AMsymbols[mk];
409
+ }
410
+ // if str[0] is a digit or - return maxsubstring of digits.digits
411
+ AMcurrentSymbol=CONST;
412
+ k = 1;
413
+ st = str.slice(0,1);
414
+ var integ = true;
415
+ while ("0"<=st && st<="9" && k<=str.length) {
416
+ st = str.slice(k,k+1);
417
+ k++;
418
+ }
419
+ if (st == decimalsign) {
420
+ st = str.slice(k,k+1);
421
+ if ("0"<=st && st<="9") {
422
+ integ = false;
423
+ k++;
424
+ while ("0"<=st && st<="9" && k<=str.length) {
425
+ st = str.slice(k,k+1);
426
+ k++;
427
+ }
428
+ }
429
+ }
430
+ if ((integ && k>1) || k>2) {
431
+ st = str.slice(0,k-1);
432
+ tagst = "mn";
433
+ } else {
434
+ k = 2;
435
+ st = str.slice(0,1); //take 1 character
436
+ tagst = (("A">st || st>"Z") && ("a">st || st>"z")?"mo":"mi");
437
+ }
438
+ if (st=="-" && AMpreviousSymbol==INFIX) {
439
+ AMcurrentSymbol = INFIX; //trick "/" into recognizing "-" on second parse
440
+ return {input:st, tag:tagst, output:st, ttype:UNARY, func:true};
441
+ }
442
+ return {input:st, tag:tagst, output:st, ttype:CONST};
443
+ }
444
+
445
+ function AMremoveBrackets(node) {
446
+ var st;
447
+ if (node.nodeName=="mrow") {
448
+ st = node.firstChild.firstChild.nodeValue;
449
+ if (st=="(" || st=="[" || st=="{") node.removeChild(node.firstChild);
450
+ }
451
+ if (node.nodeName=="mrow") {
452
+ st = node.lastChild.firstChild.nodeValue;
453
+ if (st==")" || st=="]" || st=="}") node.removeChild(node.lastChild);
454
+ }
455
+ }
456
+
457
+ /*Parsing ASCII math expressions with the following grammar
458
+ v ::= [A-Za-z] | greek letters | numbers | other constant symbols
459
+ u ::= sqrt | text | bb | other unary symbols for font commands
460
+ b ::= frac | root | stackrel binary symbols
461
+ l ::= ( | [ | { | (: | {: left brackets
462
+ r ::= ) | ] | } | :) | :} right brackets
463
+ S ::= v | lEr | uS | bSS Simple expression
464
+ I ::= S_S | S^S | S_S^S | S Intermediate expression
465
+ E ::= IE | I/I Expression
466
+ Each terminal symbol is translated into a corresponding mathml node.*/
467
+
468
+ var AMnestingDepth,AMpreviousSymbol,AMcurrentSymbol;
469
+
470
+ function AMparseSexpr(str) { //parses str and returns [node,tailstr]
471
+ var symbol, node, result, i, st,// rightvert = false,
472
+ newFrag = document.createDocumentFragment();
473
+ str = AMremoveCharsAndBlanks(str,0);
474
+ symbol = AMgetSymbol(str); //either a token or a bracket or empty
475
+ if (symbol == null || symbol.ttype == RIGHTBRACKET && AMnestingDepth > 0) {
476
+ return [null,str];
477
+ }
478
+ if (symbol.ttype == DEFINITION) {
479
+ str = symbol.output+AMremoveCharsAndBlanks(str,symbol.input.length);
480
+ symbol = AMgetSymbol(str);
481
+ }
482
+ switch (symbol.ttype) {
483
+ case UNDEROVER:
484
+ case CONST:
485
+ str = AMremoveCharsAndBlanks(str,symbol.input.length);
486
+ return [AMcreateMmlNode(symbol.tag, //its a constant
487
+ document.createTextNode(symbol.output)),str];
488
+ case LEFTBRACKET: //read (expr+)
489
+ AMnestingDepth++;
490
+ str = AMremoveCharsAndBlanks(str,symbol.input.length);
491
+ result = AMparseExpr(str,true);
492
+ AMnestingDepth--;
493
+ if (typeof symbol.invisible == "boolean" && symbol.invisible)
494
+ node = AMcreateMmlNode("mrow",result[0]);
495
+ else {
496
+ node = AMcreateMmlNode("mo",document.createTextNode(symbol.output));
497
+ node = AMcreateMmlNode("mrow",node);
498
+ node.appendChild(result[0]);
499
+ }
500
+ return [node,result[1]];
501
+ case TEXT:
502
+ if (symbol!=AMquote) str = AMremoveCharsAndBlanks(str,symbol.input.length);
503
+ if (str.charAt(0)=="{") i=str.indexOf("}");
504
+ else if (str.charAt(0)=="(") i=str.indexOf(")");
505
+ else if (str.charAt(0)=="[") i=str.indexOf("]");
506
+ else if (symbol==AMquote) i=str.slice(1).indexOf("\"")+1;
507
+ else i = 0;
508
+ if (i==-1) i = str.length;
509
+ st = str.slice(1,i);
510
+ if (st.charAt(0) == " ") {
511
+ node = AMcreateElementMathML("mspace");
512
+ node.setAttribute("width","1ex");
513
+ newFrag.appendChild(node);
514
+ }
515
+ newFrag.appendChild(
516
+ AMcreateMmlNode(symbol.tag,document.createTextNode(st)));
517
+ if (st.charAt(st.length-1) == " ") {
518
+ node = AMcreateElementMathML("mspace");
519
+ node.setAttribute("width","1ex");
520
+ newFrag.appendChild(node);
521
+ }
522
+ str = AMremoveCharsAndBlanks(str,i+1);
523
+ return [AMcreateMmlNode("mrow",newFrag),str];
524
+ case UNARY:
525
+ str = AMremoveCharsAndBlanks(str,symbol.input.length);
526
+ result = AMparseSexpr(str);
527
+ if (result[0]==null) return [AMcreateMmlNode(symbol.tag,
528
+ document.createTextNode(symbol.output)),str];
529
+ if (typeof symbol.func == "boolean" && symbol.func) { // functions hack
530
+ st = str.charAt(0);
531
+ if (st=="^" || st=="_" || st=="/" || st=="|" || st==",") {
532
+ return [AMcreateMmlNode(symbol.tag,
533
+ document.createTextNode(symbol.output)),str];
534
+ } else {
535
+ node = AMcreateMmlNode("mrow",
536
+ AMcreateMmlNode(symbol.tag,document.createTextNode(symbol.output)));
537
+ node.appendChild(result[0]);
538
+ return [node,result[1]];
539
+ }
540
+ }
541
+ AMremoveBrackets(result[0]);
542
+ if (symbol.input == "sqrt") { // sqrt
543
+ return [AMcreateMmlNode(symbol.tag,result[0]),result[1]];
544
+ } else if (typeof symbol.acc == "boolean" && symbol.acc) { // accent
545
+ node = AMcreateMmlNode(symbol.tag,result[0]);
546
+ node.appendChild(AMcreateMmlNode("mo",document.createTextNode(symbol.output)));
547
+ return [node,result[1]];
548
+ } else { // font change command
549
+ if (!isIE && typeof symbol.codes != "undefined") {
550
+ for (i=0; i<result[0].childNodes.length; i++)
551
+ if (result[0].childNodes[i].nodeName=="mi" || result[0].nodeName=="mi") {
552
+ st = (result[0].nodeName=="mi"?result[0].firstChild.nodeValue:
553
+ result[0].childNodes[i].firstChild.nodeValue);
554
+ var newst = [];
555
+ for (var j=0; j<st.length; j++)
556
+ if (st.charCodeAt(j)>64 && st.charCodeAt(j)<91) newst = newst +
557
+ String.fromCharCode(symbol.codes[st.charCodeAt(j)-65]);
558
+ else newst = newst + st.charAt(j);
559
+ if (result[0].nodeName=="mi")
560
+ result[0]=AMcreateElementMathML("mo").
561
+ appendChild(document.createTextNode(newst));
562
+ else result[0].replaceChild(AMcreateElementMathML("mo").
563
+ appendChild(document.createTextNode(newst)),result[0].childNodes[i]);
564
+ }
565
+ }
566
+ node = AMcreateMmlNode(symbol.tag,result[0]);
567
+ node.setAttribute(symbol.atname,symbol.atval);
568
+ return [node,result[1]];
569
+ }
570
+ case BINARY:
571
+ str = AMremoveCharsAndBlanks(str,symbol.input.length);
572
+ result = AMparseSexpr(str);
573
+ if (result[0]==null) return [AMcreateMmlNode("mo",
574
+ document.createTextNode(symbol.input)),str];
575
+ AMremoveBrackets(result[0]);
576
+ var result2 = AMparseSexpr(result[1]);
577
+ if (result2[0]==null) return [AMcreateMmlNode("mo",
578
+ document.createTextNode(symbol.input)),str];
579
+ AMremoveBrackets(result2[0]);
580
+ if (symbol.input=="root" || symbol.input=="stackrel")
581
+ newFrag.appendChild(result2[0]);
582
+ newFrag.appendChild(result[0]);
583
+ if (symbol.input=="frac") newFrag.appendChild(result2[0]);
584
+ return [AMcreateMmlNode(symbol.tag,newFrag),result2[1]];
585
+ case INFIX:
586
+ str = AMremoveCharsAndBlanks(str,symbol.input.length);
587
+ return [AMcreateMmlNode("mo",document.createTextNode(symbol.output)),str];
588
+ case SPACE:
589
+ str = AMremoveCharsAndBlanks(str,symbol.input.length);
590
+ node = AMcreateElementMathML("mspace");
591
+ node.setAttribute("width","1ex");
592
+ newFrag.appendChild(node);
593
+ newFrag.appendChild(
594
+ AMcreateMmlNode(symbol.tag,document.createTextNode(symbol.output)));
595
+ node = AMcreateElementMathML("mspace");
596
+ node.setAttribute("width","1ex");
597
+ newFrag.appendChild(node);
598
+ return [AMcreateMmlNode("mrow",newFrag),str];
599
+ case LEFTRIGHT:
600
+ // if (rightvert) return [null,str]; else rightvert = true;
601
+ AMnestingDepth++;
602
+ str = AMremoveCharsAndBlanks(str,symbol.input.length);
603
+ result = AMparseExpr(str,false);
604
+ AMnestingDepth--;
605
+ var st = "";
606
+ if (result[0].lastChild!=null)
607
+ st = result[0].lastChild.firstChild.nodeValue;
608
+ if (st == "|") { // its an absolute value subterm
609
+ node = AMcreateMmlNode("mo",document.createTextNode(symbol.output));
610
+ node = AMcreateMmlNode("mrow",node);
611
+ node.appendChild(result[0]);
612
+ return [node,result[1]];
613
+ } else { // the "|" is a \mid
614
+ node = AMcreateMmlNode("mo",document.createTextNode(symbol.output));
615
+ node = AMcreateMmlNode("mrow",node);
616
+ return [node,str];
617
+ }
618
+ default:
619
+ //alert("default");
620
+ str = AMremoveCharsAndBlanks(str,symbol.input.length);
621
+ return [AMcreateMmlNode(symbol.tag, //its a constant
622
+ document.createTextNode(symbol.output)),str];
623
+ }
624
+ }
625
+
626
+ function AMparseIexpr(str) {
627
+ var symbol, sym1, sym2, node, result, underover;
628
+ str = AMremoveCharsAndBlanks(str,0);
629
+ sym1 = AMgetSymbol(str);
630
+ result = AMparseSexpr(str);
631
+ node = result[0];
632
+ str = result[1];
633
+ symbol = AMgetSymbol(str);
634
+ if (symbol.ttype == INFIX && symbol.input != "/") {
635
+ str = AMremoveCharsAndBlanks(str,symbol.input.length);
636
+ // if (symbol.input == "/") result = AMparseIexpr(str); else ...
637
+ result = AMparseSexpr(str);
638
+ if (result[0] == null) // show box in place of missing argument
639
+ result[0] = AMcreateMmlNode("mo",document.createTextNode("\u25A1"));
640
+ else AMremoveBrackets(result[0]);
641
+ str = result[1];
642
+ // if (symbol.input == "/") AMremoveBrackets(node);
643
+ if (symbol.input == "_") {
644
+ sym2 = AMgetSymbol(str);
645
+ underover = (sym1.ttype == UNDEROVER);
646
+ if (sym2.input == "^") {
647
+ str = AMremoveCharsAndBlanks(str,sym2.input.length);
648
+ var res2 = AMparseSexpr(str);
649
+ AMremoveBrackets(res2[0]);
650
+ str = res2[1];
651
+ node = AMcreateMmlNode((underover?"munderover":"msubsup"),node);
652
+ node.appendChild(result[0]);
653
+ node.appendChild(res2[0]);
654
+ node = AMcreateMmlNode("mrow",node); // so sum does not stretch
655
+ } else {
656
+ node = AMcreateMmlNode((underover?"munder":"msub"),node);
657
+ node.appendChild(result[0]);
658
+ }
659
+ } else {
660
+ node = AMcreateMmlNode(symbol.tag,node);
661
+ node.appendChild(result[0]);
662
+ }
663
+ }
664
+ return [node,str];
665
+ }
666
+
667
+ function AMparseExpr(str,rightbracket) {
668
+ var symbol, node, result, i, nodeList = [],
669
+ newFrag = document.createDocumentFragment();
670
+ do {
671
+ str = AMremoveCharsAndBlanks(str,0);
672
+ result = AMparseIexpr(str);
673
+ node = result[0];
674
+ str = result[1];
675
+ symbol = AMgetSymbol(str);
676
+ if (symbol.ttype == INFIX && symbol.input == "/") {
677
+ str = AMremoveCharsAndBlanks(str,symbol.input.length);
678
+ result = AMparseIexpr(str);
679
+ if (result[0] == null) // show box in place of missing argument
680
+ result[0] = AMcreateMmlNode("mo",document.createTextNode("\u25A1"));
681
+ else AMremoveBrackets(result[0]);
682
+ str = result[1];
683
+ AMremoveBrackets(node);
684
+ node = AMcreateMmlNode(symbol.tag,node);
685
+ node.appendChild(result[0]);
686
+ newFrag.appendChild(node);
687
+ symbol = AMgetSymbol(str);
688
+ }
689
+ else if (node!=undefined) newFrag.appendChild(node);
690
+ } while ((symbol.ttype != RIGHTBRACKET &&
691
+ (symbol.ttype != LEFTRIGHT || rightbracket)
692
+ || AMnestingDepth == 0) && symbol!=null && symbol.output!="");
693
+ if (symbol.ttype == RIGHTBRACKET || symbol.ttype == LEFTRIGHT) {
694
+ // if (AMnestingDepth > 0) AMnestingDepth--;
695
+ var len = newFrag.childNodes.length;
696
+ if (len>0 && newFrag.childNodes[len-1].nodeName == "mrow" && len>1 &&
697
+ newFrag.childNodes[len-2].nodeName == "mo" &&
698
+ newFrag.childNodes[len-2].firstChild.nodeValue == ",") { //matrix
699
+ var right = newFrag.childNodes[len-1].lastChild.firstChild.nodeValue;
700
+ if (right==")" || right=="]") {
701
+ var left = newFrag.childNodes[len-1].firstChild.firstChild.nodeValue;
702
+ if (left=="(" && right==")" && symbol.output != "}" ||
703
+ left=="[" && right=="]") {
704
+ var pos = []; // positions of commas
705
+ var matrix = true;
706
+ var m = newFrag.childNodes.length;
707
+ for (i=0; matrix && i<m; i=i+2) {
708
+ pos[i] = [];
709
+ node = newFrag.childNodes[i];
710
+ if (matrix) matrix = node.nodeName=="mrow" &&
711
+ (i==m-1 || node.nextSibling.nodeName=="mo" &&
712
+ node.nextSibling.firstChild.nodeValue==",")&&
713
+ node.firstChild.firstChild.nodeValue==left &&
714
+ node.lastChild.firstChild.nodeValue==right;
715
+ if (matrix)
716
+ for (var j=0; j<node.childNodes.length; j++)
717
+ if (node.childNodes[j].firstChild.nodeValue==",")
718
+ pos[i][pos[i].length]=j;
719
+ if (matrix && i>1) matrix = pos[i].length == pos[i-2].length;
720
+ }
721
+ if (matrix) {
722
+ var row, frag, n, k, table = document.createDocumentFragment();
723
+ for (i=0; i<m; i=i+2) {
724
+ row = document.createDocumentFragment();
725
+ frag = document.createDocumentFragment();
726
+ node = newFrag.firstChild; // <mrow>(-,-,...,-,-)</mrow>
727
+ n = node.childNodes.length;
728
+ k = 0;
729
+ node.removeChild(node.firstChild); //remove (
730
+ for (j=1; j<n-1; j++) {
731
+ if (typeof pos[i][k] != "undefined" && j==pos[i][k]){
732
+ node.removeChild(node.firstChild); //remove ,
733
+ row.appendChild(AMcreateMmlNode("mtd",frag));
734
+ k++;
735
+ } else frag.appendChild(node.firstChild);
736
+ }
737
+ row.appendChild(AMcreateMmlNode("mtd",frag));
738
+ if (newFrag.childNodes.length>2) {
739
+ newFrag.removeChild(newFrag.firstChild); //remove <mrow>)</mrow>
740
+ newFrag.removeChild(newFrag.firstChild); //remove <mo>,</mo>
741
+ }
742
+ table.appendChild(AMcreateMmlNode("mtr",row));
743
+ }
744
+ node = AMcreateMmlNode("mtable",table);
745
+ if (typeof symbol.invisible == "boolean" && symbol.invisible) node.setAttribute("columnalign","left");
746
+ newFrag.replaceChild(node,newFrag.firstChild);
747
+ }
748
+ }
749
+ }
750
+ }
751
+ str = AMremoveCharsAndBlanks(str,symbol.input.length);
752
+ if (typeof symbol.invisible != "boolean" || !symbol.invisible) {
753
+ node = AMcreateMmlNode("mo",document.createTextNode(symbol.output));
754
+ newFrag.appendChild(node);
755
+ }
756
+ }
757
+ return [newFrag,str];
758
+ }
759
+
760
+ function AMparseMath(str) {
761
+ var result, node = AMcreateElementMathML("mstyle");
762
+ if (mathcolor != "") node.setAttribute("mathcolor",mathcolor);
763
+ if (displaystyle) node.setAttribute("displaystyle","true");
764
+ if (mathfontfamily != "") node.setAttribute("fontfamily",mathfontfamily);
765
+ AMnestingDepth = 0;
766
+ node.appendChild(AMparseExpr(str.replace(/^\s+/g,""),false)[0]);
767
+ node = AMcreateMmlNode("math",node);
768
+ if (showasciiformulaonhover) //fixed by djhsu so newline
769
+ node.setAttribute("title",str.replace(/\s+/g," "));//does not show in Gecko
770
+ if (mathfontfamily != "" && (isIE || mathfontfamily != "serif")) {
771
+ var fnode = AMcreateElementXHTML("font");
772
+ fnode.setAttribute("face",mathfontfamily);
773
+ fnode.appendChild(node);
774
+ return fnode;
775
+ }
776
+ return node;
777
+ }
778
+
779
+ function AMstrarr2docFrag(arr, linebreaks) {
780
+ var newFrag=document.createDocumentFragment();
781
+ var expr = false;
782
+ for (var i=0; i<arr.length; i++) {
783
+ if (expr) newFrag.appendChild(AMparseMath(arr[i]));
784
+ else {
785
+ var arri = (linebreaks ? arr[i].split("\n\n") : [arr[i]]);
786
+ newFrag.appendChild(AMcreateElementXHTML("span").
787
+ appendChild(document.createTextNode(arri[0])));
788
+ for (var j=1; j<arri.length; j++) {
789
+ newFrag.appendChild(AMcreateElementXHTML("p"));
790
+ newFrag.appendChild(AMcreateElementXHTML("span").
791
+ appendChild(document.createTextNode(arri[j])));
792
+ }
793
+ }
794
+ expr = !expr;
795
+ }
796
+ return newFrag;
797
+ }
798
+
799
+ function AMprocessNodeR(n, linebreaks) {
800
+ var mtch, str, arr, frg, i;
801
+ if (n.childNodes.length == 0) {
802
+ if ((n.nodeType!=8 || linebreaks) &&
803
+ n.parentNode.nodeName!="form" && n.parentNode.nodeName!="FORM" &&
804
+ n.parentNode.nodeName!="textarea" && n.parentNode.nodeName!="TEXTAREA" &&
805
+ n.parentNode.nodeName!="pre" && n.parentNode.nodeName!="PRE") {
806
+ str = n.nodeValue;
807
+ if (!(str == null)) {
808
+ str = str.replace(/\r\n\r\n/g,"\n\n");
809
+ if (doubleblankmathdelimiter) {
810
+ str = str.replace(/\x20\x20\./g," "+AMdelimiter1+".");
811
+ str = str.replace(/\x20\x20,/g," "+AMdelimiter1+",");
812
+ str = str.replace(/\x20\x20/g," "+AMdelimiter1+" ");
813
+ }
814
+ str = str.replace(/\x20+/g," ");
815
+ str = str.replace(/\s*\r\n/g," ");
816
+ mtch = false;
817
+ str = str.replace(new RegExp(AMescape2, "g"),
818
+ function(st){mtch=true;return "AMescape2"});
819
+ str = str.replace(new RegExp(AMescape1, "g"),
820
+ function(st){mtch=true;return "AMescape1"});
821
+ str = str.replace(new RegExp(AMdelimiter2regexp, "g"),AMdelimiter1);
822
+ arr = str.split(AMdelimiter1);
823
+ for (i=0; i<arr.length; i++)
824
+ arr[i]=arr[i].replace(/AMescape2/g,AMdelimiter2).
825
+ replace(/AMescape1/g,AMdelimiter1);
826
+ if (arr.length>1 || mtch) {
827
+ if (checkForMathML) {
828
+ checkForMathML = false;
829
+ var nd = AMisMathMLavailable();
830
+ AMnoMathML = nd != null;
831
+ if (AMnoMathML && notifyIfNoMathML)
832
+ if (alertIfNoMathML)
833
+ alert("To view the ASCIIMathML notation use Internet Explorer 6 +\nMathPlayer (free from www.dessci.com)\n\
834
+ or Firefox/Mozilla/Netscape");
835
+ else AMbody.insertBefore(nd,AMbody.childNodes[0]);
836
+ }
837
+ if (!AMnoMathML) {
838
+ frg = AMstrarr2docFrag(arr,n.nodeType==8);
839
+ var len = frg.childNodes.length;
840
+ n.parentNode.replaceChild(frg,n);
841
+ return len-1;
842
+ } else return 0;
843
+ }
844
+ }
845
+ } else return 0;
846
+ } else if (n.nodeName!="math") {
847
+ for (i=0; i<n.childNodes.length; i++)
848
+ i += AMprocessNodeR(n.childNodes[i], linebreaks);
849
+ }
850
+ return 0;
851
+ }
852
+
853
+ function AMprocessNode(n, linebreaks, spanclassAM) {
854
+ var frag,st;
855
+ if (spanclassAM!=null) {
856
+ frag = document.getElementsByTagName("span")
857
+ for (var i=0;i<frag.length;i++)
858
+ if (frag[i].className == "AM")
859
+ AMprocessNodeR(frag[i],linebreaks);
860
+ } else {
861
+ try {
862
+ st = n.innerHTML;
863
+ } catch(err) {}
864
+ if (st==null ||
865
+ st.indexOf(AMdelimiter1)!=-1 || st.indexOf(AMdelimiter2)!=-1)
866
+ AMprocessNodeR(n,linebreaks);
867
+ }
868
+ if (isIE) { //needed to match size and font of formula to surrounding text
869
+ frag = document.getElementsByTagName('math');
870
+ for (var i=0;i<frag.length;i++) frag[i].update()
871
+ }
872
+ }
873
+
874
+ var AMbody;
875
+ var AMnoMathML = false, AMtranslated = false;
876
+
877
+ function translate(spanclassAM) {
878
+ if (!AMtranslated) { // run this only once
879
+ AMtranslated = true;
880
+ AMinitSymbols();
881
+ AMbody = document.getElementsByTagName("body")[0];
882
+ AMprocessNode(AMbody, false, spanclassAM);
883
+ }
884
+ }
885
+
886
+ if (isIE) { // avoid adding MathPlayer info explicitly to each webpage
887
+ document.write("<object id=\"mathplayer\"\
888
+ classid=\"clsid:32F66A20-7614-11D4-BD11-00104BD3F987\"></object>");
889
+ document.write("<?import namespace=\"m\" implementation=\"#mathplayer\"?>");
890
+ }
891
+
892
+ // GO1.1 Generic onload by Brothercake
893
+ // http://www.brothercake.com/
894
+ //onload function (replaces the onload="translate()" in the <body> tag)
895
+ function generic()
896
+ {
897
+ translate();
898
+ };
899
+ //setup onload function
900
+ if(typeof window.addEventListener != 'undefined')
901
+ {
902
+ //.. gecko, safari, konqueror and standard
903
+ window.addEventListener('load', generic, false);
904
+ }
905
+ else if(typeof document.addEventListener != 'undefined')
906
+ {
907
+ //.. opera 7
908
+ document.addEventListener('load', generic, false);
909
+ }
910
+ else if(typeof window.attachEvent != 'undefined')
911
+ {
912
+ //.. win/ie
913
+ window.attachEvent('onload', generic);
914
+ }
915
+ //** remove this condition to degrade older browsers
916
+ else
917
+ {
918
+ //.. mac/ie5 and anything else that gets this far
919
+ //if there's an existing onload function
920
+ if(typeof window.onload == 'function')
921
+ {
922
+ //store it
923
+ var existing = onload;
924
+ //add new onload handler
925
+ window.onload = function()
926
+ {
927
+ //call existing onload function
928
+ existing();
929
+ //call generic onload function
930
+ generic();
931
+ };
932
+ }
933
+ else
934
+ {
935
+ //setup onload function
936
+ window.onload = generic;
937
+ }
938
+ }