示例#1
0
 def createLatex(self, parent, token, page):
     label = token['label']
     if not token['satisfied']:
         brace = latex.Brace()
         latex.Command(brace, 'textcolor',
                       args=[latex.Brace(string='red')],
                       string=label)
         args = [brace]
     else:
         args = [latex.Brace(string=label)]
     return latex.Environment(parent, 'Requirement', args=args)
示例#2
0
    def createLatex(self, parent, token, page):

        if token['icon'] and (token['brand'] == 'construction'):
            src = 'media/framework/under-construction.png'
            wrapfig = latex.Environment(parent, 'wrapfigure',
                                        args=[latex.Brace(string='l'),
                                              latex.Brace(string='1in', escape=False)])
            latex.Command(wrapfig, 'includegraphics',
                          args=[latex.Bracket(string='height=0.6in', escape=False)],
                          string=src)
        return parent
示例#3
0
    def addNewCommand(self, cmd, content):
        """
        Add a NewDocumentCommand to latex preamble.
        """
        num = 0
        for match in re.finditer(r'#(?P<num>[0-9]+)', content):
            num = max(num, int(match.group('num')))

        args = [latex.Brace(string=cmd, escape=False), latex.Brace(string='m'*num)]
        self._commands[cmd] = latex.Command(None, 'NewDocumentCommand', args=args, escape=False,
                                            string=content, start='\n')
示例#4
0
 def createLatex(self, parent, token, page):
     pad = len(token.parent) * 0.01
     width = '{}\\textwidth'.format(token['medium'] / 12. - pad)
     env = latex.Environment(parent,
                             'minipage',
                             args=[
                                 latex.Bracket(string='t'),
                                 latex.Brace(string=width, escape=False)
                             ])
     if token is not token.parent.children[-1]:
         latex.Command(parent, 'hfill')
     return env
示例#5
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)
示例#6
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)
示例#7
0
    def createLatex(self, parent, token, page):

        env = latex.Environment(parent, token['command'])
        style = latex.parse_style(token)

        width = style.get('width', None)
        if width and token(0).name == 'Image':
            token(0).set('style', 'width:{};'.format(width))

        if style.get('text-align', None) == 'center':
            latex.Command(env, 'centering')

        return env
示例#8
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
示例#9
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))
示例#10
0
    def _processPages(self, root):
        """
        Build a main latex file that includes the others.
        """

        main = base.NodeBase(None, None)
        latex.Command(main, 'documentclass', string='report', end='')
        for package, options in self.translator.renderer.getPackages().items():
            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='\\setlength{\\parindent}{0pt}', start='\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().values():
            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=str(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='unsrtnat')
            latex.Command(doc, 'bibliography', string=','.join(bib_files), start='\n',
                          escape=False)

        return main
示例#11
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
示例#12
0
    def createLatex(self, parent, token, page):
        master = parent

        if token['halign']:
            halign = token['halign']
            if halign != 'center':
                halign = 'flush{}'.format(halign)
            master = latex.Environment(master, halign)

        if token['border']:
            master = latex.Environment(master, 'fbox')

        if token['color']:
            master = latex.Brace(master)
            latex.Command(master, 'color', string=token['color'])

        return master
示例#13
0
    def latexImage(self, parent, token, page, src):

        args = []
        style = latex.parse_style(token)
        width = style.get('width', None)
        if width:
            if width.endswith('%'):
                width = u'{}\\textwidth'.format(int(width[:-1])/100.)
            args.append(latex.Bracket(string=u'width={}'.format(width), escape=False))

        if style.get('text-align', None) == 'center':
            env = latex.Environment(parent, 'center')
        else:
            env = parent

        node = self.translator.findPage(src)
        fname = os.path.join(self.translator.destination, node.local)
        img = latex.Command(env, 'includegraphics', string=fname, args=args, escape=False)
        return img
示例#14
0
文件: devel.py 项目: lszeng-hnu/moose
    def createLatex(self, parent, token, page):

        # Create label option and render caption text
        cap = token(0)
        cap.parent = None
        label = latex.create_settings(label=cap['key'])

        text = tokens.String(None)
        cap.copyToToken(text)
        title = latex.Brace()
        self.translator.renderer.render(title, text, page)

        # Create example environment with upper and lower part
        example = latex.Environment(parent, 'example', args=[label, title])

        code = token.children[0]
        code.parent = None
        self.translator.renderer.render(example, code, page)  # upper
        latex.Command(example, 'tcblower', start='\n')
        return example
示例#15
0
    def createLatex(self, parent, token, page):

        groups = self._getParameters(token, token['parameters'])
        for group, params in groups.iteritems():
            if not params:
                continue

            for name, param in params.iteritems():
                if param['deprecated']:
                    continue

                args = [latex.Brace(string=name), latex.Bracket(string=group), latex.Bracket()]
                latex.Command(args[2], 'texttt', string=param['cpp_type'])
                default = _format_default(param) or ''
                if default:
                    args.append(latex.Bracket(string=default))

                latex.Environment(parent, 'InputParameter',
                                  args=args,
                                  string=param['description'])
示例#16
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
示例#17
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 = unicode(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
示例#18
0
 def createLatex(self, parent, token, page):  #pylint: disable=no-self-use,unused-argument
     latex.Command(parent, 'item', start='\n', end=' ')
     return parent
示例#19
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
示例#20
0
 def createLatex(self, token, parent):  #pylint: disable=no-self-use,unused-argument
     return latex.Command(parent,
                          self.LATEX_SECTIONS[token.level],
                          start='\n',
                          end='\n')
示例#21
0
 def createLatex(self, parent, token, page):
     caption = latex.Command(parent, 'caption')
     if token['key']:
         latex.Command(caption, 'label', string=token['key'], escape=True)
     return caption
示例#22
0
文件: bibtex.py 项目: llarsen71/moose
 def createLatex(self, parent, token, page):
     latex.Command(parent,
                   token['cite'],
                   string=u','.join(token['keys']),
                   escape=False)
     return parent
示例#23
0
 def createLatex(self, parent, token, page):  #pylint: disable=no-self-use,unused-argument
     return latex.Command(parent, 'textsubscript', info=token.info)
示例#24
0
文件: sqa.py 项目: lszeng-hnu/moose
 def createLatex(self, parent, token, page):
     prefix = token.siblings[0]['label'].split('.')[0]
     return latex.Command(parent, 'section*', string=prefix + ':~', escape=False)
示例#25
0
 def createLatex(self, token, parent):  #pylint: disable=no-self-use
     label = token.get('id', re.sub(r' +', r'-', token.text.lower()))
     return latex.Command(parent, 'label', string=label)
示例#26
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
示例#27
0
 def createLatex(self, parent, token, page):
     icon = token['faicon'] or token['icon']
     latex.Command(parent, 'faicon', string=icon, escape=False)
示例#28
0
 def createLatex(self, token, parent):  #pylint: disable=no-self-use
     code = latex.Command(parent, 'texttt')
     latex.String(code, content=token.code)
     return
示例#29
0
文件: sqa.py 项目: lszeng-hnu/moose
 def createLatex(self, parent, token, page):
     latex.Command(parent, 'item', start='\n', end=' ')
     return parent
示例#30
0
 def createLatex(self, token, parent):  #pylint: disable=no-self-use,unused-argument
     return latex.Command(parent, 'sout')