def createLatex(self, parent, token, page): # Argument list (see ALERT above) args = [] if token(0)['prefix']: args.append(latex.Bracket(string=token['brand'])) else: args.append(latex.Bracket()) args.append(latex.Brace(string=token['brand'])) if token(0).children: title = latex.Bracket() self.renderer.render(title, token(0), page) args.append(title) c_icon = token(1)['icon'] and (token['brand'] == 'construction') if c_icon: latex.Command(parent, 'tcbset', string=u'height from=1in to 200in', escape=False) env = latex.Environment(parent, 'alert', args=args) if c_icon: latex.Command(parent, 'tcbset', string=u'height from=0in to 200in', escape=False) token(0).parent = None return env
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 _getOptions(args, kwargs): txt = [] for key in args: txt.append(key) for key, value in kwargs.iteritems(): txt.append(u'{}={}'.format(key, str(value))) return latex.Bracket(string=u','.join(txt), escape=False)
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
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
def createLatex(self, parent, token, page): #pylint: disable=no-self-use,unused-argument url = token['url'].lstrip('#') if url.startswith('https://') or url.startswith('http://'): cmd = latex.Command(parent, 'href', args=[latex.Brace(string=url)], info=token.info) else: cmd = latex.Command(parent, 'hyperref', args=[latex.Bracket(string=url)], info=token.info) return cmd
def testCustomCommand(self): cmd = latex.CustomCommand(None, 'foo') self.assertEqual(cmd.write(), '\\foo') latex.Bracket(cmd, string=u'bar') latex.Brace(cmd, string=u'test') self.assertEqual(cmd.write(), '\\foo[bar]{test}') cmd = latex.CustomCommand(None, 'foo', start='this', end='that') self.assertEqual(cmd.write(), 'this\\foothat')
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 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 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]
def createLatex(self, parent, token, page): fname = token['src'] if fname.startswith('http'): fname, errcode = self.extension.getOnlineMedia(parent, fname) if errcode: return parent else: dest = os.path.join(os.path.dirname(page.destination), token['src']) dest = os.path.dirname(os.path.abspath(dest)) fname, errcode = self.extension.convertImage(token['media_source'], '.png', dest) if errcode: return parent img = self.extension.latexImage(latex.Environment(parent, 'center'), token, fname) img['args'] = [latex.Bracket(string=u'width=\\textwidth', escape=False)] return parent
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 testBracket(self): enc = latex.Bracket() self.assertEqual(enc.enclose, ('[', ']'))