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)
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
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')
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
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)
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)
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
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
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))
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
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
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
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
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
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'])
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
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
def createLatex(self, parent, token, page): #pylint: disable=no-self-use,unused-argument latex.Command(parent, 'item', start='\n', end=' ') return parent
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
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')
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
def createLatex(self, parent, token, page): latex.Command(parent, token['cite'], string=u','.join(token['keys']), escape=False) return parent
def createLatex(self, parent, token, page): #pylint: disable=no-self-use,unused-argument return latex.Command(parent, 'textsubscript', info=token.info)
def createLatex(self, parent, token, page): prefix = token.siblings[0]['label'].split('.')[0] return latex.Command(parent, 'section*', string=prefix + ':~', escape=False)
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)
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
def createLatex(self, parent, token, page): icon = token['faicon'] or token['icon'] latex.Command(parent, 'faicon', string=icon, escape=False)
def createLatex(self, token, parent): #pylint: disable=no-self-use code = latex.Command(parent, 'texttt') latex.String(code, content=token.code) return
def createLatex(self, parent, token, page): latex.Command(parent, 'item', start='\n', end=' ') return parent
def createLatex(self, token, parent): #pylint: disable=no-self-use,unused-argument return latex.Command(parent, 'sout')