diff --git a/jcvi/graphics/base.py b/jcvi/graphics/base.py index 6e594f66..f1ed271c 100644 --- a/jcvi/graphics/base.py +++ b/jcvi/graphics/base.py @@ -3,10 +3,11 @@ import copy import os.path as op -from os import remove - +import re import sys +from os import remove + from functools import partial from typing import Optional, List, Tuple, Union @@ -408,11 +409,14 @@ def fontprop(ax, name, size=12): return prop -def markup(s): +def markup(s: str): + """ + Change the string to latex format, and italicize the text between *. + """ + if not rcParams["text.usetex"]: + return s if "$" in s: return s - import re - s = latex(s) s = re.sub(r"\*(.*)\*", r"\\textit{\1}", s) return s diff --git a/tests/graphics/test_base.py b/tests/graphics/test_base.py index 88066444..0477bd90 100644 --- a/tests/graphics/test_base.py +++ b/tests/graphics/test_base.py @@ -3,6 +3,8 @@ import pytest +from jcvi.graphics.base import latex, markup, rc + @pytest.mark.parametrize( "s,expected", @@ -24,15 +26,21 @@ def test_shorten(s, expected): @pytest.mark.parametrize( "s,expected", [ - ("grape_grape vs peach_peach", "grape\_grape vs peach\_peach"), + ("grape_grape vs peach_peach", r"grape\_grape vs peach\_peach"), ], ) def test_latex(s, expected): - from jcvi.graphics.base import latex - assert latex(s) == expected, "Expect {}".format(expected) +def test_markup(): + rc("text", usetex=True) + s = "Prupe_1G289800.1" + assert markup(s) == r"Prupe\_1G289800.1" + rc("text", usetex=False) + assert markup(s) == s + + @pytest.mark.parametrize( "figname,format,expected", [