示例#1
0
def add_html(meta, fmt):
    """Adds html to the meta data."""

    warnings = warninglevel == 2 and targets

    if warnings:
        msg = textwrap.dedent("""\
                  pandoc-eqnos: Wrote the following blocks to
                  header-includes.  If you use pandoc's
                  --include-in-header option then you will need to
                  manually include these yourself.
              """)
        STDERR.write('\n')
        STDERR.write(textwrap.fill(msg))
        STDERR.write('\n')

    # Update the header-includes metadata.  Pandoc's
    # --include-in-header option will override anything we do here.  This
    # is a known issue and is owing to a design decision in pandoc.
    # See https://github.com/jgm/pandoc/issues/3139.

    if targets:
        cond = fmt == 'html4' or \
               (fmt == 'html' and version(PANDOCVERSION) < version('2.0'))
        attr = ' type="text/css"' if cond else ''
        pandocxnos.add_to_header_includes(meta, 'html',
                                          EQUATION_STYLE_HTML % attr)
def processor(meta, blocks):  # pylint: disable=unused-argument
    """Document processor."""

    if has_lettrine:
        pandocxnos.add_to_header_includes(
            meta, 'tex', textwrap.dedent(r'''
            \usepackage{lettrine}
            '''))
示例#3
0
def processor(meta, blocks):
    """Document processor."""

    has_epigraph = False  # Flags that an epigraph was found
    noindent = False      # Flags that next para should not be indented

    # Process the blocks
    for block in blocks:
        if block['t'] == 'Div':
            attrs = PandocAttributes(block['c'][0])

            # Process epigraph divs
            if 'epigraph' in attrs.classes:

                # Insert tex into div content
                content = block['c'][1]
                content[0]['c'].insert(0, PRE)
                content[-2]['c'].append(MID)
                for el in content[-1]['c']:
                    content[-2]['c'].append(el)
                content[-2]['c'].append(POST)
                del content[-1]

                # Set flags and continue
                has_epigraph = True
                noindent = True
                continue

        # Don't indent the first non-empty paragraph after an epigraph
        if block['t'] == 'Para' and noindent:
            content = stringify(quotify(copy.deepcopy(block['c'])))
            if content.strip():
                block['c'].insert(0, RawInline('tex', r'\noindent '))
                noindent = False

    if has_epigraph:
        pandocxnos.add_to_header_includes(
            meta, 'tex', textwrap.dedent(r'''
            \usepackage{epigraph}
            '''), warninglevel)
示例#4
0
def add_html(meta):
    """Adds html to the meta data."""

    warnings = warninglevel == 2 and references

    if warnings:
        msg = textwrap.dedent("""\
                  pandoc-eqnos: Wrote the following blocks to
                  header-includes.  If you use pandoc's
                  --include-in-header option then you will need to
                  manually include these yourself.
              """)
        STDERR.write('\n')
        STDERR.write(textwrap.fill(msg))
        STDERR.write('\n')

    # Update the header-includes metadata.  Pandoc's
    # --include-in-header option will override anything we do here.  This
    # is a known issue and is owing to a design decision in pandoc.
    # See https://github.com/jgm/pandoc/issues/3139.

    if references:
        pandocxnos.add_to_header_includes(meta, 'html', EQUATION_STYLE_HTML)
示例#5
0
def add_tex(meta):
    """Adds tex to the meta data."""

    warnings = warninglevel == 2 and targets and \
      (pandocxnos.cleveref_required() or len(names) or secoffset or \
       numbersections)
    if warnings:
        msg = textwrap.dedent("""\
                  pandoc-theoremnos: Wrote the following blocks to
                  header-includes.  If you use pandoc's
                  --include-in-header option then you will need to
                  manually include these yourself.
              """)
        STDERR.write('\n')
        STDERR.write(textwrap.fill(msg))
        STDERR.write('\n')

    # Update the header-includes metadata.  Pandoc's
    # --include-in-header option will override anything we do here.  This
    # is a known issue and is owing to a design decision in pandoc.
    # See https://github.com/jgm/pandoc/issues/3139.

    if pandocxnos.cleveref_required() and targets:
        tex = """
            %%%% pandoc-theoremnos: required package
            \\usepackage{amsthm}
            \\usepackage%s{cleveref}
        """ % ('[capitalise]' if capitalise else '')
        pandocxnos.add_to_header_includes(
            meta, 'tex', tex, regex=r'\\usepackage(\[[\w\s,]*\])?\{cleveref\}')

    if secoffset and targets:
        pandocxnos.add_to_header_includes(meta,
                                          'tex',
                                          SECOFFSET_TEX % secoffset,
                                          regex=r'\\setcounter\{section\}')

    if names:
        tex = """
            %% pandoc-theoremnos: set theorem types
            """
        firstid = None
        for thid, thname in names.items():
            tex += """\\newtheorem{%s}%s{%s}%s
            """ % (thid, '[%s]' % firstid if firstid is not None else '',
                   thname, '[section]' if numbersections and firstid is None \
                   else '')

            if sharedcounter and firstid is None:
                firstid = thid

        pandocxnos.add_to_header_includes(meta, 'tex', tex)

    if warnings:
        STDERR.write('\n')
示例#6
0
def add_tex(meta):
    """Adds tex to the meta data."""

    # pylint: disable=too-many-boolean-expressions
    warnings = warninglevel == 2 and targets and \
      (pandocxnos.cleveref_required() or has_unnumbered_figures or
       plusname_changed or starname_changed or has_tagged_figures or
       captionname_changed or numbersections or secoffset)
    if warnings:
        msg = textwrap.dedent("""\
                  pandoc-fignos: Wrote the following blocks to
                  header-includes.  If you use pandoc's
                  --include-in-header option then you will need to
                  manually include these yourself.
              """)
        STDERR.write('\n')
        STDERR.write(textwrap.fill(msg))
        STDERR.write('\n')

    # Update the header-includes metadata.  Pandoc's
    # --include-in-header option will override anything we do here.  This
    # is a known issue and is owing to a design decision in pandoc.
    # See https://github.com/jgm/pandoc/issues/3139.

    if pandocxnos.cleveref_required() and targets:
        tex = """
            %%%% pandoc-fignos: required package
            \\usepackage%s{cleveref}
        """ % ('[capitalise]' if capitalise else '')
        pandocxnos.add_to_header_includes(
            meta, 'tex', tex, regex=r'\\usepackage(\[[\w\s,]*\])?\{cleveref\}')

    if has_unnumbered_figures or (separator_changed and targets):
        tex = """
            %%%% pandoc-fignos: required package
            \\usepackage{caption}
        """
        pandocxnos.add_to_header_includes(
            meta, 'tex', tex, regex=r'\\usepackage(\[[\w\s,]*\])?\{caption\}')

    if plusname_changed and targets:
        tex = """
            %%%% pandoc-fignos: change cref names
            \\crefname{figure}{%s}{%s}
        """ % (plusname[0], plusname[1])
        pandocxnos.add_to_header_includes(meta, 'tex', tex)

    if starname_changed and targets:
        tex = """
            %%%% pandoc-fignos: change Cref names
            \\Crefname{figure}{%s}{%s}
        """ % (starname[0], starname[1])
        pandocxnos.add_to_header_includes(meta, 'tex', tex)

    if has_unnumbered_figures:
        pandocxnos.add_to_header_includes(meta, 'tex',
                                          NO_PREFIX_CAPTION_ENV_TEX)

    if has_tagged_figures and targets:
        pandocxnos.add_to_header_includes(meta, 'tex', TAGGED_FIGURE_ENV_TEX)

    if captionname_changed and targets:
        pandocxnos.add_to_header_includes(meta, 'tex',
                                          CAPTION_NAME_TEX % captionname)

    if separator_changed and targets:
        pandocxnos.add_to_header_includes(meta, 'tex',
                                          CAPTION_SEPARATOR_TEX % separator)

    if numbersections and targets:
        pandocxnos.add_to_header_includes(meta, 'tex', NUMBER_BY_SECTION_TEX)

    if secoffset and targets:
        pandocxnos.add_to_header_includes(meta,
                                          'tex',
                                          SECOFFSET_TEX % secoffset,
                                          regex=r'\\setcounter\{section\}')

    if warnings:
        STDERR.write('\n')
def processor(meta, blocks):  # pylint: disable=unused-argument
    """Document processor."""
    if replaced_figure_env:
        pandocxnos.add_to_header_includes(meta, 'tex', MARGINFIGURE_TEX,
                                          warninglevel)
示例#8
0
def add_tex(meta):
    """Adds tex to the meta data."""

    warnings = warninglevel == 2 and targets and \
               (pandocxnos.cleveref_required() or
                plusname_changed or starname_changed or numbersections or secoffset)
    if warnings:
        msg = textwrap.dedent("""\
                  pandoc-eqnos: Wrote the following blocks to
                  header-includes.  If you use pandoc's
                  --include-in-header option then you will need to
                  manually include these yourself.
              """)
        STDERR.write('\n')
        STDERR.write(textwrap.fill(msg))
        STDERR.write('\n')

    # Update the header-includes metadata.  Pandoc's
    # --include-in-header option will override anything we do here.  This
    # is a known issue and is owing to a design decision in pandoc.
    # See https://github.com/jgm/pandoc/issues/3139.

    if pandocxnos.cleveref_required() and targets:
        tex = """
            %%%% pandoc-eqnos: required package
            \\usepackage%s{cleveref}
        """ % ('[capitalise]' if capitalise else '')
        pandocxnos.add_to_header_includes(
            meta, 'tex', tex, regex=r'\\usepackage(\[[\w\s,]*\])?\{cleveref\}')

        if not eqref:
            pandocxnos.add_to_header_includes(meta, 'tex',
                                              DISABLE_CLEVEREF_BRACKETS_TEX)

    if plusname_changed and targets:
        tex = """
            %%%% pandoc-eqnos: change cref names
            \\crefname{equation}{%s}{%s}
        """ % (plusname[0], plusname[1])
        pandocxnos.add_to_header_includes(meta, 'tex', tex)

    if starname_changed and targets:
        tex = """
            %%%% pandoc-eqnos: change Cref names
            \\Crefname{equation}{%s}{%s}
        """ % (starname[0], starname[1])
        pandocxnos.add_to_header_includes(meta, 'tex', tex)

    if numbersections and targets:
        pandocxnos.add_to_header_includes(meta, 'tex', NUMBER_BY_SECTION_TEX)

    if secoffset and targets:
        pandocxnos.add_to_header_includes(meta,
                                          'tex',
                                          SECOFFSET_TEX % secoffset,
                                          regex=r'\\setcounter\{section\}')

    if warnings:
        STDERR.write('\n')