]> granicus.if.org Git - multimarkdown/commitdiff
FIXED: Improve consistency of math token handling
authorFletcher T. Penney <fletcher@fletcherpenney.net>
Fri, 13 Oct 2017 12:36:05 +0000 (08:36 -0400)
committerFletcher T. Penney <fletcher@fletcherpenney.net>
Fri, 13 Oct 2017 12:36:05 +0000 (08:36 -0400)
15 files changed:
Sources/libMultiMarkdown/html.c
Sources/libMultiMarkdown/latex.c
Sources/libMultiMarkdown/opendocument-content.c
Sources/libMultiMarkdown/opendocument-content.h
tests/MMD6Tests/Integrated.fodt
tests/MMD6Tests/Math.fodt
tests/MMD6Tests/Math.html
tests/MMD6Tests/Math.htmlc
tests/MMD6Tests/Math.tex
tests/MMD6Tests/Math.text
tests/MMD6Tests/Superscript.fodt
tests/MMD6Tests/Superscript.html
tests/MMD6Tests/Superscript.htmlc
tests/MMD6Tests/Superscript.tex
tests/MMD6Tests/Superscript.text

index c2549d30847e940ba17ae63610b202de28b51149..9dbd56e4f74989ee398fcaf43ecf9001fc1beecb 100644 (file)
@@ -2113,6 +2113,26 @@ void mmd_export_token_html_raw(DString * out, const char * source, token * t, sc
                        print_const("&quot;");
                        break;
 
+               case SUBSCRIPT:
+                       if (t->child) {
+                               print_const("~");
+                               mmd_export_token_tree_html_raw(out, source, t->child, scratch);
+                       } else {
+                               print_token(t);
+                       }
+
+                       break;
+
+               case SUPERSCRIPT:
+                       if (t->child) {
+                               print_const("^");
+                               mmd_export_token_tree_html_raw(out, source, t->child, scratch);
+                       } else {
+                               print_token(t);
+                       }
+
+                       break;
+
                case CODE_FENCE:
                        if (t->next) {
                                t->next->type = TEXT_EMPTY;
index 389f686021d9c261d1e780c6695db3d0f04ed083..73cf534f510ef8d6ac2c9f2e48347a489b238c29 100644 (file)
@@ -1992,6 +1992,26 @@ void mmd_export_token_latex_raw(DString * out, const char * source, token * t, s
                        print_token(t);
                        break;
 
+               case SUBSCRIPT:
+                       if (t->child) {
+                               print_const("\\ensuremath{\\sim}");
+                               mmd_export_token_tree_latex_raw(out, source, t->child, scratch);
+                       } else {
+                               print_token(t);
+                       }
+
+                       break;
+
+               case SUPERSCRIPT:
+                       if (t->child) {
+                               print_const("\\^{}");
+                               mmd_export_token_tree_latex_raw(out, source, t->child, scratch);
+                       } else {
+                               print_token(t);
+                       }
+
+                       break;
+
                case CODE_FENCE:
                        if (t->next) {
                                t->next->type = TEXT_EMPTY;
@@ -2159,6 +2179,26 @@ void mmd_export_token_latex_tt(DString * out, const char * source, token * t, sc
                        print_const("\\}\\}");
                        break;
 
+               case SUBSCRIPT:
+                       if (t->child) {
+                               print_const("\\ensuremath{\\sim}");
+                               mmd_export_token_tree_latex_tt(out, source, t->child, scratch);
+                       } else {
+                               print_const("\\ensuremath{\\sim}");
+                       }
+
+                       break;
+
+               case SUPERSCRIPT:
+                       if (t->child) {
+                               print_const("\\^{}");
+                               mmd_export_token_tree_latex_tt(out, source, t->child, scratch);
+                       } else {
+                               print_const("\\^{}");
+                       }
+
+                       break;
+
                case TEXT_BRACE_LEFT:
                        print_const("\\{");
                        break;
index 467c6301779fcc2e5ee072fcf2897b5309ad39c2..1ef47da851738d6cc884d0391380f23c7ce67286 100644 (file)
@@ -324,6 +324,33 @@ void mmd_export_token_opendocument_raw(DString * out, const char * source, token
                        print_const("&quot;");
                        break;
 
+               case MATH_BRACKET_OPEN:
+               case MATH_BRACKET_CLOSE:
+               case MATH_PAREN_OPEN:
+               case MATH_PAREN_CLOSE:
+                       print_token(t);
+                       break;
+
+               case SUBSCRIPT:
+                       if (t->child) {
+                               print_const("~");
+                               mmd_export_token_tree_opendocument_raw(out, source, t->child, scratch);
+                       } else {
+                               print_token(t);
+                       }
+
+                       break;
+
+               case SUPERSCRIPT:
+                       if (t->child) {
+                               print_const("^");
+                               mmd_export_token_tree_opendocument_raw(out, source, t->child, scratch);
+                       } else {
+                               print_token(t);
+                       }
+
+                       break;
+
                case CODE_FENCE:
                        if (t->next) {
                                t->next->type = TEXT_EMPTY;
@@ -361,6 +388,47 @@ void mmd_export_token_tree_opendocument_raw(DString * out, const char * source,
 }
 
 
+void mmd_export_token_tree_opendocument_math(DString * out, const char * source, token * t, scratch_pad * scratch) {
+       while (t != NULL) {
+               if (scratch->skip_token) {
+                       scratch->skip_token--;
+               } else {
+                       mmd_export_token_opendocument_math(out, source, t, scratch);
+               }
+
+               t = t->next;
+       }
+}
+
+
+void mmd_export_token_opendocument_math(DString * out, const char * source, token * t, scratch_pad * scratch) {
+       if (t == NULL) {
+               return;
+       }
+
+       switch (t->type) {
+               case MATH_BRACKET_OPEN:
+                       print_const("\\[");
+                       break;
+
+               case MATH_BRACKET_CLOSE:
+                       print_const("\\]");
+                       break;
+
+               case MATH_PAREN_OPEN:
+                       print_const("\\(");
+                       break;
+
+               case MATH_PAREN_CLOSE:
+                       print_const("\\)");
+                       break;
+
+               default:
+                       mmd_export_token_opendocument_raw(out, source, t, scratch);
+                       break;
+       }
+}
+
 void mmd_export_link_opendocument(DString * out, const char * source, token * text, link * link, scratch_pad * scratch) {
        if (link->url) {
                print_const("<text:a xlink:type=\"simple\" xlink:href=\"");
@@ -1780,8 +1848,13 @@ parse_citation:
                case PAIR_HTML_COMMENT:
                        break;
 
-               case PAIR_EMPH:
                case PAIR_MATH:
+                       print_const("<text:span text:style-name=\"math\">");
+                       mmd_export_token_tree_opendocument_math(out, source, t->child, scratch);
+                       print_const("</text:span>");
+                       break;
+
+               case PAIR_EMPH:
                case PAIR_PAREN:
                case PAIR_QUOTE_DOUBLE:
                case PAIR_QUOTE_SINGLE:
index 4bfd49ecb770e99dd53a8e88efe1305494b6d18b..b795cb9058cf427890523f4daac3ce5005387038 100644 (file)
@@ -112,6 +112,7 @@ void mmd_print_string_opendocument(DString * out, const char * str);
 void mmd_print_localized_char_opendocument(DString * out, unsigned short type, scratch_pad * scratch);
 
 void mmd_export_token_opendocument_raw(DString * out, const char * source, token * t, scratch_pad * scratch);
+void mmd_export_token_opendocument_math(DString * out, const char * source, token * t, scratch_pad * scratch);
 
 void mmd_export_link_opendocument(DString * out, const char * source, token * text, link * link, scratch_pad * scratch);
 void mmd_export_image_opendocument(DString * out, const char * source, token * text, link * link, scratch_pad * scratch, bool is_figure);
index f12d4162699c9b87edf38d979bd009b1f36e7849..b6f7f7917f561b8f328fd1f34a4e1bddcddcca56 100644 (file)
@@ -362,11 +362,11 @@ draw:z-index="0" draw:style-name="fr1" svg:width="40pt">
 
 <text:p text:style-name="Standard"><text:span text:style-name="math">\[ {x}_{1,2}=\frac{-b\pm \sqrt{{b}^{2}-4ac}}{2a} \]</text:span></text:p>
 
-<text:p text:style-name="Standard">foo <text:span text:style-name="math">\({e}^{i\pi }+1=0\)</text:span> bar</text:p>
+<text:p text:style-name="Standard">foo <text:span text:style-name="math">${e}^{i\pi }+1=0$</text:span> bar</text:p>
 
-<text:p text:style-name="Standard">foo <text:span text:style-name="math">\({e}^{i\pi }+1=0\)</text:span>, bar</text:p>
+<text:p text:style-name="Standard">foo <text:span text:style-name="math">${e}^{i\pi }+1=0$</text:span>, bar</text:p>
 
-<text:p text:style-name="Standard"><text:span text:style-name="math">\[{x}_{1,2}=\frac{-b\pm \sqrt{{b}^{2}-4ac}}{2a}\]</text:span></text:p>
+<text:p text:style-name="Standard"><text:span text:style-name="math">$${x}_{1,2}=\frac{-b\pm \sqrt{{b}^{2}-4ac}}{2a}$$</text:span></text:p>
 
 <text:h text:outline-level="1"><text:bookmark text:name="smartquotes"/>Smart Quotes </text:h>
 
index a512bf86d97aae2d791e895bb167fc4139520f57..43dd04de35c0b1989ceecdd62198e6ad05cefce5 100644 (file)
@@ -282,11 +282,11 @@ office:mimetype="application/vnd.oasis.opendocument.text">
 
 <text:p text:style-name="Standard"><text:span text:style-name="math">\[ {x}_{1,2}=\frac{-b\pm \sqrt{{b}^{2}-4ac}}{2a} \]</text:span></text:p>
 
-<text:p text:style-name="Standard">foo <text:span text:style-name="math">\({e}^{i\pi }+1=0\)</text:span> bar</text:p>
+<text:p text:style-name="Standard">foo <text:span text:style-name="math">${e}^{i\pi }+1=0$</text:span> bar</text:p>
 
-<text:p text:style-name="Standard">foo <text:span text:style-name="math">\({e}^{i\pi }+1=0\)</text:span>, bar</text:p>
+<text:p text:style-name="Standard">foo <text:span text:style-name="math">${e}^{i\pi }+1=0$</text:span>, bar</text:p>
 
-<text:p text:style-name="Standard"><text:span text:style-name="math">\[{x}_{1,2}=\frac{-b\pm \sqrt{{b}^{2}-4ac}}{2a}\]</text:span></text:p>
+<text:p text:style-name="Standard"><text:span text:style-name="math">$${x}_{1,2}=\frac{-b\pm \sqrt{{b}^{2}-4ac}}{2a}$$</text:span></text:p>
 
 <text:p text:style-name="Standard">5</text:p>
 
@@ -308,9 +308,9 @@ office:mimetype="application/vnd.oasis.opendocument.text">
 
 <text:p text:style-name="Standard">$${x}_{1,2}=\frac{-b\pm \sqrt{{b}^{2}-4ac}}{2a}$$b</text:p>
 
-<text:p text:style-name="Standard"><text:span text:style-name="math">\(\nabla \times \mathbf{E} = - \frac{\partial \mathbf{B}}{\partial t}\)</text:span></text:p>
+<text:p text:style-name="Standard"><text:span text:style-name="math">$\nabla \times \mathbf{E} = - \frac{\partial \mathbf{B}}{\partial t}$</text:span></text:p>
 
-<text:p text:style-name="Standard"><text:span text:style-name="math">\[\nabla \times \mathbf{E} = - \frac{\partial \mathbf{B}}{\partial t}\]</text:span></text:p>
+<text:p text:style-name="Standard"><text:span text:style-name="math">$$\nabla \times \mathbf{E} = - \frac{\partial \mathbf{B}}{\partial t}$$</text:span></text:p>
 
 <text:p text:style-name="Standard">15</text:p>
 
@@ -318,9 +318,9 @@ office:mimetype="application/vnd.oasis.opendocument.text">
 
 <text:p text:style-name="Standard"><text:span text:style-name="math">\[\nabla \times \mathbf{E} = - \frac{\partial \mathbf{B}}{\partial t}\]</text:span></text:p>
 
-<text:p text:style-name="Standard"><text:span text:style-name="math">\(\begin{equation}\nabla \times \mathbf{E} = - \frac{\partial \mathbf{B}}{\partial t}\end{equation}\)</text:span></text:p>
+<text:p text:style-name="Standard"><text:span text:style-name="math">$\begin{equation}\nabla \times \mathbf{E} = - \frac{\partial \mathbf{B}}{\partial t}\end{equation}$</text:span></text:p>
 
-<text:p text:style-name="Standard"><text:span text:style-name="math">\[\begin{equation}\nabla \times \mathbf{E} = - \frac{\partial \mathbf{B}}{\partial t}\end{equation}\]</text:span></text:p>
+<text:p text:style-name="Standard"><text:span text:style-name="math">$$\begin{equation}\nabla \times \mathbf{E} = - \frac{\partial \mathbf{B}}{\partial t}\end{equation}$$</text:span></text:p>
 
 <text:p text:style-name="Standard"><text:span text:style-name="math">\(\begin{equation}\nabla \times \mathbf{E} = - \frac{\partial \mathbf{B}}{\partial t}\end{equation}\)</text:span></text:p>
 
@@ -330,9 +330,15 @@ office:mimetype="application/vnd.oasis.opendocument.text">
 
 <text:p text:style-name="Standard"><text:span text:style-name="Source_20_Text">\begin{equation}\nabla \times \mathbf{E} = - \frac{\partial \mathbf{B}}{\partial t}\end{equation}</text:span></text:p>
 
-<text:p text:style-name="Standard"><text:span text:style-name="math">\(a *foo* b\)</text:span></text:p>
+<text:p text:style-name="Standard"><text:span text:style-name="math">$a *foo* b$</text:span></text:p>
 
 <text:p text:style-name="Standard"><text:span text:style-name="math">\[a *foo* b\]</text:span></text:p>
+
+<text:p text:style-name="Standard"><text:span text:style-name="math">\[\pi^2\]</text:span></text:p>
+
+<text:p text:style-name="Standard">25</text:p>
+
+<text:p text:style-name="Standard"><text:span text:style-name="math">\[\pi~2\]</text:span></text:p>
 </office:text>
 </office:body>
 </office:document>
index b12f0a3eb7465690118f797bd9b06e8b7fbebb6d..2405da2034d7d729c8e6e04c97b89b2c40aa135e 100644 (file)
 
 <p><span class="math">\[a *foo* b\]</span></p>
 
+<p><span class="math">\[\pi^2\]</span></p>
+
+<p>25</p>
+
+<p><span class="math">\[\pi~2\]</span></p>
+
 </body>
 </html>
 
index e85b5dd1ffb4e0038b7027c7ec8331aa2ce2138f..d54b7d57ab7ea5f3f5c6953a650f07d628e0aa86 100644 (file)
@@ -56,3 +56,9 @@ latex config: article</p>
 <p>$a <em>foo</em> b$</p>
 
 <p>\[a <em>foo</em> b\]</p>
+
+<p>\[\pi^2\]</p>
+
+<p>25</p>
+
+<p>\[\pi~2\]</p>
index 1c700292641df1cad6c55b11bb2fd1264cc57090..12c830c3445654d0d32acae9b36a0ec765fed9cc 100644 (file)
@@ -58,5 +58,11 @@ $a *foo* b$
 
 \[a *foo* b\]
 
+\[\pi^2\]
+
+25
+
+\[\pi~2\]
+
 \input{mmd6-article-footer}
 \end{document}
index a618607b7a104dff24bb06cfe257ece5a0362fac..8327524b20391fecaa4a6f700864c0812773c5ad 100644 (file)
@@ -56,3 +56,9 @@ $$\begin{equation}\nabla \times \mathbf{E} = - \frac{\partial \mathbf{B}}{\parti
 $a *foo* b$
 
 \\[a *foo* b\\]
+
+\\[\pi^2\\]
+
+25
+
+\\[\pi~2\\]
index 68be201c915217686a843727e338b9677e88fb63..5e73b9dbfdb3c04c782b5d6def72315982bfc6df 100644 (file)
@@ -317,6 +317,16 @@ office:mimetype="application/vnd.oasis.opendocument.text">
 <text:p text:style-name="Standard">CH<text:span text:style-name="MMD-Subscript">3</text:span>CH<text:span text:style-name="MMD-Subscript">2</text:span>CH<text:span text:style-name="MMD-Subscript">2</text:span>CH<text:span text:style-name="MMD-Subscript">3</text:span></text:p>
 
 <text:p text:style-name="Standard">CH<text:span text:style-name="MMD-Subscript">3</text:span>CH<text:span text:style-name="MMD-Subscript">2</text:span>CH<text:span text:style-name="MMD-Subscript">2</text:span>CH~3</text:p>
+
+<text:p text:style-name="Standard"><text:span text:style-name="Source_20_Text">\pi^2</text:span></text:p>
+
+<text:p text:style-name="Standard"><text:span text:style-name="Source_20_Text">\pi^2^</text:span></text:p>
+
+<text:p text:style-name="Standard"><text:span text:style-name="Source_20_Text">CH~4</text:span></text:p>
+
+<text:p text:style-name="Standard">20</text:p>
+
+<text:p text:style-name="Standard"><text:span text:style-name="Source_20_Text">CH~4~</text:span></text:p>
 </office:text>
 </office:body>
 </office:document>
index 959ba48f17d06e260426d9255d81755444505a2f..593423f0dea1c3a9a39e1350e94ca75a0e83d734 100644 (file)
 
 <p>CH<sub>3</sub>CH<sub>2</sub>CH<sub>2</sub>CH~3</p>
 
+<p><code>\pi^2</code></p>
+
+<p><code>\pi^2^</code></p>
+
+<p><code>CH~4</code></p>
+
+<p>20</p>
+
+<p><code>CH~4~</code></p>
+
 </body>
 </html>
 
index 051321c03d62713fe0aeeaea214f37bd1393324c..cc377a070ebc5fa6398786dc3d63a64db7dad87c 100644 (file)
@@ -40,3 +40,13 @@ latex config:        article</p>
 <p>CH~3~CH~2~CH~2~CH~3~</p>
 
 <p>CH~3~CH~2~CH~2~CH~3</p>
+
+<p><code>\pi^2</code></p>
+
+<p><code>\pi^2^</code></p>
+
+<p><code>CH~4</code></p>
+
+<p>20</p>
+
+<p><code>CH~4~</code></p>
index 28ec3c9743cf1804044972a580b3d71962129f35..3dd646a44d9006a0c59b5ce49c1f4ff25f207854 100644 (file)
@@ -42,5 +42,15 @@ CH\textsubscript{3}CH\textsubscript{2}CH\textsubscript{2}CH\textsubscript{3}
 
 CH\textsubscript{3}CH\textsubscript{2}CH\textsubscript{2}CH\ensuremath{\sim}3
 
+\texttt{\textbackslash{}pi\^{}2}
+
+\texttt{\textbackslash{}pi\^{}2\^{}}
+
+\texttt{CH\ensuremath{\sim}4}
+
+20
+
+\texttt{CH\ensuremath{\sim}4\ensuremath{\sim}}
+
 \input{mmd6-article-footer}
 \end{document}
index 8c5c7bd712288b283bebdb8464f259cc2497249f..63d282f308f8bab01755914fa8a0e928565c16ec 100644 (file)
@@ -39,4 +39,14 @@ H~2~O
 
 CH~3~CH~2~CH~2~CH~3~
 
-CH~3~CH~2~CH~2~CH~3
\ No newline at end of file
+CH~3~CH~2~CH~2~CH~3
+
+`\pi^2`
+
+`\pi^2^`
+
+`CH~4`
+
+20
+
+`CH~4~`