Example #1
0
    def __init__(self,
                 fn,
                 imdir="static/images",
                 imurl="",
                 fp=None,
                 extra_filters=None,
                 latex_string=None,
                 add_wrap=False,
                 fix_plastex_optarg_bug=True,
                 abox=None,
                 imurl_fmt=None,
                 verbose=False):
        '''
        fn            = tex filename (should end in .tex)
        imdir         = directory where images are to be stored
        imurl         = web root for images
        fp            = file object (optional) - used instead of open(fn), if provided
        extra_filters = dict with key=regular exp, value=function for search-replace, for
                        post-processing of XHTML output
        latex_string  = latex string (overrides fp and fn)
        add_wrap      = if True, then assume latex is partial, and add preamble and postfix
        fix_plastex_optarg_bug = if True, then filter the input latex to fix the plastex bug 
                                 triggered e.g. by \begin{edXchapter} and \begin{edXsection}
                                 being placed with no empty newline inbetween
        abox          = (class) use this in place of AnswerBox
        imurl_fmt     = (str) image url format expression
        verbose       = if True, then do verbose logging
        '''

        if fn.endswith('.tex'):
            ofn = fn[:-4] + '.xhtml'
        else:
            ofn = fn + ".xhtml"

        self.input_fn = fn
        self.output_fn = ofn
        self.fp = fp
        self.latex_string = latex_string
        self.add_wrap = add_wrap
        self.verbose = verbose
        self.renderer = MyRenderer(imdir,
                                   imurl,
                                   extra_filters,
                                   abox,
                                   imurl_fmt=imurl_fmt,
                                   verbose=verbose)
        self.fix_plastex_optarg_bug = fix_plastex_optarg_bug

        # Instantiate a TeX processor and parse the input text
        tex = TeX()
        tex.ownerDocument.config['files']['split-level'] = -100
        tex.ownerDocument.config['files']['filename'] = self.output_fn
        tex.ownerDocument.config['general']['theme'] = 'plain'

        plasTeXconfig.add_section('logging')
        plasTeXconfig['logging'][''] = CRITICAL

        self.tex = tex
        if not self.verbose:
            tex.disableLogging()
Example #2
0
def parseLaTeX(string):
    # PlasTeX bug - this variable doent get reinitialised
    MathShift.inEnv = []

    # Instantiate a TeX processor and parse the input text
    tex = TeX()
    tex.disableLogging()

    # Parse the LaTeX
    tex.input(string)
    return tex.parse()
Example #3
0
 def create_tex():
     """Create a TeX object, ready to parse a tex file."""
     tex = TeX()
     tex.disableLogging()
     tex.ownerDocument.context.loadBaseMacros()
     sys.path.append(os.path.dirname(__file__))
     tex.ownerDocument.context.loadPackage(tex, "plastex_patchedbabel")
     tex.ownerDocument.context.loadPackage(tex, "plastex_chord")
     tex.ownerDocument.context.loadPackage(tex, "plastex_songs")
     sys.path.pop()
     return tex
Example #4
0
def parseLaTeX(string):
    # PlasTeX bug - this variable doent get reinitialised
    MathShift.inEnv = []

    # Instantiate a TeX processor and parse the input text
    tex = TeX()
    tex.disableLogging()

    # Parse the LaTeX
    tex.input(string)
    return tex.parse()
Example #5
0
    def __init__(self,
                 fn,
                 imdir="static/images",
                 imurl="",
                 fp=None,
                 extra_filters=None,
                 latex_string=None,
                 add_wrap=False,
                 fix_plastex_optarg_bug=True,
                 verbose=False):
        '''
        fn            = tex filename (should end in .tex)
        imdir         = directory where images are to be stored
        imurl         = web root for images
        fp            = file object (optional) - used instead of open(fn), if provided
        extra_filters = dict with key=regular exp, value=function for search-replace, for
                        post-processing of XHTML output
        latex_string  = latex string (overrides fp and fn)
        add_wrap      = if True, then assume latex is partial, and add preamble and postfix
        fix_plastex_optarg_bug = if True, then filter the input latex to fix the plastex bug 
                                 triggered e.g. by \begin{edXchapter} and \begin{edXsection}
                                 being placed with no empty newline inbetween
        verbose       = if True, then do verbose logging
        '''

        if fn.endswith('.tex'):
            ofn = fn[:-4]+'.xhtml'
        else:
            ofn = fn + ".xhtml"

        self.input_fn = fn
        self.output_fn = ofn
        self.fp = fp
        self.latex_string = latex_string
        self.add_wrap = add_wrap
        self.verbose = verbose
        self.renderer = MyRenderer(imdir, imurl, extra_filters)
        self.fix_plastex_optarg_bug = fix_plastex_optarg_bug

        # Instantiate a TeX processor and parse the input text
        tex = TeX()
        tex.ownerDocument.config['files']['split-level'] = -100
        tex.ownerDocument.config['files']['filename'] = self.output_fn
        tex.ownerDocument.config['general']['theme'] = 'plain'

        plasTeXconfig.add_section('logging')
        plasTeXconfig['logging'][''] = CRITICAL

        self.tex = tex
        if not self.verbose:
            tex.disableLogging()
Example #6
0
    def runDocument(self, content):
        """
        Compile a document with the given content

        Arguments:
        content - string containing the content of the document

        Returns: TeX document

        """
        tex = TeX()
        tex.disableLogging()
        tex.input(r'''\documentclass{article}\usepackage{longtable}\begin{document}%s\end{document}''' % content)
        return tex.parse()
Example #7
0
    def runDocument(self, content):
        """
        Compile a document with the given content

        Arguments:
        content - string containing the content of the document

        Returns: TeX document

        """
        tex = TeX()
        tex.disableLogging()
        tex.input(ur'''\document{article}\begin{document}%s\end{document}''' % content)
        return tex.parse()
Example #8
0
    def runDocument(packages='', content=''):
        """
        Compile a document with the given content

        Arguments:
        packages - string containing comma separated packages to use
        content - string containing the content of the document

        Returns: TeX document

        """

        doc = TeXDocument(config=config)
        tex = TeX(doc)
        tex.disableLogging()
        tex.input(r'''
                \documentclass{article}
                \usepackage{%s}
                \begin{document}%s\end{document}''' % (packages, content))
        doc = tex.parse()
        doc.userdata['working-dir'] = os.path.dirname(__file__)
        return doc