def handle_ref(self, tag: QqTag): """ Examples: See Theorem \ref{thm:existence} Other way: See \ref[Theorem|thm:existence] In this case word ``Theorem'' will be part of a reference: e.g. in HTML it will look like See <a href="#label_thm:existence">Theorem 1</a> If you want to omit number, just use \nonumber tag like so: See \ref[Theorem\nonumber|thm:existence] This will produce HTML like See <a href="#label_thm:existence">Theorem</a> Uses tags: ref, nonumber :param tag: :return: """ doc, html, text = Doc().tagtext() if tag.is_simple: prefix = None label = tag.value else: prefix, labelfield = tag.split_by_sep() label = "".join(labelfield).strip() number = self.label2number.get(label, "???") target = self.label2tag[label] href = "" if self.mode == 'bychapters': if 'snippet' not in [t.name for t in tag.ancestor_path()]: # check that we're not inside snippet now fromindex = self.tag2chapter(tag) else: fromindex = None href = self.url_for_chapter(self.tag2chapter(target), fromindex=fromindex) eqref = target.name in self.formulaenvs or target.name == 'item' and target.parent.name in self.formulaenvs if eqref: href += "#mjx-eqn-" + str(number) else: href += "#" + self.label2id(label) with html("span", klass="ref"): with html("a", klass="a-ref", href=href, title=self.label2title.get(label, "")): if prefix: doc.asis(self.format(prefix, blanks_to_pars=False)) if eqref and hasattr(self, 'url_for_eq_snippet'): doc.attr(('data-url', self.url_for_eq_snippet(number))) if not tag.exists("nonumber"): if prefix: doc.asis(" ") if eqref: text("(" + number + ")") else: text(number) return doc.getvalue()
def handle_ref(self, tag: QqTag): """ Examples: See Theorem \ref{thm:existence} Other way: See \ref[Theorem|thm:existence] In this case word ``Theorem'' will be part of a reference: e.g. in HTML it will look like See <a href="#label_thm:existence">Theorem 1</a> If you want to omit number, just use \nonumber tag like so: See \ref[Theorem\nonumber|thm:existence] This will produce HTML like See <a href="#label_thm:existence">Theorem</a> Uses tags: ref, nonumber :param tag: :return: """ doc, html, text = Doc().tagtext() if tag.is_simple: prefix = None label = tag.value else: prefix, labelfield = tag.split_by_sep() label = "".join(labelfield).strip() number = self.label2number.get(label, "???") target = self.label2tag[label] href = "" if self.mode == 'bychapters': if 'snippet' not in [t.name for t in tag.ancestor_path()]: # check that we're not inside snippet now fromindex = self.tag2chapter(tag) else: fromindex = None href = self.url_for_chapter(self.tag2chapter(target), fromindex=fromindex) eqref = target.name in self.formulaenvs or target.name == 'item' and target.parent.name in self.formulaenvs if eqref: href += "#mjx-eqn-" + str(number) else: href += "#"+self.label2id(label) with html("span", klass="ref"): with html("a", klass="a-ref", href=href, title=self.label2title.get(label, "")): if prefix: doc.asis(self.format(prefix, blanks_to_pars=False)) if eqref and hasattr(self, 'url_for_eq_snippet'): doc.attr(('data-url', self.url_for_eq_snippet(number))) if not tag.exists("nonumber"): if prefix: doc.asis(" ") if eqref: text("(" + number + ")") else: text(number) return doc.getvalue()