Automatic Theorem Numbering
Can now refer to numbered theorems by \ref{...}, as in LaTeX
This commit is contained in:
parent
da81a2fbdb
commit
2fb41f12ce
|
@ -181,7 +181,6 @@
|
||||||
\newcommand{\quadrupleintegral}{\iiiint}
|
\newcommand{\quadrupleintegral}{\iiiint}
|
||||||
\newcommand{\conint}{\oint}
|
\newcommand{\conint}{\oint}
|
||||||
\newcommand{\contourintegral}{\oint}
|
\newcommand{\contourintegral}{\oint}
|
||||||
\newcommand{\qed}{\blacksquare}
|
|
||||||
\newcommand{\infinity}{\infty}
|
\newcommand{\infinity}{\infty}
|
||||||
\renewcommand{\empty}{\emptyset}
|
\renewcommand{\empty}{\emptyset}
|
||||||
\newcommand{\bottom}{\bot}
|
\newcommand{\bottom}{\bot}
|
||||||
|
@ -212,9 +211,9 @@
|
||||||
\newtheorem*{uprop}{Proposition}
|
\newtheorem*{uprop}{Proposition}
|
||||||
\newtheorem*{ucor}{Corollary}
|
\newtheorem*{ucor}{Corollary}
|
||||||
\theoremstyle{definition}
|
\theoremstyle{definition}
|
||||||
\newtheorem{def}{Definition}
|
\newtheorem{defn}{Definition}
|
||||||
\newtheorem{example}{Example}
|
\newtheorem{example}{Example}
|
||||||
\newtheorem*{udef}{Definition}
|
\newtheorem*{udefn}{Definition}
|
||||||
\newtheorem*{uexample}{Example}
|
\newtheorem*{uexample}{Example}
|
||||||
\theoremstyle{remark}
|
\theoremstyle{remark}
|
||||||
\newtheorem{remark}{Remark}
|
\newtheorem{remark}{Remark}
|
||||||
|
|
|
@ -17,12 +17,13 @@ table.plaintable {
|
||||||
margin-left:30px;
|
margin-left:30px;
|
||||||
}
|
}
|
||||||
.noborder td, .noborder th {border:0}
|
.noborder td, .noborder th {border:0}
|
||||||
body {counter-reset: theorem lemma proposition corollary example remark}
|
body {counter-reset: theorem lemma proposition corollary definition example remark note}
|
||||||
.un_theorem *, .num_theorem *,
|
.un_theorem *, .num_theorem *,
|
||||||
.un_lemma *, .num_lemma *,
|
.un_lemma *, .num_lemma *,
|
||||||
.un_prop *, .num_prop *,
|
.un_prop *, .num_prop *,
|
||||||
.un_cor *, .num_cor * {font-style: italic}
|
.un_cor *, .num_cor * {font-style: italic}
|
||||||
span.theorem_label {font-style:normal; font-weight:bold;}
|
span.theorem_label {font-style:normal; font-weight:bold;}
|
||||||
|
.proof span.theorem_label {font-style:italic;}
|
||||||
.num_theorem .theorem_label:after {
|
.num_theorem .theorem_label:after {
|
||||||
content: " " counter(theorem); counter-increment: theorem;}
|
content: " " counter(theorem); counter-increment: theorem;}
|
||||||
.num_lemma .theorem_label:after {
|
.num_lemma .theorem_label:after {
|
||||||
|
@ -31,7 +32,11 @@ span.theorem_label {font-style:normal; font-weight:bold;}
|
||||||
content: " " counter(proposition); counter-increment: proposition;}
|
content: " " counter(proposition); counter-increment: proposition;}
|
||||||
.num_cor .theorem_label:after {
|
.num_cor .theorem_label:after {
|
||||||
content: " " counter(corollary); counter-increment: corollary;}
|
content: " " counter(corollary); counter-increment: corollary;}
|
||||||
|
.num_defn .theorem_label:after {
|
||||||
|
content: " " counter(definition); counter-increment: definition;}
|
||||||
.num_example .theorem_label:after {
|
.num_example .theorem_label:after {
|
||||||
content: " " counter(example); counter-increment: example;}
|
content: " " counter(example); counter-increment: example;}
|
||||||
.num_remark .theorem_label:after {
|
.num_remark .theorem_label:after {
|
||||||
content: " " counter(remark); counter-increment: remark;}
|
content: " " counter(remark); counter-increment: remark;}
|
||||||
|
.num_note .theorem_label:after {
|
||||||
|
content: " " counter(note); counter-increment: note;}
|
||||||
|
|
|
@ -393,12 +393,13 @@ span.keyboard {
|
||||||
text-align:center;
|
text-align:center;
|
||||||
}
|
}
|
||||||
|
|
||||||
body {counter-reset: theorem lemma proposition corollary example remark}
|
body {counter-reset: theorem lemma proposition corollary definition example remark note}
|
||||||
.un_theorem *, .num_theorem *,
|
.un_theorem *, .num_theorem *,
|
||||||
.un_lemma *, .num_lemma *,
|
.un_lemma *, .num_lemma *,
|
||||||
.un_prop *, .num_prop *,
|
.un_prop *, .num_prop *,
|
||||||
.un_cor *, .num_cor * {font-style: italic}
|
.un_cor *, .num_cor * {font-style: italic}
|
||||||
span.theorem_label {font-style:normal; font-weight:bold;}
|
span.theorem_label {font-style:normal; font-weight:bold;}
|
||||||
|
.proof span.theorem_label {font-style:italic;}
|
||||||
.num_theorem .theorem_label:after {
|
.num_theorem .theorem_label:after {
|
||||||
content: " " counter(theorem); counter-increment: theorem;}
|
content: " " counter(theorem); counter-increment: theorem;}
|
||||||
.num_lemma .theorem_label:after {
|
.num_lemma .theorem_label:after {
|
||||||
|
@ -407,8 +408,12 @@ span.theorem_label {font-style:normal; font-weight:bold;}
|
||||||
content: " " counter(proposition); counter-increment: proposition;}
|
content: " " counter(proposition); counter-increment: proposition;}
|
||||||
.num_cor .theorem_label:after {
|
.num_cor .theorem_label:after {
|
||||||
content: " " counter(corollary); counter-increment: corollary;}
|
content: " " counter(corollary); counter-increment: corollary;}
|
||||||
|
.num_defn .theorem_label:after {
|
||||||
|
content: " " counter(definition); counter-increment: definition;}
|
||||||
.num_example .theorem_label:after {
|
.num_example .theorem_label:after {
|
||||||
content: " " counter(example); counter-increment: example;}
|
content: " " counter(example); counter-increment: example;}
|
||||||
.num_remark .theorem_label:after {
|
.num_remark .theorem_label:after {
|
||||||
content: " " counter(remark); counter-increment: remark;}
|
content: " " counter(remark); counter-increment: remark;}
|
||||||
|
.num_note .theorem_label:after {
|
||||||
|
content: " " counter(note); counter-increment: note;}
|
||||||
|
|
||||||
|
|
|
@ -904,7 +904,6 @@ class WikiControllerTest < Test::Unit::TestCase
|
||||||
\newcommand{\quadrupleintegral}{\iiiint}
|
\newcommand{\quadrupleintegral}{\iiiint}
|
||||||
\newcommand{\conint}{\oint}
|
\newcommand{\conint}{\oint}
|
||||||
\newcommand{\contourintegral}{\oint}
|
\newcommand{\contourintegral}{\oint}
|
||||||
\newcommand{\qed}{\blacksquare}
|
|
||||||
\newcommand{\infinity}{\infty}
|
\newcommand{\infinity}{\infty}
|
||||||
\renewcommand{\empty}{\emptyset}
|
\renewcommand{\empty}{\emptyset}
|
||||||
\newcommand{\bottom}{\bot}
|
\newcommand{\bottom}{\bot}
|
||||||
|
@ -935,9 +934,9 @@ class WikiControllerTest < Test::Unit::TestCase
|
||||||
\newtheorem*{uprop}{Proposition}
|
\newtheorem*{uprop}{Proposition}
|
||||||
\newtheorem*{ucor}{Corollary}
|
\newtheorem*{ucor}{Corollary}
|
||||||
\theoremstyle{definition}
|
\theoremstyle{definition}
|
||||||
\newtheorem{def}{Definition}
|
\newtheorem{defn}{Definition}
|
||||||
\newtheorem{example}{Example}
|
\newtheorem{example}{Example}
|
||||||
\newtheorem*{udef}{Definition}
|
\newtheorem*{udefn}{Definition}
|
||||||
\newtheorem*{uexample}{Example}
|
\newtheorem*{uexample}{Example}
|
||||||
\theoremstyle{remark}
|
\theoremstyle{remark}
|
||||||
\newtheorem{remark}{Remark}
|
\newtheorem{remark}{Remark}
|
||||||
|
|
29
vendor/plugins/maruku/lib/maruku/ext/div.rb
vendored
29
vendor/plugins/maruku/lib/maruku/ext/div.rb
vendored
|
@ -70,9 +70,8 @@ MaRuKu::In::Markdown::register_block_extension(
|
||||||
if al_string =~ /^\{(.*)\}\s*$/
|
if al_string =~ /^\{(.*)\}\s*$/
|
||||||
inside = $1
|
inside = $1
|
||||||
cs = MaRuKu::In::Markdown::SpanLevelParser::CharSource
|
cs = MaRuKu::In::Markdown::SpanLevelParser::CharSource
|
||||||
# al = al_string &&
|
al = al_string &&
|
||||||
# doc.read_attribute_list(cs.new(inside), its_context=nil, break_on=[nil])
|
doc.read_attribute_list(cs.new(inside), its_context=nil, break_on=[nil])
|
||||||
al = doc.read_attribute_list(cs.new(inside), its_context=nil, break_on=[nil])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
src = MaRuKu::In::Markdown::BlockLevelParser::LineSource.new(lines)
|
src = MaRuKu::In::Markdown::BlockLevelParser::LineSource.new(lines)
|
||||||
|
@ -85,8 +84,28 @@ MaRuKu::In::Markdown::register_block_extension(
|
||||||
|
|
||||||
module MaRuKu; class MDElement
|
module MaRuKu; class MDElement
|
||||||
|
|
||||||
def md_div(children, a=nil)
|
def md_div(children, al=nil)
|
||||||
self.md_el(:div, children, meta={}, a)
|
type = label = num = nil
|
||||||
|
doc.refid2ref ||= {}
|
||||||
|
if al
|
||||||
|
al.each do |k, v|
|
||||||
|
case k
|
||||||
|
when :class
|
||||||
|
type = $1 if v =~ /^num_(\w*)/
|
||||||
|
when :id
|
||||||
|
label = v
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if type
|
||||||
|
doc.refid2ref[type] ||= {}
|
||||||
|
num = doc.refid2ref[type].length + 1 || 1
|
||||||
|
end
|
||||||
|
e = self.md_el(:div, children, meta={:label => label, :type => type, :num => num}, al)
|
||||||
|
if type && label
|
||||||
|
doc.refid2ref[type].update({label => e})
|
||||||
|
end
|
||||||
|
e
|
||||||
end
|
end
|
||||||
|
|
||||||
end end
|
end end
|
||||||
|
|
|
@ -2,7 +2,7 @@ module MaRuKu
|
||||||
|
|
||||||
class MDDocument
|
class MDDocument
|
||||||
# Hash equation id (String) to equation element (MDElement)
|
# Hash equation id (String) to equation element (MDElement)
|
||||||
attr_accessor :eqid2eq
|
attr_accessor :eqid2eq, :refid2ref
|
||||||
|
|
||||||
def is_math_enabled?
|
def is_math_enabled?
|
||||||
get_setting :math_enabled
|
get_setting :math_enabled
|
||||||
|
@ -103,3 +103,17 @@ end
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# This adds support for \ref
|
||||||
|
RegRef = /\\ref\{(\w*)\}/
|
||||||
|
MaRuKu::In::Markdown::register_span_extension(
|
||||||
|
:chars => [?\\, ?(],
|
||||||
|
:regexp => RegRef,
|
||||||
|
:handler => lambda { |doc, src, con|
|
||||||
|
return false if not doc.is_math_enabled?
|
||||||
|
refid = src.read_regexp(RegRef).captures.compact.first
|
||||||
|
r = doc.md_el(:divref, [], meta={:refid=>refid})
|
||||||
|
con.push r
|
||||||
|
true
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
|
@ -165,6 +165,23 @@ module MaRuKu; module Out; module HTML
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def to_html_divref
|
||||||
|
ref= nil
|
||||||
|
self.doc.refid2ref.each_value { |h|
|
||||||
|
ref = h[self.refid] if h.has_key?(self.refid)
|
||||||
|
}
|
||||||
|
if ref
|
||||||
|
num = ref.num
|
||||||
|
a = Element.new 'a'
|
||||||
|
a.attributes['class'] = 'maruku-ref'
|
||||||
|
a.attributes['href'] = "#" + self.refid
|
||||||
|
a << Text.new(num.to_s)
|
||||||
|
a
|
||||||
|
else
|
||||||
|
maruku_error "Cannot find div #{self.refid.inspect}"
|
||||||
|
Text.new "\\ref{#{self.refid}}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end end end
|
end end end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue