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')
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')
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')