Skip to content

Commit

Permalink
Created Package to convert xml to texinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
adityawagh114 committed Jul 12, 2021
1 parent 6b80a9e commit 535b3b8
Show file tree
Hide file tree
Showing 11 changed files with 1,675 additions and 0 deletions.
6 changes: 6 additions & 0 deletions wxmx2texi/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# wxmx2texi

## Steps to run
- Download this package and save in the maxima directory such that maxima can find this package.
- Load the package by executing the command load(wxmx2texi) in maxima.
- Pass the location of the xml file as an argument to wxmx2texi() function.
58 changes: 58 additions & 0 deletions wxmx2texi/test_xml_files/content1.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>


<wxMaximaDocument version="1.5" zoom="100" activecell="73">

<cell type="section" sectioning_level="2">
<editor type="section" sectioning_level="2">
<line>All cell types</line>
</editor>

</cell>

<cell type="subsection" sectioning_level="3">
<editor type="subsection" sectioning_level="3">
<line>Subsection cells</line>
</editor>

</cell>

<cell type="subsection" sectioning_level="4">
<editor type="subsection" sectioning_level="4">
<line>Sub-sub-section cells</line>
</editor>

</cell>

<cell type="subsection" sectioning_level="5">
<editor type="subsection" sectioning_level="5">
<line>Sub-sub-sub-section cells</line>
</editor>

</cell>




<cell type="subsection" sectioning_level="5">
<editor type="subsection" sectioning_level="5">
<line>72*2</line>
</editor>

</cell>


<cell type="subsection" sectioning_level="5">
<editor type="subsection" sectioning_level="5">
<line>a^2+b^2</line>
</editor>

<cell type="subsection" sectioning_level="5">
<editor type="subsection" sectioning_level="5">
<line>sin(a+2*b)</line>
</editor>

</cell>


</wxMaximaDocument>
15 changes: 15 additions & 0 deletions wxmx2texi/test_xml_files/content1_output.texi
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@iftex
@tex
\begin{verbatim}All cell types\end{verbatim}\begin{verbatim}Subsection cells\end{verbatim}\begin{verbatim}Sub-sub-section cells\end{verbatim}\begin{verbatim}Sub-sub-sub-section cells\end{verbatim}$$144$$$$b^2+a^2$$
@end tex
@end iftex
@ifhtml
@html
<math xmlns="http://www.w3.org/1998/Math/MathML"> <mtext>All cell types</mtext><mspace linebreak='newline' /><mtext>Subsection cells</mtext><mspace linebreak='newline' /><mtext>Sub-sub-section cells</mtext><mspace linebreak='newline' /><mtext>Sub-sub-sub-section cells</mtext><mspace linebreak='newline' /><mn>144</mn> <mspace linebreak='newline' /><msup><mrow><mi>b</mi> </mrow> <mn>2</mn> </msup> <mo>+</mo> <msup><mrow><mi>a</mi> </mrow> <mn>2</mn> </msup> <mspace linebreak='newline' /></math>
@end html
@end ifhtml
@ifinfo
@example
All cell types, Subsection cells, Sub-sub-section cells, Sub-sub-sub-section cells, 72*2, a^2+b^2,
@end example
@end ifinfo
39 changes: 39 additions & 0 deletions wxmx2texi/test_xml_files/content2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>


<wxMaximaDocument version="1.5" zoom="100" activecell="73">

<cell type="section" sectioning_level="2">
<editor type="section" sectioning_level="2">
<line> x/(x^2+y^2) = 1;</line>
</editor>

</cell>

<cell type="section" sectioning_level="2">
<editor type="section" sectioning_level="2">
<line> x^2/(x^2+y^2) = 1;</line>
</editor>

</cell>

<cell type="section" sectioning_level="2">
<editor type="section" sectioning_level="2">
<line> (a+b)/8;</line>
</editor>

</cell>

<cell type="section" sectioning_level="2">
<editor type="section" sectioning_level="2">
<line> x^2+x^3+x^4;</line>
</editor>

</cell>






</wxMaximaDocument>
15 changes: 15 additions & 0 deletions wxmx2texi/test_xml_files/content2_output.texi
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@iftex
@tex
$${{x}\over{y^2+x^2}}=1$$$${{x^2}\over{y^2+x^2}}=1$$$${{b+a}\over{8}}$$$$x^4+x^3+x^2$$
@end tex
@end iftex
@ifhtml
@html
<math xmlns="http://www.w3.org/1998/Math/MathML"> <mfrac><mrow><mi>x</mi> </mrow> <mrow><msup><mrow><mi>y</mi> </mrow> <mn>2</mn> </msup> <mo>+</mo> <msup><mrow><mi>x</mi> </mrow> <mn>2</mn> </msup> </mrow></mfrac> <mo>=</mo> <mn>1</mn> <mspace linebreak='newline' /><mfrac><mrow><msup><mrow><mi>x</mi> </mrow> <mn>2</mn> </msup> </mrow> <mrow><msup><mrow><mi>y</mi> </mrow> <mn>2</mn> </msup> <mo>+</mo> <msup><mrow><mi>x</mi> </mrow> <mn>2</mn> </msup> </mrow></mfrac> <mo>=</mo> <mn>1</mn> <mspace linebreak='newline' /><mfrac><mrow><mi>b</mi> <mo>+</mo> <mi>a</mi> </mrow> <mrow><mn>8</mn> </mrow></mfrac> <mspace linebreak='newline' /><msup><mrow><mi>x</mi> </mrow> <mn>4</mn> </msup> <mo>+</mo> <msup><mrow><mi>x</mi> </mrow> <mn>3</mn> </msup> <mo>+</mo> <msup><mrow><mi>x</mi> </mrow> <mn>2</mn> </msup> <mspace linebreak='newline' /></math>
@end html
@end ifhtml
@ifinfo
@example
x/(x^2+y^2) = 1;, x^2/(x^2+y^2) = 1;, (a+b)/8;, x^2+x^3+x^4;,
@end example
@end ifinfo
111 changes: 111 additions & 0 deletions wxmx2texi/test_xml_files/content3.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<?xml version="1.0" encoding="UTF-8"?>


<wxMaximaDocument version="1.5" zoom="100" activecell="73">


<cell type="code">
<input>
<editor type="input">
<line>integrate(f(1),t,0,T);</line>
<line>integrate(f(10),t,0,T);</line>
<line>integrate(f(100),t,0,T);</line>
</editor>
</input>
</cell>

<cell type="code">
<input>
<editor type="input">
<line>&apos;integrate(sin(x),x,1,a(x)/b(x));</line>
</editor>
</input>
</cell>


<cell type="code">
<input>
<editor type="input">
<line>x[x(1)]^x(1)+1;</line>
<line>x[x(1)]^x(10)+1;</line>
<line>x[x(10)]^x(1)+1;</line>
<line></line>
<line>x[x(100)]^x(100)+1;</line>
</editor>
</input>
</cell>

<cell type="code">
<input>
<editor type="input">
<line>x[x[x[x[1]]]]^y^z^a^b;</line>
</editor>
</input>
</cell>


<cell type="code">
<input>
<editor type="input">
<line>a: (x+y)^2;</line>
</editor>
</input>
</cell>


<cell type="subsection" sectioning_level="3">
<editor type="subsection" sectioning_level="3">
<line>Special cases for the TeX export</line>
</editor>

</cell>

<cell type="text">
<editor type="text">
<line>Function names should be exported as upright text:</line>
</editor>

</cell>

<cell type="code">
<input>
<editor type="input">
<line>function(x):=10;</line>
</editor>
</input>
</cell>



<cell type="code">
<input>
<editor type="input">
<line>ab≠a*b;</line>
</editor>
</input>
</cell>

<cell type="text">
<editor type="text">
<line>What makes this more complicated is that the auto-subscript mechanism adds more corner cases here:</line>
</editor>

</cell>

<cell type="code">
<input>
<editor type="input">
<line>a_b*c;</line>
<line>a*b_c;</line>
<line>a_b*c;</line>
<line>aa*b_c;</line>
<line>a*bb_c;</line>
<line>aa*bb_c;</line>
<line>aa_c*b;</line>
<line>a_c*bb;</line>
<line>aa_c*bb;</line>
</editor>
</input>
</cell>

</wxMaximaDocument>
15 changes: 15 additions & 0 deletions wxmx2texi/test_xml_files/content3_output.texi
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@iftex
@tex
$${\it integrate}\left(f\left(1\right) , t , 0 , T\right)$$$${\it integrate}\left(f\left(10\right) , t , 0 , T\right)$$$${\it integrate}\left(f\left(100\right) , t , 0 , T\right)$$$$\int_{1}^{{{a\left(x\right)}\over{b\left(x\right)}}}{\sin x\;dx}$$$$x_{x\left(1\right)}^{x\left(1\right)}+1$$$$x_{x\left(1\right)}^{x\left(10\right)}+1$$$$x_{x\left(10\right)}^{x\left(1\right)}+1$$\begin{verbatim}\end{verbatim}$$x_{x\left(100\right)}^{x\left(100\right)}+1$$$$x_{x_{x_{x_{1}}}}^{y^{z^{a^{b}}}}$$$$a:\left(y+x\right)^2$$\begin{verbatim}Special cases for the TeX export\end{verbatim}\begin{verbatim}Function names should be exported as upright text:\end{verbatim}$${\it function}\left(x\right):=10$$\begin{verbatim}ab≠a*b;\end{verbatim}\begin{verbatim}What makes this more complicated is that the auto-subscript mechanism adds more corner cases here:\end{verbatim}$${\it a\_b}\,c$$$$a\,{\it b\_c}$$$${\it a\_b}\,c$$$${\it aa}\,{\it b\_c}$$$$a\,{\it bb\_c}$$$${\it aa}\,{\it bb\_c}$$$${\it aa\_c}\,b$$$${\it a\_c}\,{\it bb}$$$${\it aa\_c}\,{\it bb}$$
@end tex
@end iftex
@ifhtml
@html
<math xmlns="http://www.w3.org/1998/Math/MathML"> <mi>integrate</mi> <mfenced separators=""><mi>f</mi> <mfenced separators=""><mn>1</mn> </mfenced> <mo>,</mo><mi>t</mi> <mo>,</mo><mn>0</mn> <mo>,</mo><mi>T</mi> </mfenced> <mspace linebreak='newline' /><mi>integrate</mi> <mfenced separators=""><mi>f</mi> <mfenced separators=""><mn>10</mn> </mfenced> <mo>,</mo><mi>t</mi> <mo>,</mo><mn>0</mn> <mo>,</mo><mi>T</mi> </mfenced> <mspace linebreak='newline' /><mi>integrate</mi> <mfenced separators=""><mi>f</mi> <mfenced separators=""><mn>100</mn> </mfenced> <mo>,</mo><mi>t</mi> <mo>,</mo><mn>0</mn> <mo>,</mo><mi>T</mi> </mfenced> <mspace linebreak='newline' /><mrow><munderover><mo>&int;</mo> <mrow><mn>1</mn> </mrow> <mrow><mfrac><mrow><mi>a</mi> <mfenced separators=""><mi>x</mi> </mfenced> </mrow> <mrow><mi>b</mi> <mfenced separators=""><mi>x</mi> </mfenced> </mrow></mfrac> </mrow> </munderover> <mrow><mi>sin</mi> <mi>x</mi> </mrow> <mspace width="mediummathspace"/> <mrow><mo>&DifferentialD;</mo><mi><mi>x</mi> </mi> </mrow></mrow> <mspace linebreak='newline' /><msup><mrow><msub><mrow><mi>x</mi> </mrow><mrow><mi>x</mi> <mfenced separators=""><mn>1</mn> </mfenced> </mrow></msub> </mrow> <mrow><mi>x</mi> <mfenced separators=""><mn>1</mn> </mfenced> </mrow></msup> <mo>+</mo> <mn>1</mn> <mspace linebreak='newline' /><msup><mrow><msub><mrow><mi>x</mi> </mrow><mrow><mi>x</mi> <mfenced separators=""><mn>1</mn> </mfenced> </mrow></msub> </mrow> <mrow><mi>x</mi> <mfenced separators=""><mn>10</mn> </mfenced> </mrow></msup> <mo>+</mo> <mn>1</mn> <mspace linebreak='newline' /><msup><mrow><msub><mrow><mi>x</mi> </mrow><mrow><mi>x</mi> <mfenced separators=""><mn>10</mn> </mfenced> </mrow></msub> </mrow> <mrow><mi>x</mi> <mfenced separators=""><mn>1</mn> </mfenced> </mrow></msup> <mo>+</mo> <mn>1</mn> <mspace linebreak='newline' /><mtext></mtext><mspace linebreak='newline' /><msup><mrow><msub><mrow><mi>x</mi> </mrow><mrow><mi>x</mi> <mfenced separators=""><mn>100</mn> </mfenced> </mrow></msub> </mrow> <mrow><mi>x</mi> <mfenced separators=""><mn>100</mn> </mfenced> </mrow></msup> <mo>+</mo> <mn>1</mn> <mspace linebreak='newline' /><msup><mrow><msub><mrow><mi>x</mi> </mrow><mrow><msub><mrow><mi>x</mi> </mrow><mrow><msub><mrow><mi>x</mi> </mrow><mrow><msub><mrow><mi>x</mi> </mrow><mrow><mn>1</mn> </mrow></msub> </mrow></msub> </mrow></msub> </mrow></msub> </mrow> <mrow><msup><mrow><mi>y</mi> </mrow> <mrow><msup><mrow><mi>z</mi> </mrow> <mrow><msup><mrow><mi>a</mi> </mrow> <mrow><mi>b</mi> </mrow></msup> </mrow></msup> </mrow></msup> </mrow></msup> <mspace linebreak='newline' /><mi>a</mi> <mo>:</mo><msup><mrow><mfenced separators=""><mi>y</mi> <mo>+</mo> <mi>x</mi> </mfenced> </mrow> <mn>2</mn> </msup> <mspace linebreak='newline' /><mtext>Special cases for the TeX export</mtext><mspace linebreak='newline' /><mtext>Function names should be exported as upright text:</mtext><mspace linebreak='newline' /><mi>function</mi> <mfenced separators=""><mi>x</mi> </mfenced> <mo>:=</mo><mn>10</mn> <mspace linebreak='newline' /><mtext>ab≠a*b;</mtext><mspace linebreak='newline' /><mtext>What makes this more complicated is that the auto-subscript mechanism adds more corner cases here:</mtext><mspace linebreak='newline' /><mi>a_b</mi> <mspace width="thinmathspace"/><mi>c</mi> <mspace linebreak='newline' /><mi>a</mi> <mspace width="thinmathspace"/><mi>b_c</mi> <mspace linebreak='newline' /><mi>a_b</mi> <mspace width="thinmathspace"/><mi>c</mi> <mspace linebreak='newline' /><mi>aa</mi> <mspace width="thinmathspace"/><mi>b_c</mi> <mspace linebreak='newline' /><mi>a</mi> <mspace width="thinmathspace"/><mi>bb_c</mi> <mspace linebreak='newline' /><mi>aa</mi> <mspace width="thinmathspace"/><mi>bb_c</mi> <mspace linebreak='newline' /><mi>aa_c</mi> <mspace width="thinmathspace"/><mi>b</mi> <mspace linebreak='newline' /><mi>a_c</mi> <mspace width="thinmathspace"/><mi>bb</mi> <mspace linebreak='newline' /><mi>aa_c</mi> <mspace width="thinmathspace"/><mi>bb</mi> <mspace linebreak='newline' /></math>
@end html
@end ifhtml
@ifinfo
@example
integrate(f(1),t,0,T);, integrate(f(10),t,0,T);, integrate(f(100),t,0,T);, 'integrate(sin(x),x,1,a(x)/b(x));, x[x(1)]^x(1)+1;, x[x(1)]^x(10)+1;, x[x(10)]^x(1)+1;, , x[x(100)]^x(100)+1;, x[x[x[x[1]]]]^y^z^a^b;, a: (x+y)^2;, Special cases for the TeX export, Function names should be exported as upright text:, function(x):=10;, ab≠a*b;, What makes this more complicated is that the auto-subscript mechanism adds more corner cases here:, a_b*c;, a*b_c;, a_b*c;, aa*b_c;, a*bb_c;, aa*bb_c;, aa_c*b;, a_c*bb;, aa_c*bb;,
@end example
@end ifinfo
39 changes: 39 additions & 0 deletions wxmx2texi/wcatchable_syntax_error.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
;;This is a modified version of the package catchable_syntax_error.lisp.

;; copyright 2019 by Robert Dodier
;; I release this work under terms of the GNU General Public License v2

;; Helper for MREAD-SYNERR.
;; Adapted from local function PRINTER in built-in MREAD-SYNERR.
(declaim (sb-ext:muffle-conditions cl:warning))


(defun mread-synerr-printer (x)
(cond ((symbolp x)
(print-invert-case (stripdollar x)))
((stringp x)
(maybe-invert-string-case x))
(t x)))

;; Punt to Maxima function 'error' so that syntax errors can be caught by 'errcatch'.
;; This definition replaces the built-in MREAD-SYNERR
;; which throws to the top level of the interpreter in a way which cannot
;; be intercepted by 'errcatch'.
;;
;; After a syntax error is detected, the global variable 'error'
;; contains the error message (which is also printed on the console
;; when the error occurs).
;;
;; Aside from punting to 'error', this implementation doesn't try to
;; do anything else which the built-in MREAD-SYNERR does. In particular
;; this implementation doesn't try to output any input-line information.

(defun mread-synerr (format-string &rest l)
(let*
((format-string-1 (concatenate 'string "syntax error: " format-string))
(format-string-args (mapcar #'mread-synerr-printer l))
(message-string (apply #'format nil format-string-1 format-string-args)))
(declare (special *parse-stream*))
(when (eql *parse-stream* *standard-input*)
(read-line *parse-stream* nil nil))
($error "")))
Loading

0 comments on commit 535b3b8

Please sign in to comment.