Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorder helper functions in fonts.py, clarify 'times' vs 'times new roman', and clarify 'usepackage{times}' vs 'usepackage{ptm}' #125

Merged
merged 4 commits into from
Nov 20, 2023
Merged
Changes from 3 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
208 changes: 117 additions & 91 deletions tueplots/fonts.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,147 +3,181 @@

def neurips2021(*, family="serif"):
"""Fonts for Neurips 2021."""
return _neurips_and_iclr_common(family=family)
# NeurIPS' style-files states that it uses Times New Roman
# font, but includes the 'ptm' package, which implements
# the 'Times' font.
# Therefore, refer to 'Times' instead of 'Times New Roman'
return _times(family=family)


def neurips2021_tex(*, family="serif"):
"""Fonts for Neurips 2021. LaTeX version."""
return _neurips_and_iclr_tex_common(family=family)
return _times_tex_via_pkg_ptm(family=family)


def neurips2022(*, family="serif"):
"""Fonts for Neurips 2022."""
return _neurips_and_iclr_common(family=family)
# NeurIPS' style-files states that it uses Times New Roman
# font, but includes the 'ptm' package, which implements
# the 'Times' font.
# Therefore, refer to 'Times' instead of 'Times New Roman'
return _times(family=family)


def neurips2022_tex(*, family="serif"):
"""Fonts for Neurips 2022. LaTeX version."""
return _neurips_and_iclr_tex_common(family=family)
return _times_tex_via_pkg_ptm(family=family)


def neurips2023(*, family="serif"):
"""Fonts for Neurips 2023."""
return _neurips_and_iclr_common(family=family)
# NeurIPS' style-files states that it uses Times New Roman
# font, but includes the 'ptm' package, which implements
# the 'Times' font.
# Therefore, refer to 'Times' instead of 'Times New Roman'
return _times(family=family)


def neurips2023_tex(*, family="serif"):
"""Fonts for Neurips 2023. LaTeX version."""
return _neurips_and_iclr_tex_common(family=family)
return _times_tex_via_pkg_ptm(family=family)


def iclr2023_tex(*, family="serif"):
"""Fonts for ICLR 2023. LaTeX version."""
return _neurips_and_iclr_tex_common(family=family)
return _times_tex_via_pkg_times(family=family)


def iclr2024_tex(*, family="serif"):
"""Fonts for ICLR 2024. LaTeX version."""
return _neurips_and_iclr_tex_common(family=family)
return _times_tex_via_pkg_times(family=family)


def iclr2023(*, family="serif"):
"""Fonts for ICLR 2023. LaTeX version."""
return _neurips_and_iclr_common(family=family)
return _times(family=family)


def iclr2024(*, family="serif"):
"""Fonts for ICLR 2024. LaTeX version."""
return _neurips_and_iclr_common(family=family)
return _times(family=family)


def cvpr2024_tex(*, family="serif"):
"""Fonts for CVPR 2024. LaTeX version."""
return _neurips_and_iclr_tex_common(family=family)
return _times_tex_via_pkg_ptm(family=family)


def cvpr2024(*, family="serif"):
"""Fonts for CVPR 2024. LaTeX version."""
return _neurips_and_iclr_common(family=family)


def _neurips_and_iclr_common(*, family="serif"):
"""Default fonts for Neurips."""
return {
"text.usetex": False,
"font.serif": ["Times New Roman"],
"mathtext.fontset": "stix", # free ptmx replacement, for ICML and NeurIPS
"mathtext.rm": "Times New Roman",
"mathtext.it": "Times New Roman:italic",
"mathtext.bf": "Times New Roman:bold",
"font.family": family,
}


def _neurips_and_iclr_tex_common(*, family="serif"):
"""Default fonts for Neurips. LaTeX version."""
preamble = r"\renewcommand{\rmdefault}{ptm}\renewcommand{\sfdefault}{phv}"
if family == "serif":
return {
"text.usetex": True,
"font.family": "serif",
"text.latex.preamble": preamble,
}
preamble += (
r"\renewcommand{\familydefault}{\sfdefault} \usepackage{sansmath} \sansmath"
)
return {
"text.usetex": True,
"font.family": "sans-serif",
"text.latex.preamble": preamble,
}


def icml2022(*, family="serif"):
"""Fonts for ICML 2022."""

return {
"text.usetex": False,
"font.serif": ["Times"],
"mathtext.fontset": "stix", # free ptmx replacement, for ICML and NeurIPS
"mathtext.rm": "Times",
"mathtext.it": "Times:italic",
"mathtext.bf": "Times:bold",
"font.family": family,
}
return _times(family=family)


def icml2022_tex(*, family="serif"):
"""Fonts for ICML 2022. LaTeX version."""
return _tex_times(family=family)
return _times_tex_via_pkg_times(family=family)


def jmlr2001_tex(*, family="serif"):
"""Fonts for JMLR. LaTeX version."""
return _tex_computer_modern(family=family)
return _computer_modern_tex(family=family)


def tmlr2023_tex(*, family="serif"):
"""Fonts for TMLR. LaTeX version."""
return _tex_computer_modern(family=family)
return _computer_modern_tex(family=family)


def aistats2022_tex(*, family="serif"):
"""Fonts for AISTATS 2022. LaTeX version."""
return _tex_computer_modern(family=family)
return _computer_modern_tex(family=family)


def aistats2023_tex(*, family="serif"):
"""Fonts for AISTATS 2023. LaTeX version."""
return _tex_times(family=family)
return _times_tex_via_pkg_times(family=family)


def uai2023_tex(*, family="serif"):
"""Fonts for UAI 2023. LaTeX version."""
return _tex_times(family=family)
return _times_tex_via_pkg_times(family=family)


def aaai2024_tex(*, family="serif"):
"""Fonts for AAAI 2024. LaTeX version."""
return _tex_times(family=family)
return _times_tex_via_pkg_times(family=family)


def _tex_times(*, family):
preamble = r"\usepackage{times} "
def icml2022(*, family="serif"):
"""Fonts for ICML 2022."""
return _times(family=family)


def beamer_moml():
"""Fonts that are compatible with the beamer template of the method-of-machine-learning group in Tübingen."""
return {
"text.usetex": False,
"mathtext.fontset": "custom",
"mathtext.it": "sans:italic",
"font.sans-serif": ["Roboto Condensed"],
"font.family": "sans-serif",
"font.weight": "light",
"axes.labelweight": "light",
"axes.titleweight": "light",
}


def beamer_moml_dark_bg():
"""Fonts for :func:`beamer_moml` with dark background."""
return {
"text.usetex": False,
"font.serif": ["Roboto Condensed"],
"font.family": "serif",
"font.weight": "light",
"axes.labelweight": "light",
"axes.titleweight": "light",
}


# Helper functions below


def _times(*, family="serif"):
"""Times font.

Used, e.g., for ICML 2022.
"""

return {
"text.usetex": False,
"font.serif": ["Times"],
"mathtext.fontset": "stix", # free ptmx replacement, for ICML and NeurIPS
"mathtext.rm": "Times",
"mathtext.it": "Times:italic",
"mathtext.bf": "Times:bold",
"font.family": family,
}


# def _times_new_roman(*, family="serif"):
# """Default fonts for Neurips."""
# return {
# "text.usetex": False,
# "font.serif": ["Times New Roman"],
# "mathtext.fontset": "stix", # free ptmx replacement, for ICML and NeurIPS
# "mathtext.rm": "Times New Roman",
# "mathtext.it": "Times New Roman:italic",
# "mathtext.bf": "Times New Roman:bold",
# "font.family": family,
# }

libbylbaker marked this conversation as resolved.
Show resolved Hide resolved

def _times_tex_via_pkg_ptm(*, family):
"""Times font, implemented in Latex via the ptm-package.

Default fonts for Neurips.
"""
preamble = r"\renewcommand{\rmdefault}{ptm}\renewcommand{\sfdefault}{phv}"
if family == "serif":
return {
"text.usetex": True,
Expand All @@ -160,14 +194,15 @@ def _tex_times(*, family):
}


def _tex_computer_modern(*, family):
def _times_tex_via_pkg_times(*, family):
preamble = r"\usepackage{times} "
if family == "serif":
return {
"text.usetex": True,
"font.family": "serif",
"text.latex.preamble": "",
"text.latex.preamble": preamble,
}
preamble = (
preamble += (
r"\renewcommand{\familydefault}{\sfdefault} \usepackage{sansmath} \sansmath"
)
return {
Expand All @@ -177,27 +212,18 @@ def _tex_computer_modern(*, family):
}


def beamer_moml():
"""Fonts that are compatible with the beamer template of the method-of-machine-learning group in Tübingen."""
def _computer_modern_tex(*, family):
if family == "serif":
return {
"text.usetex": True,
"font.family": "serif",
"text.latex.preamble": "",
}
preamble = (
r"\renewcommand{\familydefault}{\sfdefault} \usepackage{sansmath} \sansmath"
)
return {
"text.usetex": False,
"mathtext.fontset": "custom",
"mathtext.it": "sans:italic",
"font.sans-serif": ["Roboto Condensed"],
"text.usetex": True,
"font.family": "sans-serif",
"font.weight": "light",
"axes.labelweight": "light",
"axes.titleweight": "light",
}


def beamer_moml_dark_bg():
"""Fonts for :func:`beamer_moml` with dark background."""
return {
"text.usetex": False,
"font.serif": ["Roboto Condensed"],
"font.family": "serif",
"font.weight": "light",
"axes.labelweight": "light",
"axes.titleweight": "light",
"text.latex.preamble": preamble,
}
Loading