def wiki_ref_and_label_common(section_label2title, format, filestr): # .... see section ref{my:sec} is replaced by # see the section "...section heading..." pattern = r'[Ss]ection(s?)\s+ref\{' replacement = r'the section\g<1> ref{' filestr = re.sub(pattern, replacement, filestr) pattern = r'[Cc]hapter(s?)\s+ref\{' replacement = r'the chapter\g<1> ref{' filestr = re.sub(pattern, replacement, filestr) # Remove Exercise, Project, Problem in references since those words # are used in the title of the section too pattern = r'(the\s*)?([Ee]xercises?|[Pp]rojects?|[Pp]roblems?)\s+ref\{' replacement = r'ref{' filestr = re.sub(pattern, replacement, filestr) # remove label{...} from output filestr = re.sub(r'label\{.+?\}', '', filestr) # all the remaining # anchors in titles do not work... # replace all references to sections: for label in section_label2title: title = section_label2title[label] filestr = filestr.replace('ref{%s}' % label, '[#%s]' % title.replace(' ', '_')) from common import ref2equations filestr = ref2equations(filestr) # replace remaining ref{x} as x filestr = re.sub(r'ref\{(.+?)\}', '\g<1>', filestr) return filestr
def plain_ref_and_label(section_label2title, format, filestr): # .... see section ref{my:sec} is replaced by # see the section "...section heading..." pattern = r'[Ss]ection(s?)\s+ref\{' replacement = r'the section\g<1> ref{' filestr = re.sub(pattern, replacement, filestr) pattern = r'[Cc]hapter(s?)\s+ref\{' replacement = r'the chapter\g<1> ref{' filestr = re.sub(pattern, replacement, filestr) # Remove Exercise, Project, Problem in references since those words # are used in the title of the section too pattern = r'(the\s*)?([Ee]xercises?|[Pp]rojects?|[Pp]roblems?)\s+ref\{' replacement = r' ref{' filestr = re.sub(pattern, replacement, filestr) # remove label{...} from output (when only label{} on a line, remove # the newline too, leave label in figure captions, and remove all the rest) #filestr = re.sub(r'^label\{.+?\}\s*$', '', filestr, flags=re.MULTILINE) cpattern = re.compile(r'^label\{.+?\}\s*$', flags=re.MULTILINE) filestr = cpattern.sub('', filestr) #filestr = re.sub(r'^(FIGURE:.+)label\{(.+?)\}', '\g<1>{\g<2>}', filestr, flags=re.MULTILINE) cpattern = re.compile(r'^(FIGURE:.+)label\{(.+?)\}', flags=re.MULTILINE) filestr = cpattern.sub('\g<1>{\g<2>}', filestr) filestr = re.sub(r'label\{.+?\}', '', filestr) # all the remaining # replace all references to sections: for label in section_label2title: filestr = filestr.replace('ref{%s}' % label, '"%s"' % section_label2title[label]) from common import ref2equations filestr = ref2equations(filestr) return filestr
def rst_ref_and_label(section_label2title, format, filestr): filestr = ref_and_label_commoncode(section_label2title, format, filestr) # replace all references to sections: for label in section_label2title: filestr = filestr.replace('ref{%s}' % label, '`%s`_' % section_label2title[label]) from common import ref2equations filestr = ref2equations(filestr) # replace remaining ref{x} as x_ filestr = re.sub(r'ref\{(.+?)\}', '`\g<1>`_', filestr) return filestr
def wiki_ref_and_label_common(section_label2title, format, filestr): filestr = fix_ref_section_chapter(filestr, format) # remove label{...} from output filestr = re.sub(r'label\{.+?\}', '', filestr) # all the remaining # anchors in titles do not work... # replace all references to sections: for label in section_label2title: title = section_label2title[label] filestr = filestr.replace('ref{%s}' % label, '[#%s]' % title.replace(' ', '_')) from common import ref2equations filestr = ref2equations(filestr) # replace remaining ref{x} as x filestr = re.sub(r'ref\{(.+?)\}', '\g<1>', filestr) return filestr
def plain_ref_and_label(section_label2title, format, filestr): # .... see section ref{my:sec} is replaced by # see the section "...section heading..." pattern = r'[Ss]ection(s?)\s+ref\{' replacement = r'the section\g<1> ref{' filestr = re.sub(pattern, replacement, filestr) pattern = r'[Cc]hapter(s?)\s+ref\{' replacement = r'the chapter\g<1> ref{' filestr = re.sub(pattern, replacement, filestr) # Need special adjustment to handle start of sentence (capital) or not. pattern = r'([.?!]\s+|\n\n|[%=~-]\n+)the (sections?|chapters?)\s+ref' replacement = r'\g<1>The \g<2> ref' filestr = re.sub(pattern, replacement, filestr) # Remove Exercise, Project, Problem in references since those words # are used in the title of the section too pattern = r'(the\s*)?([Ee]xercises?|[Pp]rojects?|[Pp]roblems?)\s+ref\{' replacement = r' ref{' filestr = re.sub(pattern, replacement, filestr) # remove label{...} from output (when only label{} on a line, remove # the newline too, leave label in figure captions, and remove all the rest) #filestr = re.sub(r'^label\{.+?\}\s*$', '', filestr, flags=re.MULTILINE) cpattern = re.compile(r'^label\{.+?\}\s*$', flags=re.MULTILINE) filestr = cpattern.sub('', filestr) #filestr = re.sub(r'^(FIGURE:.+)label\{(.+?)\}', '\g<1>{\g<2>}', filestr, flags=re.MULTILINE) cpattern = re.compile(r'^(FIGURE:.+)label\{(.+?)\}', flags=re.MULTILINE) filestr = cpattern.sub('\g<1>{\g<2>}', filestr) filestr = re.sub(r'label\{.+?\}', '', filestr) # all the remaining # replace all references to sections: for label in section_label2title: filestr = filestr.replace('ref{%s}' % label, '"%s"' % section_label2title[label]) from common import ref2equations filestr = ref2equations(filestr) return filestr
def plain_ref_and_label(section_label2title, format, filestr): filestr = fix_ref_section_chapter(filestr, format) # remove label{...} from output (when only label{} on a line, remove # the newline too, leave label in figure captions, and remove all the rest) #filestr = re.sub(r'^label\{.+?\}\s*$', '', filestr, flags=re.MULTILINE) cpattern = re.compile(r'^label\{.+?\}\s*$', flags=re.MULTILINE) filestr = cpattern.sub('', filestr) #filestr = re.sub(r'^(FIGURE:.+)label\{(.+?)\}', '\g<1>{\g<2>}', filestr, flags=re.MULTILINE) cpattern = re.compile(r'^(FIGURE:.+)label\{(.+?)\}', flags=re.MULTILINE) filestr = cpattern.sub('\g<1>{\g<2>}', filestr) filestr = re.sub(r'label\{.+?\}', '', filestr) # all the remaining # replace all references to sections: for label in section_label2title: filestr = filestr.replace('ref{%s}' % label, '"%s"' % section_label2title[label]) from common import ref2equations filestr = ref2equations(filestr) return filestr
def matlabnb_ref_and_label(section_label2title, format, filestr): filestr = fix_ref_section_chapter(filestr, format) # remove label{...} from output (when only label{} on a line, remove # the newline too, leave label in figure captions, and remove all the rest) #filestr = re.sub(r'^label\{.+?\}\s*$', '', filestr, flags=re.MULTILINE) cpattern = re.compile(r'^label\{.+?\}\s*$', flags=re.MULTILINE) filestr = cpattern.sub('', filestr) #filestr = re.sub(r'^(FIGURE:.+)label\{(.+?)\}', '\g<1>{\g<2>}', filestr, flags=re.MULTILINE) cpattern = re.compile(r'^(FIGURE:.+)label\{(.+?)\}', flags=re.MULTILINE) filestr = cpattern.sub('\g<1>{\g<2>}', filestr) filestr = re.sub(r'label\{.+?\}', '', filestr) # all the remaining # replace all references to sections: for label in section_label2title: filestr = filestr.replace('ref{%s}' % label, '"%s"' % section_label2title[label]) from common import ref2equations filestr = ref2equations(filestr) return filestr
def wiki_ref_and_label_common(section_label2title, format, filestr): # .... see section ref{my:sec} is replaced by # see the section "...section heading..." pattern = r"[Ss]ection(s?)\s+ref\{" replacement = r"the section\g<1> ref{" filestr = re.sub(pattern, replacement, filestr) pattern = r"[Cc]hapter(s?)\s+ref\{" replacement = r"the chapter\g<1> ref{" filestr = re.sub(pattern, replacement, filestr) # Need special adjustment to handle start of sentence (capital) or not. pattern = r"([.?!]\s+|\n\n|[=]{2,}\n+)the (sections?|chapters?)\s+ref" replacement = r"\g<1>The \g<2> ref" filestr = re.sub(pattern, replacement, filestr) # Remove Exercise, Project, Problem in references since those words # are used in the title of the section too pattern = r"(the\s*)?([Ee]xercises?|[Pp]rojects?|[Pp]roblems?)\s+ref\{" replacement = r"ref{" filestr = re.sub(pattern, replacement, filestr) # remove label{...} from output filestr = re.sub(r"label\{.+?\}", "", filestr) # all the remaining # anchors in titles do not work... # replace all references to sections: for label in section_label2title: title = section_label2title[label] filestr = filestr.replace("ref{%s}" % label, "[#%s]" % title.replace(" ", "_")) from common import ref2equations filestr = ref2equations(filestr) # replace remaining ref{x} as x filestr = re.sub(r"ref\{(.+?)\}", "\g<1>", filestr) return filestr