diff --git a/aastex/_aastex.py b/aastex/_aastex.py index c7f3487..bd5dc55 100644 --- a/aastex/_aastex.py +++ b/aastex/_aastex.py @@ -571,6 +571,19 @@ def __init__( class Document(pylatex.Document): + """ + An article using the AASTeX class. + + Parameters + ---------- + linenumbers + Whether to number the lines of the article. + The AAS journals `require line numbers + `_ + for review, so they are on by default, and can be turned off for a + version meant to be read rather than reviewed. + """ + def __init__( self, default_filepath: str | pathlib.Path = "default_filepath", @@ -586,9 +599,18 @@ def __init__( indent: None | bool = None, geometry_options: None | dict = None, data: None | list = None, + linenumbers: bool = True, ): if document_options is None: document_options = ["twocolumn"] + elif isinstance(document_options, str): + document_options = [document_options] + else: + document_options = list(document_options) + + if linenumbers and "linenumbers" not in document_options: + document_options.append("linenumbers") + super().__init__( default_filepath=str(default_filepath), documentclass=documentclass, diff --git a/aastex/_tests/test_aastex.py b/aastex/_tests/test_aastex.py index 7191d07..9d119ff 100644 --- a/aastex/_tests/test_aastex.py +++ b/aastex/_tests/test_aastex.py @@ -398,6 +398,32 @@ class TestGridline: pass +def test_document_linenumbers_default(): + """The AAS journals require line numbers for review.""" + assert "linenumbers" in aastex.Document().dumps() + + +def test_document_linenumbers_disabled(): + assert "linenumbers" not in aastex.Document(linenumbers=False).dumps() + + +@pytest.mark.parametrize( + argnames="document_options", + argvalues=[ + "twocolumn", + ["twocolumn"], + ["twocolumn", "linenumbers"], + ], +) +def test_document_linenumbers_options(document_options: str | list[str]): + """Line numbers are added to the given options without disturbing them.""" + dumps = aastex.Document(document_options=document_options).dumps() + options = dumps.split("{aastex701}")[0] + + assert options.count("linenumbers") == 1 + assert "twocolumn" in options + + @pytest.mark.parametrize( argnames="a", argvalues=[