Exemple #1
0
    def createLatex(self, parent, token, page):

        item = latex.String(parent)
        end = ' \\\\\n' if token is token.parent.children[-1] else ' &'
        latex.String(parent, content=end, escape=False)

        return item
Exemple #2
0
    def createLatex(self, parent, token, page):

        ctoken = token(1)
        opts = get_listing_options(ctoken)

        cap = token(0)
        key = cap['key']
        if key:
            latex.String(opts[0], content="label={},".format(key))

        tok = tokens.Token()
        cap.copyToToken(tok)
        if key:
            latex.String(opts[0], content="caption=")
        else:
            latex.String(opts[0], content="title=")

        if not cap.children:
            latex.String(opts[0], content="\\mbox{}", escape=False)
        else:
            self.translator.renderer.render(latex.Brace(opts[0]), tok, page)

        latex.Environment(parent,
                          'lstlisting',
                          string=ctoken['content'].strip('\n'),
                          escape=False,
                          after_begin='\n',
                          before_end='\n',
                          args=opts,
                          info=token.info)

        token.children = list()
        return parent
Exemple #3
0
    def createLatex(self, parent, token, page):
        prev = token.previous
        if prev and prev.name != 'SQARequirementDetails':
            latex.Command(parent, 'newline', start='\n', end='\n')
        latex.String(parent, content='Prerequisite(s):~', escape=False)

        labels = [label for _, _, label in token['specs']]
        latex.String(parent, content='; '.join(labels))
Exemple #4
0
    def _processPages(self, root):
        """
        Build a main latex file that includes the others.
        """

        main = base.NodeBase(None, None)
        latex.Command(main, 'documentclass', string=u'report', end='')
        for package, options in self.translator.renderer.getPackages(
        ).iteritems():
            args = []
            if options[0] or options[1]:
                args = [self._getOptions(*options)]

            latex.Command(main,
                          'usepackage',
                          args=args,
                          string=package,
                          start='\n',
                          end='')

        latex.String(main,
                     content=u'\\setlength{\\parindent}{0pt}',
                     start=u'\n',
                     escape=False)

        for preamble in self.translator.renderer.getPreamble():
            latex.String(main, content='\n' + preamble, escape=False)

        # New Commands
        for cmd in self.translator.renderer.getNewCommands().itervalues():
            cmd.parent = main

        doc = latex.Environment(main, 'document', end='\n')
        for node in anytree.PreOrderIter(root, filter_=lambda n: 'page' in n):
            page = node['page']
            if self.translator.getMetaData(page, 'active'):
                cmd = latex.Command(doc, 'input', start='\n')
                latex.String(cmd,
                             content=unicode(page.destination),
                             escape=False)

        # BibTeX
        bib_files = [
            n.source for n in self.translator.content
            if n.source.endswith('.bib')
        ]
        if bib_files:
            latex.Command(doc,
                          'bibliographystyle',
                          start='\n',
                          string=u'unsrtnat')
            latex.Command(doc,
                          'bibliography',
                          string=u','.join(bib_files),
                          start='\n',
                          escape=False)

        return main
Exemple #5
0
    def createLatex(self, parent, token, page):

        items = parent
        if token.name == 'TableHead':
            latex.String(parent, content='\\toprule\n', escape=False)
            items = latex.String(parent)
            latex.String(parent, content='\\midrule\n', escape=False)
        elif (token.name == 'TableBody') and (token is token.parent.children[-1]):
            items = latex.String(parent)
            latex.String(parent, content='\\bottomrule', escape=False)
        return items
Exemple #6
0
    def createLatex(self, parent, token, page):  #pylint: disable=no-self-use
        if token.name == 'LatexInlineEquation':
            latex.String(parent,
                         content='${}$'.format(token['tex']),
                         escape=False)
        else:
            cmd = 'equation' if token['number'] else 'equation*'
            env = latex.Environment(parent, cmd)
            if token['label']:
                latex.Command(env, 'label', string=token['label'], end='\n')
            latex.String(env, content=token['tex'], escape=False)

        return parent
Exemple #7
0
    def createLatex(self, parent, token, page):

        latex.Command(parent, 'newline', start='\n', end='\n')
        latex.String(parent, content='Issue(s):~', escape=False)
        no_seperator = True

        for issue in token['issues']:
            if not no_seperator:
                latex.String(parent, content='; ')
                no_seperator = False

            url = self.getURL(issue, token)
            if url is None:
                latex.Command(parent, 'textcolor', args=[latex.Brace(string='red')], string=issue)
            else:
                latex.Command(parent, 'href', args=[latex.Brace(string=url)], string=unicode(issue))
Exemple #8
0
 def createLatex(self, token, parent):  #pylint: disable=no-self-use
     if isinstance(token, LatexInlineEquation):
         latex.String(parent, content=u'${}$'.format(token.tex))
     else:
         cmd = 'equation' if token.number else 'equation*'
         latex.Environment(parent, cmd, string=unicode(token.tex))
     return parent
Exemple #9
0
 def createLatex(self, parent, token, page): #pylint: disable=no-self-use
     if token.name == 'LatexInlineEquation':
         latex.String(parent, content=u'${}$'.format(token['tex']))
     else:
         cmd = 'equation' if token['number'] else 'equation*'
         latex.Environment(parent, cmd, string=unicode(token['tex']))
     return parent
Exemple #10
0
    def createLatexHelper(self, parent, token, page, desired):
        func = lambda p, t, u, l: latex.Command(p, 'hyperref', token=t,
                                                args=[latex.Bracket(string=l)])
        # Create optional content
        bookmark = token['bookmark']

        if desired is None:
            self._createOptionalContent(parent, token, page)
            return None

        url = str(desired.relativeDestination(page))
        head = heading.find_heading(self.translator, desired, bookmark)

        tok = tokens.Token(None)
        if head is None:
            msg = "The linked page ({}) does not contain a heading, so the filename " \
                  "is being utilized.".format(desired.local)
            LOG.warning(common.report_error(msg, page.source,
                                            token.info.line if token.info else None,
                                            token.info[0] if token.info else token.text(),
                                            prefix='WARNING'))
            latex.String(parent, content=page.local)

        else:
            label = head.get('id') or re.sub(r' +', r'-', head.text().lower())
            href = func(parent, token, url, label)

            if len(token) == 0:
                head.copyToToken(tok)
            else:
                token.copyToToken(tok)

            self.renderer.render(href, tok, page)
        return None
Exemple #11
0
    def createLatex(self, parent, token, page):
        prev = token.previous
        if prev and prev.name != 'SQARequirementDetails':
            latex.Command(parent, 'newline', start='\n', end='\n')
        latex.String(parent, content='Issue(s):~', escape=False)
        no_seperator = True

        for issue in token['issues']:
            if not no_seperator:
                latex.String(parent, content='; ')
                no_seperator = False

            url = self.getURL(issue, token)
            if url is None:
                latex.Command(parent, 'textcolor', args=[latex.Brace(string='red')], string=issue)
            else:
                latex.Command(parent, 'href', args=[latex.Brace(string=url)], string=str(issue))
Exemple #12
0
    def createLatex(self, parent, token, page):

        env = latex.Environment(parent, 'tabulary',
                                args=[latex.Brace(None, string=u'\\linewidth', escape=False),
                                      latex.Brace(None, string=u'LL')])

        for key, value in self.extension.getAcronyms(True).iteritems():
            latex.String(env, content=u'{}&{}\\\\'.format(key, value), escape=False)
Exemple #13
0
    def createLatex(self, parent, token, page):

        latex.Command(parent, 'newline', start='\n', end='\n')
        latex.String(parent, content='Design:~', escape=False)

        no_seperator = True
        for design in token['design']:
            if not no_seperator:
                latex.String(parent, content='; ')
                no_seperator = False

            node = self.findDesign(design, token)
            if node:
                link = autolink.AutoLink(None, page=page)
                link.info = token.info
                self.createLatexHelper(parent, link, page, node)
            else:
                latex.Command(parent, 'textcolor', args=[latex.Brace(string='red')], string=design)
Exemple #14
0
    def createLatex(self, parent, token, page):
        prev = token.previous
        if prev and prev.name != 'RenderSQARequirementDetails':
            latex.Command(parent, 'newline', start='\n', end='\n')

        latex.String(parent, content='Design:~', escape=False)
        no_seperator = True
        for design in token['design']:
            if not no_seperator:
                latex.String(parent, content='; ')
                no_seperator = False

            node = self.findDesign(token['filename'], design, token['line'])
            if node:
                link = autolink.AutoLink(None, page=page)
                link.info = token.info
                self.createLatexHelper(parent, link, page, node)
            else:
                latex.Command(parent, 'textcolor', args=[latex.Brace(string='red')], string=design)
Exemple #15
0
 def createLatex(self, parent, token, page):
     prev = token.previous
     if prev and prev.name != 'SQARequirementDetails':
         latex.Command(parent, 'newline', start='\n', end='\n')
     spath = token['spec_path']
     if spath == '.':
         spec = 'Specification: {}'.format(token['spec_name'])
     else:
         spec = 'Specification: {}:{}'.format(token['spec_path'], token['spec_name'])
     latex.String(parent, content=spec)
Exemple #16
0
 def createLatex(self, parent, token, page):
     labels = self.translator.getMetaData(page, 'labels')
     key = token['key']
     if key in labels:
         latex.String(parent,
                      content=self.extension['prefix'] + '~',
                      escape=False)
         latex.Command(parent, 'eqref', string=key)
         return parent
     return core.RenderShortcutLink.createLatex(self, parent, token, page)
Exemple #17
0
    def createLatex(self, parent, token, page):

        src = token['tex']
        _, ext = os.path.splitext(src)
        if not src:
            msg = "Videos ({}) are not supported with LaTeX output, the 'latex_src' setting " \
                  "should be utilized to supply an image ('.jpg', '.png', or '.pdf')."
            raise exceptions.MooseDocsException(msg, token['src'], ext)
        elif ext not in ('.jpg', '.png', '.pdf'):
            msg = "Images ({}) with the '{}' extension are not supported. The image " \
                  "should be converted to a '.jpg', '.png', or '.pdf'."
            raise exceptions.MooseDocsException(msg, src, ext)

        img = self.extension.latexImage(parent, token, page, src)
        if token['src'].startswith('http'):
            latex.String(img.parent, content=u'\\newline(', escape=False)
            latex.Command(img.parent, 'url', string=token['src'])
            latex.String(img.parent, content=u')')

        return parent
Exemple #18
0
def get_listing_options(token):
    opts = latex.Bracket(None)

    lang = token['language'] or ''
    if lang.lower() == 'cpp':
        lang = 'C++'
    elif lang.lower() == 'text':
        lang = None

    if lang:
        latex.String(opts, content="language={},".format(lang))

    return [opts]
Exemple #19
0
    def createLatex(self, parent, token, page):
        node = self.getShortcut(token)

        link = node['link'].lstrip('#')
        if len(node) == 0:
            latex.String(parent, content='{}~'.format(node['prefix']), escape=False)
            h = latex.Command(parent, 'ref',
                              string=link,
                              info=token.info)
        else:
            h = latex.Command(parent, 'href',
                              args=[latex.Brace(string=link)],
                              string=node.children[0]['content'],
                              info=token.info)
        return h
Exemple #20
0
    def createLatex(self, parent, token, page):
        if token['header']:
            return None

        title = latex.Brace(string=token(0)['content'])
        reg = latex.Bracket(string=token['group'])
        args = [title, reg]

        if token['base']:
            args.append(latex.Bracket(string=token['base']))

        token(0).parent = None
        env = latex.Environment(parent, 'ObjectDescription', args=args)
        if len(token) == 0:
            latex.String(env, content="\\textcolor{red}{No Description.}", escape=False)
        return env
Exemple #21
0
    def _processPages(self, root):
        """
        Build a main latex file that includes the others.
        """

        main = base.NodeBase()
        latex.Command(main, 'documentclass', string=u'report', end='')
        for package in self._packages:
            latex.Command(main,
                          'usepackage',
                          string=package,
                          start='\n',
                          end='')

        func = lambda n: isinstance(n, page.MarkdownNode)
        nodes = [n for n in anytree.PreOrderIter(root, filter_=func)]
        for node in nodes:

            # If the parallel implementation was better this would not be needed.
            node.tokenize()
            node.render(node.ast)

            if node.depth == 1:
                title = latex.Command(main, 'title', start='\n')
                for child in node.result.children[0]:  #[0].children:
                    child.parent = title
                node.result.children[0].parent = None

        doc = latex.Environment(main, 'document', end='\n')
        latex.Command(doc, 'maketitle')
        for node in nodes:
            node.write()
            cmd = latex.Command(doc, 'input', start='\n')
            latex.String(cmd, content=unicode(node.destination), escape=False)

        return main
Exemple #22
0
 def createLatex(self, parent, token, page):  #pylint: disable=no-self-use
     return latex.String(parent, content=' ' * token['count'])
Exemple #23
0
 def createLatex(self, parent, token, page):
     return latex.String(parent, content='\\\\')
Exemple #24
0
 def createLatex(self, parent, token, page):  #pylint: disable=no-self-use,unused-argument
     return latex.String(parent, content=' ')
Exemple #25
0
 def createLatex(self, parent, token, page):  #pylint: disable=no-self-use
     code = latex.Command(parent, 'texttt', info=token.info)
     latex.String(code, content=token['content'])
     return
Exemple #26
0
 def createLatex(self, token, parent):  #pylint: disable=no-self-use
     return latex.String(parent, content=token.content)
Exemple #27
0
 def createLatex(self, parent, token, page):
     acro = self.extension.getAcronym(token['acronym'])
     content = unicode(acro.key) if acro.used else u'{} ({})'.format(
         acro.name, acro.key)
     latex.String(parent, content=content)
Exemple #28
0
 def createLatex(self, token, parent):  #pylint: disable=no-self-use
     code = latex.Command(parent, 'texttt')
     latex.String(code, content=token.code)
     return
Exemple #29
0
 def testString(self):
     s = latex.String(content=u'foo')
     self.assertEqual(s.content, 'foo')
Exemple #30
0
 def createLatex(self, token, parent):  #pylint: disable=no-self-use,unused-argument
     math = latex.InlineMath(parent)
     latex.String(math, content=u'_{')
     cmd = latex.Command(math, 'text')
     latex.String(math, content=u'}')
     return cmd