WeBWorK Main Forum

TikZ support in WeBWorK

TikZ support in WeBWorK

by Sean Fitzpatrick -
Number of replies: 8
In the localOverrides.conf folder I noticed the line

#####################
# Additional PG modules
#####################

#push (@{${pg}{modules}}, [qw(TikZ_Image2)]);

It seems related to this pull request:
https://github.com/openwebwork/pg/pull/292

Is this something that's working (even experimentally)?

We're working on a PreTeXt version of APEX Calculus, which has lots of exercises with TikZ images. (Some, like related rates diagrams, aren't really replaceable by pg graphs.) TikZ support would simplify some problems for us.
In reply to Sean Fitzpatrick

Re: TikZ support in WeBWorK

by Michael Gage -
It's being worked on experimentally. Actually a lot of work was done a year or more ago but the initial developer graduated or something and finishing it wasn't a priority compared to some other things. I looked at it a week ago and was hoping to finish it -- or at least figure out what was left out -- but I got distracted by other things -- including finishing webwork-2.15 -- particularly the documentation. (Any help, particularly with documentation, will be appreciated -- hint, hint :-) -- talk to Tani Wallach.)

I'll be out of town for next week, but I'd like to get back to exploring tikZ after that. I _think_ that the main points to finish up are making it work for hardcopy in addition to html output (where I think it already works). Also adding svg capabilities. (the old pull request for SVG is out of date although it may have some useful items in it). Neither of these should be that hard, they just require some uninterrupted blocks of time. :-) and I guess encouragement that it will be used and should be moved up the priority stack.


In reply to Sean Fitzpatrick

Re: TikZ support in WeBWorK

by Michael Gage -
You should be able to pull a copy of that pull request onto a local version
running the develop branch (the webwork-2.15 branch might also work) and then load and run the pg problems in

pg/t/tikz_test/

and see what you get. No guarantees -- there has been no recent testing.


In reply to Michael Gage

Re: TikZ support in WeBWorK

by Sean Fitzpatrick -
Thanks. I'll add this to my to-do list. (This is supposed to shrink during summer but keeps growing...)
Based on past experience with problems bundled with static images, I'd like to avoid creating them if possible. (Making a new version to adjust notation and then discovering that you have to track down the image file is no fun.)

I know Alex was looking at Jim Fowler's "tikzjax" which is a cool toy.

But let's try this first and see if we can make it work.
In reply to Sean Fitzpatrick

Re: TikZ support in WeBWorK

by Sean Fitzpatrick -
Initial attempt unsuccessful. I'm trying on 2.15.
In /opt/webwork/pg I did `git fetch origin pull/292/head:tikztest`
and switched to this branch.

After uncommenting the line I referenced above I tried loading the two test problems but they're throwing errors like so:
  • ERRORS in rendering problem: 1 |ULmath/tikz_test1.pg| ERRORS from evaluating PG file:
    Undefined subroutine &WeBWorK::PG::IO::pdflatexCommand called at [PG]/lib/TikZ_Image2.pm line 31
  • Died within TikZ_Image2::new called at line 35 of (eval 3350)
  • from within main::tikz_graph called at line 54 of (eval 3350)
I suspect I've missed a step. Or maybe it's not working on 2.15.
In reply to Sean Fitzpatrick

Re: TikZ support in WeBWorK

by Michael Gage -
The pdflatexCommand should be at:

https://github.com/openwebwork/pg/pull/292/files#diff-0d03a671b8940542da4473be8390bf53R290

Check the contents of pg/lib/WeBWorK/PG/IO.pm and see if the pdflatexCommand is there.


I'm not a git expert so your git command might have worked correctly but I would have done it like this:

git remote add mgage https://github.com/mgage/pg

(this adds mgage as a remote)

git fetch mgage

git pull mgage tikz

(as with all things git -- there are usually many ways to do this)

Recheck the contents of pg/lib/WeBWorK/PG/IO.pm and see if the pdflatexCommand is there.

The other thing we always forget (all of us) is to restart the apache server. The .pm files are only read when a child starts up -- so changing the file won't change any behavior until a new child is created to serve requests.

Report back. If none of these ideas work we'll delve deeper. Thanks for working on this.


In reply to Michael Gage

Re: TikZ support in WeBWorK

by Sean Fitzpatrick -
Apparently this was another one of those times where doing apache2ctl --graceful wasn't enough. Rebooting got me further, but still issues.

Now the questions display, but no image. Content of the first problem now displays as:

Print hi
working_dir = /opt/webwork/courses/Math-2580A-Spring-2019/templates/tikz_build
file_name = potato2
destination_path = /opt/webwork/courses/Math-2580A-Spring-2019/templates/setUndefined_Set/potato2
path = ;
alias =

image = setmaker

svg = setmaker


pdflatex /usr/bin/pdflatex --shell-escape
convert
copy /bin/cp

end this


Warning messages:

Empty string used as input into the function alias

------
The file name did not have an extension.
Every file name used as an argument to alias must have an extension.
The permissable extensions are .jpg, .pdf, .gif, .png, .mpg, .mp4, .ogg, .webm and .html .



Warning messages

  • Can't open [TMPL]/tikz_build/hardcopy.tex for writing
  • print() on closed filehandle $fh at [PG]/lib/TikZ_Image2.pm line 133
  • print() on closed filehandle $fh at [PG]/lib/TikZ_Image2.pm line 134
  • print() on closed filehandle $fh at [PG]/lib/TikZ_Image2.pm line 135
  • render: /usr/bin/pdflatex --shell-escape
  • file [TMPL]/tikz_build/hardcopy.pdf was not created

So the pg file is looking for the working directory tikz_build, but it's not there. Adding this folder under templates, we get a new error message:

  • render: /usr/bin/pdflatex --shell-escape
  • file [TMPL]/tikz_build/hardcopy.pdf was not created
Hardcopy.tex is being written.
If I pull the .tex file off the server I can compile it.

So something is going wrong with pdflatex -- maybe a permissions issue?


In reply to Sean Fitzpatrick

Re: TikZ support in WeBWorK

by Michael Gage -
This is starting to sound familiar. I remember now that automatically building build_tikz when it didn't exist wasn't implemented yet.

Here is what I get below.

The permissions on gage_course/templates/tikz_build are
drwxrwxr-x 12 _www admin 408 Dec 28 2016 ./

(_www is the apache server).

This is a start. I don't think this is where tikz_build protective directo ry
should go. What I planned to do next was to imitate what is done in
webwork2/lib/WeBWorK/ContentGenerator/Hardcopy.pm to
1. create a containing directory (with a uniqID) in something like pg/DATA
2. dump files into it including the tikz code,
3. run pdflatex on it,
4. move the result to somewhere useful
5. then remove the containing directory to clean things up.
6. Also make sure it gets indexed properly by alias() ) At the moment alias() may not be indexing pdf files and svg files but we can fix that as well. They should be treated much like html pages -- they don't need any converting - these just need to aliases and stored.

Does that make sense? Does it sound reasonable?


In reply to Michael Gage

Re: TikZ support in WeBWorK

by Michael Gage -
I've moved this discussion to the issues page on
github: https://github.com/openwebwork/pg/issues/418

and the pull request: https://github.com/openwebwork/pg/pull/292