WeBWorK Problems

How to add inline HTML elements to a PG file? (div)

Re: How to add inline HTML elements to a PG file? (div)

by Davide Cervone -
Number of replies: 0
It is certainly possible to do this, but one of the things to keep in mind is what you want to appear in the hardcopy versions of the problem. If the graph is generated by javascript, that will not appear in the printed output, and many students (at least here) prefer to work off line and then enter their answers. While I certainly support doing innovative things on-line, it is important to keep in mind the other views of the problem that may be produced as well.

That being said, the way to do what you want is through the MODES() macro, which allows you to provide different text to be used in the various viewing modes. For example,

    TEXT(MODES(
        HTML => "This is only on screen",
        TeX  => "This is only in hardcopy",
    ));
will produce different output on screen from in hardcopy. So you can use something like
    TEXT(MODES(
        HTML => '<div>...</div>',
        TeX => '[ You need to log into WeBWorK to see the
                    graph for this problem ]',
    ));
would do what you want. You can do something like
    TEXT(MODES(
        HTML => '<script ...>...</script>',
        TeX => "",
     ));
to insert javascript into the page, though there are other methods as well (there is a macro that inserts javascript into the document <HEAD>, but I don't remember its name).

There are more possible choices for the modes (like HTML_dpng for image mode, HTML_tth for formatted text mode, and so on if you need to do something specific in one of these modes, but HTML will cover all of these. Hope that helps out.

Davide