def process(meta): """Saves metadata fields in global variables and returns a few computed fields.""" # pylint: disable=global-statement global capitalize global captionname global use_cleveref_default global plusname global starname global numbersections # Read in the metadata fields and do some checking if 'tablenos-caption-name' in meta: captionname = get_meta(meta, 'tablenos-caption-name') assert type(captionname) in STRTYPES for name in ['tablenos-cleveref', 'xnos-cleveref', 'cleveref']: # 'xnos-cleveref' enables cleveref in all 3 of fignos/eqnos/tablenos # 'cleveref' is deprecated if name in meta: use_cleveref_default = get_meta(meta, name) assert use_cleveref_default in [True, False] for name in [ 'tablenos-capitalize', 'tablenos-capitalise', 'xnos-capitalize', 'xnos-capitalise' ]: # 'tablenos-capitalise' is an alternative spelling # 'xnos-capitalise' enables capitalise in all 3 of fignos/eqnos/tablenos # 'xnos-capitalize' is an alternative spelling if name in meta: capitalize = get_meta(meta, name) assert capitalize in [True, False] break if 'tablenos-plus-name' in meta: tmp = get_meta(meta, 'tablenos-plus-name') if type(tmp) is list: plusname = tmp else: plusname[0] = tmp assert len(plusname) == 2 for name in plusname: assert type(name) in STRTYPES if 'tablenos-star-name' in meta: tmp = get_meta(meta, 'tablenos-star-name') if type(tmp) is list: starname = tmp else: starname[0] = tmp assert len(starname) == 2 for name in starname: assert type(name) in STRTYPES if 'xnos-number-sections' in meta and meta['xnos-number-sections']['c']: numbersections = True
def process(meta): """Saves metadata fields in global variables and returns a few computed fields.""" # pylint: disable=global-statement global capitalize global use_cleveref_default global plusname global starname global numbersections # Read in the metadata fields and do some checking for name in ['eqnos-cleveref', 'xnos-cleveref', 'cleveref']: # 'xnos-cleveref' enables cleveref in all 3 of fignos/eqnos/tablenos # 'cleveref' is deprecated if name in meta: use_cleveref_default = check_bool(get_meta(meta, name)) break for name in [ 'eqnos-capitalize', 'eqnos-capitalise', 'xnos-capitalize', 'xnos-capitalise' ]: # 'eqnos-capitalise' is an alternative spelling # 'xnos-capitalise' enables capitalise in all 3 of fignos/eqnos/tablenos # 'xnos-capitalize' is an alternative spelling if name in meta: capitalize = check_bool(get_meta(meta, name)) break if 'eqnos-plus-name' in meta: tmp = get_meta(meta, 'eqnos-plus-name') if isinstance(tmp, list): plusname = tmp else: plusname[0] = tmp assert len(plusname) == 2 for name in plusname: assert isinstance(name, STRTYPES) if 'eqnos-star-name' in meta: tmp = get_meta(meta, 'eqnos-star-name') if isinstance(tmp, list): starname = tmp else: starname[0] = tmp assert len(starname) == 2 for name in starname: assert isinstance(name, STRTYPES) if 'xnos-number-sections' in meta: numbersections = check_bool(get_meta(meta, 'xnos-number-sections'))
def action(key, value, fmt, meta): # pylint: disable=unused-argument """Processes elements.""" global replaced_figure_env # pylint: disable=global-statement if is_figure(key, value): attrs = PandocAttributes(value[0]['c'][0], 'pandoc') # Convert figures with `marginfigure` class to marginfigures if 'marginfigure' in attrs.classes: if 'documentclass' in meta and \ get_meta(meta, 'documentclass') in \ ['tufte-book', 'tufte-handout']: replaced_figure_env = True # Get the marginfigure options offset = attrs['offset'] if 'offset' in attrs else '0pt' # LaTeX used to apply the environment pre = RawBlock('tex', r'\begin{marginfigure_}[%s]' % offset) post = RawBlock('tex', r'\end{marginfigure_}') return [pre, Para(value), post] if warninglevel: STDERR.write(WARNING) return None
def action(key, value, fmt, meta): # pylint: disable=unused-argument """Processes elements.""" if key == 'Div': attrs = PandocAttributes(value[0], 'pandoc') if 'marginnote' in attrs.classes: offset = attrs['offset'] if 'offset' in attrs else '0pt' if 'documentclass' in meta and \ get_meta(meta, 'documentclass') in \ ['tufte-book', 'tufte-handout']: pre = RawInline('tex', r'\marginnote[%s]{'%offset) post = RawInline('tex', r'}') assert value[1][0]['t'] == 'Para' assert value[1][-1]['t'] == 'Para' value[1][0]['c'].insert(0, pre) value[1][-1]['c'].append(post) elif warninglevel: STDERR.write(WARNING)
def main(): """Main program""" # Read the command-line arguments parser = argparse.ArgumentParser(description='Pandoc latex extensions.') version = '%(prog)s {version}'.format(version=__version__) parser.add_argument('--version', action='version', version=version) parser.add_argument('fmt') args = parser.parse_args() # Get the output format and document fmt = args.fmt doc = json.loads(STDIN.read()) # This filter only operates on latex documents if fmt != 'latex': json.dump(doc, STDOUT) STDOUT.flush() # Chop up the doc meta = doc['meta'] blocks = doc['blocks'] # Get the warning level warninglevel = 2 # 0 - no warnings; 1 - some warnings; 2 - all warnings for name in [ 'pandoc-latex-extensions-warning-level', 'xnos-warning-level' ]: if name in meta: warninglevel = int(get_meta(meta, name)) break # Set the warninglevel in each plugin for plugin in PLUGINS: plugin.warninglevel = warninglevel # Apply the actions altered = functools.reduce(lambda x, action: walk(x, action, fmt, meta), ACTIONS, blocks) # Apply the processors if warninglevel == 2: msg = textwrap.dedent("""\ pandoc-latex-extensions: 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') for processor in PROCESSORS: processor(meta, altered) # Finish up doc['blocks'] = altered json.dump(doc, STDOUT) STDOUT.flush()
def process(meta): """Saves metadata fields in global variables and returns a few computed fields.""" # pylint: disable=global-statement global captionname, cleveref_default, plusname, starname, numbersections # Read in the metadata fields and do some checking if 'tablenos-caption-name' in meta: captionname = get_meta(meta, 'tablenos-caption-name') assert type(captionname) in STRTYPES if 'cleveref' in meta: cleveref_default = get_meta(meta, 'cleveref') assert cleveref_default in [True, False] if 'tablenos-cleveref' in meta: cleveref_default = get_meta(meta, 'tablenos-cleveref') assert cleveref_default in [True, False] if 'tablenos-plus-name' in meta: tmp = get_meta(meta, 'tablenos-plus-name') if type(tmp) is list: plusname = tmp else: plusname[0] = tmp assert len(plusname) == 2 for name in plusname: assert type(name) in STRTYPES if 'tablenos-star-name' in meta: tmp = get_meta(meta, 'tablenos-star-name') if type(tmp) is list: starname = tmp else: starname[0] = tmp assert len(starname) == 2 for name in starname: assert type(name) in STRTYPES if 'xnos-number-sections' in meta and meta['xnos-number-sections']['c']: numbersections = True
def process(meta): """Saves metadata fields in global variables and returns a few computed fields.""" # pylint: disable=global-statement global captionname, cleveref_default, plusname, starname # Read in the metadata fields and do some checking if 'tablenos-caption-name' in meta: captionname = get_meta(meta, 'tablenos-caption-name') assert type(captionname) in STRTYPES if 'cleveref' in meta: cleveref_default = get_meta(meta, 'cleveref') assert cleveref_default in [True, False] if 'tablenos-cleveref' in meta: cleveref_default = get_meta(meta, 'tablenos-cleveref') assert cleveref_default in [True, False] if 'tablenos-plus-name' in meta: tmp = get_meta(meta, 'tablenos-plus-name') if type(tmp) is list: plusname = tmp else: plusname[0] = tmp assert len(plusname) == 2 for name in plusname: assert type(name) in STRTYPES if 'tablenos-star-name' in meta: tmp = get_meta(meta, 'tablenos-star-name') if type(tmp) is list: starname = tmp else: starname[0] = tmp assert len(starname) == 2 for name in starname: assert type(name) in STRTYPES
def process(meta): """Saves metadata fields in global variables and returns a few computed fields.""" # pylint: disable=global-statement global capitalize global captionname global use_cleveref_default global plusname global starname global numbersections # Read in the metadata fields and do some checking if 'tablenos-caption-name' in meta: captionname = get_meta(meta, 'tablenos-caption-name') assert isinstance(captionname, STRTYPES) for name in ['tablenos-cleveref', 'xnos-cleveref', 'cleveref']: # 'xnos-cleveref' enables cleveref in all 3 of fignos/eqnos/tablenos # 'cleveref' is deprecated if name in meta: use_cleveref_default = check_bool(get_meta(meta, name)) for name in ['tablenos-capitalize', 'tablenos-capitalise', 'xnos-capitalize', 'xnos-capitalise']: # 'tablenos-capitalise' is an alternative spelling # 'xnos-capitalise' enables capitalise in all 3 of fignos/eqnos/tablenos # 'xnos-capitalize' is an alternative spelling if name in meta: capitalize = check_bool(get_meta(meta, name)) break if 'tablenos-plus-name' in meta: tmp = get_meta(meta, 'tablenos-plus-name') if isinstance(tmp, list): plusname = tmp else: plusname[0] = tmp assert len(plusname) == 2 for name in plusname: assert isinstance(name, STRTYPES) if 'tablenos-star-name' in meta: tmp = get_meta(meta, 'tablenos-star-name') if isinstance(tmp, list): starname = tmp else: starname[0] = tmp assert len(starname) == 2 for name in starname: assert isinstance(name, STRTYPES) if 'xnos-number-sections' in meta: numbersections = check_bool(get_meta(meta, 'xnos-number-sections'))
def test_get_meta_1(self): """Tests get_meta() #1.""" ## test.md empty # Command: pandoc test.md -t json -M foo=bar src = eval(r'''{"meta":{"foo":{"t":"MetaString","c":"bar"}},"blocks":[],"pandoc-api-version":[1,17,5,1]}''') # Check src against current pandoc md = subprocess.Popen(('echo', ''), stdout=subprocess.PIPE) output = eval(subprocess.check_output( 'pandoc -t json -M foo=bar'.split(), stdin=md.stdout).strip()) self.assertEqual(src, output) expected = 'bar' # Make the comparison self.assertEqual(get_meta(src['meta'], 'foo'), expected)
def test_get_meta_1(self): """Tests get_meta() #1.""" ## test.md empty # Command: pandoc test.md -t json -M foo=bar src = eval(r'''{"meta":{"foo":{"t":"MetaString","c":"bar"}},"blocks":[],"pandoc-api-version":[%s]}'''%PANDOC_API_VERSION) # Check src against current pandoc md = subprocess.Popen(('echo', ''), stdout=subprocess.PIPE) output = eval(subprocess.check_output( 'pandoc -t json -M foo=bar'.split(), stdin=md.stdout).strip()) self.assertEqual(src, output) expected = 'bar' # Make the comparison self.assertEqual(get_meta(src['meta'], 'foo'), expected)
def test_get_meta_3(self): """Tests get_meta() #3.""" ## test.md: ---\nfoo:\n - bar\n - baz\n... ## # Command: pandoc test.md -t json src = eval(r'''{"meta":{"foo":{"t":"MetaList","c":[{"t":"MetaInlines","c":[{"t":"Str","c":"bar"}]},{"t":"MetaInlines","c":[{"t":"Str","c":"baz"}]}]}},"blocks":[],"pandoc-api-version":[%s]}'''%PANDOC_API_VERSION) # Check src against current pandoc md = subprocess.Popen(('echo', '---\nfoo:\n - bar\n - baz\n...'), stdout=subprocess.PIPE) output = eval(subprocess.check_output( 'pandoc -t json'.split(), stdin=md.stdout).strip()) self.assertEqual(src, output) expected = ['bar', 'baz'] # Make the comparison self.assertEqual(get_meta(src['meta'], 'foo'), expected)
def test_get_meta_3(self): """Tests get_meta() #3.""" ## test.md: ---\nfoo:\n - bar\n - baz\n... ## # Command: pandoc test.md -t json src = eval(r'''{"meta":{"foo":{"t":"MetaList","c":[{"t":"MetaInlines","c":[{"t":"Str","c":"bar"}]},{"t":"MetaInlines","c":[{"t":"Str","c":"baz"}]}]}},"blocks":[],"pandoc-api-version":[1,17,5,1]}''') # Check src against current pandoc md = subprocess.Popen(('echo', '---\nfoo:\n - bar\n - baz\n...'), stdout=subprocess.PIPE) output = eval(subprocess.check_output( 'pandoc -t json'.split(), stdin=md.stdout).strip()) self.assertEqual(src, output) expected = ['bar', 'baz'] # Make the comparison self.assertEqual(get_meta(src['meta'], 'foo'), expected)
def test_get_meta_4(self): """Tests get_meta() #4.""" ## test.md: ---\nfoo: True\n... ## # Command: pandoc test.md -t json src = eval(r'''{"blocks": [], "pandoc-api-version": [1, 17, 5, 1], "meta": {"foo": {"t": "MetaBool", "c": True}}}''') # Check src against current pandoc md = subprocess.Popen(('echo', '---\nfoo: True\n...'), stdout=subprocess.PIPE) output = eval(subprocess.check_output( 'pandoc -t json'.split(), stdin=md.stdout).strip().decode("utf-8").replace('true', 'True')) self.assertEqual(src, output) expected = True # Make the comparison self.assertEqual(get_meta(src['meta'], 'foo'), expected)
def action(key, value, fmt, meta): # pylint: disable=unused-argument """Processes elements.""" if key == 'Span': attrs = PandocAttributes(value[0], 'pandoc') if 'newthought' in attrs.classes: if 'documentclass' in meta and \ get_meta(meta, 'documentclass') in \ ['tufte-book', 'tufte-handout']: pre = RawInline('tex', r'\newthought{') post = RawInline('tex', r'}') value[1].insert(0, pre) value[1].append(post) elif warninglevel: STDERR.write(WARNING)
def test_get_meta_4(self): """Tests get_meta() #4.""" ## test.md: ---\nfoo: True\n... ## # Command: pandoc test.md -t json src = eval(r'''{"blocks": [], "pandoc-api-version": [1, 17, 5, 4], "meta": {"foo": {"t": "MetaBool", "c": True}}}''') # Check src against current pandoc md = subprocess.Popen(('echo', '---\nfoo: True\n...'), stdout=subprocess.PIPE) output = eval(subprocess.check_output( 'pandoc -t json'.split(), stdin=md.stdout).strip().decode("utf-8").replace('true', 'True')) self.assertEqual(src, output) expected = True # Make the comparison self.assertEqual(get_meta(src['meta'], 'foo'), expected)
# pylint: disable=global-statement global capitalize global use_cleveref_default global plusname global starname global numbersections global use_eqref # Read in the metadata fields and do some checking for name in ['eqnos-cleveref', 'xnos-cleveref', 'cleveref']: # 'xnos-cleveref' enables cleveref in all 3 of fignos/eqnos/tablenos # 'cleveref' is deprecated if name in meta: use_cleveref_default = check_bool(get_meta(meta, name)) break for name in ['eqnos-capitalize', 'eqnos-capitalise', 'xnos-capitalize', 'xnos-capitalise']: # 'eqnos-capitalise' is an alternative spelling # 'xnos-capitalise' enables capitalise in all 3 of fignos/eqnos/tablenos # 'xnos-capitalize' is an alternative spelling if name in meta: capitalize = check_bool(get_meta(meta, name)) break if 'eqnos-plus-name' in meta: tmp = get_meta(meta, 'eqnos-plus-name') if isinstance(tmp, list): plusname = tmp
def process(meta): """Saves metadata fields in global variables and returns a few computed fields.""" # pylint: disable=global-statement global captionname # The caption name global separator # The caption separator global cleveref # Flags that clever references should be used global capitalise # Flags that plusname should be capitalised global plusname # Sets names for mid-sentence references global starname # Sets names for references at sentence start global numbersections # Flags that sections should be numbered by section global secoffset # Section number offset global warninglevel # 0 - no warnings; 1 - some; 2 - all global captionname_changed # Flags the caption name changed global separator_changed # Flags the caption separator changed global plusname_changed # Flags that the plus name changed global starname_changed # Flags that the star name changed # Read in the metadata fields and do some checking for name in ['fignos-warning-level', 'xnos-warning-level']: if name in meta: warninglevel = int(get_meta(meta, name)) pandocxnos.set_warning_level(warninglevel) break metanames = [ 'fignos-warning-level', 'xnos-warning-level', 'fignos-caption-name', 'fignos-caption-separator', 'xnos-caption-separator', 'fignos-cleveref', 'xnos-cleveref', 'xnos-capitalise', 'xnos-capitalize', 'fignos-plus-name', 'fignos-star-name', 'fignos-number-by-section', 'xnos-number-by-section', 'xnos-number-offset' ] if warninglevel: for name in meta: if (name.startswith('fignos') or name.startswith('xnos')) and \ name not in metanames: msg = textwrap.dedent(""" pandoc-fignos: unknown meta variable "%s" """ % name) STDERR.write(msg) if 'fignos-caption-name' in meta: old_captionname = captionname captionname = get_meta(meta, 'fignos-caption-name') captionname_changed = captionname != old_captionname assert isinstance(captionname, STRTYPES) for name in ['fignos-caption-separator', 'xnos-caption-separator']: if name in meta: old_separator = separator separator = get_meta(meta, name) if separator not in \ ['none', 'colon', 'period', 'space', 'quad', 'newline']: msg = textwrap.dedent(""" pandoc-fignos: caption separator must be one of none, colon, period, space, quad, or newline. """ % name) STDERR.write(msg) continue separator_changed = separator != old_separator break for name in ['fignos-cleveref', 'xnos-cleveref']: # 'xnos-cleveref' enables cleveref in all 3 of fignos/eqnos/tablenos if name in meta: cleveref = check_bool(get_meta(meta, name)) break for name in ['xnos-capitalise', 'xnos-capitalize']: # 'xnos-capitalise' enables capitalise in all 3 of # fignos/eqnos/tablenos. Since this uses an option in the caption # package, it is not possible to select between the three (use # 'fignos-plus-name' instead. 'xnos-capitalize' is an alternative # spelling if name in meta: capitalise = check_bool(get_meta(meta, name)) break if 'fignos-plus-name' in meta: tmp = get_meta(meta, 'fignos-plus-name') old_plusname = copy.deepcopy(plusname) if isinstance(tmp, list): # The singular and plural forms were given plusname = tmp else: # Only the singular form was given plusname[0] = tmp plusname_changed = plusname != old_plusname assert len(plusname) == 2 for name in plusname: assert isinstance(name, STRTYPES) if plusname_changed: starname = [name.title() for name in plusname] if 'fignos-star-name' in meta: tmp = get_meta(meta, 'fignos-star-name') old_starname = copy.deepcopy(starname) if isinstance(tmp, list): starname = tmp else: starname[0] = tmp starname_changed = starname != old_starname assert len(starname) == 2 for name in starname: assert isinstance(name, STRTYPES) for name in ['fignos-number-by-section', 'xnos-number-by-section']: if name in meta: numbersections = check_bool(get_meta(meta, name)) break if 'xnos-number-offset' in meta: secoffset = int(get_meta(meta, 'xnos-number-offset'))
def process(meta): """Saves metadata fields in global variables and returns a few computed fields.""" # pylint: disable=global-statement global cleveref # Flags that clever references should be used global capitalise # Flags that plusname should be capitalised global names # Sets theorem types and names global warninglevel # 0 - no warnings; 1 - some; 2 - all global LABEL_PATTERN global numbersections global secoffset global sharedcounter # Read in the metadata fields and do some checking for name in ['theoremnos-warning-level', 'xnos-warning-level']: if name in meta: warninglevel = int(get_meta(meta, name)) pandocxnos.set_warning_level(warninglevel) break metanames = [ 'theoremnos-warning-level', 'xnos-warning-level', 'theoremnos-cleveref', 'xnos-cleveref', 'xnos-capitalise', 'xnos-capitalize', 'xnos-caption-separator', # Used by pandoc-fignos/tablenos 'theoremnos-names', 'xnos-number-by-section', 'theoremnos-shared-counter', 'theoremnos-number-by-section', 'xnos-number-offset' ] if warninglevel: for name in meta: if (name.startswith('theoremnos') or name.startswith('xnos')) and \ name not in metanames: msg = textwrap.dedent(""" pandoc-theoremnos: unknown meta variable "%s"\n """ % name) STDERR.write(msg) for name in ['theoremnos-cleveref', 'xnos-cleveref']: # 'xnos-cleveref' enables cleveref in all 3 of fignos/eqnos/tablenos if name in meta: cleveref = check_bool(get_meta(meta, name)) break for name in ['xnos-capitalise', 'xnos-capitalize']: # 'xnos-capitalise' enables capitalise in all 4 of # fignos/eqnos/tablenos/theoremonos. Since this uses an option in # the caption package, it is not possible to select between the four. # 'xnos-capitalize' is an alternative spelling if name in meta: capitalise = check_bool(get_meta(meta, name)) break for name in ['theoremnos-number-by-section', 'xnos-number-by-section']: if name in meta: numbersections = check_bool(get_meta(meta, name)) break if 'xnos-number-offset' in meta: secoffset = int(get_meta(meta, 'xnos-number-offset')) if 'theoremnos-shared-counter' in meta: sharedcounter = check_bool(get_meta(meta, 'theoremnos-shared-counter')) if 'theoremnos-names' in meta: assert meta['theoremnos-names']['t'] == 'MetaList' for entry in get_meta(meta, 'theoremnos-names'): assert isinstance(entry, dict), "%s is of type %s" % \ (entry, type(entry)) assert 'id' in entry and isinstance(entry['id'], STRTYPES) assert 'name' in entry and isinstance(entry['name'], STRTYPES) names[entry['id']] = entry['name'] Ntargets[entry['id']] = 0 Ntargets['shared'] = 0 if names: LABEL_PATTERN = \ re.compile("(%s):%s" % ('|'.join(names.keys()), r'[\w/-]*'))
def process(meta): """Saves metadata fields in global variables and returns a few computed fields.""" # pylint: disable=global-statement global cleveref # Flags that clever references should be used global capitalise # Flags that plusname should be capitalised global plusname # Sets names for mid-sentence references global starname # Sets names for references at sentence start global secoffset # Section number offset global warninglevel # 0 - no warnings; 1 - some; 2 - all # Read in the metadata fields and do some checking for name in ['secnos-warning-level', 'xnos-warning-level']: if name in meta: warninglevel = int(get_meta(meta, name)) pandocxnos.set_warning_level(warninglevel) break metanames = ['secnos-warning-level', 'xnos-warning-level', 'secnos-cleveref', 'xnos-cleveref', 'xnos-capitalise', 'xnos-capitalize', 'xnos-caption-separator', # Used by pandoc-fignos/tablenos 'secnos-plus-name', 'secnos-star-name', 'xnos-number-by-section', 'xnos-number-offset'] if warninglevel: for name in meta: if (name.startswith('secnos') or name.startswith('xnos')) and \ name not in metanames: msg = textwrap.dedent(""" pandoc-secnos: unknown meta variable "%s"\n """ % name) STDERR.write(msg) for name in ['secnos-cleveref', 'xnos-cleveref']: # 'xnos-cleveref' enables cleveref in all four of # fignos/eqnos/tablenos/secnos if name in meta: cleveref = check_bool(get_meta(meta, name)) break for name in ['xnos-capitalise', 'xnos-capitalize']: # 'xnos-capitalise' enables capitalise in all four of # fignos/eqnos/tablenos/secnos. Since this uses an option in the # caption package, it is not possible to select between the three (use # 'secnos-plus-name' instead. 'xnos-capitalize' is an alternative # spelling if name in meta: capitalise = check_bool(get_meta(meta, name)) break if 'secnos-plus-name' in meta: value = get_meta(meta, 'secnos-plus-name') if isinstance(value, str): try: value_ = \ dict(itemstr.split(':') for itemstr in value.split(',')) for division in value_: set_name('plus', division, value_[division]) except ValueError: set_name('plus', 'section', value) else: # Dict expected for division in value: set_name('plus', division, value[division]) if 'secnos-star-name' in meta: value = get_meta(meta, 'secnos-star-name') if isinstance(value, str): try: value_ = \ dict(itemstr.split(':') for itemstr in value.split(',')) for division in value_: set_name('star', division, value_[division]) except ValueError: set_name('star', 'section', value) else: # Dict expected for division in value: set_name('star', division, value[division]) if 'xnos-number-offset' in meta: secoffset = int(get_meta(meta, 'xnos-number-offset'))
def process(meta): """Saves metadata fields in global variables and returns a few computed fields.""" # pylint: disable=global-statement global cleveref # Flags that clever references should be used global capitalise # Flags that plusname should be capitalised global plusname # Sets names for mid-sentence references global starname # Sets names for references at sentence start global numbersections # Flags that sections should be numbered by section global secoffset # Section number offset global warninglevel # 0 - no warnings; 1 - some; 2 - all global plusname_changed # Flags that the plus name changed global starname_changed # Flags that the star name changed global eqref # Flags that \eqref should be used global default_env # Default equations environment # Read in the metadata fields and do some checking for name in ['eqnos-warning-level', 'xnos-warning-level']: if name in meta: warninglevel = int(get_meta(meta, name)) pandocxnos.set_warning_level(warninglevel) break metanames = [ 'eqnos-warning-level', 'xnos-warning-level', 'eqnos-cleveref', 'xnos-cleveref', 'xnos-capitalise', 'xnos-capitalize', 'xnos-caption-separator', # Used by pandoc-fignos/tablenos 'eqnos-plus-name', 'eqnos-star-name', 'eqnos-number-by-section', 'xnos-number-by-section', 'xnos-number-offset', 'eqnos-eqref', 'eqnos-default-env' ] if warninglevel: for name in meta: if (name.startswith('eqnos') or name.startswith('xnos')) and \ name not in metanames: msg = textwrap.dedent(""" pandoc-eqnos: unknown meta variable "%s"\n """ % name) STDERR.write(msg) for name in ['eqnos-cleveref', 'xnos-cleveref']: # 'xnos-cleveref' enables cleveref in all 3 of fignos/eqnos/tablenos if name in meta: cleveref = check_bool(get_meta(meta, name)) break for name in ['xnos-capitalise', 'xnos-capitalize']: # 'xnos-capitalise' enables capitalise in all 3 of # fignos/eqnos/tablenos. Since this uses an option in the caption # package, it is not possible to select between the three (use # 'eqnos-plus-name' instead. 'xnos-capitalize' is an alternative # spelling if name in meta: capitalise = check_bool(get_meta(meta, name)) break if 'eqnos-plus-name' in meta: tmp = get_meta(meta, 'eqnos-plus-name') old_plusname = copy.deepcopy(plusname) if isinstance(tmp, list): # The singular and plural forms were given plusname = tmp else: # Only the singular form was given plusname[0] = tmp plusname_changed = plusname != old_plusname assert len(plusname) == 2 for name in plusname: assert isinstance(name, STRTYPES) if plusname_changed: starname = [name.title() for name in plusname] if 'eqnos-star-name' in meta: tmp = get_meta(meta, 'eqnos-star-name') old_starname = copy.deepcopy(starname) if isinstance(tmp, list): starname = tmp else: starname[0] = tmp starname_changed = starname != old_starname assert len(starname) == 2 for name in starname: assert isinstance(name, STRTYPES) for name in ['eqnos-number-by-section', 'xnos-number-by-section']: if name in meta: numbersections = check_bool(get_meta(meta, name)) break if 'xnos-number-offset' in meta: secoffset = int(get_meta(meta, 'xnos-number-offset')) if 'eqnos-eqref' in meta: eqref = check_bool(get_meta(meta, 'eqnos-eqref')) # Note: Eqref and cleveref are mutually exclusive. If both are # enabled, then cleveref will be used but with bracketed equation # numbers. if 'eqnos-default-env' in meta: default_env = get_meta(meta, 'eqnos-default-env')