Exemplo n.º 1
0
    def test_inline(self):
        """Test math postitions"""
        pos = tex.math_positions(
            'some stuff $crazy tex!$ other stuff $more tex$')
        self.assertEqual([(11, 23), (36, 46)], pos)

        pos = tex.math_positions('$crazy tex!$ other stuff $more tex$')
        self.assertEqual([(0, 12), (25, 35)], pos)

        pos = tex.math_positions('$crazy tex!$')
        self.assertEqual([(0, 12)], pos)
Exemplo n.º 2
0
    def test_display2(self):
        txt = "critical density \\[p_{c}\n(Ng)[something] or other \\] which is in the intermeidiate"
        pos = tex.math_positions(txt)
        self.assertEqual([(17, 52)], pos)

        txt = "\\[p_{c}\n(Ng)[something] or other \\] which is in the intermediate"
        pos = tex.math_positions(txt)
        self.assertEqual([(0, 35)], pos)

        txt = "critical density \\[p_{c}\n(Ng)[something] or other \\]"
        pos = tex.math_positions(txt)
        self.assertEqual([(17, 52)], pos)
Exemplo n.º 3
0
    def test_split(self):
        txt = 'some stuff $crazy tex!$ other stuff $more tex$ more at the end'
        txtf = tex.split_for_maths(tex.math_positions(txt), txt)
        self.assertEqual(
            ''.join(txtf),
            txt,
        )

        self.assertEqual(len([True for chunk in txtf if tex.isMath(chunk)]), 2)

        txtf = tex.split_for_maths(tex.math_positions(dispaly_txt),
                                   dispaly_txt)
        self.assertEqual(''.join(txtf), dispaly_txt)
        self.assertTrue(any([tex.isMath(chunk) for chunk in txtf]))
Exemplo n.º 4
0
def _highlight_whole_texism(value: str) -> str:
    """
    Move highlighting from within TeXism to encapsulate whole statement.

    The overview is 
    1. The TeX positions are located
    2. The string is split into a list of strings on these boundaries
    3. Each TeX string has its tags moved out of it in a balanced way
    4. Each non-TeX string is split into span tags and non-span tags
    5. The list mapped so that non-TeX and TeX get escaped and span tags become Markup
    6. The list of strings joined.
    """
    pos = math_positions(value)
    if pos:
        splits = split_for_maths(pos, value)
    else:
        splits = [value]  #no math found so use whole value

    corrected: List[Union[str, Math]] = []
    for txt in splits:
        if not isMath(txt):
            corrected.append(txt)  # might want to escape non-tex here?
        else:
            corrected.extend(
                _de_highlight_math(txt))  # might want to escape tex here?

    return Markup(''.join([_escape(part) for part in corrected]))
Exemplo n.º 5
0
 def test_display(self):
     """Test math postitions"""
     txt = dispaly_txt
     pos = tex.math_positions(txt)
     for start, end in pos:
         self.assertEqual('$', txt[start],
                          "should start with $ or $$ delimiter")
         self.assertEqual('$', txt[end - 1],
                          "should end with $ or $$ delimiter")
Exemplo n.º 6
0
 def test_inline_pren(self):
     txt = 'critical density \\(p_{c}(Ng)\\) which is in the intermediate'
     pos = tex.math_positions(txt)
     self.assertEqual([(17, 30)], pos)