Render units of parameters in upstanding latex

Fixes issue #856
This commit is contained in:
Jan Böhmer 2025-03-29 12:33:18 +01:00
parent 5b111d80f1
commit 4e1b1a4ffa
6 changed files with 45 additions and 18 deletions

View file

@ -25,9 +25,20 @@ import "katex/dist/katex.css";
export default class extends Controller {
static targets = ["input", "preview"];
static values = {
unit: {type: Boolean, default: false} //Render as upstanding (non-italic) text, useful for units
}
updatePreview()
{
katex.render(this.inputTarget.value, this.previewTarget, {
let value = "";
if (this.unitValue) {
value = "\\mathrm{" + this.inputTarget.value + "}";
} else {
value = this.inputTarget.value;
}
katex.render(value, this.previewTarget, {
throwOnError: false,
});
}

View file

@ -111,4 +111,11 @@ ul.structural_link li a:hover {
.permission-checkbox:checked {
background-color: var(--bs-success);
border-color: var(--bs-success);
}
/***********************************************
* Katex rendering with same height as text
***********************************************/
.katex-same-height-as-text .katex {
font-size: 1.0em;
}