|
100 | 100 | \iiint \iint \iint \oiiint"""] |
101 | 101 | ] |
102 | 102 |
|
103 | | -from docutils import nodes, statemachine |
104 | | -from docutils.parsers.rst import Directive |
105 | | -class math_symbol_table_directive(Directive): |
106 | | - has_content = True |
107 | | - def run(self): |
108 | | - def get_n(n, l): |
109 | | - part = [] |
110 | | - for x in l: |
111 | | - part.append(x) |
112 | | - if len(part) == n: |
113 | | - yield part |
114 | | - part = [] |
115 | | - yield part |
| 103 | +def run(state_machine): |
| 104 | + def get_n(n, l): |
| 105 | + part = [] |
| 106 | + for x in l: |
| 107 | + part.append(x) |
| 108 | + if len(part) == n: |
| 109 | + yield part |
| 110 | + part = [] |
| 111 | + yield part |
116 | 112 |
|
117 | | - lines = [] |
118 | | - for category, columns, syms in symbols: |
119 | | - syms = syms.split() |
120 | | - syms.sort() |
121 | | - lines.append("**%s**" % category) |
| 113 | + lines = [] |
| 114 | + for category, columns, syms in symbols: |
| 115 | + syms = syms.split() |
| 116 | + syms.sort() |
| 117 | + lines.append("**%s**" % category) |
| 118 | + lines.append('') |
| 119 | + max_width = 0 |
| 120 | + for sym in syms: |
| 121 | + max_width = max(max_width, len(sym)) |
| 122 | + max_width = max_width * 2 + 16 |
| 123 | + header = " " + (('=' * max_width) + ' ') * columns |
| 124 | + format = '%%%ds' % max_width |
| 125 | + for chunk in get_n(20, get_n(columns, syms)): |
| 126 | + lines.append(header) |
| 127 | + for part in chunk: |
| 128 | + line = [] |
| 129 | + for sym in part: |
| 130 | + line.append(format % (":math:`%s` ``%s``" % (sym, sym))) |
| 131 | + lines.append(" " + " ".join(line)) |
| 132 | + lines.append(header) |
122 | 133 | lines.append('') |
123 | | - max_width = 0 |
124 | | - for sym in syms: |
125 | | - max_width = max(max_width, len(sym)) |
126 | | - max_width = max_width * 2 + 16 |
127 | | - header = " " + (('=' * max_width) + ' ') * columns |
128 | | - format = '%%%ds' % max_width |
129 | | - for chunk in get_n(20, get_n(columns, syms)): |
130 | | - lines.append(header) |
131 | | - for part in chunk: |
132 | | - line = [] |
133 | | - for sym in part: |
134 | | - line.append(format % (":math:`%s` ``%s``" % (sym, sym))) |
135 | | - lines.append(" " + " ".join(line)) |
136 | | - lines.append(header) |
137 | | - lines.append('') |
138 | | - self.state_machine.insert_input(lines, "Symbol table") |
139 | | - return [] |
140 | 134 |
|
141 | | -from docutils.parsers.rst import directives |
142 | | -directives.register_directive('math_symbol_table', |
143 | | - math_symbol_table_directive) |
| 135 | + state_machine.insert_input(lines, "Symbol table") |
| 136 | + return [] |
| 137 | + |
| 138 | +try: |
| 139 | + from docutils.parsers.rst import Directive |
| 140 | +except ImportError: |
| 141 | + from docutils.parsers.rst.directives import _directives |
| 142 | + def math_symbol_table_directive(name, arguments, options, content, lineno, |
| 143 | + content_offset, block_text, state, state_machine): |
| 144 | + return run(state_machine) |
| 145 | + math_symbol_table_directive.arguments = None |
| 146 | + math_symbol_table_directive.options = {} |
| 147 | + math_symbol_table_directive.content = False |
| 148 | + _directives['math_symbol_table'] = math_symbol_table_directive |
| 149 | +else: |
| 150 | + class math_symbol_table_directive(Directive): |
| 151 | + has_content = False |
| 152 | + def run(self): |
| 153 | + return run(self.state_machine) |
| 154 | + from docutils.parsers.rst import directives |
| 155 | + directives.register_directive('math_symbol_table', |
| 156 | + math_symbol_table_directive) |
144 | 157 |
|
145 | 158 | if __name__ == "__main__": |
146 | 159 | # Do some verification of the tables |
|
0 commit comments