def rst_bib(filestr, citations, pubfile, pubdata, numbering=True): """ Replace doconce citations and bibliography with reST syntax. If numbering is True, the keys used in the bibliography are replaced by numbers (RefX). This will often look better. """ if not citations: return filestr filestr = cite_with_multiple_args2multiple_cites(filestr) if numbering: # Find max no of digits n = len(str(max(citations.values()))) cite = '[Ref%%0%dd]' % n # cannot have blanks in ref label for label in citations: if numbering: filestr = filestr.replace('cite{%s}' % label, cite % citations[label] + '_') else: filestr = filestr.replace('cite{%s}' % label, '[%s]_' % label) if pubfile is not None: bibtext = bibliography(pubdata, citations, format='rst') if numbering: for label in citations: bibtext = bibtext.replace('[%s]' % label, cite % citations[label]) filestr = re.sub(r'^BIBFILE:.+$', bibtext, filestr, flags=re.MULTILINE) return filestr
def rst_bib(filestr, citations, pubfile, pubdata, numbering=True): """ Replace doconce citations and bibliography with reST syntax. If numbering is True, the keys used in the bibliography are replaced by numbers (RefX). This will often look better. """ if not citations: return filestr filestr = cite_with_multiple_args2multiple_cites(filestr) if numbering: # Find max no of digits n = len(str(max(citations.values()))) cite = '[Ref%%0%dd]' % n # cannot have blanks in ref label for label in citations: if numbering: filestr = filestr.replace('cite{%s}' % label, cite % citations[label] + '_') else: filestr = filestr.replace('cite{%s}' % label, '[%s]_' % label) if pubfile is not None: # Could use rst format, but we stick to the common doconce format bibtext = bibliography(pubdata, citations, format='rst') if numbering: for label in citations: bibtext = bibtext.replace('[%s]' % label, cite % citations[label]) filestr = re.sub(r'^BIBFILE:.+$', bibtext, filestr, flags=re.MULTILINE) return filestr
def rst_bib(filestr, citations, pubfile, pubdata, numbering=True): """ Replace doconce citations and bibliography with reST syntax. If numbering is True, the keys used in the bibliography are replaced by numbers (RefX). This will often look better. """ if not citations: return filestr filestr = cite_with_multiple_args2multiple_cites(filestr) if numbering: # Find max no of digits n = len(str(max(citations.values()))) cite = "[Ref%%0%dd]" % n # cannot have blanks in ref label for label in citations: if numbering: filestr = filestr.replace("cite{%s}" % label, cite % citations[label] + "_") else: filestr = filestr.replace("cite{%s}" % label, "[%s]_" % label) if pubfile is not None: # Could use rst format, but we stick to the common doconce format bibtext = bibliography(pubdata, citations, format="rst") if numbering: for label in citations: bibtext = bibtext.replace("[%s]" % label, cite % citations[label]) filestr = re.sub(r"^BIBFILE:.+$", bibtext, filestr, flags=re.MULTILINE) return filestr
def pandoc_index_bib(filestr, index, citations, pubfile, pubdata): # pandoc citations are of the form # bla-bla, see [@Smith04, ch. 1; @Langtangen_2008] # Method: cite{..} -> [...], doconce.py has already fixed @ and ; filestr = re.sub(r'cite\{(.+?)\}', r'[\g<1>]', filestr) if pubfile is not None: bibtext = bibliography(pubdata, citations, format='doconce') filestr = re.sub(r'^BIBFILE:.+$', bibtext, filestr, flags=re.MULTILINE) # pandoc does not support index entries, # remove all index entries filestr = re.sub(r'idx\{.+?\}' + '\n?', '', filestr) return filestr
def rst_bib(filestr, citations, pubfile, pubdata, numbering=True): """ Replace doconce citations and bibliography with reST syntax. If numbering is True, the keys used in the bibliography are replaced by numbers (RefX). This will often look better. """ if not citations: return filestr filestr = cite_with_multiple_args2multiple_cites(filestr) if numbering: # Find max no of digits n = len(str(max(citations.values()))) cite = '[Ref%%0%dd]' % n # cannot have blanks in ref label for label in citations: if numbering: filestr = filestr.replace('cite{%s}' % label, cite % citations[label] + '_') else: filestr = filestr.replace('cite{%s}' % label, '[%s]_' % label) if pubfile is not None: # Could use rst format, but we stick to the common doconce format bibtext = bibliography(pubdata, citations, format='rst') if numbering: for label in citations: try: bibtext = bibtext.replace( '[%s]' % label, cite % citations[label]) except UnicodeDecodeError as e: if "can't decode byte" in str(e): try: bibtext = bibtext.decode('utf-8').replace( '[%s]' % label, cite % citations[label]) except UnicodeDecodeError as e: errwarn('UnicodeDecodeError: ' + e) errwarn('*** error: problems in %s' % pubfile) errwarn(' with key ' + label) errwarn(' tried to do decode("utf-8"), but it did not work') else: errwarn(e) errwarn('*** error: problems in %s' % pubfile) errwarn(' with key ' + label) _abort() filestr = re.sub(r'^BIBFILE:.+$', bibtext, filestr, flags=re.MULTILINE) return filestr
def plain_index_bib(filestr, index, citations, pubfile, pubdata): if citations: filestr = cite_with_multiple_args2multiple_cites(filestr) for label in citations: filestr = filestr.replace('cite{%s}' % label, '[%d]' % citations[label]) if pubfile is not None: bibtext = bibliography(pubdata, citations, format='doconce') bibtext = re.sub(r'label\{.+?\} ', '', bibtext) bibtext = bibtext.replace('_', '') filestr = re.sub(r'^BIBFILE:.+$', bibtext, filestr, flags=re.MULTILINE) # remove all index entries: filestr = re.sub(r'idx\{.+?\}\n?', '', filestr) # no index since line numbers from the .do.txt (in index dict) # never correspond to the output format file #filestr += '\n\n======= Index =======\n\n' #for word in index: # filestr + = '%s, line %s\n' % (word, ', '.join(index[word])) return filestr
def plain_index_bib(filestr, index, citations, pubfile, pubdata): if citations: filestr = cite_with_multiple_args2multiple_cites(filestr) for label in citations: filestr = filestr.replace("cite{%s}" % label, "[%d]" % citations[label]) if pubfile is not None: bibtext = bibliography(pubdata, citations, format="doconce") bibtext = re.sub(r"label\{.+?\} ", "", bibtext) # Remove boldface _author_ (typically 12. _John Doe and Jane Doe_.) bibtext = re.sub(r"(\d+)\. _(.+)_\.", "\g<2>", bibtext) filestr = re.sub(r"^BIBFILE:.+$", bibtext, filestr, flags=re.MULTILINE) # remove all index entries: filestr = re.sub(r"idx\{.+?\}\n?", "", filestr) # no index since line numbers from the .do.txt (in index dict) # never correspond to the output format file # filestr += '\n\n======= Index =======\n\n' # for word in index: # filestr + = '%s, line %s\n' % (word, ', '.join(index[word])) return filestr
def xml_index_bib(filestr, index, citations, pubfile, pubdata): if citations: filestr = cite_with_multiple_args2multiple_cites(filestr) for label in citations: filestr = filestr.replace('cite{%s}' % label, '<cite label="%s">%s</cite>' % \ (label, citations[label])) if pubfile is not None: bibtext = bibliography(pubdata, citations, format='xml') bibtext = """ <!-- begin bibliography --> %s <!-- end bibliography --> """ % bibtext filestr = re.sub(r'^BIBFILE:.+$', bibtext, filestr, flags=re.MULTILINE) filestr = re.sub(r'idx\{(.+?)\}\n?', r'<index>\g<1></index>', filestr) return filestr
def pandoc_index_bib(filestr, index, citations, pubfile, pubdata): # pandoc citations are of the form # bla-bla, see [@Smith04, ch. 1; @Langtangen_2008] # Method: cite{..} -> [...], doconce.py has already fixed @ and ; filestr = re.sub(r'cite\{(.+?)\}', r'[\g<1>]', filestr) if pubfile is not None: bibtext = bibliography(pubdata, citations, format='doconce') filestr = re.sub(r'^BIBFILE:.+$', bibtext, filestr, flags=re.MULTILINE) # pandoc does not support index entries, # remove all index entries (could also place them # in special comments to keep the information) filestr = re.sub(r'idx\{.+?\}' + '\n?', '', filestr) # Use HTML anchors for labels and [link text](#label) for references # outside mathematics. #filestr = re.sub(r'label\{(.+?)\}', '<a name="\g<1>"></a>', filestr) # Note: HTML5 should have <sometag id="..."></sometag> instead filestr = re.sub(r'label\{(.+?)\}', '<div id="\g<1>"></div>', filestr) return filestr