def texify(string): """Return a modified version of the argument string where non-ASCII symbols have been converted into LaTeX escape codes. """ output = '' for w in string.split(): output += unicode_to_tex(w) + ' ' output = output.strip() return output
def create_bibentry(self, refkey, reference): """ returns a string with a bibtex-entry from cite2c reference data. currently three common reference types are implemented: articles, books and chapter of books. non-ascii characters are only checked for in autor, title and journal name Parameters ---------- refkey: str Zotero/Cite2c key of references reference: dictionary Dictonary with cite2c reference data as taken from cite2c JSON metadata """ if (reference["type"] == "article-journal"): entry = "@article{" + refkey + ",\n" elif (reference["type"] == "book"): entry = "@book{" + refkey + ",\n" elif (reference["type"] == "chapter"): entry = "@inbook{" + refkey + ",\n" else: # default type is misc! entry = "@misc{" + refkey + ",\n" print("Warning: Unknown type of reference "+refkey) if ("author" in reference): entry += " author = {" entry += " and ".join(map(lambda a: unicode_tex.unicode_to_tex(a["family"]) + ", " + unicode_tex.unicode_to_tex(a["given"]), reference["author"])) entry += "}, \n" else: print("Warning: No author(s) of reference " + refkey) if ("title" in reference): if reference["type"] == "chapter": entry += " chapter = {" + unicode_tex.unicode_to_tex(reference["title"]) + "}, \n" else: entry += " title = {" + unicode_tex.unicode_to_tex(reference["title"]) + "}, \n" else: print("Warning: No title of reference " + refkey) if ("container-title" in reference): if reference["type"] == "chapter": entry += " title = {" + unicode_tex.unicode_to_tex(reference["container-title"]) + "}, \n" else: entry += " journal = {" + unicode_tex.unicode_to_tex(reference["container-title"]) + "}, \n" if ("issued" in reference): entry += " year = {" + reference["issued"]["year"] + "}, \n" if ("publisher" in reference): entry += " publisher = {" + reference["publisher"] + "}, \n" if ("page" in reference): entry += " pages = {" + re.sub("-", "--", reference["page"]) + "}, \n" if ("volume" in reference): entry += " volume = {" + reference["volume"] + "}, \n" if ("issue" in reference): entry += " issue = {" + reference["issue"] + "}, \n" if ("DOI" in reference): entry += " doi = {" + reference["DOI"] + "}, \n" if ("URL" in reference): entry += " url = {" + reference["URL"] + "}, \n" entry += "}\n" entry += "\n" return entry