Merge branch 'main' into feature/brightspots

This commit is contained in:
Tim Grelka
2026-02-15 13:22:23 +01:00
committed by GitHub
2 changed files with 165 additions and 68 deletions
+99 -10
View File
@@ -1,11 +1,100 @@
document.addEventListener("DOMContentLoaded", function() { document.addEventListener("DOMContentLoaded", function() {
function formatThousands(input) {
let s = String(input).trim();
// Extract exponent (e or E) and convert to \cdot 10^{...}
let exponent = "";
const expMatch = s.match(/([eE])([+-]?\d+)$/);
if (expMatch) {
let expValue = expMatch[2];
// Remove leading "+"
if (expValue[0] === "+") {
expValue = expValue.slice(1);
}
// Parse exponent as a numeric value
const expNum = parseInt(expValue, 10);
// Suppress exponent if it is 0 (no \cdot 10^0 shown)
if (expNum !== 0) {
exponent = "\\cdot 10^{" + expNum + "}";
}
s = s.slice(0, -expMatch[0].length);
}
// Sign (+, -, \pm). Also accept "\\pm" (double-escaped backslash) and optional whitespace.
let sign = "";
const pmMatch = s.match(/^(?:\\\\pm|\\pm)\s*/);
if (pmMatch) {
sign = "\\pm";
s = s.slice(pmMatch[0].length);
} else if (s[0] === "+" || s[0] === "-") {
sign = s[0];
s = s.slice(1);
}
// Find decimal point (last . or ,)
let intPart = s;
let fracSep = "";
let fracDigits = "";
const decMatch = s.match(/([.,])(\d+)$/);
if (decMatch) {
intPart = s.slice(0, decMatch.index);
fracSep = decMatch[1];
fracDigits = decMatch[2];
}
// Thousand grouping in integer part
if (intPart.length >= 5) {
intPart = intPart.replace(/\B(?=(\d{3})+(?!\d))/g, "\\,");
}
// Thousand grouping in fractional part (from left in 3-digit blocks)
if (fracDigits.length >= 4) {
fracDigits = fracDigits.replace(/(\d{3})(?=\d)/g, "$1\\,");
}
// Reassemble
return sign + intPart + (fracDigits ? (fracSep + fracDigits) : "") + exponent;
}
var macros = { var macros = {
",": (context) => context.future()?.text === " " ? "{\\char`,}" : "\\char`,", ",": (context) => context.future()?.text === " " ? "{\\char`,}" : "\\char`,",
"\\qty": "{#1\\,\\mathrm{#2}}", "\\num": (context) => {
"\\qtyrange": "{#1\\text{--}#2\\,\\mathrm{#3}}", const [arg] = context.consumeArgs(1);
const raw = arg.reverse().map(t => t.text).join("");
return formatThousands(raw);
},
"\\qty": (context) => {
const [numTok, unitTok] = context.consumeArgs(2);
const rawNum = numTok.reverse().map(t => t.text).join("");
const unit = unitTok.reverse().map(t => t.text).join("");
const formattedNum = formatThousands(rawNum);
if (unit.startsWith("\\degree")) {
return formattedNum + "\\mathrm{" + unit + "}";
} else {
return formattedNum + "\\,\\mathrm{" + unit + "}";
}
},
"\\qtyrange": (context) => {
const [aTok, bTok, unitTok] = context.consumeArgs(3);
const aRaw = aTok.reverse().map(t => t.text).join("");
const bRaw = bTok.reverse().map(t => t.text).join("");
const unit = unitTok.reverse().map(t => t.text).join("");
const aFmt = formatThousands(aRaw);
const bFmt = formatThousands(bRaw);
if (unit.startsWith("\\degree")) {
return aFmt + "\\text{--}\\," + bFmt + "\\mathrm{" + unit + "}";
} else {
return aFmt + "\\,\\text{--}\\," + bFmt + "\\,\\mathrm{" + unit + "}";
}
},
"\\unit": "{\\mathrm{#1}}", "\\unit": "{\\mathrm{#1}}",
"\\num": "{#1}",
"\\squared": "{^{2}}", "\\squared": "{^{2}}",
"\\cubed": "{^{3}}", "\\cubed": "{^{3}}",
"\\per": "/", "\\per": "/",
@@ -52,18 +141,18 @@ document.addEventListener("DOMContentLoaded", function() {
"\\tesla": "\\text{T}", "\\tesla": "\\text{T}",
"\\bit": "\\text{b}", "\\bit": "\\text{b}",
"\\baud": "\\text{Bd}", "\\baud": "\\text{Bd}",
"\\degree": "^\\circ", "\\degreeCelsius": "\\,\\degree\\text{C}",
"\\degreeCelsius": "^\\circ\\text{C}",
}; };
renderMathInElement(document.body, { renderMathInElement(document.body, {
delimiters: [ delimiters: [
{left: '$$', right: '$$', display: true}, // Note: $$ has to come before $ { left: '$$', right: '$$', display: true }, // Note: $$ has to come before $
{left: '$', right: '$', display: false}, { left: '$', right: '$', display: false },
{left: '\\[', right: '\\]', display: true}, { left: '\\[', right: '\\]', display: true },
{left: "\\(", right: "\\)", display: false}, { left: "\\(", right: "\\)", display: false },
], ],
throwOnError : false, throwOnError: false,
macros: macros macros: macros
}); });
}); });
+11 -3
View File
@@ -1,5 +1,6 @@
import json import json
import random import random
import re
import shutil import shutil
from pathlib import Path from pathlib import Path
@@ -124,8 +125,7 @@ class Build:
page_template = self.env.get_template("html/page.html") page_template = self.env.get_template("html/page.html")
return page_template.render(content=content, course_wrapper=course_wrapper, sidebar=sidebar) return page_template.render(content=content, course_wrapper=course_wrapper, sidebar=sidebar)
def __picture_handler(self, id): def __copy_picture(self, id):
self.config.p_build_pictures.mkdir(parents=True, exist_ok=True)
file = f"{id}.svg" file = f"{id}.svg"
try: try:
shutil.copyfile(self.config.p_data_pictures / file, self.config.p_build_pictures / file) shutil.copyfile(self.config.p_data_pictures / file, self.config.p_build_pictures / file)
@@ -136,6 +136,10 @@ class Build:
except FileNotFoundError: except FileNotFoundError:
tqdm.write(f"\033[31mPicture #{id} not found\033[0m") tqdm.write(f"\033[31mPicture #{id} not found\033[0m")
def __picture_handler(self, id):
self.config.p_build_pictures.mkdir(parents=True, exist_ok=True)
return self.__copy_picture(id)
def __photo_handler(self, id): def __photo_handler(self, id):
self.config.p_build_photos.mkdir(parents=True, exist_ok=True) self.config.p_build_photos.mkdir(parents=True, exist_ok=True)
file = f"{id}.png" file = f"{id}.png"
@@ -170,7 +174,11 @@ class Build:
def __include_handler(self, include): def __include_handler(self, include):
with (self.config.p_data_html / f"{include}.html").open() as file: with (self.config.p_data_html / f"{include}.html").open() as file:
return file.read() code = file.read()
svg_list = re.findall(r"(\d+)\.svg", code or "")
for id in svg_list:
self.__copy_picture(id)
return code
def __build_section( def __build_section(
self, self,