Skip to content
Open
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
4 changes: 2 additions & 2 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
version: 2

build:
os: ubuntu-22.04
os: ubuntu-lts-latest
tools:
python: "3.11"
python: "3.12"
apt_packages:
- graphviz
- texlive-publishers
Expand Down
99 changes: 68 additions & 31 deletions aastex/_aastex.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import dataclasses
import pathlib
import shutil

import matplotlib.figure
import astropy.units as u
import uuid
Expand Down Expand Up @@ -80,41 +82,48 @@ class Author(pylatex.base_classes.LatexObject):
affiliation: Affiliation
"""The organization affiliated with the author"""

orcid: None | str = None
"""The optional ORCID of 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.
The email address of the author.
"""

orcid: None | str = None
"""The optional ORCID of the author."""

corresponding: bool = False
"""Whether this author is the corresponding author."""

def dumps(self) -> str:

result = ""

show = None

if self.corresponding:
result += (
pylatex.Command(
command="correspondingauthor",
arguments=self.name,
).dumps()
+ "\n"
)
show = "show"

author = pylatex.Command(
command="author",
arguments=self.name,
options=NoEscape(self.orcid) if self.orcid is not None else None,
).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()
email = pylatex.Command(
command="email",
arguments=self.email,
options=show,
).dumps()

email = pylatex.Command(
command="email",
arguments=self.email,
).dumps()
affilation = self.affiliation.dumps()

result += f"\n{corresponding_author}\n{email}"
result += f"{author}\n{email}\n{affilation}"

return result

Expand Down Expand Up @@ -261,6 +270,7 @@ class Figure(
pylatex.Figure,
):
marker_prefix = "fig"
# separate_paragraph = False

def __init__(
self,
Expand Down Expand Up @@ -417,7 +427,7 @@ class Document(pylatex.Document):
def __init__(
self,
default_filepath: str | pathlib.Path = "default_filepath",
documentclass: str = "aastex631",
documentclass: str = "aastex701",
document_options: None | str | list[str] = None,
fontenc: str = "T1",
inputenc: str = "utf8",
Expand Down Expand Up @@ -448,15 +458,7 @@ def __init__(
data=data,
)
self.escape = False
self.preamble.append(
NoEscape(
"\\usepackage{savesym}\n"
"\\savesymbol{tablenum}\n"
"\\usepackage{siunitx}\n"
"\\restoresymbol{SIX}{tablenum}\n"
)
)
self.preamble.append(pylatex.Command("bibliographystyle", "aasjournal"))
self.preamble.append(pylatex.Command("bibliographystyle", "aasjournalv7"))

def set_variable_quantity(
self,
Expand Down Expand Up @@ -492,6 +494,41 @@ def set_variable_quantity(
),
)

def generate_pdf(self, filepath=None, *, clean=True, clean_tex=True,
compiler=None, compiler_args=None, silent=True,):

base = pathlib.Path(__file__).parent
cls = base / "aastex701.cls"
bst = base / "aasjournalv7.bst"
orcid = base / "orcid-ID.png"

filepath = pathlib.Path(filepath)

directory = filepath.parent
directory.mkdir(parents=True, exist_ok=True)

cls_copy = directory / cls.name
bst_copy = directory / bst.name
orcid_copy = directory / orcid.name

shutil.copyfile(cls, cls_copy)
shutil.copyfile(bst, bst_copy)
shutil.copyfile(orcid, orcid_copy)

super().generate_pdf(
filepath=filepath,
clean=clean,
clean_tex=clean_tex,
compiler=compiler,
compiler_args=compiler_args,
silent=silent,
)

if clean_tex:
cls_copy.unlink()
bst_copy.unlink()
orcid_copy.unlink()


class Bibliography(pylatex.base_classes.CommandBase):
def __init__(
Expand Down
1 change: 1 addition & 0 deletions aastex/_tests/test_aastex.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def test_dumps(self, a: aastex.Affiliation):
affiliation=aastex.Affiliation("Fancy University"),
orcid="0000-0000-0000-0000",
email="jane.doe@tmp.com",
corresponding=True,
),
],
)
Expand Down
Loading
Loading