Skip to content

Commit

Permalink
rust: Allow abbrev
Browse files Browse the repository at this point in the history
  • Loading branch information
felixhekhorn committed Jul 18, 2024
1 parent 865da0c commit de55c1e
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 23 deletions.
65 changes: 65 additions & 0 deletions crates/doc-header.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css" integrity="sha384-wcIxkf4k558AjM3Yz3BBFQUbk/zgIYC2R0QpeeYb+TwlBVMrlgLqwRjRtGZiK7ww" crossorigin="anonymous">
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.js" integrity="sha384-hIoBPJpTUs74ddyc4bFZSM1TVlQDA60VBbJS0oA934VSz82sBx1X7kSx2ATBDIyd" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/contrib/auto-render.min.js" integrity="sha384-43gviWU0YVjaDtb/GhzOouOXtZMP/7XUzwPTstBeZFe/+rCMvRwr4yROQP43s0Xk" crossorigin="anonymous"></script>
<script>
document.addEventListener("DOMContentLoaded", function() {
// activate KaTeX
renderMathInElement(document.body, {
// customised options
// • auto-render specific keys, e.g.:
delimiters: [
{left: '$$', right: '$$', display: true},
{left: '$', right: '$', display: false},
{left: '\\(', right: '\\)', display: false},
{left: '\\[', right: '\\]', display: true}
],
// • rendering keys, e.g.:
throwOnError : false
});

// Allow abbreviations
let abbrevs = {
"EKO": "Evolution Kernel Operator",
"PDF": "Parton Distribution Function(s)",
"FF": "Fragmentation Function(s)",
"FNS": "Flavor Number Scheme",
"FFNS": "Fixed Flavor Number Scheme",
"VFNS": "Variable Flavor Number Scheme",
"LO": "Leading Order",
"NLO": "Next-to-Leading Order",
"NNLO": "Next-to-Next-to-Leading Order",
"N3LO": "Next-to-Next-to-Next-to-Leading Order",
"LL": "Leading Log",
"NLL": "Next-to-Leading Log",
"NNLL": "Next-to-Next-to-Leading Log",
"DGLAP": "Dokshitzer-Gribov-Lipatov-Altarelli-Parisi",
"PID": "(Monte Carlo) parton identifier",
"OME": "Operator Matrix Element",
"RGE": "Renormalization Group Equation",
"MHOU": "Missing Higher Order Uncertainties",
"QCD": "Quantum Chromodynamics",
"QED": "Quantum Electrodynamics",
"DIS": "Deep Inelastic Scattering",
"BFKL": "Balitsky-Fadin-Kuraev-Lipatov",
"FHMRUVV": "Falcioni, Herzog, Moch, Ruijl, Ueda, Vermaseren and Vogt",
"API": "Application Program Interface",
};
// parse abbreviations
let parsedAbbrevs = {};
for (el in abbrevs) {
parsedAbbrevs["|" + el + "|"] = "<abbr title='"+abbrevs[el]+"' >"+el+"</abbr>";
}
// do the actual replace
function replaceAbbrev(el) {
let txt = el.textContent;
for (k in parsedAbbrevs)
txt = txt.replace(k, parsedAbbrevs[k]);
el.innerHTML = txt;
}
// search texts
let longs = document.getElementsByClassName("docblock");
for (let el of longs) replaceAbbrev(el);
let shorts = document.getElementsByClassName("docblock-short");
for (let el of shorts) replaceAbbrev(el);
});
</script>
2 changes: 1 addition & 1 deletion crates/eko/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ rust-version.workspace = true
version.workspace = true

[package.metadata.docs.rs]
rustdoc-args = ["--html-in-header", "katex-header.html"]
rustdoc-args = ["--html-in-header", "doc-header.html"]

[lib]
name = "ekors"
Expand Down
1 change: 1 addition & 0 deletions crates/eko/doc-header.html
1 change: 0 additions & 1 deletion crates/eko/katex-header.html

This file was deleted.

2 changes: 1 addition & 1 deletion crates/ekore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ rust-version.workspace = true
version.workspace = true

[package.metadata.docs.rs]
rustdoc-args = ["--html-in-header", "katex-header.html"]
rustdoc-args = ["--html-in-header", "doc-header.html"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
1 change: 1 addition & 0 deletions crates/ekore/doc-header.html
1 change: 0 additions & 1 deletion crates/ekore/katex-header.html

This file was deleted.

19 changes: 0 additions & 19 deletions crates/katex-header.html

This file was deleted.

20 changes: 20 additions & 0 deletions crates/parse-abbrev.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""Parse abbreviations from sphinx to Rust."""

import pathlib
import re

SRC = (
pathlib.Path(__file__).parents[1]
/ "doc"
/ "source"
/ "shared"
/ "abbreviations.rst"
)

cnt = SRC.read_text("utf-8")
for el in cnt.split(".."):
test = re.match(r"\s*(.+)\s+replace::\n\s+:abbr:`(.+?)\((.+)\)`", el.strip())
if test is None:
continue
# Print to terminal - the user can dump to the relevant file
print(f'"{test[2].strip()}": "{test[3].strip()}",')

0 comments on commit de55c1e

Please sign in to comment.