From eee6e9e14fd1d07d2048d8c0472ba34a5b6611f9 Mon Sep 17 00:00:00 2001 From: Olivier Labbe <olivier.labbe@univ-grenoble-alpes.fr> Date: Wed, 26 Feb 2025 16:16:41 +0100 Subject: [PATCH 1/6] Config MathJax to use TeX in formulas --- src/ptf/cmds/xml/jats/jats_parser.py | 13 +++++++++++-- src/ptf/cmds/xml_cmds.py | 5 ++++- src/ptf/static/ptf/css/bs5/base.css | 2 +- src/ptf/static/ptf/css/bs5/ptf.css | 4 ++-- src/ptf/static/ptf/css/ptf.css | 2 +- src/ptf/static/ptf/js/mathjax-config.js | 4 ++-- 6 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/ptf/cmds/xml/jats/jats_parser.py b/src/ptf/cmds/xml/jats/jats_parser.py index a1c48761..2ce87202 100644 --- a/src/ptf/cmds/xml/jats/jats_parser.py +++ b/src/ptf/cmds/xml/jats/jats_parser.py @@ -407,7 +407,7 @@ class JatsBase(XmlParserBase): img_url = os.path.join(kwargs["base_url"], "png", img_url) else: img_url = os.path.join(kwargs["base_url"], "jpg", img_url) - + img_text = '<a href="' + img_url + '" data-lightbox="image-' img_text += str(len(self.figures)) + '" title="">' img_text += '<img src="' + img_url + f'" class="{classe}"/>' @@ -495,7 +495,10 @@ class JatsBase(XmlParserBase): if label or node.tag == "disp-formula": html += '<table class="formula"><tr><td class="formula-inner">' - html += '<span class="mathjax-formula" ' + if self.formula_with_tex: + html += '<span class="mathjax-formula formula-with-tex" ' + else: + html += '<span class="mathjax-formula" ' if formula_id: html += 'id="' + formula_id + '" ' alt_text = tex_math.replace("\n", "") if node.tag == "disp-formula" else tex_math @@ -2137,12 +2140,17 @@ class JatsIssue(IssueData, JatsBase): for child in node: tag = normalize(child.tag) + kwargs = {} if tag == "article": + if self.journal and self.journal.pid in ["CRCHIM"] and int(self.year) > 2024: + kwargs["formula_with_tex"] = True + article = JatsArticle( tree=child, issue=self, from_folder=self.from_folder, no_bib=self.no_bib, + **kwargs ) self.warnings.extend(article.warnings) self.articles.append(article) @@ -2485,6 +2493,7 @@ class JatsArticle(ArticleData, JatsArticleBase): self.for_tex_file = kwargs["for_tex_file"] if "for_tex_file" in kwargs else False self.from_folder = kwargs["from_folder"] if "from_folder" in kwargs else None self.no_bib = kwargs.get("no_bib", False) + self.formula_with_tex = kwargs.get("formula_with_tex", False) self.parse_tree(kwargs["tree"]) diff --git a/src/ptf/cmds/xml_cmds.py b/src/ptf/cmds/xml_cmds.py index ad4edf72..339a20ef 100644 --- a/src/ptf/cmds/xml_cmds.py +++ b/src/ptf/cmds/xml_cmds.py @@ -784,7 +784,10 @@ class addArticleXmlCmd(addXmlCmd): self.provider_col = provider_col def set_article_single_mode(self): - self.xarticle = jats_parser.JatsArticle(tree=self.tree) + kwargs = {} + if self.issue and self.issue.my_collection.pid in ["CRCHIM"] and int(self.issue.year) > 2024: + kwargs["formula_with_tex"] = True + self.xarticle = jats_parser.JatsArticle(tree=self.tree, **kwargs) self.warnings.extend(self.xarticle.warnings) # TODO: MaxiDML: allow the creation of an issue on the fly diff --git a/src/ptf/static/ptf/css/bs5/base.css b/src/ptf/static/ptf/css/bs5/base.css index 41bcce50..7f0d95ba 100644 --- a/src/ptf/static/ptf/css/bs5/base.css +++ b/src/ptf/static/ptf/css/bs5/base.css @@ -128,7 +128,7 @@ /* Not sure if it can break things, add a scrollbar to formulas for tiny screens */ table.formula { - overflow-x: scroll; + overflow-x: auto; display: block; margin: 0 auto; max-width: fit-content; diff --git a/src/ptf/static/ptf/css/bs5/ptf.css b/src/ptf/static/ptf/css/bs5/ptf.css index 2ed9f45e..ebcc703a 100644 --- a/src/ptf/static/ptf/css/bs5/ptf.css +++ b/src/ptf/static/ptf/css/bs5/ptf.css @@ -844,7 +844,7 @@ body:has(> #lightbox-root.showed) .outline-sm { display: block; } -#summary th, td { +#summary th, #summary td { padding: 15px; } @@ -1238,4 +1238,4 @@ hr.panel-title-separator { width: 96%; padding-top: 10px; padding-left: 10px; -} \ No newline at end of file +} diff --git a/src/ptf/static/ptf/css/ptf.css b/src/ptf/static/ptf/css/ptf.css index d4bfcc18..fb940006 100644 --- a/src/ptf/static/ptf/css/ptf.css +++ b/src/ptf/static/ptf/css/ptf.css @@ -873,7 +873,7 @@ ul.cms-breadcrumb { display: block; } -#summary th, td { +#summary th, #summary td { padding: 15px; } diff --git a/src/ptf/static/ptf/js/mathjax-config.js b/src/ptf/static/ptf/js/mathjax-config.js index fe6c3471..03e84639 100644 --- a/src/ptf/static/ptf/js/mathjax-config.js +++ b/src/ptf/static/ptf/js/mathjax-config.js @@ -1,6 +1,6 @@ function replaceMml() { console.log("Replacing mml"); - $(".mathjax-formula").each(function () { + $(".mathjax-formula.formula-with-tex").each(function () { var formula = $(this); var tex = formula.data("tex"); if (tex != "") { @@ -64,7 +64,7 @@ window.MathJax = { startup: { pageReady: function () { console.log("MathJax pageReady"); - //replaceMml(); + replaceMml(); // // Do the usual startup (which does a typeset). // When that is all done, un-hide the page. -- GitLab From d0b2e38f1a12b156231b6892fda2b019fcb4d8e0 Mon Sep 17 00:00:00 2001 From: Olivier Labbe <olivier.labbe@univ-grenoble-alpes.fr> Date: Wed, 26 Feb 2025 16:30:39 +0100 Subject: [PATCH 2/6] Config MathJax to use TeX in formulas --- src/ptf/cmds/xml/jats/jats_parser.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ptf/cmds/xml/jats/jats_parser.py b/src/ptf/cmds/xml/jats/jats_parser.py index 2ce87202..e73035d7 100644 --- a/src/ptf/cmds/xml/jats/jats_parser.py +++ b/src/ptf/cmds/xml/jats/jats_parser.py @@ -98,6 +98,7 @@ class JatsBase(XmlParserBase): self.add_span_around_tex_formula = False # Used to create a Tex file from an XML value (ie abstract) self.for_tex_file = False + self.formula_with_tex = False def parse_tree(self, tree): self.tree = tree -- GitLab From 713cd2a90e5d03a7547b616356b87a9a1c501b02 Mon Sep 17 00:00:00 2001 From: Olivier Labbe <olivier.labbe@univ-grenoble-alpes.fr> Date: Thu, 27 Feb 2025 12:01:09 +0100 Subject: [PATCH 3/6] Config MathJax to use TeX in formulas --- src/ptf/static/ptf/js/mathjax-config.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ptf/static/ptf/js/mathjax-config.js b/src/ptf/static/ptf/js/mathjax-config.js index 03e84639..b9750fee 100644 --- a/src/ptf/static/ptf/js/mathjax-config.js +++ b/src/ptf/static/ptf/js/mathjax-config.js @@ -11,7 +11,7 @@ function replaceMml() { window.MathJax = { loader: { - load: ["[tex]/upgreek", "[tex]/textmacros", "[tex]/noerrors", "[tex]/physics"], + load: ["[tex]/upgreek", "[tex]/textmacros", "[tex]/noerrors", "[tex]/physics", "[tex]/textcomp"], }, tex: { inlineMath: [ @@ -19,7 +19,7 @@ window.MathJax = { ["\\(", "\\)"], ], packages: { - "[+]": ["upgreek", "textmacros", "noerrors", "physics"], + "[+]": ["upgreek", "textmacros", "noerrors", "physics", "textcomp"], }, processEscapes: true, // use \$ to produce a literal dollar sign processEnvironments: true, -- GitLab From f9e5cc9312ac60d777645c548fbd0f0296cc6a06 Mon Sep 17 00:00:00 2001 From: Olivier Labbe <olivier.labbe@univ-grenoble-alpes.fr> Date: Thu, 27 Feb 2025 17:09:26 +0100 Subject: [PATCH 4/6] mathjax formula with TeX for CRAS 2025 --- src/ptf/cmds/xml/jats/jats_parser.py | 12 ++++++++---- src/ptf/cmds/xml_cmds.py | 10 +++++++--- src/ptf/static/ptf/js/mathjax-config.js | 3 +++ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/ptf/cmds/xml/jats/jats_parser.py b/src/ptf/cmds/xml/jats/jats_parser.py index e73035d7..4774c40f 100644 --- a/src/ptf/cmds/xml/jats/jats_parser.py +++ b/src/ptf/cmds/xml/jats/jats_parser.py @@ -347,7 +347,6 @@ class JatsBase(XmlParserBase): => change the location to "file:/..." for Elsevier JATS (the xarticle has a pii attribute) """ href = "" - style = "" classe = "article-body-img" for attrib in node.attrib: name = normalize(attrib) @@ -1506,7 +1505,7 @@ class JatsBase(XmlParserBase): if self.no_bib: href = "http://www.numdam.org/item/" + os.path.basename(href) - rel = 'full-text' + rel = "full-text" data = { "rel": rel, "mimetype": node_type, @@ -2143,7 +2142,12 @@ class JatsIssue(IssueData, JatsBase): kwargs = {} if tag == "article": - if self.journal and self.journal.pid in ["CRCHIM"] and int(self.year) > 2024: + if ( + self.journal + and self.journal.pid + in ["CRMATH", "CRMECA", "CRPHYS", "CRGEOS", "CRCHIM", "CRBIOL"] + and int(self.year) > 2024 + ): kwargs["formula_with_tex"] = True article = JatsArticle( @@ -2151,7 +2155,7 @@ class JatsIssue(IssueData, JatsBase): issue=self, from_folder=self.from_folder, no_bib=self.no_bib, - **kwargs + **kwargs, ) self.warnings.extend(article.warnings) self.articles.append(article) diff --git a/src/ptf/cmds/xml_cmds.py b/src/ptf/cmds/xml_cmds.py index 339a20ef..5e42dd48 100644 --- a/src/ptf/cmds/xml_cmds.py +++ b/src/ptf/cmds/xml_cmds.py @@ -785,7 +785,7 @@ class addArticleXmlCmd(addXmlCmd): def set_article_single_mode(self): kwargs = {} - if self.issue and self.issue.my_collection.pid in ["CRCHIM"] and int(self.issue.year) > 2024: + if self.issue and self.issue.is_cr() and int(self.issue.year) > 2024: kwargs["formula_with_tex"] = True self.xarticle = jats_parser.JatsArticle(tree=self.tree, **kwargs) self.warnings.extend(self.xarticle.warnings) @@ -867,8 +867,12 @@ class addArticleXmlCmd(addXmlCmd): node = tree.find("body") self.xarticle.body = xml_utils.get_text_from_node(node) self.xarticle.body_xml = xml_utils.get_xml_from_text("body", self.xarticle.body) - elif not self.xarticle.body_xml and self.xarticle.body_html: # Triggered when an article is accepted in editor and submitted to trammel. - self.xarticle.body_xml = xml_utils.get_xml_from_text("body", xml_utils.remove_html(self.xarticle.body_html)) + elif ( + not self.xarticle.body_xml and self.xarticle.body_html + ): # Triggered when an article is accepted in editor and submitted to trammel. + self.xarticle.body_xml = xml_utils.get_xml_from_text( + "body", xml_utils.remove_html(self.xarticle.body_html) + ) def internal_do(self): super().internal_do() diff --git a/src/ptf/static/ptf/js/mathjax-config.js b/src/ptf/static/ptf/js/mathjax-config.js index b9750fee..df5384be 100644 --- a/src/ptf/static/ptf/js/mathjax-config.js +++ b/src/ptf/static/ptf/js/mathjax-config.js @@ -21,6 +21,7 @@ window.MathJax = { packages: { "[+]": ["upgreek", "textmacros", "noerrors", "physics", "textcomp"], }, + textmacros: {packages: {'[+]': ['textcomp']}}, processEscapes: true, // use \$ to produce a literal dollar sign processEnvironments: true, macros: { @@ -43,6 +44,8 @@ window.MathJax = { bb: "\\mathbb ", dbar: "\\overline\\partial", protect: "", + rmDelta: "\\Delta", + hyphen: "\\text{-}", }, noundefined: { color: "red", -- GitLab From 51f1b47bc9aefea652149746f6cd3a3154a78e58 Mon Sep 17 00:00:00 2001 From: Olivier Labbe <olivier.labbe@univ-grenoble-alpes.fr> Date: Fri, 28 Feb 2025 09:21:48 +0100 Subject: [PATCH 5/6] Config MathJax to use TeX in formulas --- src/ptf/cmds/xml/jats/jats_parser.py | 13 ++++++------- src/ptf/cmds/xml_cmds.py | 9 +++++++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/ptf/cmds/xml/jats/jats_parser.py b/src/ptf/cmds/xml/jats/jats_parser.py index 4774c40f..db0058f0 100644 --- a/src/ptf/cmds/xml/jats/jats_parser.py +++ b/src/ptf/cmds/xml/jats/jats_parser.py @@ -2142,13 +2142,12 @@ class JatsIssue(IssueData, JatsBase): kwargs = {} if tag == "article": - if ( - self.journal - and self.journal.pid - in ["CRMATH", "CRMECA", "CRPHYS", "CRGEOS", "CRCHIM", "CRBIOL"] - and int(self.year) > 2024 - ): - kwargs["formula_with_tex"] = True + try: + year = int(self.year) + if year > 2024: + kwargs["formula_with_tex"] = True + except ValueError: + pass article = JatsArticle( tree=child, diff --git a/src/ptf/cmds/xml_cmds.py b/src/ptf/cmds/xml_cmds.py index 554a367a..90591872 100644 --- a/src/ptf/cmds/xml_cmds.py +++ b/src/ptf/cmds/xml_cmds.py @@ -847,8 +847,13 @@ class addArticleXmlCmd(addXmlCmd): def set_article_single_mode(self): kwargs = {} - if self.issue and self.issue.is_cr() and int(self.issue.year) > 2024: - kwargs["formula_with_tex"] = True + if self.issue: + try: + year = int(self.issue.year) + if year > 2024: + kwargs["formula_with_tex"] = True + except ValueError: + pass self.xarticle = jats_parser.JatsArticle(tree=self.tree, **kwargs) self.warnings.extend(self.xarticle.warnings) -- GitLab From 6cb51fc6c394024b00fdb80248816494ad9cc7d8 Mon Sep 17 00:00:00 2001 From: Olivier Labbe <olivier.labbe@univ-grenoble-alpes.fr> Date: Tue, 11 Mar 2025 17:13:06 +0100 Subject: [PATCH 6/6] display tex directly --- src/ptf/cmds/xml/jats/jats_parser.py | 7 ++++--- src/ptf/static/ptf/js/mathjax-config.js | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/ptf/cmds/xml/jats/jats_parser.py b/src/ptf/cmds/xml/jats/jats_parser.py index 9d993a3e..b24b0f72 100644 --- a/src/ptf/cmds/xml/jats/jats_parser.py +++ b/src/ptf/cmds/xml/jats/jats_parser.py @@ -502,10 +502,11 @@ class JatsBase(XmlParserBase): if formula_id: html += 'id="' + formula_id + '" ' alt_text = tex_math.replace("\n", "") if node.tag == "disp-formula" else tex_math - if math_text: - html += f'data-tex="{alt_text}">{math_text}</span>' + + if self.formula_with_tex or not math_text: + html += f'data-tex="{alt_text}">{escape(tex_math)}</span>' else: - html += f'data-tex="{alt_text}">{tex_math}</span>' + html += f'data-tex="{alt_text}">{math_text}</span>' if label or node.tag == "disp-formula": html += '</td><td class="formula-label">' diff --git a/src/ptf/static/ptf/js/mathjax-config.js b/src/ptf/static/ptf/js/mathjax-config.js index df5384be..445b8722 100644 --- a/src/ptf/static/ptf/js/mathjax-config.js +++ b/src/ptf/static/ptf/js/mathjax-config.js @@ -67,7 +67,7 @@ window.MathJax = { startup: { pageReady: function () { console.log("MathJax pageReady"); - replaceMml(); + // replaceMml(); // // Do the usual startup (which does a typeset). // When that is all done, un-hide the page. -- GitLab