Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion assets/controllers/pages/latex_preview_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ export default class extends Controller {
{
let value = "";
if (this.unitValue) {
value = "\\mathrm{" + this.inputTarget.value + "}";
//Escape percentage signs
value = this.inputTarget.value.replace(/%/g, '\\%');

value = "\\mathrm{" + value + "}";
} else {
value = this.inputTarget.value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ export default class extends Controller
tmp += '<span>' + katex.renderToString(data.symbol) + '</span>'
}
if (data.unit) {
tmp += '<span class="ms-2">' + katex.renderToString('[' + data.unit + ']') + '</span>'
let unit = data.unit.replace(/%/g, '\\%');
unit = "\\mathrm{" + unit + "}";
tmp += '<span class="ms-2">' + katex.renderToString('[' + unit + ']') + '</span>'
}


Expand Down
15 changes: 9 additions & 6 deletions src/Entity/Parameters/AbstractParameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,19 +217,19 @@ public function getFormattedValue(bool $latex_formatted = false): string

$str = '';
$bracket_opened = false;
if ($this->value_typical) {
if ($this->value_typical !== null) {
$str .= $this->getValueTypicalWithUnit($latex_formatted);
if ($this->value_min || $this->value_max) {
$bracket_opened = true;
$str .= ' (';
}
}

if ($this->value_max && $this->value_min) {
if ($this->value_max !== null && $this->value_min !== null) {
$str .= $this->getValueMinWithUnit($latex_formatted).' ... '.$this->getValueMaxWithUnit($latex_formatted);
} elseif ($this->value_max) {
} elseif ($this->value_max !== null) {
$str .= 'max. '.$this->getValueMaxWithUnit($latex_formatted);
} elseif ($this->value_min) {
} elseif ($this->value_min !== null) {
$str .= 'min. '.$this->getValueMinWithUnit($latex_formatted);
}

Expand Down Expand Up @@ -449,15 +449,18 @@ protected function formatWithUnit(float $value, string $format = '%g', bool $wit
if (!$with_latex) {
$unit = $this->unit;
} else {
$unit = '$\mathrm{'.$this->unit.'}$';
//Escape the percentage sign for convenience (as latex uses it as comment and it is often used in units)
$escaped = preg_replace('/\\\\?%/', "\\\\%", $this->unit);

$unit = '$\mathrm{'.$escaped.'}$';
}

return $str.' '.$unit;
}

return $str;
}

/**
* Returns the class of the element that is allowed to be associated with this attachment.
* @return string
Expand Down
Loading