התוכן למטה הועתק מחומר ישן, ואיבד את העיצוב שהיה שם.

דורש עדכונים והוספת עיצוב.

Hebrew in WeBWorK problems

Brief instructions

Header section- standard lines 1:

In a PG problem, after the loadMacros() call which usually is just after the "DOCUMENT();" line, add the following lines:

SET_PROBLEM_LANGUAGE("he-IL");

SET_PROBLEM_TEXTDIRECTION("rtl");

to set the problem language to Hebrew and the main text direction for the problem to RTL. Assume that the values submitted may be case-sensitive.

Header section- standard lines 2:

In PG problems which needs RTL support such as a Hebrew you need to be loading PGbasicmacros.pl which is usually loaded by loading PGstandard.pl to get access to several "commands" you need.

Most problems seem to load PGstandard.pl already, but if not - you may need to  add it.

Use the commands to change between LTR and RTL text direction, and to set the language, as needed.

Changing between LTR and RTL text direction

When working in a RTL problem, the main text direction is right-to-left, but that makes trouble when you include things such as English words in a line or include math and answer input boxes in a line.

 

For example, in RTL mode, the following line of PG code

 

$BR

\( i^3 = \) \{​​​​​​​ ans_rule(5) \}​​​​​​​.

$BR

 

will show the "i^3 =" on the far right of a new line, and then put the answer input box "next" on the RTL line, so it will appear to the left of "i^3 = ". Thus the output line will look something like:

 

              [ input box ] i^3 =

 

To overcome simple order issues like this, in PGbasicmacros.pl there are special macros which you should used.


In brief - the correct approach to this is to use

$BR

\{​​​​​​​ openSpan( {​​​​​​​ "lang" => "en", "dir" => "ltr" }​​​​​​​ ) \}​​​​​​​

\( i^3 = \) \{​​​​​​​ ans_rule(5) \}​​​​​​​.

\{ closeSpan() \}

$BR

so that the line of mixed math and input boxes is processed in left-to-right mode.



To overcome order issues where you need a HTML span element which also changes the language of the included text (required by the WCAG accessibility rules for almost all changes of language) - you need to use one of the following options:

Inline direction change

Used "inside" a line / paragraph.

The openSpan() and closeSpan() commands

Sample code to include English (lang code "en") text inline inside a block of Hebrew RTL text (for plain PG):

\{​​​​​​​ openSpan( {​​​​​​​ "lang" => "en", "dir" => "ltr" }​​​​​​​ ) \}​​​​​​​

        the inline English text

\{​​​​​​​ closeSpan() \}​​​​​​​

Sample code to include Hebrew (lang code "he") text inline inside a block of English LTR text (for plain PG):

\{​​​​​​​ openSpan( {​​​​​​​ "lang" => "he", "dir" => "rtl" }​​​​​​​ ) \}​​​​​​​

        הטקסט בעברית

\{​​​​​​​ closeSpan() \}​​​​​​​

The Hebrew text should be typed in logical order, as you read it.

TODO - explain for PGML

take 2 additional optional arguments which default to being empty strings.

The second argument is a string to use in the TeX output mode (used to make the PDF files) and the third one is for preTeXt output mode (a new use case of WW). We will need to use at least the second one in the future.

FIXME - explain how to use the second argument

Block level direction change

Used for an entire block / paragraph in the other direction.

The openDiv() and closeDiv() commands

Sample code to change a block to English (lang code "en") and LTR:

\{​​​​​​​ openDiv( {​​​​​​​ "lang" => "en", "dir" => "ltr" }​​​​​​​ ) \}​​​​​​​

                the inline English text

\{​​​​​​​ closeDiv() \}​​​​​​​

Sample code to change a block to Hebrew (lang code "he") and RTL (for use inside a mostly English problem, or nested inside a LTR div inside a RTL question):

\{​​​​​​​ openDiv( {​​​​​​​ "lang" => "he", "dir" => "rtl" }​​​​​​​ ) \}​​​​​​​

        הטקסט בעברית

\{​​​​​​​ closeDiv() \}​​​​​​​

The Hebrew text should be typed in logical order, as you read it.

TODO - explain for PGML

The options hash which is the first argument of openSpan() and openDiv() also allows setting CSS class names to be included in the opening tag. That will

allow the use of CSS to add additional styling via classes defined in an external CSS file (or in some other manners to be considered). The code basically

allows alpha-numeric class names (also "-" and "_") which start with a letter, and drop anything considered invalid.

There is also an expert option to add CSS data to a HTML style element directly. The code does very little validation to style requested but will quickly

reject any setting it thinks uses invalid characters.

Examples.

\{​​​​​​​ openSpan( {​​​​​​​ "lang" => "en", "dir" => "ltr",

        "class" => "myClass3 myClass4" }​​​​​​​ ) \}​​​​​​​

    (algebraic form)

\{​​​​​​​ closeSpan() \}​​​​​​​

\{​​​​​​​ openSpan( {​​​​​​​ "lang" => "en", "dir" => "ltr",

        "allowStyle" => 1,

        "style" => "font-weight: bold; color: #0000e0;" }​​​​​​​ ) \}​​​​​​​

    (algebraic form)

\{​​​​​​​ closeSpan() \}​​​​​​​

Note: Spans can be nested inside other spans and inside Divs. Divs can be nested inside other Divs, but NOT inside Spans.

 

Warning: Do not use $BLTR and $ELTR as they only handle the change for HTML mode, and do not fix the output for LaTeX output.

For HTML mode only a fix for the "order" problem above would be by using:

$BR

$BLTR

\( i^3 = \) \{​​​​​​​ ans_rule(5) \}​​​​​​​.

$ELTR

$BR

Warning:

The use of such pairs "begin" and "end" formatting commands is somewhat dangerous, as failing to balance the pairs or to nest them in a valid manner will causes some of the following issues, depending on the particular error.

formally invalid HTML which appears properly in most browsers but violates web accessibility requirements

invalid HTML which does not appear properly

broken LaTeX syntax which will cause a failure to produce a PDF version of an assignment including the given problem.

LaTeX syntax which happens to work out "by luck" (as some out-of-order nesting issues really use the same endings, so are valid for LaTeX).

Example of an invalid nesting

   $BBOLD $BUL text to be in underlined bold $EBOLD $EUL

which will make formally invalid HTML but probably will work out fine in LaTeX. The correct form of that line is

   $BBOLD $BUL text to be in underlined bold $EUL $EBOLD

so the close tags appear in the order needed (close first what opened last).

 

 

 

Some HTML background:

 

HTML documents have a main (document level) text language and text direction.

It is possible to change the text language and text direction for almost any HTML tag.

When "paragraphs" need to have a different setting, usually the best approach is to include all sequences of such paragraphs in a enveloping block level DIV element which changes the text language and/or text direction for the contained section.

When a different setting is needed "inline" in the middle of a "block" of text whose settings are different, then the "inline" portion which needs the setting changes are enclosed in an inline span containing element of the form <span lang="x" dir="y"> other language </span>

The code changes I have made to PG allow us to control the primary text language and text direction setting of a PG problem in a manner which will set those values on a DIV element which contains the PG problem and which is added at the "webwork2" level (and not only via the main language setting of a course in WeBWorK.

 

Adding RTL support in a WW course:

In the course configuration page, change the setting on the line "Mode in which the LANG and DIR settings for a single problem are determined." to "auto::" (or some other option starting with "auto:" which may set a different default language/direction than the course language would set otherwise) and "Save the changes".

(The default value of "force::ltr" will not allow the per-problem settings to take effect.)

This course-wide setting allows the next per-problem setting to work (and other options exist to disable it).



Last modified: Friday, 23 July 2021, 9:57 AM