Skip to content

Commit

Permalink
add section numbering, and change theorem numbering to per-section
Browse files Browse the repository at this point in the history
  • Loading branch information
Adeel Khan committed Jul 30, 2016
1 parent 0503b74 commit dce3216
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions app/views/layouts/default.rhtml
Expand Up @@ -68,10 +68,32 @@
<script type="text/javascript">
/* counters for theorem environments */
var envs = ["theorem", "lemma", "prop", "cor", "defn", "example", "note", "remark"];
var selector = envs.map(function(s) {return ".num_" + s + " .theorem_label"}).join(",");
var theorem_label_selector = envs.map(function(s) {return ".num_" + s + " .theorem_label"}).join(",");
document.observe("dom:loaded", function() {
$$(selector).each(function(label, index) {
label.insert(" " + (index+1));
// add numbering to the table of contents
$$(".maruku_toc > ul li a").each(function(x, index) {
x.insert({top: (index+1) + ". "});
});

// find the context menu and mark all h2 elements;
// we want to skip them below in the numbering
$$(".toc.clickDown h2").each(function(x) {
x.addClassName("context_menu")
});

// now add the theorem numbering
var section_counter = 0;
var theorem_counter = 0;
// find both section titles and theorem labels, and iterate
$$(theorem_label_selector + ",#revision h2:not(.context_menu)").each(function(tag, index) {
if (tag.tagName == "h2") { // this is a section title
section_counter += 1;
theorem_counter = 0;
tag.insert({top: section_counter + ". "});
} else { // this is a theorem label
theorem_counter += 1;
tag.insert(" " + section_counter + "." + theorem_counter);
}
});
});
</script>
Expand Down

0 comments on commit dce3216

Please sign in to comment.