Skip to content

Commit 449edae

Browse files
committed
Make MathJax show errors for bad TeX.
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 for users that have the `view_problem_debugging_info` permission (which is those with the ta role or higher by default). So students will still see the usual faulty TeX code in yellow. Another option would be to just remove the `noerrors` MathJax extension instead of optionally loading it. I am not sure why this package was added. It seems that I added it when I upgraded from MathJax version 2 to version 3, but I don't remember why. Perhaps it was just in the configuration that @dpvc recommended, or maybe I added it for some reason. Perhaps it was just about maintaining compatibility with version 2 of MathJax. For version 2 (as I understand it), the `noerrors` extension was included by default, but with MathJax version 3 it must be explicitly loaded. Even if we decide to drop the `noerrors` extension, the change from the `webwork_url` to the `webwork_js_config` method in the `WeBWorK::ContentGenerator` module should be made anyway. 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 d3708c5 commit 449edae

File tree

5 files changed

+15
-13
lines changed

5 files changed

+15
-13
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?.mathjax_show_errors ? [] : ['noerrors'] } },
44
loader: { load: ['input/asciimath', '[tex]/noerrors'] },
55
startup: {
66
ready() {

lib/WeBWorK/ContentGenerator.pm

Lines changed: 11 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,20 @@ 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({
695+
webwork_url => $c->location,
696+
$c->authen->was_verified && $c->authz->hasPermissions($c->param('user'), 'view_problem_debugging_info')
697+
? (mathjax_show_errors => \1)
698+
: ()
699+
});
699700
}
700701

701702
=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 = <%== $c->webwork_js_config %>;</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)