mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-01-21 09:39:34 +00:00
Only escape the percentage sign, so that you can still use latex for units
This commit is contained in:
parent
186e0c8561
commit
36c7e5e8c6
1 changed files with 4 additions and 17 deletions
|
|
@ -449,15 +449,10 @@ abstract class AbstractParameter extends AbstractNamedDBElement implements Uniqu
|
||||||
if (!$with_latex) {
|
if (!$with_latex) {
|
||||||
$unit = $this->unit;
|
$unit = $this->unit;
|
||||||
} else {
|
} else {
|
||||||
// if chars occur that will mess up the latex formatting, display them plain, regardless of the desired output
|
//Escape the percentage sign for convenience (as latex uses it as comment and it is often used in units)
|
||||||
if (str_contains($this->unit, '~') || str_contains($this->unit, '^') || str_contains($this->unit, '\\'))
|
$escaped = preg_replace('/(\%)/', "\\\\$1", $this->unit);
|
||||||
{
|
|
||||||
$unit = $this->unit;
|
$unit = '$\mathrm{'.$escaped.'}$';
|
||||||
}
|
|
||||||
else // otherwise, style the chars with latex, but escape latex special chars
|
|
||||||
{
|
|
||||||
$unit = '$\mathrm{'.$this->latexEscape($this->unit).'}$';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $str.' '.$unit;
|
return $str.' '.$unit;
|
||||||
|
|
@ -466,14 +461,6 @@ abstract class AbstractParameter extends AbstractNamedDBElement implements Uniqu
|
||||||
return $str;
|
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.
|
* Returns the class of the element that is allowed to be associated with this attachment.
|
||||||
* @return string
|
* @return string
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue