[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
MATHJAX_CONFIGURATION should only have extra configuration
From: |
Gavin Smith |
Subject: |
MATHJAX_CONFIGURATION should only have extra configuration |
Date: |
Sat, 12 Oct 2024 22:36:09 +0100 |
On Thu, Sep 05, 2024 at 04:11:03PM +0200, Rudolf Adamkovič wrote:
> Patrice Dumas <pertusus@free.fr> writes:
>
> > Here it is:
> > https://git.savannah.gnu.org/cgit/texinfo.git/commit/?id=edc041b0aa896ecdf03b7951224e850041a3bed1
>
> Thank you, Patrice!
>
> I set `MATHJAX_CONFIGURATION' to
>
> loader: {
> load: [\'[tex]/physics\'],
> versionWarnings: false
> },
> options: {
> enableMenu: false,
> skipHtmlTags: {"[-]": ["pre"]},
> ignoreHtmlClass: "tex2jax_ignore",
> processHtmlClass: "tex2jax_process"
> },
> tex: {
> packages: {\'[+]\': [\'physics\']}
> },
> chtml: {
> fontURL: "../contrib/mathjax/fonts/"
> }
>
> and it works like a charm!
>
> As you can see, I am
>
> - loading and enabling the Physics package,
> - pointing MathJax to local fonts, and
> - disabling the contextual menu;
>
> all of which previously required setting `HTML_MATH' to "mathjax", then
> pointing `MATHJAX_SCRIPT` to a dummy file, and finally loading MathJax
> manually in the `EXTRA_HEAD'.
>
I don't like the requirement for the user to replicate everything in
MATHJAX_CONFIGURATION. I think they should just be able to specify
settings they want to override or add. Here's sample code for <head>:
--------------------cut
<script type='text/javascript'>
MathJax = {
options: {
skipHtmlTags: {'[-]': ['pre']}, // do not skip pre
ignoreHtmlClass: 'tex2jax_ignore',
processHtmlClass: 'tex2jax_process'
},
tex: {
processEscapes: false, // do not use \$ to produce a literal dollar
sign
processEnvironments: false, // do not process \begin{xxx}...\end{xxx}
outside math mode
processRefs: false, // do not process \ref{...} outside of math mode
displayMath: [ // start/end delimiter pairs for display math
['\\[', '\\]']
],
},
};
var MathJax_conf = {
options: { enableMenu: false }
};
for (let component in MathJax_conf) {
if (!MathJax.hasOwnProperty(component)) {
MathJax[component] = MathJax_conf[component];
} else {
for (let field in MathJax_conf[component]) {
MathJax[component][field] = MathJax_conf[component][field];
}
}
}
</script>
--------------------cut
I am a JavaScript novice so would appreciate it if someone could have
a look. The intention is that we just override a field if it is
specified in MATHJAX_CONFIGURATION.
Here, the only thing the user specifies is "options: { enableMenu: false }".
The user runs a command like
texi2any --html -c HTML_MATH=mathjax -c MATHJAX_CONFIGURATION='options: {
enableMenu: false }' ../doc/texinfo.texi
Here is a patch to the code to make MATHJAX_CONFIGURATION operate as
described:
diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm
index 547df90efa..617267a9df 100644
--- a/tp/Texinfo/Convert/HTML.pm
+++ b/tp/Texinfo/Convert/HTML.pm
@@ -11233,13 +11233,48 @@ sub _file_header_information($$;$)
my $mathjax_script = $self->get_conf('MATHJAX_SCRIPT');
my $mathjax_configuration = $self->get_conf('MATHJAX_CONFIGURATION');
+ my $default_mathjax_configuration = " options: {
+ skipHtmlTags: {'[-]': ['pre']}, // do not skip pre
+ ignoreHtmlClass: 'tex2jax_ignore',
+ processHtmlClass: 'tex2jax_process'
+ },
+ tex: {
+ processEscapes: false, // do not use \\\$ to produce a literal dollar
sign
+ processEnvironments: false, // do not process \\begin{xxx}...\\end{xxx}
outside math mode
+ processRefs: false, // do not process \\ref{...} outside of math
mode
+ displayMath: [ // start/end delimiter pairs for display math
+ ['\\\\[', '\\\\]']
+ ],
+ },";
+
$extra_head .=
"<script type='text/javascript'>
MathJax = {
+$default_mathjax_configuration
+};
+";
+
+ if (defined($mathjax_configuration)) {
+ $extra_head .=
+"var MathJax_conf = {
$mathjax_configuration
};
-</script>"
-.'<script type="text/javascript" id="MathJax-script" async
+
+for (let component in MathJax_conf) {
+ if (!MathJax.hasOwnProperty(component)) {
+ MathJax[component] = MathJax_conf[component];
+ } else {
+ for (let field in MathJax_conf[component]) {
+ MathJax[component][field] = MathJax_conf[component][field];
+ }
+ }
+}
+";
+ }
+
+ $extra_head .= "</script>\n";
+ $extra_head .=
+'<script type="text/javascript" id="MathJax-script" async
src="'.$self->url_protect_url_text($mathjax_script).'">
</script>';
@@ -13030,25 +13065,7 @@ sub _setup_output($)
$mathjax_source =
'http://docs.mathjax.org/en/latest/web/hosting.html#getting-mathjax-via-git';
$self->set_conf('MATHJAX_SOURCE', $mathjax_source);
}
-
- my $mathjax_configuration = $self->get_conf('MATHJAX_CONFIGURATION');
- if (!defined($mathjax_configuration)) {
- $mathjax_configuration = " options: {
- skipHtmlTags: {'[-]': ['pre']}, // do not skip pre
- ignoreHtmlClass: 'tex2jax_ignore',
- processHtmlClass: 'tex2jax_process'
- },
- tex: {
- processEscapes: false, // do not use \\\$ to produce a literal dollar
sign
- processEnvironments: false, // do not process \\begin{xxx}...\\end{xxx}
outside math mode
- processRefs: false, // do not process \\ref{...} outside of math
mode
- displayMath: [ // start/end delimiter pairs for display math
- ['\\\\[', '\\\\]']
- ],
- },";
- $self->set_conf('MATHJAX_CONFIGURATION', $mathjax_configuration);
- }
- }
+ }
my $setup_status = $self->run_stage_handlers($self->{'stage_handlers'},
$self->{'document'}, 'setup');
- MATHJAX_CONFIGURATION should only have extra configuration,
Gavin Smith <=