mailr20235 - in /trunk/docs/latex: fetch_docstrings.py relax.tex


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by edward on June 20, 2013 - 16:21:
Author: bugman
Date: Thu Jun 20 16:21:15 2013
New Revision: 20235

URL: http://svn.gna.org/viewcvs/relax?rev=20235&view=rev
Log:
The relax language definition is now auto-generated by the 
fetch_docstrings.py script.

This is for use in the relax user manual using the listings package.  The 
fetch_docstrings.py
script now creates the docs/latex/script_definition.tex file.  This is used 
by the relax.tex file
via an \include{} statement.  This setup allows all of the relax user 
functions to be dynamically
set as keywords for the relax language definition.


Modified:
    trunk/docs/latex/fetch_docstrings.py
    trunk/docs/latex/relax.tex

Modified: trunk/docs/latex/fetch_docstrings.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/docs/latex/fetch_docstrings.py?rev=20235&r1=20234&r2=20235&view=diff
==============================================================================
--- trunk/docs/latex/fetch_docstrings.py (original)
+++ trunk/docs/latex/fetch_docstrings.py Thu Jun 20 16:21:15 2013
@@ -23,6 +23,8 @@
 """User function definition conversion to LaTeX for the relax manual."""
 
 # Python module imports.
+from os import sep
+from os.path import dirname
 from re import search
 from string import ascii_letters, ascii_lowercase, punctuation, whitespace
 import sys
@@ -50,6 +52,7 @@
         self.in_quote = False
         self.table_count = 1
         self.uf_table_labels = []
+        self.path = dirname(file)
 
         # Set up the words to index.
         self.index_entries()
@@ -58,7 +61,10 @@
         self.file = open(file, 'w')
 
         # Loop over the user functions.
+        uf_names = []
         for self.uf_name, self.uf in uf_info.uf_loop():
+            # Add to the list.
+            uf_names.append(self.uf_name)
             # The user function class.
             self.uf_class = None
             if search('\.', self.uf_name):
@@ -83,6 +89,9 @@
 
         # Close the LaTeX file.
         self.file.close()
+
+        # Create the relax lstlisting definition.
+        self.script_definitions(uf_names)
 
 
     def break_functions(self, text):
@@ -740,6 +749,92 @@
 
         # Return the string.
         return string
+
+
+    def script_definitions(self, uf_names):
+        """Create a LaTeX file defining the relax language syntax for the 
listings package.
+
+        @param uf_names:    The list of all user function names.
+        @type uf_names:     list of str
+        """
+
+        # Open the file.
+        file = open(self.path + sep + 'script_definition.tex', 'w')
+
+        # Python keywords.
+        py_keywords = [
+            'and',
+            'assert',
+            'break',
+            'continue',
+            'del',
+            'else',
+            'exec',
+            'global',
+            'if',
+            'in',
+            'is',
+            'for',
+            'not',
+            'or',
+            'pass',
+            'print',
+            'raise',
+            'return',
+            'while',
+            'yield'
+        ]
+        py_keywords2 = [
+            'as',
+            'from',
+            'import',
+        ]
+        py_keywords3 = [
+            'class',
+            'def',
+        ]
+
+        # The relax language.
+        file.write("\lstdefinelanguage{relax}{\n")
+
+        # Allow the user function '.' character to be part of the keywords.
+        file.write("    alsoletter={.},\n")
+
+        # Output the first set of Python keywords.
+        file.write("    morekeywords={")
+        for name in py_keywords:
+            file.write("%s," % name)
+        file.write("},\n")
+
+        # Output the second set of Python keywords.
+        file.write("    morekeywords=[2]{")
+        for name in py_keywords2:
+            file.write("%s," % name)
+        file.write("},\n")
+
+        # Output the third set of Python keywords.
+        file.write("    morekeywords=[3]{")
+        for name in py_keywords3:
+            file.write("%s," % name)
+        file.write("},\n")
+
+        # Output the relax user functions as keywords.
+        file.write("    morekeywords=[4]{")
+        for name in uf_names:
+            file.write("%s," % name)
+        file.write("},\n")
+
+        # The rest of the definition.
+        file.write("    moreprocnamekeys={def,class},\n")
+        file.write("    sensitive=true,\n")
+        file.write("    morecomment=[l]{\#},\n")
+        file.write("    morestring=[b]',\n")
+        file.write("    morestring=[b]\",\n")
+        file.write("    morestring=[b]\"\"\",\n")
+        file.write("}\n")
+
+        # Close the file.
+        file.close()
 
 
     def tabular_wrapping(self, table, max_char=100):

Modified: trunk/docs/latex/relax.tex
URL: 
http://svn.gna.org/viewcvs/relax/trunk/docs/latex/relax.tex?rev=20235&r1=20234&r2=20235&view=diff
==============================================================================
--- trunk/docs/latex/relax.tex (original)
+++ trunk/docs/latex/relax.tex Thu Jun 20 16:21:15 2013
@@ -42,51 +42,7 @@
 \usepackage[procnames]{listings}
 \usepackage[svgnames]{xcolor}
 \usepackage{textcomp}
-\lstdefinelanguage{relax}{
-    alsoletter={.},
-    morekeywords={
-        and,
-        assert,
-        break,
-        continue,
-        del,
-        else,
-        exec,
-        global,
-        if,
-        in,
-        is,
-        for,
-        not,
-        or,
-        pass,
-        print,
-        raise,
-        return,
-        while,
-        yield,
-    },
-    morekeywords=[2]{
-        as,
-        from,
-        import,
-    },
-    morekeywords=[3]{
-        class,
-        def,
-    },
-    morekeywords=[4]{
-        pipe.create,
-        spin.name,
-        spin.element,
-    },
-    moreprocnamekeys={def,class},
-    sensitive=true,
-    morecomment=[l]{\#},
-    morestring=[b]',
-    morestring=[b]",
-    morestring=[b]""",
-}
+\include{script_definition}
 \lstset{
     backgroundcolor=\color{white},
     basewidth=0.5em,




Related Messages


Powered by MHonArc, Updated Thu Jun 20 16:40:02 2013