From 777f9d3fd8caf56e6bc6999a4b05379307d0733f Mon Sep 17 00:00:00 2001 From: Justin Gassner Date: Tue, 12 Sep 2023 07:36:33 +0200 Subject: Initial commit --- _plugins/enunciation.rb | 32 ++++++++++++++++++++++++++++++++ _plugins/proof.rb | 12 ++++++++++++ _plugins/singledollar.rb | 19 +++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 _plugins/enunciation.rb create mode 100644 _plugins/proof.rb create mode 100644 _plugins/singledollar.rb (limited to '_plugins') diff --git a/_plugins/enunciation.rb b/_plugins/enunciation.rb new file mode 100644 index 0000000..75c777a --- /dev/null +++ b/_plugins/enunciation.rb @@ -0,0 +1,32 @@ +module Jekyll + class EnunciationTagBlock < Liquid::Block + + def initialize(tag_name, arg, parse_context) + super + @arg = arg.strip + end + + def render(context) + text = super + # If the enunciation ends with a KaTeX displayed equation, + # then we remove the bottom margin. + if text[-3,3] == "$$\n" + text += '{: .katex-display .mb-0 }' + end + # Check if a description was given. + if @arg.length < 1 + "{: .#{block_name} }\n #{text.gsub!(/^/,'> ')}" + else + "{: .#{block_name}-title }\n> #{block_name.capitalize} (#{@arg})\n>\n#{text.gsub!(/^/,'> ')}" + end + end + + end +end + +Liquid::Template.register_tag('definition', Jekyll::EnunciationTagBlock) +Liquid::Template.register_tag('theorem', Jekyll::EnunciationTagBlock) +Liquid::Template.register_tag('proposition', Jekyll::EnunciationTagBlock) +Liquid::Template.register_tag('lemma', Jekyll::EnunciationTagBlock) +Liquid::Template.register_tag('corollary', Jekyll::EnunciationTagBlock) +Liquid::Template.register_tag('axiom', Jekyll::EnunciationTagBlock) diff --git a/_plugins/proof.rb b/_plugins/proof.rb new file mode 100644 index 0000000..ab824e5 --- /dev/null +++ b/_plugins/proof.rb @@ -0,0 +1,12 @@ +module Jekyll + class ProofTagBlock < Liquid::Block + + def render(context) + text = super + "Proof #{text} $\\square\\enspace$" + end + + end +end + +Liquid::Template.register_tag('proof', Jekyll::ProofTagBlock) diff --git a/_plugins/singledollar.rb b/_plugins/singledollar.rb new file mode 100644 index 0000000..fe665ab --- /dev/null +++ b/_plugins/singledollar.rb @@ -0,0 +1,19 @@ +# https://gist.github.com/sp301415/db9f7bee03bda483aa2ca7c0ca92fbfa + +require 'kramdown/parser/kramdown' +require 'kramdown-parser-gfm' + +class Kramdown::Parser::GFMKatex < Kramdown::Parser::GFM + # Override inline math parser + @@parsers.delete(:inline_math) + + INLINE_MATH_START = /(\$+)([^\$]+)(\$+)/m + + def parse_inline_math + start_line_number = @src.current_line_number + @src.pos += @src.matched_size + @tree.children << Element.new(:math, @src.matched[1..-2], nil, category: :span, location: start_line_number) + end + + define_parser(:inline_math, INLINE_MATH_START, '\$') +end -- cgit v1.2.3-70-g09d2