mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-01-19 16:49: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) {
|
||||
$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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue