diff --git a/aastex/_aastex.py b/aastex/_aastex.py index 0f0ff0f..b941362 100644 --- a/aastex/_aastex.py +++ b/aastex/_aastex.py @@ -23,7 +23,6 @@ "Title", "Affiliation", "Author", - "CorrespondingAuthor", "Acronym", "Abstract", "Section", @@ -76,33 +75,37 @@ class Author(pylatex.base_classes.LatexObject): name: str """Name of the author""" - affiliation: Affiliation - """organization affiliated with the author""" - def dumps(self) -> str: - return pylatex.Command("author", self.name).dumps() + self.affiliation.dumps() + affiliation: Affiliation + """The organization affiliated with the author""" + email: None | str = None + """ + The optional email address of the author. + + If this is not :obj:`None`, this author is assumed to be the corresponding + author. + """ -@dataclasses.dataclass -class CorrespondingAuthor(pylatex.base_classes.LatexObject): - """The corresponding author of this article.""" + def dumps(self) -> str: + author = pylatex.Command("author", self.name).dumps() + affilation = self.affiliation.dumps() + result = f"{author}\n{affilation}" + + if self.email is not None: + corresponding_author = pylatex.Command( + command="correspondingauthor", + arguments=self.name, + ).dumps() - name: str - """Name of the corresponding author""" + email = pylatex.Command( + command="email", + arguments=self.email, + ).dumps() - email: str - """Email address of the corresponding author""" + result += f"\n{corresponding_author}\n{email}" - def dumps(self) -> str: - author = pylatex.Command( - command="correspondingauthor", - arguments=self.name, - ) - email = pylatex.Command( - command="email", - arguments=self.email, - ) - return author.dumps() + email.dumps() + return result @dataclasses.dataclass diff --git a/aastex/_tests/test_aastex.py b/aastex/_tests/test_aastex.py index 3b8f584..aa09781 100644 --- a/aastex/_tests/test_aastex.py +++ b/aastex/_tests/test_aastex.py @@ -41,6 +41,7 @@ def test_dumps(self, a: aastex.Affiliation): aastex.Author( name="Jane Doe", affiliation=aastex.Affiliation("Fancy University"), + email="jane.doe@tmp.com", ), ], ) @@ -51,26 +52,10 @@ def test_name(self, a: aastex.Author): def test_affiliation(self, a: aastex.Author): assert isinstance(a.affiliation, aastex.Affiliation) - def test_dumps(self, a: aastex.Author): - assert isinstance(a.dumps(), str) - - -@pytest.mark.parametrize( - argnames="a", - argvalues=[ - aastex.CorrespondingAuthor( - name="Jane Doe", - email="jane.doe@tmp.com", - ), - ], -) -class TestCorrespondingAuthor: - - def test_name(self, a: aastex.Author): - assert isinstance(a.name, str) - def test_email(self, a: aastex.Author): - assert isinstance(a.email, str) + result = a.email + if result is not None: + assert isinstance(result, str) def test_dumps(self, a: aastex.Author): assert isinstance(a.dumps(), str)