Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

  • 9753e50
  • /
  • res2tex.py
Raw File Download
Permalinks

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
content badge Iframe embedding
swh:1:cnt:faf31fd54a6a55c941f2cb42f3d378efe905f3e3
directory badge Iframe embedding
swh:1:dir:9753e50b7268a47325aaba182ffb3074cc1a3a21
Citations

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
res2tex.py
import argparse
import json


def main(fname, standalone=False):
    with open(fname, "r") as src:
        data = json.load(src)
    # use dicts to get an ordered sets
    lines = {}
    cols = {}
    for ds, vals in data.items():
        lines["_".join(ds.split("_")[:-2])] = None
        for item in vals:
            cols[item] = None
    cols = ["Dataset"] + list(cols)
    # escape "#" chars
    cols_escape = []
    for name in cols:
        if "#" in name:
            name = "\\" + name
        cols_escape.append(name)
    cols_dict = {name: i for i, name in enumerate(cols)}
    cols = cols_escape
    lines = list(lines)
    res = []
    if standalone:
        res.append(r"\documentclass{standalone}")
        res.append("")
        res.append(r"\usepackage{booktabs}")
        res.append("")
        res.append(r"\begin{document}")
        res.append("")
    res.append(r"\begin{tabular}[ht]{l" + "c" * (len(cols) - 1) + "}")
    res.append(r"  \toprule")
    res.append("  " + " & ".join(cols) + r" \\")
    res.append(r"  \midrule")
    res.append("")
    for ds in lines:
        curr = ["\\_".join(ds.split("_"))] * len(cols)
        for it, val in data[ds + "_order_expl"].items():
            curr[cols_dict[it]] = str(val)
        for it, val in data[ds + "_order_impl"].items():
            if "#" not in it:
                curr[cols_dict[it]] = str(val)
        # consistency check
        for i, val in enumerate(curr):
            if i != 0 and val == curr[0]:
                curr[i] = "Err."
        res.append("  " + " & ".join(curr) + r" \\")
    res.append(r"  \bottomrule")
    res.append(r"\end{tabular}")
    if standalone:
        res.append("")
        res.append(r"\end{document}")
    print("\n".join(res))


if __name__ == "__main__":
    parser = argparse.ArgumentParser(
        description="Generate a LaTeX table from JSON results"
    )
    parser.add_argument("JSON_File", type=str, help="Path to JSON results file")
    parser.add_argument(
        "-s",
        "--standalone",
        action="store_true",
        help="Embed output in standalone LaTeX file",
    )
    args = parser.parse_args()
    main(args.JSON_File, args.standalone)

Software Heritage — Copyright (C) 2015–2025, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Contact— JavaScript license information— Web API

back to top