From: Fletcher T. Penney Date: Fri, 13 Oct 2017 12:36:05 +0000 (-0400) Subject: FIXED: Improve consistency of math token handling X-Git-Tag: 6.2.2^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6c85fb52968622023a1884e723c53f8d0900999f;p=multimarkdown FIXED: Improve consistency of math token handling --- diff --git a/Sources/libMultiMarkdown/html.c b/Sources/libMultiMarkdown/html.c index c2549d3..9dbd56e 100644 --- a/Sources/libMultiMarkdown/html.c +++ b/Sources/libMultiMarkdown/html.c @@ -2113,6 +2113,26 @@ void mmd_export_token_html_raw(DString * out, const char * source, token * t, sc print_const("""); 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; diff --git a/Sources/libMultiMarkdown/latex.c b/Sources/libMultiMarkdown/latex.c index 389f686..73cf534 100644 --- a/Sources/libMultiMarkdown/latex.c +++ b/Sources/libMultiMarkdown/latex.c @@ -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; diff --git a/Sources/libMultiMarkdown/opendocument-content.c b/Sources/libMultiMarkdown/opendocument-content.c index 467c630..1ef47da 100644 --- a/Sources/libMultiMarkdown/opendocument-content.c +++ b/Sources/libMultiMarkdown/opendocument-content.c @@ -324,6 +324,33 @@ void mmd_export_token_opendocument_raw(DString * out, const char * source, token print_const("""); 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(""); + mmd_export_token_tree_opendocument_math(out, source, t->child, scratch); + print_const(""); + break; + + case PAIR_EMPH: case PAIR_PAREN: case PAIR_QUOTE_DOUBLE: case PAIR_QUOTE_SINGLE: diff --git a/Sources/libMultiMarkdown/opendocument-content.h b/Sources/libMultiMarkdown/opendocument-content.h index 4bfd49e..b795cb9 100644 --- a/Sources/libMultiMarkdown/opendocument-content.h +++ b/Sources/libMultiMarkdown/opendocument-content.h @@ -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); diff --git a/tests/MMD6Tests/Integrated.fodt b/tests/MMD6Tests/Integrated.fodt index f12d416..b6f7f79 100644 --- a/tests/MMD6Tests/Integrated.fodt +++ b/tests/MMD6Tests/Integrated.fodt @@ -362,11 +362,11 @@ draw:z-index="0" draw:style-name="fr1" svg:width="40pt"> \[ {x}_{1,2}=\frac{-b\pm \sqrt{{b}^{2}-4ac}}{2a} \] -foo \({e}^{i\pi }+1=0\) bar +foo ${e}^{i\pi }+1=0$ bar -foo \({e}^{i\pi }+1=0\), bar +foo ${e}^{i\pi }+1=0$, bar -\[{x}_{1,2}=\frac{-b\pm \sqrt{{b}^{2}-4ac}}{2a}\] +$${x}_{1,2}=\frac{-b\pm \sqrt{{b}^{2}-4ac}}{2a}$$ Smart Quotes diff --git a/tests/MMD6Tests/Math.fodt b/tests/MMD6Tests/Math.fodt index a512bf8..43dd04d 100644 --- a/tests/MMD6Tests/Math.fodt +++ b/tests/MMD6Tests/Math.fodt @@ -282,11 +282,11 @@ office:mimetype="application/vnd.oasis.opendocument.text"> \[ {x}_{1,2}=\frac{-b\pm \sqrt{{b}^{2}-4ac}}{2a} \] -foo \({e}^{i\pi }+1=0\) bar +foo ${e}^{i\pi }+1=0$ bar -foo \({e}^{i\pi }+1=0\), bar +foo ${e}^{i\pi }+1=0$, bar -\[{x}_{1,2}=\frac{-b\pm \sqrt{{b}^{2}-4ac}}{2a}\] +$${x}_{1,2}=\frac{-b\pm \sqrt{{b}^{2}-4ac}}{2a}$$ 5 @@ -308,9 +308,9 @@ office:mimetype="application/vnd.oasis.opendocument.text"> $${x}_{1,2}=\frac{-b\pm \sqrt{{b}^{2}-4ac}}{2a}$$b -\(\nabla \times \mathbf{E} = - \frac{\partial \mathbf{B}}{\partial t}\) +$\nabla \times \mathbf{E} = - \frac{\partial \mathbf{B}}{\partial t}$ -\[\nabla \times \mathbf{E} = - \frac{\partial \mathbf{B}}{\partial t}\] +$$\nabla \times \mathbf{E} = - \frac{\partial \mathbf{B}}{\partial t}$$ 15 @@ -318,9 +318,9 @@ office:mimetype="application/vnd.oasis.opendocument.text"> \[\nabla \times \mathbf{E} = - \frac{\partial \mathbf{B}}{\partial t}\] -\(\begin{equation}\nabla \times \mathbf{E} = - \frac{\partial \mathbf{B}}{\partial t}\end{equation}\) +$\begin{equation}\nabla \times \mathbf{E} = - \frac{\partial \mathbf{B}}{\partial t}\end{equation}$ -\[\begin{equation}\nabla \times \mathbf{E} = - \frac{\partial \mathbf{B}}{\partial t}\end{equation}\] +$$\begin{equation}\nabla \times \mathbf{E} = - \frac{\partial \mathbf{B}}{\partial t}\end{equation}$$ \(\begin{equation}\nabla \times \mathbf{E} = - \frac{\partial \mathbf{B}}{\partial t}\end{equation}\) @@ -330,9 +330,15 @@ office:mimetype="application/vnd.oasis.opendocument.text"> \begin{equation}\nabla \times \mathbf{E} = - \frac{\partial \mathbf{B}}{\partial t}\end{equation} -\(a *foo* b\) +$a *foo* b$ \[a *foo* b\] + +\[\pi^2\] + +25 + +\[\pi~2\] diff --git a/tests/MMD6Tests/Math.html b/tests/MMD6Tests/Math.html index b12f0a3..2405da2 100644 --- a/tests/MMD6Tests/Math.html +++ b/tests/MMD6Tests/Math.html @@ -62,6 +62,12 @@

\[a *foo* b\]

+

\[\pi^2\]

+ +

25

+ +

\[\pi~2\]

+ diff --git a/tests/MMD6Tests/Math.htmlc b/tests/MMD6Tests/Math.htmlc index e85b5dd..d54b7d5 100644 --- a/tests/MMD6Tests/Math.htmlc +++ b/tests/MMD6Tests/Math.htmlc @@ -56,3 +56,9 @@ latex config: article

$a foo b$

\[a foo b\]

+ +

\[\pi^2\]

+ +

25

+ +

\[\pi~2\]

diff --git a/tests/MMD6Tests/Math.tex b/tests/MMD6Tests/Math.tex index 1c70029..12c830c 100644 --- a/tests/MMD6Tests/Math.tex +++ b/tests/MMD6Tests/Math.tex @@ -58,5 +58,11 @@ $a *foo* b$ \[a *foo* b\] +\[\pi^2\] + +25 + +\[\pi~2\] + \input{mmd6-article-footer} \end{document} diff --git a/tests/MMD6Tests/Math.text b/tests/MMD6Tests/Math.text index a618607..8327524 100644 --- a/tests/MMD6Tests/Math.text +++ b/tests/MMD6Tests/Math.text @@ -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\\] diff --git a/tests/MMD6Tests/Superscript.fodt b/tests/MMD6Tests/Superscript.fodt index 68be201..5e73b9d 100644 --- a/tests/MMD6Tests/Superscript.fodt +++ b/tests/MMD6Tests/Superscript.fodt @@ -317,6 +317,16 @@ office:mimetype="application/vnd.oasis.opendocument.text"> CH3CH2CH2CH3 CH3CH2CH2CH~3 + +\pi^2 + +\pi^2^ + +CH~4 + +20 + +CH~4~ diff --git a/tests/MMD6Tests/Superscript.html b/tests/MMD6Tests/Superscript.html index 959ba48..593423f 100644 --- a/tests/MMD6Tests/Superscript.html +++ b/tests/MMD6Tests/Superscript.html @@ -46,6 +46,16 @@

CH3CH2CH2CH~3

+

\pi^2

+ +

\pi^2^

+ +

CH~4

+ +

20

+ +

CH~4~

+ diff --git a/tests/MMD6Tests/Superscript.htmlc b/tests/MMD6Tests/Superscript.htmlc index 051321c..cc377a0 100644 --- a/tests/MMD6Tests/Superscript.htmlc +++ b/tests/MMD6Tests/Superscript.htmlc @@ -40,3 +40,13 @@ latex config: article

CH~3~CH~2~CH~2~CH~3~

CH~3~CH~2~CH~2~CH~3

+ +

\pi^2

+ +

\pi^2^

+ +

CH~4

+ +

20

+ +

CH~4~

diff --git a/tests/MMD6Tests/Superscript.tex b/tests/MMD6Tests/Superscript.tex index 28ec3c9..3dd646a 100644 --- a/tests/MMD6Tests/Superscript.tex +++ b/tests/MMD6Tests/Superscript.tex @@ -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} diff --git a/tests/MMD6Tests/Superscript.text b/tests/MMD6Tests/Superscript.text index 8c5c7bd..63d282f 100644 --- a/tests/MMD6Tests/Superscript.text +++ b/tests/MMD6Tests/Superscript.text @@ -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~`