-
🇧🇪 @rubdosthe
texmf/Acronyms.styfile is probably used by @schrieveslaach as some global file with acronyms. If you swap that for your own filename with acronyms, it works.I updated this script to use the acronym definition instead of the label for the short form:
#!/usr/bin/python3 import os from panflute import * import re acronyms = {} refcounts = {} def resolveAcronyms(elem, doc): if isinstance(elem, Span) and "acronym-label" in elem.attributes: label = elem.attributes["acronym-label"] if label in acronyms: # this is the case: "singular" in form and "long" in form: acronym, value = acronyms[label] form = elem.attributes["acronym-form"] if label in refcounts and "short" in form: if "singular" in form: value = acronym else: value = acronym + "s" elif "full" in form or "short" in form: # remember that label has been used if "short" in form: refcounts[label] = True if "singular" in form: value = value + " (" + acronym + ")" else: value = value + "s (" + acronym + "s)" elif "abbrv" in form: if "singular" in form: value = acronym else: value = acronym + "s" return Span(Str(value)) def loadAcronyms(): pattern = re.compile(r"\\newacronym(\[.*\])?\{(?P<label>[A-Za-z]+)\}\{(?P<acronym>[A-Za-z]+)\}\{(?P<value>[A-Za-z 0-9\-]+)\}") d = os.path.dirname(__file__) filename = os.path.join(d, 'main.tex') with open(filename, 'r', encoding='utf-8') as acronymsFile: for line in acronymsFile: match = pattern.match(line) if match: acronyms[match.group('label')] = (match.group('acronym'), match.group('value')) def main(doc=None): loadAcronyms() return run_filter(resolveAcronyms, doc=doc) if __name__ == "__main__": main()
Please register or sign in to comment