~ubuntu-branches/ubuntu/trusty/nwchem/trusty-proposed

« back to all changes in this revision

Viewing changes to src/tools/ga-5-2/python/docs/scipy_11/publisher/writer.py

  • Committer: Package Import Robot
  • Author(s): Michael Banck, Daniel Leidert, Andreas Tille, Michael Banck
  • Date: 2013-07-04 12:14:55 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20130704121455-5tvsx2qabor3nrui
Tags: 6.3-1
* New upstream release.
* Fixes anisotropic properties (Closes: #696361).
* New features include:
  + Multi-reference coupled cluster (MRCC) approaches
  + Hybrid DFT calculations with short-range HF 
  + New density-functionals including Minnesota (M08, M11) and HSE hybrid
    functionals
  + X-ray absorption spectroscopy (XAS) with TDDFT
  + Analytical gradients for the COSMO solvation model
  + Transition densities from TDDFT 
  + DFT+U and Electron-Transfer (ET) methods for plane wave calculations
  + Exploitation of space group symmetry in plane wave geometry optimizations
  + Local density of states (LDOS) collective variable added to Metadynamics
  + Various new XC functionals added for plane wave calculations, including
    hybrid and range-corrected ones
  + Electric field gradients with relativistic corrections 
  + Nudged Elastic Band optimization method
  + Updated basis sets and ECPs 

[ Daniel Leidert ]
* debian/watch: Fixed.

[ Andreas Tille ]
* debian/upstream: References

[ Michael Banck ]
* debian/upstream (Name): New field.
* debian/patches/02_makefile_flags.patch: Refreshed.
* debian/patches/06_statfs_kfreebsd.patch: Likewise.
* debian/patches/07_ga_target_force_linux.patch: Likewise.
* debian/patches/05_avoid_inline_assembler.patch: Removed, no longer needed.
* debian/patches/09_backported_6.1.1_fixes.patch: Likewise.
* debian/control (Build-Depends): Added gfortran-4.7 and gcc-4.7.
* debian/patches/10_force_gcc-4.7.patch: New patch, explicitly sets
  gfortran-4.7 and gcc-4.7, fixes test suite hang with gcc-4.8 (Closes:
  #701328, #713262).
* debian/testsuite: Added tests for COSMO analytical gradients and MRCC.
* debian/rules (MRCC_METHODS): New variable, required to enable MRCC methods.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
__all__ = ['writer']
 
2
 
 
3
import docutils.core as dc
 
4
import docutils.writers
 
5
from docutils import nodes
 
6
 
 
7
from docutils.writers.latex2e import (Writer, LaTeXTranslator,
 
8
                                      PreambleCmds)
 
9
 
 
10
from rstmath import mathEnv
 
11
import code_block
 
12
 
 
13
from options import options
 
14
 
 
15
PreambleCmds.float_settings = '''
 
16
\\usepackage[font={small,it},labelfont=bf]{caption}
 
17
\\usepackage{float}
 
18
'''
 
19
 
 
20
class Translator(LaTeXTranslator):
 
21
    def __init__(self, *args, **kwargs):
 
22
        LaTeXTranslator.__init__(self, *args, **kwargs)
 
23
 
 
24
    # Handle author declarations
 
25
 
 
26
    current_field = ''
 
27
 
 
28
    author_names = []
 
29
    author_institutions = []
 
30
    author_emails = []
 
31
    paper_title = ''
 
32
    table_caption = []
 
33
 
 
34
    abstract_in_progress = False
 
35
    non_breaking_paragraph = False
 
36
 
 
37
    def visit_docinfo(self, node):
 
38
        pass
 
39
 
 
40
    def depart_docinfo(self, node):
 
41
        pass
 
42
 
 
43
    def visit_author(self, node):
 
44
        self.author_names.append(self.encode(node.astext()))
 
45
        raise nodes.SkipNode
 
46
 
 
47
    def depart_author(self, node):
 
48
        pass
 
49
 
 
50
    def visit_classifier(self, node):
 
51
        pass
 
52
 
 
53
    def depart_classifier(self, node):
 
54
        pass
 
55
 
 
56
    def visit_field_name(self, node):
 
57
        self.current_field = node.astext()
 
58
        raise nodes.SkipNode
 
59
 
 
60
    def visit_field_body(self, node):
 
61
        text = self.encode(node.astext())
 
62
 
 
63
        if self.current_field == 'email':
 
64
            self.author_emails.append(text)
 
65
        elif self.current_field == 'institution':
 
66
            self.author_institutions.append(text)
 
67
 
 
68
        self.current_field = ''
 
69
 
 
70
        raise nodes.SkipNode
 
71
 
 
72
    def depart_field_body(self, node):
 
73
        raise nodes.SkipNode
 
74
 
 
75
    def depart_document(self, node):
 
76
        LaTeXTranslator.depart_document(self, node)
 
77
 
 
78
        title = self.paper_title
 
79
        authors = ', '.join(self.author_names)
 
80
 
 
81
        author_notes = ['''
 
82
The corresponding author is with %s, e-mail: \protect\href{%s}{%s}.
 
83
        ''' % (self.author_institutions[0], 'mailto:' + self.author_emails[0],
 
84
       self.author_emails[0])]
 
85
 
 
86
        author_notes = ''.join('\\thanks{%s}' % n for n in author_notes)
 
87
 
 
88
        title_template = '\\title{%s}\\author{%s%s}\\maketitle'
 
89
        title_template = title_template % (title,
 
90
                                           authors,
 
91
                                           author_notes)
 
92
 
 
93
        marks = r'''
 
94
        \renewcommand{\leftmark}{%s}
 
95
        \renewcommand{\rightmark}{%s}
 
96
        ''' % (options['proceedings_title'], title.upper())
 
97
        title_template += marks
 
98
 
 
99
        self.body_pre_docinfo = [title_template]
 
100
 
 
101
    def end_open_abstract(self, node):
 
102
        if 'abstract' not in node['classes'] and self.abstract_in_progress:
 
103
            self.out.append('\\end{abstract}')
 
104
            self.abstract_in_progress = False
 
105
 
 
106
    def visit_title(self, node):
 
107
        self.end_open_abstract(node)
 
108
 
 
109
        if self.section_level == 1:
 
110
            if self.paper_title:
 
111
                import warnings
 
112
                warnings.warn(RuntimeWarning("Title set twice--ignored. "
 
113
                                             "Could be due to ReST"
 
114
                                             "error.)"))
 
115
            else:
 
116
                self.paper_title = self.encode(node.astext())
 
117
            raise nodes.SkipNode
 
118
 
 
119
        elif node.astext() == 'References':
 
120
            raise nodes.SkipNode
 
121
 
 
122
        LaTeXTranslator.visit_title(self, node)
 
123
 
 
124
    def visit_paragraph(self, node):
 
125
        self.end_open_abstract(node)
 
126
 
 
127
        if 'abstract' in node['classes'] and not self.abstract_in_progress:
 
128
            self.out.append('\\begin{abstract}')
 
129
            self.abstract_in_progress = True
 
130
 
 
131
        elif 'keywords' in node['classes']:
 
132
            self.out.append('\\begin{IEEEkeywords}')
 
133
 
 
134
        elif self.non_breaking_paragraph:
 
135
            self.non_breaking_paragraph = False
 
136
 
 
137
        else:
 
138
            self.out.append('\n\n')
 
139
 
 
140
    def depart_paragraph(self, node):
 
141
        if 'keywords' in node['classes']:
 
142
            self.out.append('\\end{IEEEkeywords}')
 
143
 
 
144
    def visit_figure(self, node):
 
145
        self.requirements['float_settings'] = PreambleCmds.float_settings
 
146
        if 'classes' in node.attributes:
 
147
            placements = ''.join(node.attributes['classes'])
 
148
            self.out.append('\\begin{figure}[%s]'%placements)
 
149
        else:
 
150
            self.out.append('\\begin{figure}')
 
151
        if node.get('ids'):
 
152
            self.out += ['\n'] + self.ids_to_labels(node)
 
153
 
 
154
    def visit_image(self, node):
 
155
        attrs = node.attributes
 
156
 
 
157
        # Only add \columnwidth if scale or width have not been specified.
 
158
        if 'scale' not in node.attributes and 'width' not in node.attributes:
 
159
            node.attributes['width'] = '\columnwidth'
 
160
 
 
161
        node.attributes['align'] = 'left'
 
162
 
 
163
        LaTeXTranslator.visit_image(self, node)
 
164
 
 
165
    def visit_footnote(self, node):
 
166
        # Work-around for a bug in docutils where
 
167
        # "%" is prepended to footnote text
 
168
        LaTeXTranslator.visit_footnote(self, node)
 
169
        self.out[-1] = self.out[1].strip('%')
 
170
 
 
171
        self.non_breaking_paragraph = True
 
172
 
 
173
    def visit_table(self, node):
 
174
        self.out.append(r'\begin{table}')
 
175
        LaTeXTranslator.visit_table(self, node)
 
176
 
 
177
    def depart_table(self, node):
 
178
        LaTeXTranslator.depart_table(self, node)
 
179
 
 
180
        self.out.append(r'\caption{%s}' % ''.join(self.table_caption))
 
181
        self.table_caption = []
 
182
 
 
183
        self.out.append(r'\end{table}')
 
184
        self.active_table.set('preamble written', 1)
 
185
 
 
186
    def visit_thead(self, node):
 
187
        # Store table caption locally and then remove it
 
188
        # from the table so that docutils doesn't render it
 
189
        # (in the wrong place)
 
190
        self.table_caption = self.active_table.caption
 
191
        self.active_table.caption = []
 
192
 
 
193
        LaTeXTranslator.visit_thead(self, node)
 
194
 
 
195
    def depart_thead(self, node):
 
196
        LaTeXTranslator.depart_thead(self, node)
 
197
 
 
198
    def visit_literal_block(self, node):
 
199
        self.non_breaking_paragraph = True
 
200
 
 
201
        if 'language' in node.attributes:
 
202
            # do highlighting
 
203
            from pygments import highlight
 
204
            from pygments.lexers import PythonLexer, get_lexer_by_name
 
205
            from pygments.formatters import LatexFormatter
 
206
 
 
207
            extra_opts = 'fontsize=\\footnotesize'
 
208
 
 
209
            linenos = node.attributes.get('linenos', False)
 
210
            linenostart = node.attributes.get('linenostart', 1)
 
211
            if linenos:
 
212
                extra_opts += ',xleftmargin=2.25mm,numbersep=3pt'
 
213
 
 
214
            lexer = get_lexer_by_name(node.attributes['language'])
 
215
            tex = highlight(node.astext(), lexer,
 
216
                            LatexFormatter(linenos=linenos,
 
217
                                           linenostart=linenostart,
 
218
                                           verboptions=extra_opts))
 
219
 
 
220
            self.out.append(tex)
 
221
            raise nodes.SkipNode
 
222
        else:
 
223
            LaTeXTranslator.visit_literal_block(self, node)
 
224
 
 
225
    def depart_literal_block(self, node):
 
226
        LaTeXTranslator.depart_literal_block(self, node)
 
227
 
 
228
 
 
229
    # Math directives from rstex
 
230
 
 
231
    def visit_InlineMath(self, node):
 
232
        self.requirements['amsmath'] = r'\usepackage{amsmath}'
 
233
        self.body.append('$' + node['latex'] + '$')
 
234
        raise nodes.SkipNode
 
235
 
 
236
    def visit_PartMath(self, node):
 
237
        self.requirements['amsmath'] = r'\usepackage{amsmath}'
 
238
        self.body.append(mathEnv(node['latex'], node['label'], node['type']))
 
239
        self.non_breaking_paragraph = True
 
240
        raise nodes.SkipNode
 
241
 
 
242
    def visit_PartLaTeX(self, node):
 
243
        if node["usepackage"]:
 
244
            for package in node["usepackage"]:
 
245
                self.requirements[package] = r'\usepackage{%s}' % package
 
246
        self.body.append("\n" + node['latex'] + "\n")
 
247
        raise nodes.SkipNode
 
248
 
 
249
 
 
250
writer = Writer()
 
251
writer.translator_class = Translator