def visit_footnote(self, node):
        # Work-around for a bug in docutils where
        # "%" is prepended to footnote text
        LaTeXTranslator.visit_footnote(self, node)
        self.out[-1] = self.out[1].strip('%')

        self.non_breaking_paragraph = True
Exemple #2
0
    def __init__(self, document):
        LaTeXTranslator.__init__(self, document)
        self.label_prefix = ""
        self.docinfo = {}
        self.head_prefix = []
        self.head = []
        self.body_prefix = []
        self.in_title = False
        self.in_anydesc = False  # _title is different if it is a funcdesc
        self.admonition_stack = []

        # Disable a bunch of methods from the base class.
        empty_method = lambda self: None
        for nodetype in ('field_argument',
                         'field_body',
                         'field_list',
                         'field_name'):
            setattr(self, 'visit_' + nodetype, empty_method)
            setattr(self, 'depart_' + nodetype, empty_method)
        self.head_prefix = []
        # definitions must be guarded if multiple modules are included
        self.definitions = [
                "\\ifx\\locallinewidth\\undefined\\newlength{\\locallinewidth}\\fi\n"
                "\\setlength{\\locallinewidth}{\\linewidth}\n"
            ]
    def __init__(self, *args, **kwargs):
        LaTeXTranslator.__init__(self, *args, **kwargs)

        # Handle author declarations

        self.current_field = ''

        self.copyright_holder = None
        self.author_names = []
        self.author_institutions = []
        self.author_institution_map = dict()
        self.author_emails = []
        self.corresponding = []
        self.equal_contributors = []
        self.paper_title = ''
        self.abstract_text = []
        self.keywords = ''
        self.table_caption = []
        self.video_url = ''
        self.bibliography = ''

        # This gets read by the underlying docutils implementation.
        # If present, it is a list with the first entry the style name
        # and the second entry the BiBTeX file (see `visit_field_body`)
        self.bibtex = None

        self.abstract_in_progress = False
        self.non_breaking_paragraph = False

        self.figure_type = 'figure'
        self.figure_alignment = 'left'
        self.table_type = 'table'

        self.active_table.set_table_style('booktabs')
    def visit_literal_block(self, node):
        self.non_breaking_paragraph = True

        if "language" in node.attributes:
            # do highlighting
            from pygments import highlight
            from pygments.lexers import PythonLexer, get_lexer_by_name
            from pygments.formatters import LatexFormatter

            extra_opts = "fontsize=\\footnotesize"

            linenos = node.attributes.get("linenos", False)
            linenostart = node.attributes.get("linenostart", 1)
            if linenos:
                extra_opts += ",xleftmargin=2.25mm,numbersep=3pt"

            lexer = get_lexer_by_name(node.attributes["language"])
            tex = highlight(
                node.astext(), lexer, LatexFormatter(linenos=linenos, linenostart=linenostart, verboptions=extra_opts)
            )

            self.out.append("\\vspace{1mm}\n" + tex + "\\vspace{1mm}\n")
            raise nodes.SkipNode
        else:
            LaTeXTranslator.visit_literal_block(self, node)
    def visit_literal_block(self, node):
        self.non_breaking_paragraph = True

        if 'language' in node.attributes:
            # do highlighting
            from pygments import highlight
            from pygments.lexers import get_lexer_by_name
            from pygments.formatters import LatexFormatter

            extra_opts = 'fontsize=\\footnotesize'

            linenos = node.attributes.get('linenos', False)
            linenostart = node.attributes.get('linenostart', 1)
            if linenos:
                extra_opts += ',xleftmargin=2.25mm,numbersep=3pt'

            lexer = get_lexer_by_name(node.attributes['language'])
            tex = highlight(node.astext(), lexer,
                            LatexFormatter(linenos=linenos,
                                           linenostart=linenostart,
                                           verboptions=extra_opts))

            self.out.append(tex)
            raise nodes.SkipNode
        else:
            LaTeXTranslator.visit_literal_block(self, node)
        def __init__ (self, document):
                LaTeXTranslator.__init__ (self, document)
                self.head_prefix = [x for x in self.head_prefix if ('{typearea}' not in x)]
                hyperref_posn = [i for i in range (len (self.head_prefix)) if ('{hyperref}' in self.head_prefix[i])]
                self.head_prefix = [curline+'\n' for curline in self.head_prefix]

                try:
                    self.head_prefix[hyperref_posn[0]] = '\\usepackage{hyperref}\n'
                except:
                    self.head_prefix[2] = '\\usepackage{hyperref}\n'
                
##                 self.head_prefix.extend ([
##                         '\\definecolor{rrblitbackground}{rgb}{0.55, 0.3, 0.1}\n',
##                         '\\newenvironment{rtbliteral}{\n',
##                         '\\begin{ttfamily}\n',
##                         '\\color{rrblitbackground}\n',
##                         '}{\n',
##                         '\\end{ttfamily}\n',
##                         '}\n',
##                 ])
                theme = document.settings.theme
                if theme:
                    self.head_prefix.append('\\usetheme{%s}\n' % theme)

                self.overlay_bullets = string_to_bool(document.settings.overlaybullets, False)#using a False default because
                #True is the actual default.  If you are trying to pass in a value
                #and I can't determine what you really meant, I am assuming you
                #want something other than the actual default.
                self.centerfigs = string_to_bool(document.settings.centerfigs, False)#same reasoning as above

                self.frame_level = 0

                # this fixes the hardcoded section titles in docutils 0.4
                self.d_class = DocumentClass ('article')
Exemple #7
0
    def depart_document(self, node):
        'customize document title a la beamer'
        LaTeXTranslator.depart_document(self, node)
        if self.title or self.author_stack or self.date:
            authors = ['\\\\\n'.join(author_entry)
                       for author_entry in self.author_stack]
            title = [''.join(self.title)] + self.title_labels
            shorttitle = ''.join(self.title)
            shortauthor = ''.join(self.pdfauthor)

            if self.subtitle:
                title += [r'\\ % subtitle',
                             r'\large{%s}' % ''.join(self.subtitle)
                         ] + self.subtitle_labels
            docinfo_list = [shorttitle,
                            '%\n  '.join(title),
                            shortauthor,
                            ' \\and\n'.join(authors),
                            ', '.join(self.date)]
            if self.organization is None:
                docinfo_str = PreambleCmds.documenttitle % tuple(docinfo_list)
            else:
                docinfo_list.append(self.organization)
                docinfo_str = docinfo_w_institute % tuple(docinfo_list)
            self.body_pre_docinfo[:] = [docinfo_str] # replace default title
Exemple #8
0
 def depart_literal_block (self, node):
     # FIX: see `visit_literal_block`
     if (node_has_class (node, 'code-block') and self.cb_use_pygments):
         self.visit_codeblock (node)
     else:
         LaTeXTranslator.depart_literal_block (self, node)
         self.out.append ( '\\setbeamerfont{quote}{parent=quotation}\n' )
    def __init__(self, *args, **kwargs):
        LaTeXTranslator.__init__(self, *args, **kwargs)

        # Handle author declarations

        self.current_field = ''

        self.author_names = []
        self.author_institutions = []
        self.author_institution_map = dict()
        self.author_emails = []
        self.paper_title = ''
        self.abstract_text = []
        self.keywords = ''
        self.table_caption = []
        self.video_url = ''

        self.abstract_in_progress = False
        self.non_breaking_paragraph = False

        self.figure_type = 'figure'
        self.figure_alignment = 'left'
        self.table_type = 'table'

        self.active_table.set_table_style('booktabs')
Exemple #10
0
 def visit_image(self, node):
     attrs = node.attributes
     if not 'align' in attrs and self.centerfigs:
         attrs['align'] = 'center'
     if ('height' not in attrs) and ('width' not in attrs):
         attrs['height'] = '0.75\\textheight'
     LaTeXTranslator.visit_image(self, node)
Exemple #11
0
    def depart_document(self, node):
        LaTeXTranslator.depart_document(self, node)

        title = self.paper_title
        authors = ', '.join(self.author_names)

        author_notes = ['''
The corresponding author is with %s, e-mail: \protect\href{%s}{%s}.
''' % (self.author_institutions[0], self.author_emails[0],
       self.author_emails[0])]

        author_notes = ''.join('\\thanks{%s}' % n for n in author_notes)

        title_template = '\\title{%s}\\author{%s%s}\\maketitle'
        title_template = title_template % (title,
                                           authors,
                                           author_notes)

        marks = r'''
        \renewcommand{\leftmark}{%s}
        \renewcommand{\rightmark}{%s}
        ''' % (options['proceedings_title'], title.upper())
        title_template += marks

        self.body_pre_docinfo = [title_template]
 def visit_title (self, node):
         if node.astext() == 'dummy':
             raise nodes.SkipNode
         if (self.section_level == self.frame_level+1):#1
                 self.body.append ('\\frametitle{%s}\n\n' % self.encode(node.astext()))
                 raise nodes.SkipNode
         else:
                 LaTeXTranslator.visit_title (self, node)
    def depart_table(self, node):
        LaTeXTranslator.depart_table(self, node)

        self.out.append(r'\caption{%s}' % ''.join(self.table_caption))
        self.table_caption = []

        self.out.append(r'\end{%s}' % self.table_type)
        self.active_table.set('preamble written', 1)
Exemple #14
0
 def visit_section (self, node):
     if has_sub_sections (node):
         temp = self.section_level + 1
         if temp > self.frame_level:
             self.frame_level = temp
     else:
         self.out.append (self.begin_frametag(node))
     LaTeXTranslator.visit_section (self, node)
    def depart_table(self, node):
        LaTeXTranslator.depart_table(self, node)

        self.out.append(r"\caption{%s}" % "".join(self.table_caption))
        self.table_caption = []

        self.out.append(r"\end{table}")
        self.active_table.set("preamble written", 1)
    def visit_thead(self, node):
        # Store table caption locally and then remove it
        # from the table so that docutils doesn't render it
        # (in the wrong place)
        self.table_caption = self.active_table.caption
        self.active_table.caption = []

        LaTeXTranslator.visit_thead(self, node)
Exemple #17
0
 def depart_container (self, node):
     if (node_has_class (node, 'r2b-simplecolumns')):
         self.depart_columnset (node)
     elif (node_has_class (node, 'r2b-note')):
         self.depart_beamer_note (node)
     else:
         # currently the LaTeXTranslator does nothing, but just in case
         LaTeXTranslator.depart_container (self, node)
 def visit_title(self, node):
     if node.astext() == 'dummy':
         raise nodes.SkipNode
     if (self.section_level == self.frame_level + 1):  #1
         self.out.append ('\\frametitle{%s}\n\n' % \
             self.encode(node.astext()))
         raise nodes.SkipNode
     else:
         LaTeXTranslator.visit_title(self, node)
 def visit_section (self, node):
         if has_sub_sections(node):
             temp = self.section_level + 1
             if temp > self.frame_level:
                 self.frame_level = temp
                 #print('self.frame_level=%s' % self.frame_level)
         else:
             self.body.append (self.begin_frametag())
         LaTeXTranslator.visit_section (self, node)
Exemple #20
0
    def depart_table(self, node):
        LaTeXTranslator.depart_table(self, node)

        self.out.append(r'\caption{%s}' % ''.join(self.table_caption))
        self.table_caption = []

        self.out.append(r'\end{%s}' % self.table_type)
        self.active_table.set('preamble written', 1)
        self.active_table.set_table_style('booktabs')
Exemple #21
0
 def depart_section (self, node):
     # Remove counter for potential subsections:
     LaTeXTranslator.depart_section (self, node)
     if (self.section_level == self.frame_level):#0
         self.out.append (self.end_frametag())
     try: # insert raw code defered to after endframe
         self.out.append('\n'.join(node._raw_append))
     except AttributeError:
         pass
    def visit_table(self, node):
        classes = node.attributes.get('classes', [])
        if 'w' in classes:
            self.table_type = 'table*'
        else:
            self.table_type = 'table'

        self.out.append(r'\begin{%s}' % self.table_type)
        LaTeXTranslator.visit_table(self, node)
Exemple #23
0
    def visit_table(self, node):
        classes = node.attributes.get('classes', [])
        if 'w' in classes:
            self.table_type = 'table*'
        else:
            self.table_type = 'table'

        self.out.append(r'\begin{%s}' % self.table_type)
        LaTeXTranslator.visit_table(self, node)
    def visit_table(self, node):
        classes = node.attributes.get("classes", [])
        if "w" in classes:
            self.table_type = "table*"
        else:
            self.table_type = "table"

        self.out.append(r"\begin{%s}" % self.table_type)
        LaTeXTranslator.visit_table(self, node)
    def depart_document(self, node):
        self.out.append(r'\bibliography{refs}')

        LaTeXTranslator.depart_document(self, node)

        ## Generate footmarks

        # build map: institution -> (author1, author2)
        institution_authors = OrderedDict()
        for auth, inst in zip(self.author_names, self.author_institutions):
            institution_authors.setdefault(inst, []).append(auth)

        def footmark(n):
            """Insert footmark #n.  Footmark 1 is reserved for
            the corresponding author.
            """
            return ('\\setcounter{footnotecounter}{%d}' % n,
                    '%d' % n)

        # Build one footmark for each institution
        institute_footmark = {}
        for i, inst in enumerate(institution_authors):
            institute_footmark[inst] = footmark(i + 2)

        corresponding_auth_template = r'''%%
          \affil[%(footmark_counter)s]{%
          Corresponding author: \protect\href{mailto:%(email)s}{%(email)s}}'''

        title = self.paper_title
        authors = []
        institutions_mentioned = set()
        for n, (auth, inst) in enumerate(zip(self.author_names,
                                             self.author_institutions)):
            # Corresponding author
            if n == 0:
                authors += [r'\author[%d,%d]{%s}' % (n, n + 1, auth)]
                authors += [r'\affil[0]{%s}' % self.author_emails[0]]
            else:
                authors += [r'\author[%d]{%s}' % (n + 1, auth)]

            authors += [r'\affil[%d]{%s}' % (n + 1, inst)]

        title_template = r'\newcounter{footnotecounter}' \
                r'\title{%s}%s\maketitle'
        title_template = title_template % (title, '\n'.join(authors))

        self.body_pre_docinfo = ['\n'.join(self.abstract_text) + title_template]

        # Save paper stats
        self.document.stats = {'title': title,
                               'authors': ', '.join(self.author_names),
                               'author': self.author_names,
                               'author_email': self.author_emails,
                               'author_institution': self.author_institutions,
                               'abstract': self.abstract_text,
                               'keywords': self.keywords}
    def visit_image(self, node):
        attrs = node.attributes

        # Only add \columnwidth if scale or width have not been specified.
        if 'scale' not in node.attributes and 'width' not in node.attributes:
            node.attributes['width'] = '\columnwidth'

        node.attributes['align'] = 'left'

        LaTeXTranslator.visit_image(self, node)
    def visit_image(self, node):
        attrs = node.attributes

        # Only add \columnwidth if scale or width have not been specified.
        if 'scale' not in node.attributes and 'width' not in node.attributes:
            node.attributes['width'] = '\columnwidth'

        node.attributes['align'] = 'left'

        LaTeXTranslator.visit_image(self, node)
Exemple #28
0
 def visit_literal_block (self, node):
     # FIX: the purpose of this method is unclear, but it causes parsed
     # literals in docutils 0.6 to lose indenting. Thus we've solve the
     # problem be just getting rid of it. [PMA 20091020]
     # TODO: replace leading tabs like in codeblocks?
     if (node_has_class (node, 'code-block') and self.cb_use_pygments):
         self.visit_codeblock (node)
     else:
         self.out.append ('\\setbeamerfont{quote}{parent={}}\n')
         LaTeXTranslator.visit_literal_block (self, node)
Exemple #29
0
 def visit_literal_block(self, node):
     # FIXME: the purpose of this method is unclear, but it causes parsed
     # literals in docutils 0.6 to lose indenting. Thus we've solve the
     # problem be just getting rid of it. [PMA 20091020]
     # TODO: replace leading tabs like in codeblocks?
     if node_has_class(node, 'code-block') and self.cb_use_pygments:
         self.visit_codeblock(node)
     else:
         self.out.append('\\setbeamerfont{quote}{parent={}}\n')
         LaTeXTranslator.visit_literal_block(self, node)
    def visit_image(self, node):
        attrs = node.attributes

        # Only add \columnwidth if scale or width have not been specified.
        if "scale" not in node.attributes and "width" not in node.attributes:
            node.attributes["width"] = "\columnwidth"

        node.attributes["align"] = "left"

        LaTeXTranslator.visit_image(self, node)
    def depart_document(self, node):
        LaTeXTranslator.depart_document(self, node)

        title = self.paper_title
        authors = ', '.join(self.author_names)

        d = {}
        compsocthanks = ''
        for auth, inst in zip(self.author_names, self.author_institutions):
            d.setdefault(inst, []).append(auth)

        for inst, authlist in d.iteritems():
            if len(authlist) <= 2:
                auths = ' and '.join(authlist)
            else:
                auths = ', '.join(authlist[:-1] + [
                    'and ' + authlist[-1],
                ])
            verb = ' is ' if len(authlist) == 1 else ' are '
            compsocthanks += auths + verb + 'with ' + inst_table[
                inst] + ' ' + inst + '. '

        copyright_holder = self.author_names[0] + ('.' if len(
            self.author_names) == 1 else ' et al.')
        author_notes = r'''E-mail: \protect\href{%s}{%s}.

\noindent \copyright %s %s %s
        ''' % ('mailto:' + self.author_emails[0], self.author_emails[0],
               options['proceedings']['year'], copyright_holder,
               options['proceedings']['copyright']['article'])

        author_notes = compsocthanks + author_notes

        title_template = '\\title{%s}\\author{%s\\thanks{%s}}\\maketitle'
        title_template = title_template % (title, authors, author_notes)

        marks = r'''
        \renewcommand{\leftmark}{%s}
        \renewcommand{\rightmark}{%s}
        ''' % (options['proceedings']['title']['short'], title.upper())
        title_template += marks

        self.body_pre_docinfo = [title_template]

        # Save paper stats
        self.document.stats = {
            'title': title,
            'authors': authors,
            'author': self.author_names,
            'author_institution': self.author_institutions,
            'abstract': self.abstract_text,
            'keywords': self.keywords,
            'copyright_holder': copyright_holder
        }
Exemple #32
0
    def visit_footnote(self, node):
        # Handle case where footnote consists only of math
        if len(node.astext().split()) < 2:
            node.append(nodes.label(text='_abcdefghijklmno_'))

        # Work-around for a bug in docutils where
        # "%" is prepended to footnote text
        LaTeXTranslator.visit_footnote(self, node)
        self.out[-1] = self.out[1].strip('%')

        self.non_breaking_paragraph = True
    def visit_footnote(self, node):
        # Handle case where footnote consists only of math
        if len(node.astext().split()) < 2:
            node.append(nodes.label(text='_abcdefghijklmno_'))

        # Work-around for a bug in docutils where
        # "%" is prepended to footnote text
        LaTeXTranslator.visit_footnote(self, node)
        self.out[-1] = self.out[1].strip('%')

        self.non_breaking_paragraph = True
Exemple #34
0
 def visit_image(self, node):
     attrs = node.attributes
     if 'align' not in attrs and self.centerfigs:
         attrs['align'] = 'center'
     if (
         ('height' not in attrs) and
         ('width' not in attrs) and
         ('scale' not in attrs)
     ):
         attrs['height'] = '0.75\\textheight'
     LaTeXTranslator.visit_image(self, node)
Exemple #35
0
 def visit_section(self, node):
     if node.astext() == 'blankslide':
         # this never gets reached, but I don't know if that is bad
         self.out.append('\\begin{frame}[plain]{}\n\\end{frame}')
     else:
         if has_sub_sections(node):
             temp = self.section_level + 1
             if temp > self.frame_level:
                 self.frame_level = temp
         else:
             self.out.append(self.begin_frametag(node))
         LaTeXTranslator.visit_section(self, node)
Exemple #36
0
 def visit_section(self, node):
     if node.astext() == 'blankslide':
         # this never gets reached, but I don't know if that is bad
         self.out.append('\\begin{frame}[plain]{}\n\\end{frame}')
     else:
         if has_sub_sections(node):
             temp = self.section_level + 1
             if temp > self.frame_level:
                 self.frame_level = temp
         else:
             self.out.append(begin_frametag(node, self.fragile_default))
         LaTeXTranslator.visit_section(self, node)
    def depart_document(self, node):
        LaTeXTranslator.depart_document(self, node)

        title = self.paper_title
        authors = ', '.join(self.author_names)

        d = {}
        compsocthanks = ''
        for auth, inst in zip(self.author_names, self.author_institutions):
            d.setdefault(inst, []).append(auth)

        for inst, authlist in d.iteritems():
            if len(authlist) <= 2:
                auths = ' and '.join(authlist)
            else:
                auths = ', '.join(authlist[:-1] + ['and ' + authlist[-1],])
            verb= ' is ' if len(authlist)==1 else ' are '
            compsocthanks += auths+verb+'with '+ inst_table.get(inst, '') +' '+inst+'. '
        
        copyright_holder = self.author_names[0] + ('.' if len(self.author_names) == 1 else ' et al.')
        author_notes = r'''E-mail: \protect\href{%s}{%s}.

\noindent \copyright %s %s %s
        ''' % ('mailto:' + self.author_emails[0],
               self.author_emails[0],
               options['proceedings']['year'],
               copyright_holder,
               options['proceedings']['copyright']['article'])

        author_notes = compsocthanks+author_notes

        title_template = '\\title{%s}\\author{%s\\thanks{%s}}\\maketitle'
        title_template = title_template % (title,
                                           authors,
                                           author_notes)

        marks = r'''
        \renewcommand{\leftmark}{%s}
        \renewcommand{\rightmark}{%s}
        ''' % (options['proceedings']['title']['short'], title.upper())
        title_template += marks

        self.body_pre_docinfo = [title_template]

        # Save paper stats
        self.document.stats = {'title': title,
                               'authors': authors,
                               'author': self.author_names,
                               'author_email': self.author_emails,
                               'author_institution': self.author_institutions,
                               'abstract': self.abstract_text,
                               'keywords': self.keywords,
                               'copyright_holder': copyright_holder}
    def visit_thead(self, node):
        # Store table caption locally and then remove it
        # from the table so that docutils doesn't render it
        # (in the wrong place)
        self.table_caption = self.active_table.caption
        self.active_table.caption = []

        opening = self.active_table.get_opening()
        opening = opening.replace('linewidth', 'tablewidth')
        self.active_table.get_opening = lambda: opening

        LaTeXTranslator.visit_thead(self, node)
    def visit_thead(self, node):
        # Store table caption locally and then remove it
        # from the table so that docutils doesn't render it
        # (in the wrong place)
        self.table_caption = self.active_table.caption
        self.active_table.caption = []

        opening = self.active_table.get_opening()
        opening = opening.replace('linewidth', 'tablewidth')
        self.active_table.get_opening = lambda: opening

        LaTeXTranslator.visit_thead(self, node)
Exemple #40
0
    def __init__(self, document, docstring_linker):
        # Set the document's settings.
        settings = OptionParser([LaTeXWriter()]).get_default_values()
        document.settings = settings

        LaTeXTranslator.__init__(self, document)
        self._linker = docstring_linker

        # Start at section level 3.  (Unfortunately, we now have to
        # set a private variable to make this work; perhaps the standard
        # latex translator should grow an official way to spell this?)
        self.section_level = 3
        self._section_number = [0] * self.section_level
Exemple #41
0
 def visit_container(self, node):
     """Handle containers with 'special' names, ignore the rest."""
     # NOTE: theres something weird here where ReST seems to translate
     # underscores in container identifiers into hyphens. So for the
     # moment we'll allow both.
     if node_has_class(node, 'beamer-simplecolumns'):
         self.visit_columnset(node)
         wrap_children_in_columns(node, node.children)
     elif node_has_class(node, 'beamer-note'):
         self.visit_beamer_note(node)
     else:
         # currently the LaTeXTranslator does nothing, but just in case
         LaTeXTranslator.visit_container(self, node)
Exemple #42
0
 def visit_container(self, node):
     """Handle containers with 'special' names, ignore the rest."""
     # NOTE: theres something weird here where ReST seems to translate
     # underscores in container identifiers into hyphens. So for the
     # moment we'll allow both.
     if node_has_class(node, 'beamer-simplecolumns'):
         self.visit_columnset(node)
         wrap_children_in_columns(node, node.children)
     elif node_has_class(node, 'beamer-note'):
         self.visit_beamer_note(node)
     else:
         # currently the LaTeXTranslator does nothing, but just in case
         LaTeXTranslator.visit_container(self, node)
Exemple #43
0
    def visit_title(self, node):
        if self.section_level == 1:
            if self.paper_title:
                import warnings
                warnings.warn(RuntimeWarning("Title set twice--ignored. "
                                             "Could be due to ReST"
                                             "error.)"))
            else:
                self.paper_title = self.encode(node.astext())
            raise nodes.SkipNode

        elif node.astext() == 'References':
            raise nodes.SkipNode

        LaTeXTranslator.visit_title(self, node)
Exemple #44
0
    def visit_reference(self, node):
        if node.has_key('refuri'):
            refuri = node['refuri']
            basename = os.path.splitext(refuri)[0]
            label = self.label_prefix + "-" + self.refuri_override.get(
                basename, basename)
            print "got refuri=%r, label=%r" % (refuri, label)
        elif node.has_key('refid'):
            label = self.generate_section_label(node['refid'])
            print "got refid=%r, label=%r" % (node['refid'], label)
        else:
            print "warning: unhandled reference: node=%r" % node
            LaTeXTranslator.visit_reference(self, node)

        self.body.append("section~\\ref{%s}, " % label)
        raise nodes.SkipDeparture
    def __init__(self, *args, **kwargs):
        LaTeXTranslator.__init__(self, *args, **kwargs)

        # Handle author declarations

        self.current_field = ''

        self.author_names = []
        self.author_institutions = []
        self.author_emails = []
        self.paper_title = ''
        self.abstract_text = []
        self.keywords = ''
        self.table_caption = []

        self.abstract_in_progress = False
        self.non_breaking_paragraph = False
Exemple #46
0
    def visit_thead(self, node):
        # Store table caption locally and then remove it
        # from the table so that docutils doesn't render it
        # (in the wrong place)
        if self.active_table.caption:
            self.table_caption = self.active_table.caption
            self.active_table.caption = []

        opening = self.active_table.get_opening()
        opening = opening.replace('linewidth', 'tablewidth')
        self.active_table.get_opening = lambda: opening

        # For some reason, docutils want to process longtable headers twice.  I
        # don't trust this fix entirely, but it does the trick for now.
        self.active_table.need_recurse = lambda: False

        LaTeXTranslator.visit_thead(self, node)
Exemple #47
0
 def visit_title(self, node):
     if node.astext() == 'dummy':
         raise nodes.SkipNode
     if isinstance(node.parent, nodes.admonition):
         assert self.admonition_alert_type
         self.out.append('\\begin{%s}{%s}\n' % (self.admonition_alert_type,
                                                self.encode(node.astext())))
         raise nodes.SkipNode
     if node.astext() == 'blankslide':
         # A blankslide has no title, but is otherwise processed as normal,
         # meaning that the title is blank, but the slide can have some
         # content. It must at least contain a comment.
         raise nodes.SkipNode
     elif self.section_level == self.frame_level + 1:
         self.out.append('\\frametitle{%s}\n\n' %
                         self.encode(node.astext()))
         raise nodes.SkipNode
     else:
         LaTeXTranslator.visit_title(self, node)
Exemple #48
0
    def visit_literal_block(self, node):
        self.non_breaking_paragraph = True

        if 'language' in node.attributes:
            # do highlighting
            from pygments import highlight
            from pygments.lexers import PythonLexer, get_lexer_by_name
            from pygments.formatters import LatexFormatter

            linenos = node.attributes.get('linenos', False)
            lexer = get_lexer_by_name(node.attributes['language'])
            tex = highlight(node.astext(), lexer,
                            LatexFormatter(linenos=linenos,
                                           verboptions='fontsize=\\footnotesize'))

            self.out.append(tex)
            raise nodes.SkipNode
        else:
            LaTeXTranslator.visit_literal_block(self, node)
Exemple #49
0
 def __init__(self, document):
     LaTeXTranslator.__init__(self, document)
     self.head_prefix = [
         x for x in self.head_prefix if ('{typearea}' not in x)
     ]
     hyperref_posn = [
         i for i in range(len(self.head_prefix))
         if ('{hyperref}' in self.head_prefix[i])
     ]
     self.head_prefix[hyperref_posn[0]] = '\\usepackage{hyperref}\n'
     self.head_prefix.extend([
         '\\definecolor{rrblitbackground}{rgb}{0.55, 0.3, 0.1}\n',
         '\\newenvironment{rtbliteral}{\n',
         '\\begin{ttfamily}\n',
         '\\color{rrblitbackground}\n',
         '}{\n',
         '\\end{ttfamily}\n',
         '}\n',
     ])
     # this fixes the hardcoded section titles in docutils 0.4
     self.d_class = DocumentClass('article')
Exemple #50
0
    def __init__(self, document, docstring_linker=None, directory=None,
                 docindex=None, context=None):
        # Set the document's settings.
        if self.settings is None:
            settings = OptionParser([LaTeXWriter()]).get_default_values()
            settings.output_encoding = 'utf-8'
            
            # This forces eg \EpydocUserSection rather than
            # \EpydocUserSEction*:
            settings.use_latex_toc = True
            
            self.__class__.settings = settings
        document.settings = self.settings

        LaTeXTranslator.__init__(self, document)
        self._linker = docstring_linker
        self._directory = directory
        self._docindex = docindex
        self._context = context

        # Use custom section names.
        self.d_class = _EpydocDocumentClass()
    def __init__(self, *args, **kwargs):
        LaTeXTranslator.__init__(self, *args, **kwargs)

        # Handle author declarations

        self.current_field = ''

        self.author_names = []
        self.author_institutions = []
        self.author_emails = []
        self.paper_title = ''
        self.abstract_text = []
        self.keywords = ''
        self.table_caption = []

        self.abstract_in_progress = False
        self.non_breaking_paragraph = False

        self.figure_type = 'figure'
        self.figure_alignment = 'left'
        self.table_type = 'table'

        self.d_class.sections.insert(0, 'title')
Exemple #52
0
    def __init__(self, document):
        LaTeXTranslator.__init__(self, document)
        self.label_prefix = ""
        self.docinfo = {}
        self.head_prefix = []
        self.head = []
        self.body_prefix = []
        self.in_title = False
        self.in_anydesc = False  # _title is different if it is a funcdesc
        self.admonition_stack = []

        # Disable a bunch of methods from the base class.
        empty_method = lambda self: None
        for nodetype in ('field_argument', 'field_body', 'field_list',
                         'field_name'):
            setattr(self, 'visit_' + nodetype, empty_method)
            setattr(self, 'depart_' + nodetype, empty_method)
        self.head_prefix = []
        # definitions must be guarded if multiple modules are included
        self.definitions = [
            "\\ifx\\locallinewidth\\undefined\\newlength{\\locallinewidth}\\fi\n"
            "\\setlength{\\locallinewidth}{\\linewidth}\n"
        ]
Exemple #53
0
 def depart_literal_block(self, node):
     LaTeXTranslator.depart_literal_block(self, node)
Exemple #54
0
 def depart_admonition(self, node=None):
     name = self.admonition_stack.pop()
     if name == "note":
         self.body.append('\\end{notice}\n')
     else:
         LaTeXTranslator.depart_admonition(self, node)
Exemple #55
0
 def visit_block_quote(self, node):
     self.out.append('\\begin{quotation}')
     LaTeXTranslator.visit_block_quote(self, node)
Exemple #56
0
 def visit_admonition(self, node, name=''):
     self.admonition_stack.append(name)
     if name in ('note', 'warning'):
         self.body.append('\\begin{notice}[%s]' % name)
     else:
         LaTeXTranslator.visit_admonition(self, node, name)
Exemple #57
0
 def depart_block_quote(self, node):
     LaTeXTranslator.depart_block_quote(self, node)
     self.out.append('\\end{quotation}')
Exemple #58
0
    def __init__(self, document):
        LaTeXTranslator.__init__(self, document)

        # Used for Beamer title and possibly header/footer. Set from docinfo
        # record the settings for codeblocks.
        self.organization = None
        self.cb_use_pygments = document.settings.cb_use_pygments
        self.cb_replace_tabs = document.settings.cb_replace_tabs
        self.cb_default_lang = document.settings.cb_default_lang

        self.head_prefix = [
            x for x in self.head_prefix if '{typearea}' not in x
        ]

        self.head_prefix.extend([
            '\\definecolor{rrblitbackground}{rgb}{0.55, 0.3, 0.1}\n',
            '\\newenvironment{rtbliteral}{\n',
            '\\begin{ttfamily}\n',
            '\\color{rrblitbackground}\n',
            '}{\n',
            '\\end{ttfamily}\n',
            '}\n',
        ])

        if self.cb_use_pygments:
            self.head_prefix.extend([
                '\\usepackage{fancyvrb}\n',
                '\\usepackage{color}\n',
            ])

        # set appropriate header options for theming
        theme = document.settings.theme
        if theme:
            self.head_prefix.append('\\usetheme{%s}\n' % theme)

        set_header_options(self.head_prefix, document.settings.shownotes)

        if self.cb_use_pygments:
            from pygments.formatters import LatexFormatter
            self.head_prefix.extend([
                LatexFormatter().get_style_defs(),
            ])

        self.overlay_bullets = string_to_bool(document.settings.overlaybullets,
                                              False)
        self.fragile_default = string_to_bool(
            document.settings.fragile_default, True)
        self.shortauthor = document.settings.shortauthor
        self.shorttitle = document.settings.shorttitle
        # using a False default because
        # True is the actual default. If you are trying to pass in a value
        # and I can't determine what you really meant, I am assuming you
        # want something other than the actual default.
        self.centerfigs = string_to_bool(document.settings.centerfigs,
                                         False)  # same reasoning as above
        self.in_columnset = False
        self.in_column = False
        self.in_note = False
        self.frame_level = 0

        # this fixes the hardcoded section titles in docutils 0.4
        self.d_class = DocumentClass('article')

        self.admonition_alert_type = None
Exemple #59
0
 def depart_section(self, node):
     # Remove counter for potential subsections.
     LaTeXTranslator.depart_section(self, node)
     if self.section_level == self.frame_level:
         self.out.append(end_frametag())
Exemple #60
0
 def depart_title(self, node):
     if self.section_level != self.frame_level + 1:
         LaTeXTranslator.depart_title(self, node)