Skip to content

Commit

Permalink
Add option to force italics in space group labels
Browse files Browse the repository at this point in the history
  • Loading branch information
ml-evs committed Nov 21, 2023
1 parent 3eb2447 commit 65b416f
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions matador/utils/cell_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,22 +514,27 @@ 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.
"""
import re

return "${}$".format(re.sub("-(?P<number>[0-9])", "\\\\bar{\\g<number>}", 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<number>[0-9])", "\\\\bar{\\g<number>}", label)

return f"${label}$"


def standardize_doc_cell(
Expand Down

0 comments on commit 65b416f

Please sign in to comment.