enhancements to the latex cards

This commit is contained in:
2024-08-21 20:09:12 +02:00
parent 52ac60bad5
commit 566c24eeea
7 changed files with 155 additions and 56 deletions
+30
View File
@@ -0,0 +1,30 @@
require "json"
require "js"
def print_step(label, state)
puts "Ruby: #{label} #{state}"
JS.global[:rubyOutputs].push({
label: label,
state: state
})
end
def run(config)
i = config["i"] || 1
j = config["j"] || 1
n = config["n"] || 10
print_step "Initial", { i: i, j: j, n: n }
n.times do
m = i + j
i = j
j = m
print_step "Step", { i: i, j: j }
end
return i
end
run({ "n" => 10 })
+35
View File
@@ -0,0 +1,35 @@
class CardDSL
def initialize
@blocks = []
end
def text(content)
@blocks << { type: "text", content: content }
end
def code(content)
@blocks << { type: "code", content: content }
end
def math(content)
@blocks << { type: "math", content: content }
end
def blocks
@blocks
end
end
def print_card(&block)
card = CardDSL.new
card.instance_eval(&block)
card.blocks.each { |block| p block }
# JS.global[:rubyOutputs].push(card)
end
print_card do
text "Hello, world!"
code "puts 'Hello, world!'"
math "\\begin{bmatrix} 1 & 2 \\\\ 3 & 4 \\end{bmatrix}"
end