Skip to content

Commit

Permalink
Fixed bug in aastex.Figure() where the label was being placed befor…
Browse files Browse the repository at this point in the history
…e the caption. (#5)
  • Loading branch information
byrdie committed Jun 5, 2024
1 parent d39dd6f commit ff5ebc9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
20 changes: 13 additions & 7 deletions aastex/_aastex.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,16 +272,18 @@ def __init__(
position=position,
**kwargs,
)
if isinstance(label, Label):
self._label = label
else:
self.label = label

@property
def _label(self) -> Label:
label = self.label
if not isinstance(label, Label):
if ":" in label:
label = label.split(":", 1)
self._label = Label(Marker(label[1], label[0]))
label = Label(Marker(label[1], label[0]))
else:
self._label = Label(Marker(label, self.marker_prefix))

self.append(self._label)
label = Label(Marker(label, self.marker_prefix))
return label

def __format__(self, format_spec):
return Ref(self._label.marker).dumps()
Expand Down Expand Up @@ -346,6 +348,10 @@ def add_fig(

self.add_image(filename, **add_image_kwargs)

def add_caption(self, caption) -> None:
super().add_caption(caption)
self.append(self._label)


class FigureStar(
Figure,
Expand Down
4 changes: 4 additions & 0 deletions aastex/_tests/test_aastex.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ def test_add_fig(self, a: aastex.Figure):

assert r"\includegraphics" in a.dumps()

def test_add_caption(self, a: aastex.Figure):
a.add_caption("foo")
assert r"\caption" in a.dumps()


@pytest.mark.parametrize(
argnames="a",
Expand Down

0 comments on commit ff5ebc9

Please sign in to comment.