Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
3b696b4
Add UTF8 to xmlrpc
goehle Jun 21, 2016
d2d636c
Add utf8 encoding to the base64 methods.
goehle Jul 15, 2016
539406c
picked an ascii character for the verb escape character so that it do…
goehle Aug 17, 2016
ed11055
Merge branch 'locbugs' of https://github.com/goehle/pg into develop
mgage Jul 30, 2017
a561c0e
Add additional utf8 related changes to PG files.
mgage Jul 31, 2017
da5d905
Add new test files for units.
mgage Dec 30, 2017
f121ef4
Add test for inverting matrix (#331)
mgage Dec 30, 2017
bb06758
Merge branch 'fix-matrix-errors' of https://github.com/dpvc/pg into d…
mgage Dec 30, 2017
b873d7e
Cosmetic changes
mgage Dec 30, 2017
e198260
add test for error messages -- you need to comment out some error cau…
mgage Dec 30, 2017
9575b1f
Add two test files for chemical reactions. (PR #334)
mgage Dec 30, 2017
208c087
Merge branch 'develop_test_units' into develop_unit_tests2
mgage Dec 30, 2017
e904c9d
Add PG problem with arabic characters for testing
mgage Jan 2, 2018
414b356
Added functions SET_PROBLEM_LANGUAGE() SET_PROBLEM_TEXTDIRECTION() which
May 9, 2018
67fcefc
Added SET_PROBLEM_LANGUAGE() SET_PROBLEM_TEXTDIRECTION() functions which
May 9, 2018
a20a843
Merge branch 'develop_international' into develop_utf8_ver2
mgage Jul 23, 2018
b19e682
Merge pull request #319 from mgage/develop_utf8_ver2
mgage Jul 23, 2018
b947aa8
Merge pull request #356 from taniwallach/Add_lang_and_direction_to_PG…
mgage Jul 23, 2018
0733cad
Merge branch 'develop_international' into develop
mgage Oct 21, 2018
c8d0c3c
Replace "<:encoding(utf8)" by "<::utf8" this may be due to an obsol…
mgage Oct 26, 2018
8f245ae
Merge pull request #9 from mgage/develop_unit_tests2
mgage Oct 27, 2018
4ac192d
Merge branch 'develop_candidate_local' into develop_candidate
mgage Jan 1, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/PGcore.pm
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ use Tie::IxHash;
use WeBWorK::Debug;
use MIME::Base64();
use PGUtil();

use Encode qw(encode_utf8 decode_utf8);
use utf8;
binmode(STDOUT, ":uft8");
##################################
# PGcore object
##################################
Expand Down Expand Up @@ -565,13 +567,15 @@ sub PG_restricted_eval {
sub decode_base64 ($) {
my $self = shift;
my $str = shift;
MIME::Base64::decode_base64($str);
$str = MIME::Base64::decode_base64($str);
decode_utf8($str);
}

sub encode_base64 ($;$) {
my $self = shift;
my $str = shift;
my $option = shift;
$str = encode_utf8($str);
MIME::Base64::encode_base64($str);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/PGloadfiles.pm
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ sub compile_file {
local($/);
$/ = undef; # allows us to treat the file as a single line

open(MACROFILE, "<$filePath") || die "Cannot open file: $filePath";
open(MACROFILE, "<:utf8", $filePath) || die "Cannot open file: $filePath";
my $string = 'BEGIN {push @__eval__, __FILE__};' . "\n" . <MACROFILE>;
#warn "compiling $string";
my ($result,$error,$fullerror) = $self->PG_macro_file_eval($string);
Expand Down
2 changes: 1 addition & 1 deletion lib/Units.pm
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ our %known_units = ('m' => {
'm' => 1
},
'parsec' => {
'factor' => 30.857E15,
'factor' => 3.08567758149137E16, #30.857E15,
'm' => 1
},
# VOLUME
Expand Down
2 changes: 1 addition & 1 deletion lib/Value/String.pm
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ sub compare {
#
# Mark a string to be display verbatim
#
sub verb {shift; return "\\verb".chr(0x85).(shift).chr(0x85)}
sub verb {shift; return "\\verb".chr(0x1F).(shift).chr(0x1F)}

#
# Put normal strings into \text{} and others into \verb
Expand Down
5 changes: 3 additions & 2 deletions lib/WeBWorK/PG/IO.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package WeBWorK::PG::IO;
use parent qw(Exporter);
use Encode qw( encode decode);
use JSON qw(decode_json);
use PGUtil qw(not_null);
use WeBWorK::Utils qw(path_is_subdir);
Expand Down Expand Up @@ -139,7 +140,7 @@ sub read_whole_file {
unless path_is_course_subdir($filePath);

local (*INPUT);
open(INPUT, "<$filePath") || die "$0: read_whole_file subroutine: <BR>Can't read file $filePath";
open(INPUT, "<:utf8", $filePath) || die "$0: read_whole_file subroutine: <BR>Can't read file $filePath";
local($/)=undef;
my $string = <INPUT>; # can't append spaces because this causes trouble with <<'EOF' \nEOF construction
close(INPUT);
Expand Down Expand Up @@ -201,7 +202,7 @@ sub createFile {

die 'Path is unsafe' unless path_is_course_subdir($fileName);

open(TEMPCREATEFILE, ">$fileName")
open(TEMPCREATEFILE, ">:encoding(UTF-8)",$fileName)
or die "Can't open $fileName: $!";
my @stat = stat TEMPCREATEFILE;
close(TEMPCREATEFILE);
Expand Down
8 changes: 5 additions & 3 deletions lib/WeBWorK/PG/Translator.pm
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ use Net::SMTP;
use PGcore;
use PGUtil qw(pretty_print);
use WeBWorK::PG::IO qw(fileFromPath);

use utf8;
use v5.12;
binmode(STDOUT,":utf8");
#use PadWalker; # used for processing error messages
#use Data::Dumper;

Expand Down Expand Up @@ -388,7 +390,7 @@ sub pre_load_macro_files {
local(*MACROFILE);
local($/);
$/ = undef; # allows us to treat the file as a single line
open(MACROFILE, "<$filePath") || die "Cannot open file: $filePath";
open(MACROFILE, "<:encoding(utf8)", $filePath) || die "Cannot open file: $filePath";
my $string = <MACROFILE>;
close(MACROFILE);

Expand Down Expand Up @@ -524,7 +526,7 @@ sub source_file {
local($/);
$/ = undef; # allows us to treat the file as a single line
my $err = "";
if ( open(SOURCEFILE, "<$filePath") ) {
if ( open(SOURCEFILE, "<:encoding(utf8)", $filePath) ) {
$self -> {source} = <SOURCEFILE>;
close(SOURCEFILE);
} else {
Expand Down
59 changes: 57 additions & 2 deletions macros/PG.pl
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
# initialize PGcore and PGrandom


$main::VERSION ="PG-2.13+";

sub _PG_init{
$main::VERSION ="PG-2.13+";
$main::VERSION ="PG-2.14+";
#
# Set up MathObject context for use in problems
# that don't load MathObjects.pl
Expand Down Expand Up @@ -142,6 +141,62 @@ sub POST_HEADER_TEXT {
$PG->POST_HEADER_TEXT(@_);
}

# We expect valid HTML language codes, but there can also include a region code, or other
# settings.
# See https://www.w3.org/International/questions/qa-choosing-language-tags
# Example settings: en-US, en-UK, he-IL
# Some special language codes (zh-Hans) are longer
# http://www.rfc-editor.org/rfc/bcp/bcp47.txt
# https://www.w3.org/International/articles/language-tags/
# https://www.w3.org/International/questions/qa-lang-2or3.en.html
# http://www.iana.org/assignments/language-subtag-registry/language-subtag-registry
# https://www.w3schools.com/tags/ref_language_codes.asp
# https://www.w3schools.com/tags/ref_country_codes.asp
# Tester at https://r12a.github.io/app-subtags/

sub SET_PROBLEM_LANGUAGE {
my $requested_lang = shift;

# Clean it up for safety
my $selected_lang = $requested_lang;
$selected_lang =~ s/[^a-zA-Z0-9-]//g ; # Drop any characters not permitted.

if ( $selected_lang ne $requested_lang ) {
warn "PROBLEM_LANGUAGE was edited. Requested: $requested_lang which was replaced by $selected_lang";
}
$PG->{flags}->{"language"} = $selected_lang;
}

# SET_PROBLEM_TEXTDIRECTION to set the HTML DIRection attribute to be applied
# to the DIV element containing this problem.

# We only permit valid settings for the HTML direction attribute:
# dir="ltr|rtl|auto"
# https://www.w3schools.com/tags/att_global_dir.asp

# It is likely that only problems written in RTL scripts
# will need to call the following function to set the base text direction
# for the problem.

# Note the flag may not be set, and then webwork2 will use default behavior.

sub SET_PROBLEM_TEXTDIRECTION {
my $requested_dir = shift;

# Only allow valid values:

if ( $requested_dir =~ /^ltr$/i ) {
$PG->{flags}->{"textdirection"} = "ltr";
} elsif ( $requested_dir =~ /^rtl$/i ) {
$PG->{flags}->{"textdirection"} = "rtl";
} elsif ( $requested_dir =~ /^auto$/i ) {
$PG->{flags}->{"textdirection"} = "auto"; # NOT RECOMMENDED
} else {
warn " INVALID setting for PROBLEM_TEXTDIRECTION: $requested_dir was DROPPED.";
}
}


sub AskSage {
my $python = shift;
my $options = shift;
Expand Down
83 changes: 83 additions & 0 deletions t/pg_test_problems/arabic_test.pg
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
## Translator(Kamal Saleh)
## DESCRIPTION
## Linear Algebra
## ENDDESCRIPTION

## Tagged by tda2d

## DBsubject(Lineare Algebra)
## DBchapter(Lineare Gleichungssysteme)
## DBsection(Matrix-Vektor-Form)
## Date(July 2013)
## Institution(TCNJ and Hope College)
## Author(Paul Pearson)
## Level(4)
## MO(1)
## KEYWORDS('matrix' 'equation')


## Comments from Mike Gage
## This problem won't render correctly until all of the utf8 changes are in place
## It's a good test for utf8.

## This problem should be rendered using the math4-ar template as a test of whether
## the right to left format is working properly for rendering arabic (or hebrew).

DOCUMENT(); # This should be the first executable line in the problem.

loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"PGcourse.pl",
);

TEXT(beginproblem());
$showPartialCorrectAnswers = 1;

Context('Matrix');

foreach $i (1..2) {
$u[$i] = non_zero_random(-5,5,1);
$v[$i] = non_zero_random(-5,5,1);
}
$m = random(-1,1,2) * random(2,5,1);
$n = random(-1,1,2) * random(2,5,1);

$U = Matrix([[$u[1]], [$u[2]]]);
$V = Matrix([[$v[1]], [$v[2]]]);

$answer = Matrix([ $m*$u[1]+$n*$v[1], $m*$u[2]+$n*$v[2] ])->transpose;

Context()->texStrings;
BEGIN_TEXT
لتكن
\( A \)
مصفوفة تطبيق خطي أبعادها
\( 3 \times 2 \)
و أعمدتها مستقلة خطياًًًََُ ً
.
ليكن
\( \vec{u} = $U \)
و
\( \vec{v} = $V \)
شعاعين يحققان المعادلتين
\( A\vec{u} = \vec{a} \)
و
\( A\vec{v} = \vec{b} \)
.
أوجد حل
\( \vec{x} \)
للمعادلة
\( A\vec{x} = $m \vec{a} + $n \vec{b} \).
$BR
$BR
$BLTR
\(\vec{x} = \) \{ $answer->ans_array(20) \}
$ELTR
.
END_TEXT
Context()->normalStrings;

ANS($answer->cmp);
;
ENDDOCUMENT();
57 changes: 57 additions & 0 deletions t/pg_test_problems/chem_react1.pg
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
DOCUMENT();
loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"contextReaction.pl"
);
#
#
TEXT(&beginproblem);
#
$showPartialCorrectAnswers = 1;
Context("Reaction");
#
$named_reactants ="Silver nitrate + Sodium chloride";
$named_products = "Silver chloride + Sodium nitrate";
#
# ID react, prod for complete molecular, total ionic, and net ionic equations.
#
$COMPLETE_REACTION=Formula("AgNO_{3} (aq) + NaCl (aq) --> AgCl (s) + NaNO_{3} (aq)");
#
$TOTAL_IONIC = Formula("Ag^{+1}(aq) + NO_{3}^{-1}(aq) + Na^{+1}(aq) + Cl^{-1}(aq) --> AgCl(s)+Na^{+1}(aq) + NO_{3}^{-1}(aq)");
#
$NET_IONIC=Formula("Ag^{+1}(aq) + Cl^{-1}(aq) --> AgCl(s)");
#
COMMENT("Reaction arrow is --> NOTE: two dashes and >. Charges for ions should be entered +1, +2, -1, -2, etc. Note the order and the 1 for the + and - cases");
Context()->texStrings;
BEGIN_TEXT
$BBOLD Answers should be entered using guidlines discussed in lecture. $EBOLD $BR
Consider the reaction shown below.$BR
$named_reactants \(\longrightarrow\) $named_products $BR
Write the complete molecular reaction equation.$BR
\{ans_rule(60)\}$BR
Write the total ionic equation.$BR
\{ans_rule(60)\}$BR
Write the net ionic equation for the reaction.$BR
\{ans_rule(60)\}
END_TEXT

BEGIN_TEXT

Solutions:
\($COMPLETE_REACTION\)
$PAR
\($TOTAL_IONIC\)
$PAR
\($NET_IONIC\)

END_TEXT

Context()->normalStrings;

#
ANS($COMPLETE_REACTION->cmp);
ANS($TOTAL_IONIC->cmp);
ANS($NET_IONIC->cmp);
#
ENDDOCUMENT();
56 changes: 56 additions & 0 deletions t/pg_test_problems/chem_react2.pg
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
DOCUMENT();
loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"contextReaction.pl"
);
#
#
TEXT(&beginproblem);
#
$showPartialCorrectAnswers = 1;
Context("Reaction");
Context()->variables->add('e' => $context::Reaction::ELEMENT);
#
$named_reactants ="Zinc + Copper(II) sulfate";
$named_products = "Zinc sulfate + Copper";
#
$COMPLETE_REACTION=Formula("Zn(s) + CuSO_{4}(aq) --> ZnSO_{4}(aq) + Cu(s)");
#
$OXIDATION = Formula("Zn(s) --> Zn^{+2} + 2e^{-1}");
#
$REDUCTION=Formula("Cu^{+2} + 2e^{-1} --> Cu(s)");
#
COMMENT("Reaction arrow is --> NOTE: two dashes and >. Charges for ions should be entered +1, +2, -1, -2, etc. Note the order and the 1 for the + and - cases. Electrons are added as e^{-1}");
Context()->texStrings;
BEGIN_TEXT
$BBOLD Answers should be entered using guidlines discussed in lecture. $EBOLD $BR
Consider the reaction shown below.$BR
$named_reactants \(\longrightarrow\) $named_products $BR
Write the complete molecular reaction equation.$BR
\{ans_rule(60)\}$BR
Write the oxidation half-reaction.$BR
\{ans_rule(60)\}$BR
Write the reduction half-reaction.$BR
\{ans_rule(60)\}
END_TEXT

BEGIN_TEXT

Solutions:
\($COMPLETE_REACTION\)
$PAR
\($OXIDATION\)
$PAR
\($REDUCTION\)

END_TEXT

Context()->normalStrings;

#
ANS($COMPLETE_REACTION->cmp);
ANS($OXIDATION->cmp);
ANS($REDUCTION->cmp);
#
ENDDOCUMENT();
Loading