Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make format of float numberin configurable
  • Loading branch information
kthoden committed Jul 19, 2019
1 parent 31aaf05 commit 4ea86ad
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions tei2imxml.py
Expand Up @@ -808,7 +808,7 @@ def handle_refs_hyperimage(ref):
return xml_tree
# def transform_body ends here

def assign_ids(xml_tree, data):
def assign_ids(xml_tree, data, suppress_chapter_number):
"""Walk the xml tree again. Assign ids to xml and put them into dicts, as well."""

chapterdict = {}
Expand Down Expand Up @@ -838,7 +838,10 @@ def assign_ids(xml_tree, data):

figure_anchors = chapter.findall(".//EOAfigure/anchor")
for anchor in figure_anchors:
figure_number = "%d.%d" % (chapter_counter, figure_counter)
if suppress_chapter_number:
figure_number = "%d" % (figure_counter)
else:
figure_number = "%d.%d" % (chapter_counter, figure_counter)

anchor.set("id-text", figure_number)
figure_counter += 1
Expand Down Expand Up @@ -872,15 +875,29 @@ def assign_ids(xml_tree, data):

tables = chapter.findall(".//EOAtable/table")
for table in tables:
table_number = "{}.{}".format(chapter_counter, table_counter)
if suppress_chapter_number:
table_number = "%d" % (table_counter)
else:
table_number = "%d.%d" % (chapter_counter, table_counter)
table.attrib["id-text"] = table_number
# table.set("id-text", table_number)
table_counter += 1
tabdict[table.get("id")] = table_number

equations = chapter.findall(".//EOAequation")
for equation in equations:
if suppress_chapter_number:
equation_number = "%d" % (equation_counter)
else:
equation_number = "%d.%d" % (chapter_counter, equation_counter)
equation.attrib["id-text"] = equation_number
# table.set("id-text", table_number)
equation_counter += 1
eqdict[equation.get("id")] = equation_number

chapter_counter += 1

# not implemented yet: equation, list, pagelabel, tab, theorem
# not implemented yet: list, pagelabel, tab, theorem

data["chapterdict"] = chapterdict
data["figdict"] = figdict
Expand Down Expand Up @@ -1201,6 +1218,11 @@ def main():
action="store_true",
help="Ignore warnings of missing or duplicate ids."
)
parser.add_argument(
"-s", "--suppress-chapter-number",
action="store_true",
help="In floats, only print number of figure, not chapter before."
)

parser.add_argument("-d", "--pickleddata", default="./output/imxml/tmp_files/data.pickle", help="Pickled data file to be used.")
parser.add_argument("-him", "--hyperimage", action="store_true")
Expand Down Expand Up @@ -1312,7 +1334,7 @@ def main():
element.set("id", "uid" + str(element_counter))
element_counter += 1

assigned_ids, data_to_pickle = assign_ids(xml_add_bib, data)
assigned_ids, data_to_pickle = assign_ids(xml_add_bib, data, args.suppress_chapter_number)

updated_xml_tree = update_ids(assigned_ids, args.ignore_ref_errors)
# libeoaconvert.debug_xml_here(updated_xml_tree, "updated_tree")
Expand Down

0 comments on commit 4ea86ad

Please sign in to comment.