adsfolio.formatting
- adsfolio.formatting.format_author_list_cv(names, n_max=10, n_min=3, n_me=10, me_target=None, me_fmt='\\textbf{{{}}}', use_and='\\&', authorsep='; ', oxford_comma=True, latex=True)[source]
Format an author list in a CV / publication style, with optional truncation, self-author highlighting, and LaTeX output. The function is designed to work without any external dependencies (e.g., ADS), operating purely on name strings.
- Parameters:
names (list of str) – Author names in the form “Last, First [Middle …]”. Example: “Smith, John Quentin”
n_max (int, default=10) –
Maximum number of authors to display.
If 0, all authors are shown.
If > 0 and the list exceeds this length, truncation may occur depending on n_min and n_me.
n_min (int, default=3) – Minimum number of authors to show when truncation is applied. Used together with n_max to control how many leading authors are preserved before replacing the remainder with “et al.”.
n_me (int, default=10) – Upper position limit (1-based) up to which matching target authors are retained when truncation occurs.
me_target (str, list, or None, default=None) – Short-form identifier(s) for the target author(s), typically “Last, F.”. Can be a single string or a list of strings. If provided and matched, these authors are emphasized.
me_fmt (str, default=r"textbf{{{}}}") – Formatting template to apply to target authors using
me_fmt.format(author). For LaTeX output with literal braces, escape them as{{and}}, with{}as the author name placeholder (e.g.r"\textbf{{{}}}"orr"\textit{{{}}}"). Plain format strings such as"<b>{}</b>"or constant text such as"this is me"are also accepted. Set to None to disable highlighting.latex (bool, default=True) – If True, escape author names and targets for LaTeX using
html_to_latex(). If False, names are kept as plain strings. Target author highlighting (me_fmt) and author joining (use_and, authorsep) apply in both modes.authorsep (str, default="; ") – Separator between authors.
use_and (str or None, default="&") – If None, the conjunction is omitted. All other values currently behave the same: the literal word “and” is used (2 authors: “A and B”; more: “A; B, and C”, or “A; B and C” without Oxford comma).
oxford_comma (bool, default=True) – If True, an Oxford comma is applied (”, and” before the final author). If False, no Oxford comma is used (” and” before the final author).
- Returns:
A single formatted string representing the author list.
- Return type:
Notes
First and middle names are reduced to initials.
Ordering of authors is preserved.
When truncated, the output ends with “et al.”.
The function is intended for CVs, publication lists, and grant documents, where consistent formatting and self-author highlighting are required.
Examples
Full list, no truncation, LaTeX output with self highlighted:
sample_names = [ "Kim, James T.", "Doe, Jane", "Smith, John Quentin", "Longlastname, Alice Bob", "Lee, Charles" ] format_author_list_cv( sample_names, n_max=0, me_target="Kim, J.", latex=True )
Output:
\textbf{Kim, J. T.}; Doe, J.; Smith, J. Q.; Longlastname, A. B., and Lee, C.
Truncated list with multiple targets (self and student):
format_author_list_cv( sample_names, n_max=3, n_min=2, n_me=3, me_target=["Kim, J.", "Doe, J."], latex=True )
Output:
\textbf{Kim, J. T.}; \textbf{Doe, J.}; et al.
- adsfolio.formatting.format_title_latex(title)[source]
Format a paper title for LaTeX.
Escapes special characters like &, %, $, etc.
- adsfolio.formatting.html_to_latex(text, *, bibtex=False)[source]
Convert an HTML-like string to LaTeX.
Handles the tags <sub>, <sup>, <i>, <em>, <b> and <strong>, which may be nested in any order. The entities &, < and > are decoded once and the text is escaped for LaTeX. Existing $…$ math is copied unchanged, also inside <i> or <b>. Inside <sub> or <sup> the text is always escaped, and a nested <sub> or <sup> continues the same math group (_{…} or ^{…}) without a second pair of dollar signs.
Other tags, stray closing tags, and tags that are never closed stay as literal text.