コード例 #1
0
ファイル: plastexit.py プロジェクト: mitocw/latex2edx
    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()
コード例 #2
0
ファイル: preprocessor.py プロジェクト: jamii/texsearch
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()
コード例 #3
0
ファイル: plastex.py プロジェクト: angri/patacrep
 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
コード例 #4
0
ファイル: preprocessor.py プロジェクト: jamii/texsearch
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()
コード例 #5
0
ファイル: plastexit.py プロジェクト: ybergner/latex2edx
    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()
コード例 #6
0
ファイル: Longtable.py プロジェクト: PatrickMassot/plastex
    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()
コード例 #7
0
ファイル: Encoding.py プロジェクト: muchlearning/plastex
    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()
コード例 #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