Ticket #14382: trac_14382-texttt.patch

File trac_14382-texttt.patch, 10.4 KB (added by jhpalmieri, 8 years ago)

use \text{\texttt{...}}

  • doc/de/tutorial/latex.rst

    # HG changeset patch
    # User Andrey Novoseltsev <novoselt@gmail.com>
    # Date 1364575466 21600
    # Node ID 2667d8dc48aee9868912285031f6da211e505f0b
    # Parent  06214e2286951cd38a9002310793a245cf7e1303
    Fix phantom spaces in LaTeX code of strings.
    
    diff --git a/doc/de/tutorial/latex.rst b/doc/de/tutorial/latex.rst
    a b  
    6666    sage: latex(integrate(z^4, z))
    6767    \frac{1}{5} \, z^{5}
    6868    sage: latex('a string')
    69     \verb|a|\phantom{\verb!x!}\verb|string|
     69    \text{\texttt{a{ }string}}
    7070    sage: latex(QQ)
    7171    \Bold{Q}
    7272    sage: latex(matrix(QQ, 2, 3, [[2,4,6],[-1,-1,-1]]))
  • doc/en/tutorial/latex.rst

    diff --git a/doc/en/tutorial/latex.rst b/doc/en/tutorial/latex.rst
    a b  
    6363    sage: latex(integrate(z^4, z))
    6464    \frac{1}{5} \, z^{5}
    6565    sage: latex('a string')
    66     \verb|a|\phantom{\verb!x!}\verb|string|
     66    \text{\texttt{a{ }string}}
    6767    sage: latex(QQ)
    6868    \Bold{Q}
    6969    sage: latex(matrix(QQ, 2, 3, [[2,4,6],[-1,-1,-1]]))
  • sage/combinat/free_module.py

    diff --git a/sage/combinat/free_module.py b/sage/combinat/free_module.py
    a b  
    19291929            sage: F = CombinatorialFreeModule(QQ, [('a', 'b'), (0,1,2)])
    19301930            sage: e = F.basis()
    19311931            sage: latex(e[('a','b')])    # indirect doctest
    1932             B_{\left(a, b\right)}
     1932            B_{('a', 'b')}
    19331933            sage: latex(2*e[(0,1,2)])    # indirect doctest
    19341934            2B_{\left(0, 1, 2\right)}
    19351935            sage: F = CombinatorialFreeModule(QQ, [('a', 'b'), (0,1,2)], prefix="")
     
    19401940        from sage.misc.latex import latex
    19411941
    19421942        s = latex(m)
    1943         if s.find('\\verb') != -1:
    1944             import re
    1945             s = re.sub("\\\\verb(.)(.*?)\\1", "\\2", s)
    1946             s = s.replace("\\phantom{x}", " ")
     1943        if s.find('\\text{\\textt') != -1:
     1944            # m contains "non-LaTeXed" strings, use string representation
     1945            s = str(m)
    19471946
    19481947        # dictionary with left-right pairs of "brackets".  put pairs
    19491948        # in here accept \\left and \\right as prefixes.
     
    25272526                sage: F.rename("F")
    25282527                sage: G.rename("G")
    25292528                sage: latex(tensor([F, F, G])) # indirect doctest
    2530                 \verb|F| \otimes \verb|F| \otimes \verb|G|
     2529                \text{\texttt{F}} \otimes \text{\texttt{F}} \otimes \text{\texttt{G}}
    25312530                sage: F._latex_ = lambda : "F"
    25322531                sage: G._latex_ = lambda : "G"
    25332532                sage: latex(tensor([F, F, G])) # indirect doctest
  • sage/graphs/generic_graph.py

    diff --git a/sage/graphs/generic_graph.py b/sage/graphs/generic_graph.py
    a b  
    1507015070              "0" -- "1";
    1507115071              "0" -- "2";
    1507215072              "1" -- "2";
    15073               "2" -- "3" [label=" ", texlbl="$\verb|foo|$"];
     15073              "2" -- "3" [label=" ", texlbl="$\text{\texttt{foo}}$"];
    1507415074            }
    1507515075
    1507615076        Same, with a digraph and a color for edges::
  • sage/groups/perm_gps/permgroup.py

    diff --git a/sage/groups/perm_gps/permgroup.py b/sage/groups/perm_gps/permgroup.py
    a b  
    14221422
    14231423            sage: S = SymmetricGroup(['a','b','c'])
    14241424            sage: latex(S)
    1425             \langle (\verb|a|,\verb|b|,\verb|c|), (\verb|a|,\verb|b|) \rangle
     1425            \langle (\text{\texttt{a}},\text{\texttt{b}},\text{\texttt{c}}), (\text{\texttt{a}},\text{\texttt{b}}) \rangle
    14261426        """
    14271427        return '\\langle ' + \
    14281428               ', '.join([x._latex_() for x in self.gens()]) + ' \\rangle'
  • sage/groups/perm_gps/permgroup_element.pyx

    diff --git a/sage/groups/perm_gps/permgroup_element.pyx b/sage/groups/perm_gps/permgroup_element.pyx
    a b  
    590590           
    591591            sage: S = SymmetricGroup(['a', 'b'])
    592592            sage: latex(S.gens())
    593             \left[(\verb|a|,\verb|b|)\right]
     593            \left[(\text{\texttt{a}},\text{\texttt{b}})\right]
    594594        """
    595595        from sage.misc.latex import latex
    596596        return "".join(["(" + ",".join([latex(x) for x in cycle])+")" for cycle in self.cycle_tuples()])
  • sage/misc/latex.py

    diff --git a/sage/misc/latex.py b/sage/misc/latex.py
    a b  
    312312        sage: str_function('+34.5')
    313313        '+34.5'
    314314        sage: str_function('hello_world')
    315         '\\verb|hello_world|'
     315        '\\text{\\texttt{hello{\\char`\\_}world}}'
    316316        sage: str_function('-1.00000?') # trac 12178
    317317        '-1.00000?'
    318318    """
     
    320320    # point, and/or ends with "?"
    321321    if re.match(r'(\+|-)?[0-9]*\.?[0-9]*\??$', x):
    322322        return x
    323     # Try to pick a delimiter.
    324     for delimiter in """|"'`#%&,.:;?!@_~^+-/\=<>()[]{}0123456789E""":
    325         if delimiter == "E":
    326             # x is too complicated
    327             return "\\begin{verbatim}\n%s\n\\end{verbatim}\n" % x
    328         if delimiter not in x:
    329             break
    330     wrapper = "\\verb" + delimiter + "%s" + delimiter
    331 
    332     # Strategy:
    333     # 1) break x into lines;
    334     # 2) wrap each line into \verb;
    335     # 3) assemble lines into a left-justified array.
    336    
    337     spacer = r"\phantom{\verb!%s!}"
    338     lines = []
    339     for line in x.split("\n"):
    340         parts = []
    341         nspaces = 0
    342         for part in line.split(" "):
    343             if part == "":
    344                 nspaces += 1
    345                 continue
    346             if nspaces > 0:
    347                 parts.append(spacer % ("x" * nspaces))
    348             nspaces = 1
    349             parts.append(wrapper % part)
    350         # There is also a bug with omitting empty lines in arrays...
    351         line = "".join(parts)
    352         if not line:   
    353             line = spacer % "x"
    354         lines.append(line)
    355     x = "\\\\\n".join(lines)
    356     # If the bugs were fixed, the above block could be just
    357     # x = "\\\\\n".join(wrapper % line for line in x.split("\n"))
     323    # Deal with special characters
     324    char_wrapper = r"{\char`\%s}"
     325    x = "".join(char_wrapper % c if c in "#$%&\^_{}~" else c for c in x)
     326    # Avoid grouping spaces into one
     327    x = x.replace(" ", "{ }")
     328    # And dashes too, since it causes issues for the command line...
     329    x = x.replace("-", "{-}")
     330    # Make it work in math mode, but look like typewriter
     331    line_wrapper = r"\text{\texttt{%s}}"
     332    x = "\\\\\n".join(line_wrapper % line for line in x.split("\n"))       
     333    # Preserve line breaks
    358334    if "\n" in x:
    359335        x = "\\begin{array}{l}\n%s\n\\end{array}" % x
    360336    return x
     
    973949        sage: latex(FiniteField(25,'a'))
    974950        \Bold{F}_{5^{2}}
    975951        sage: latex("hello")
    976         \verb|hello|
     952        \text{\texttt{hello}}
    977953        sage: LatexExpr(r"\frac{x^2 - 1}{x + 1} = x - 1")
    978954        \frac{x^2 - 1}{x + 1} = x - 1
    979955
     
    19461922        """
    19471923        # Get a regular LaTeX representation of x
    19481924        x = latex(x, combine_all=combine_all)
     1925           
     1926        # The following block, hopefully, can be removed in some future MathJax.
     1927        prefix = r"\text{\texttt{"
     1928        parts = x.split(prefix)
     1929        for i, part in enumerate(parts):
     1930            if i == 0:
     1931                continue    # Nothing to do with the head part
     1932            n = 1
     1933            for closing, c in enumerate(part):
     1934                if c == "{" and part[closing - 1] != "\\":
     1935                    n += 1
     1936                if c == "}" and part[closing - 1] != "\\":
     1937                    n -= 1
     1938                if n == -1:
     1939                    break
     1940            # part should end in "}}", so omit the last two characters
     1941            # from y
     1942            y = part[:closing-1]
     1943            for delimiter in """|"'`#%&,.:;?!@_~^+-/\=<>()[]{}0123456789E""":
     1944                if delimiter not in y:
     1945                    break
     1946            if delimiter == "E":
     1947                # y is too complicated
     1948                delimiter = "|"
     1949                y = "(complicated string)"
     1950            wrapper = r"\verb" + delimiter + "%s" + delimiter
     1951            spacer = r"\phantom{\verb!%s!}"
     1952            y = y.replace("{ }", " ").replace("{-}", "-")
     1953            for c in r"#$%&\^_{}~":
     1954                char_wrapper = r"{\char`\%s}" % c
     1955                y = y.replace(char_wrapper, c)
     1956            subparts = []
     1957            nspaces = 0
     1958            for subpart in y.split(" "):
     1959                if subpart == "":
     1960                    nspaces += 1
     1961                    continue
     1962                if nspaces > 0:
     1963                    subparts.append(spacer % ("x" * nspaces))
     1964                nspaces = 1
     1965                subparts.append(wrapper % subpart)
     1966            # There is a bug with omitting empty lines in arrays
     1967            if not y:   
     1968                subparts.append(spacer % "x")
     1969            subparts.append(part[closing + 1:])
     1970            parts[i] = "".join(subparts)
     1971        x = "".join(parts)
     1972
    19491973        # In MathJax:
    19501974        #   inline math: <script type="math/tex">...</script>
    19511975        #   displaymath: <script type="math/tex; mode=display">...</script>
     
    22792303        sage: t = PolynomialRing(QQ, 't').0
    22802304        sage: from sage.misc.latex import repr_lincomb
    22812305        sage: repr_lincomb(['a', 's', ''], [-t, t - 2, t^12 + 2])
    2282         '-t\\verb|a| + \\left(t - 2\\right)\\verb|s| + \\left(t^{12} + 2\\right)'
     2306        '-t\\text{\\texttt{a}} + \\left(t - 2\\right)\\text{\\texttt{s}} + \\left(t^{12} + 2\\right)'
    22832307        sage: repr_lincomb(['a', 'b'], [1,1])
    2284         '\\verb|a| + \\verb|b|'
     2308        '\\text{\\texttt{a}} + \\text{\\texttt{b}}'
    22852309
    22862310    Verify that a certain corner case works (see :trac:`5707` and
    22872311    :trac:`5766`)::
  • sage/modular/hecke/algebra.py

    diff --git a/sage/modular/hecke/algebra.py b/sage/modular/hecke/algebra.py
    a b  
    408408        EXAMPLES::
    409409
    410410            sage: latex(CuspForms(3, 24).hecke_algebra()) # indirect doctest
    411             \mathbf{T}_{\verb|Cuspidal|...Gamma0(3)...24...}
     411            \mathbf{T}_{\text{\texttt{Cuspidal...Gamma0(3)...24...}
    412412        """
    413413        from sage.misc.latex import latex
    414414        return "\\mathbf{T}_{%s}" % latex(self.__M)
  • sage/sets/set.py

    diff --git a/sage/sets/set.py b/sage/sets/set.py
    a b  
    252252        ::
    253253
    254254            sage: print latex(Primes())
    255             \verb|Set...of...all...prime...numbers:...|
     255            \text{\texttt{Set{ }of{ }all{ }prime{ }numbers:{ }2,{ }3,{ }5,{ }7,{ }...}}
    256256            sage: print latex(Set([1,1,1,5,6]))
    257257            \left\{1, 5, 6\right\}
    258258        """