Skip to content

Commit

Permalink
Don't update string when notex=True (#665)
Browse files Browse the repository at this point in the history
* markup doc

* Add test_markup()
  • Loading branch information
tanghaibao authored May 11, 2024
1 parent 9e6368f commit 06ef3fe
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
14 changes: 9 additions & 5 deletions jcvi/graphics/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
14 changes: 11 additions & 3 deletions tests/graphics/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

import pytest

from jcvi.graphics.base import latex, markup, rc


@pytest.mark.parametrize(
"s,expected",
Expand All @@ -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",
[
Expand Down

0 comments on commit 06ef3fe

Please sign in to comment.