WeBWorK Problems

Spacing problems for trig functions

Spacing problems for trig functions

by Sean Fitzpatrick -
Number of replies: 3

Below is a WeBWorK problem written in PGML. This particular problem was written in PreTeXt by Alex Jordan and generated by PreTeXt, but I believe this is an issue with WeBWorK behaviour and not PreTeXt.

The issue: when trig functions are created in PGML using MathObjects, the TeX code written for MathJax display includes a negative thin space before the argument. For example, if I define '$f=Formula("sin(x)")' and my PGML has [$f], the TeX command used by MathJax is '\sin\!\left(x\right)'.

I couldn't find a good example in the OPL because very few problems appear to use PGML.

The negative thin space looks good when the trig function is regular font size. But it does not look good if the trig function is part of a (non-display-style) fraction, or if the trig function is in an exponent. In these cases, the negative space causes the parenthesis to overlap with the trig function.

Some examples in PreTeXt HTML: trig in exponent and trig in fraction. I can confirm that the same appearance issue is there if you run these problems directly on a WeBWorK server.


#############################################
### Generated from PreTeXt source
### on 2023-06-21T10:02:43-06:00
### A recent stable commit (2022-07-01):
### 6c761d3dba23af92cba35001c852aac04ae99a5f
###
### https://pretextbook.org
###
#############################################
## DBsubject()
## DBchapter()
## DBsection()
## Level()
## KEYWORDS()
## TitleText1()
## EditionText1()
## AuthorText1()
## Section1(not reported)
## Problem1(2.5.24)
## Author()
## Institution()
## Language(en-US)

DOCUMENT();

############################################################
# Load Macros
############################################################
loadMacros(
"PGstandard.pl",
"PGML.pl",
"AnswerFormatHelp.pl",
"contextForm.pl",
"PGcourse.pl",
);
COMMENT('Authored in PreTeXt');

############################################################
# Header
############################################################
TEXT(beginproblem());

############################################################
# PG Setup Code
############################################################
$fname = list_random('f','g','h','j','k','p');
$x = list_random('q','r','t','x','y','z');
$b = random(2,9,1);
$trig= list_random('sin','cos','sec','csc','tan','cot');
if($envir{problemSeed}==1){$fname='g';$x='t';$b=5;$trig='cos'};
Context()->variables->are($x=>'Real');
$f=Formula("$b^($trig($x))")->reduce;
Context()->flags->set(reduceConstantFunctions=>0);
$fp=$f->D($x);

############################################################
# Body
############################################################

BEGIN_PGML
Compute the derivative of the given function.

[`[$fname]([$x]) = [$f]`]

[_]{$fp}{60}

END_PGML

############################################################
# End Problem
############################################################

ENDDOCUMENT();

In reply to Sean Fitzpatrick

Re: Spacing problems for trig functions

by Alex Jordan -

This is because of:     https://github.com/openwebwork/pg/blob/a29b85f259fac1924688a2a6f8b80b9715c4bc55/lib/Parser/Function.pm#L306

And there is a similar use here:   https://github.com/openwebwork/pg/blob/a29b85f259fac1924688a2a6f8b80b9715c4bc55/lib/Parser/BOP/multiply.pm#L128

When there is a construct like
\left( content \right)
LaTeX puts more space to the left of \left( and right of \right( than you might want to see. These negative spaces were probably to combat that.

I think the `\!` here could be changed to `\mathopen{}` and it would have the desired effect. I would like to see what Davide Cervone and others think about that though.