Ticket #11067: trac_11067.patch

File trac_11067.patch, 1.9 KB (added by was, 10 years ago)
  • sage-doctest

    # HG changeset patch
    # User William Stein <wstein@gmail.com>
    # Date 1301266081 25200
    # Node ID e7cfb8a848c3ddcdb19e7ea2ec379a6a3eddc029
    # Parent  e18b4ae3fcbe4afd1642b94e8646f8973fdf0716
    trac 11067 -- make it possible to use lstlisting instead of verbose in latex document without breaking "sage -t"
    
    diff --git a/sage-doctest b/sage-doctest
    a b  
    491491        string -- python program that has functions with docstrings made from the
    492492                  verbatim examples in the latex file.
    493493    """
     494    verb_words = ['verbatim', 'lstlisting']
     495   
    494496    # Close links:
    495     F = F.replace('\\end{verbatim}%link','')
    496     F = F.replace('%link\n\\begin{verbatim}','')
     497    for word in verb_words:
     498        F = F.replace('\\end{%s}%%link'%word,'')
     499        F = F.replace('%%link\n\\begin{%s}'%word,'')
    497500   
    498     # Get rid of skipped code
    499     s = ''
    500     while True:
    501         i = F.find('%skip')
    502         if i == -1:
    503             s += F
    504             break
    505         s += F[:i]
    506         F = F[i:]
    507         j = F.find('\\end{verbatim}')
    508         if j == -1:
    509             break
    510         F = F[j + len('\\end{verbatim}')+1:]
    511     F = s
    512    
    513     # Make the verbatim environ's get extracted via the usual parser above
    514     F = F.replace("\\begin{verbatim}",'"""')
    515     F = F.replace("\\end{verbatim}",'"""')
     501        # Get rid of skipped code
     502        s = ''
     503        while True:
     504            i = F.find('%skip')
     505            if i == -1:
     506                s += F
     507                break
     508            s += F[:i]
     509            F = F[i:]
     510            j = F.find('\\end{%s}'%word)
     511            if j == -1:
     512                break
     513            F = F[j + len('\\end{%s}'%word)+1:]
     514        F = s
     515
     516        # Make the verbatim environ's get extracted via the usual parser above
     517        F = F.replace("\\begin{%s}"%word,'"""')
     518        F = F.replace("\\end{%s}"%word,'"""')
    516519    return F
    517520
    518521def pythonify_rst(F):