# Commits

committed ba4eae9

• Participants
• Parent commits e7992b8
• Branches default

# File html2latex.py


         sage: s = "$$x$$abs$inline math$defg$$display math x^2$$hijk$inline math$lmno$$\mathbf{A}$$"
         sage: detect_math(s)
-
-        <div class="math">
-        x
-        </div>
-        abs
-        <span class="math">
-        inline math
-        </span>
-        defg
-        <div class="math">
-        display math x^2
-        </div>
-        hijk
-        <span class="math">
-        inline math
-        </span>
-        lmno
-        <div class="math">
-        \mathbf{A}
-        </div>
+        '\n<div class="math">\nx\n</div>\nabs<span class="math">inline math</span>defg\n<div class="math">\ndisplay math x^2\n</div>\nhijk<span class="math">inline math</span>lmno\n<div class="math">\n\\mathbf{A}\n</div>\n'
     """
     import itertools
     # find math inside $$...$$
                 self.data += ref

     def parse_html(self, text, OutputCell = False, cell_id = None, temp_dir = None):
+        r"""
+        Parse html into LaTeX
+
+            sage: A=Html2Latex()
+            sage: A.parse_html(r"<p><span>We multiply the last row by $-1$ and add to the first row</span></p>")
+            '\n\n{\n We multiply the last row by $-1$ and add to the first row\\par}\n\n'
+
+            sage: A=Html2Latex()
+            sage: A.parse_html(r'T_hi_s i^s $a^2_x$ Test_ $$x^2$$ <a href="nothing">HTML</a> string.$sin(x)$test')
+            'T\\_hi\\_s i\\^{ }s $a^2_x$ Test\\_ \n$$\nx^2\n$$\n \\href{nothing}{HTML} string.$sin(x)$test'
+
+            sage: A=Html2Latex()
+            sage: A.parse_html(r'<p>Nested Tags: <a href="http://www.sagemath.org">This is <strong>all <em>inside a html $x^2$ link to the</em> sage</strong> website.</a> Outside of link.</p>')
+            '\n\n{\n Nested Tags: \\href{http://www.sagemath.org}{This is {\\bfseries all {\\itshape inside a html $x^2$ link to the} sage} website.} Outside of link.\\par}\n\n'
+
+        Paragraph alignment is recognized::
+
+            sage: A=Html2Latex()
+            sage: A.parse_html(r'<p style="text-align: right;">aligned paragraph</p>', OutputCell = False)
+            '\n\n{\\leftskip 0 pt plus 1 fill \\rightskip 0 pt\n aligned paragraph\\par}\n\n'
+
+        Pictures::
+
+            sage: A=Html2Latex()
+            sage: A.parse_html('<img src="cell://file.png"></img>', cell_id = 9)
+            '\\includegraphics{sage_worksheet/cells/9/file.png}'
+
+            sage: A=Html2Latex()
+            sage: A.parse_html('<img src="file.png"/>')
+            '\\includegraphics[]{sage_worksheet/data/file.png}'
+
+        """
         text = detect_math(text)
         self.cell_id = cell_id
         self.temp_dir = temp_dir