Skip to content

Commit 8943bac

Browse files
committed
Make MathJax show errors for bad TeX but only in the problem editor.
There have been requests to either remove this extension or at least make it so that those editing problems do not have it loaded, as it makes it easier to determine what is wrong with TeX in a problem. This pull request makes it so that these errors are only shown in the PG problem editor. Actually they are shown any time the renderRPC endpoint is used and the `showMathJaxErrors` parameter is set to a true value, but the only time that webwork2 now does this is in the problem editor. This still includes thhe change from the `webwork_url` to the `webwork_js_config` method in the `WeBWorK::ContentGenerator` module. There is also a `webwork_url` method in the `Mojolicious::WeBWorK` module that is already available for all controller modules (since it is a Mojolicious helper method), and having this other one overrides that one and it is confusing to have both that return almost the same value. The only difference is that `WeBWorK::ContentGenerator` method called the `location` helper which returns the empty string if the root URL is '/', and the `webwork_url` helper returns '/' in that case. I don't know what I was thinking creating the `WeBWorK::ContentGenerator` method which was really just an alies for the `location` helper method anyway.
1 parent c5a2717 commit 8943bac

File tree

7 files changed

+14
-14
lines changed

7 files changed

+14
-14
lines changed

htdocs/js/MathJaxConfig/mathjax-config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
if (!window.MathJax) {
22
window.MathJax = {
3-
tex: { packages: { '[+]': ['noerrors'] } },
3+
tex: { packages: { '[+]': webworkConfig?.showMathJaxErrors ? [] : ['noerrors'] } },
44
loader: { load: ['input/asciimath', '[tex]/noerrors'] },
55
startup: {
66
ready() {

htdocs/js/PGProblemEditor/pgproblemeditor.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@
382382
requestData.set('send_pg_flags', 1);
383383
requestData.set(button.name, button.value);
384384
requestData.set('set_id', document.getElementsByName('hidden_set_id')[0]?.value ?? 'Unknown Set');
385+
requestData.set('showMathJaxErrors', 1);
385386

386387
await renderProblem(requestData);
387388

@@ -473,7 +474,8 @@
473474
displayMode: document.getElementById('action_view_displayMode_id')?.value ?? 'MathJax',
474475
language: document.querySelector('input[name="hidden_language"]')?.value ?? 'en',
475476
send_pg_flags: 1,
476-
view_problem_debugging_info: 1
477+
view_problem_debugging_info: 1,
478+
showMathJaxErrors: 1
477479
})
478480
).then(() => resolve());
479481
});

lib/FormatRenderedProblem.pm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ sub formatRenderedProblem {
267267
showCorrectAnswersOnlyButton => $ws->{inputs_ref}{showCorrectAnswersOnlyButton} // 0,
268268
showFooter => $ws->{inputs_ref}{showFooter} // '',
269269
problem_data => encode_json($rh_result->{PERSISTENCE_HASH}),
270+
showMathJaxErrors => $ws->{inputs_ref}{showMathJaxErrors} // 0,
270271
pretty_print => \&pretty_print
271272
);
272273

lib/WeBWorK/ContentGenerator.pm

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ use MIME::Base64;
3232
use Scalar::Util qw(weaken);
3333
use HTML::Entities;
3434
use Encode;
35+
use Mojo::JSON qw(encode_json);
3536

3637
use WeBWorK::File::Scoring qw(parse_scoring_file);
3738
use WeBWorK::Localize;
@@ -682,20 +683,15 @@ sub page_title ($c) {
682683
return route_title($c, $c->current_route, 1);
683684
}
684685

685-
=item webwork_url
686+
=item webwork_js_config
686687
687-
Defined in this package.
688-
689-
Outputs the $webwork_url defined in site.conf, unless $webwork_url is equal to
690-
"/", in which case this outputs the empty string.
691-
692-
This is used to set a value in a global webworkConfig javascript variable,
693-
that can be accessed in javascript files.
688+
Outputs the webwork2 JavaScript configuration. This configuration can be
689+
accessed by JavaScript files to obtain various webwork2 settings.
694690
695691
=cut
696692

697-
sub webwork_url ($c) {
698-
return $c->location;
693+
sub webwork_js_config ($c) {
694+
return encode_json({ webwork_url => $c->location });
699695
}
700696

701697
=item warnings()

templates/ContentGenerator/SampleProblemViewer.html.ep

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<%= javascript $c->url({
1515
type => 'webwork', name => 'htdocs', file => 'node_modules/minisearch/dist/umd/index.js'
1616
}), defer => undef =%>
17-
<script>const webworkConfig = { webwork_url: '<%= $c->webwork_url %>' };</script>
17+
<script>const webworkConfig = <%== $c->webwork_js_config %>;</script>
1818
<%= javascript $c->url({
1919
type => 'webwork', name => 'htdocs', file => 'js/SampleProblemViewer/documentation-search.js'
2020
}), defer => undef =%>

templates/RPCRenderFormats/default.html.ep

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
% for (@$extra_css_files) {
2020
%= stylesheet $_->{file}
2121
% }
22+
<script>const webworkConfig = <%= $showMathJaxErrors ? '{ showMathJaxErrors: true }' : 'null' %>;</script>
2223
% for (@$third_party_js) {
2324
%= javascript $_->[0], %{ $_->[1] // {} }
2425
% }

templates/layouts/system.html.ep

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
% }
2121
%
2222
% # Webwork configuration for javascript
23-
<script>const webworkConfig = { webwork_url: '<%= $c->webwork_url %>' };</script>
23+
<script>const webworkConfig = <%== $c->webwork_js_config %>;</script>
2424
%
2525
% # JS Loads
2626
<%= javascript $c->url({ type => 'webwork', name => 'htdocs', file => 'js/MathJaxConfig/mathjax-config.js' }),

0 commit comments

Comments
 (0)