Only escape the percentage sign, so that you can still use latex for units

This commit is contained in:
Jan Böhmer 2025-07-02 22:47:20 +02:00
parent 186e0c8561
commit 36c7e5e8c6

View file

@ -449,15 +449,10 @@ abstract class AbstractParameter extends AbstractNamedDBElement implements Uniqu
if (!$with_latex) {
$unit = $this->unit;
} else {
// if chars occur that will mess up the latex formatting, display them plain, regardless of the desired output
if (str_contains($this->unit, '~') || str_contains($this->unit, '^') || str_contains($this->unit, '\\'))
{
$unit = $this->unit;
}
else // otherwise, style the chars with latex, but escape latex special chars
{
$unit = '$\mathrm{'.$this->latexEscape($this->unit).'}$';
}
//Escape the percentage sign for convenience (as latex uses it as comment and it is often used in units)
$escaped = preg_replace('/(\%)/', "\\\\$1", $this->unit);
$unit = '$\mathrm{'.$escaped.'}$';
}
return $str.' '.$unit;
@ -466,14 +461,6 @@ abstract class AbstractParameter extends AbstractNamedDBElement implements Uniqu
return $str;
}
/**
* Return a latex escaped string
*/
protected function latexEscape(string $latex): string
{
return preg_replace('/(\&|\%|\$|\#|\_|\{|\})/', "\\\\$1", $latex);
}
/**
* Returns the class of the element that is allowed to be associated with this attachment.
* @return string