Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions aastex/_aastex.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
<https://journals.aas.org/pre-submission-checklist-for-aas-journal-authors/>`_
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",
Expand All @@ -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,
Expand Down
26 changes: 26 additions & 0 deletions aastex/_tests/test_aastex.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=[
Expand Down
Loading