From 65b416fd157bde061ade59e7f8946a98b470381c Mon Sep 17 00:00:00 2001 From: Matthew Evans Date: Mon, 20 Nov 2023 22:24:02 +0000 Subject: [PATCH] Add option to force italics in space group labels --- matador/utils/cell_utils.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/matador/utils/cell_utils.py b/matador/utils/cell_utils.py index e62e7cd2..596570f0 100644 --- a/matador/utils/cell_utils.py +++ b/matador/utils/cell_utils.py @@ -514,14 +514,14 @@ def doc2spg( ) -def get_space_group_label_latex(label: str) -> str: - """Return the LaTeX format of the passed space group label. Takes - any string, leaves the first character upright, italicses the rest, - handles subscripts and bars over numbers. +def get_space_group_label_latex(label: str, force_italics: bool = True) -> str: + """Return the LaTeX format of the passed space group label. Parameters: label: a given space group in "standard" plain text format, e.g. P-63m to convert to '$P\\bar{6}3m$'. + force_italics: Whether to explicitly wrap italic characters with + \\mathit{}. Returns: The best attempt to convert the label to LaTeX format. @@ -529,7 +529,12 @@ def get_space_group_label_latex(label: str) -> str: """ import re - return "${}$".format(re.sub("-(?P[0-9])", "\\\\bar{\\g}", label)) + if force_italics: + label = re.sub("([a-z])", "\\\\mathit{\\g<1>}", label) + label = re.sub("([A-Z])", "\\\\mathit{\\g<1>}\\\\,", label) + label = re.sub("-(?P[0-9])", "\\\\bar{\\g}", label) + + return f"${label}$" def standardize_doc_cell(