## Forum archive 2000-2006

### Edgar Fisher - Pictures in single column hardcopy

by Arnold Pizer -
Number of replies: 0
 Pictures in single column hardcopy topic started 7/7/2005; 2:08:14 PMlast post 7/8/2005; 10:41:49 PM
 Edgar Fisher - Pictures in single column hardcopy  7/7/2005; 2:08:14 PM (reads: 917, responses: 4) In some of the graph theory problems, I use the TEXT($BEGIN_ONE_COLUMN); construct to have the hardcopy look as much like the on screen version as possible, which is a 2x2 grid of pictures. However, each picture is on a single line by itself. I have played with the size of the displayed picture in the hardcopy and that does not have an affect. Is this a feature or a bug? Is there anyway around it? Edgar Fisher <| Post or View Comments |>  Davide P. Cervone - Re: Pictures in single column hardcopy 7/7/2005; 5:40:38 PM (reads: 999, responses: 0) I faced this same issue with many of the multivariable problems that I developed. You might find the image_match_list that is part of unionChoice.pl in the union_problib/macros directory to be useful in these situations rather than one-column mode. See for example setMVlevelsets/levels-1/levels-1.pg, setMVlevelsets/levels-6/levels6.pg, and setMVtraces/trace-1a.pg for examples. These all rely on the unionImage.pl macro file, which implements a somewhat more flexable image command. It is also possible to use ColumnTable()to help improve TeX output. This sets up two blocks of text, which are set side-by-side in two columns in the HTML pages, but vertically in one column in the TeX output. See examples in setMVtraces/trace-5a.pg and setMVtraces/trace-5a.pg. Davide <| Post or View Comments |>  Davide P. Cervone - Re: Pictures in single column hardcopy 7/7/2005; 5:51:02 PM (reads: 1023, responses: 0) PS, one thing that helps is to use a different size for the TeX images from the ones shown in the web pages. This is easy to do with the unionImage.pl file. Davide <| Post or View Comments |>  Edgar Fisher - Re: Pictures in single column hardcopy 7/7/2005; 9:36:57 PM (reads: 1023, responses: 1) I do have a different size for the TeX images, but that doesn't seem to iaffect it. I also tried the emage_match_list, but I couldn't figure out all of the macro files I needed to include to make it work. <| Post or View Comments |>  Davide P. Cervone - Re: Pictures in single column hardcopy 7/8/2005; 10:41:49 PM (reads: 1225, responses: 0) Well, I took one of your sample Graph Theory problems (IsConnected.pg) and modified it to show you some ways to handle this. Since the image() command is in PGnauGraphics.pl, you can't change the size of the TeX image from within your .pg file using the NAU macros, so I give you an example that uses image_match_list and one that calls Image() directly. These call on the Union College macros, so you will need to have those files in your macros path. Since you can now add directories to the search path for macro files, you can have your system locate these files without having to add them to pg/macros or your course macros directory. The first solution is the following:  DOCUMENT(); loadMacros( "PGstandard.pl", "PGnauGraphtheory.pl", "PGunion.pl", "imageChoice.pl", ); TEXT(beginproblem()); @y=("Which graphs of the graphs are connected?"); @n=(); @yn=(); foreach$i (0..3) { $size = random(5,8,1); # number of vertices$offset = random(0, 25 - $size, 1);$graph = GRgraph_size_random($size,0.43);$labels = join('',@ALPHABET[$offset..($offset+$size-1)]);$pic[$i] = GRpic_graph_labels($graph,$labels);$name = "Graph ".$ALPHABET[$i]; $c = GRncomponents_graph($graph); if ($c == 1) {push @y,$name} else {push @n,$name} push @yn,$name; } $cmc = new_checkbox_multiple_choice();$cmc->{ImageOptions} = [ border => 1, # size of border around images columns => 2, # number of images per row separation => 30, # space between columns vseparation => 10, # space between rows size => $pic[0]->size, # size of pictures tex_size => 400, # size for images in TeX file ];$cmc->qa(@y); $cmc->extra(@n);$cmc->makeLast(@yn); BEGIN_TEXT \{img_print_a($cmc,@pic)\}$PAR \{$cmc->print_q\}$BR \{$cmc->print_a\} END_TEXT ANS(checkbox_cmp($cmc->correct_ans)); $showPartialCorrectAnswers = 1; ENDDOCUMENT(); Here, I have streamlined your creation of the data for the match list a little. I use @ALPHABET, since it is already predefined and there is no need to recreate it. I also use letters for labeling the graphs, since that's how image_match_list will mark them. Then I add ImageOptions to the $cmc object to control img_print_a. Since img_print_a is really meant to work with a different type of list, I call it by hand rather than use it as a replacement for print_q, which would have provided it with the wrong parameters. Finally, I print the checkboxes and install the answer checker. The array of images is shown as a 2x2 grid, which will be shown that way also in the TeX file. The size of the images is looked up from one of the graphs, and the TeX size is set appropriately for a 2x2 array in the ImageOptions field of $cmc. (The TeX size is given as a percent of the column width times 10, so 400 represents 40% of the column width, which lets two images fit nicely across the column.) Personally, I think that having the checkboxes right under the graphs would be a better idea (rather than as a list at the bottom of the page), so I offer this alternative approach were we create the table by hand and set up the checkboxes ourselves rather than through one of the canned list routines.  DOCUMENT(); loadMacros( "PGstandard.pl", "PGnauGraphtheory.pl", "PGunion.pl", ); TEXT(beginproblem());$ans = ''; foreach $i (0..3) {$size = random(5,8,1); # number of vertices $offset = random(0, 25 -$size, 1); $graph = GRgraph_size_random($size,0.43); $labels = join('',@ALPHABET[$offset..$offset+$size-1]); $pic[$i] = GRpic_graph_labels($graph,$labels); $pic[$i] = Image($pic[$i],size=>$pic[$i]->size,tex_size=>400,border=>0); $letter =$ALPHABET[$i];$name = "Graph $letter";$rule[$i] = ($i? NAMED_ANS_CHECKBOX_OPTION('checks',$letter,$name): NAMED_ANS_CHECKBOX('checks',$letter,$name)); # TeX-mode uses \item, but we're not in a list, so remove it # and put a fake box in front $rule[$i] =~ s/\item/$$\bigcirc$$\ / if $displayMode eq 'TeX';$ans .= $letter if GRncomponents_graph($graph) == 1; } BEGIN_TEXT $BCENTER Select the graphs below that are${BBOLD}connected${EBOLD}:$ECENTER $PAR \{ BeginTable(spacing=>5). AlignedRow([$pic[0], $pic[1]]). AlignedRow([$rule[0],$rule[1]]). TableSpace(16,8). AlignedRow([$pic[2], $pic[3]]). AlignedRow([$rule[2],$rule[3]]). EndTable() \} END_TEXT NAMED_ANS(checks => checkbox_cmp($ans)); $showPartialCorrectAnswers = 1; ENDDOCUMENT(); Here, in the loop, we create a graph and then call Image() to get the proper HTML (or TeX) for it right away. Since the pictures already include a border, we set that to 0 in the Image() call. Next, we create the checkbox. The first one (when $i == 0 is the one that gets tied to the answer checker, so we call NAMED_ANS_CHECKBOX for that, and all others get NAMED_ANS_CHECKBOX_OPTION with the same name so they get tied to the same answer checker. (We take advantage of the fact that checkbox_cmp already knows how to collect the extra answers together and form the combined result that becomes the student's answer.) The one tricky part is that, in TeX mode, these calls produce \item calls, which we don't want, as these check boxes will not be an in an enumerated list of any kind. So we do a substitution to replace the \item by some TeX code to produce a big circle (to represent the check box) instead. Note that we take advantage of the fact that WW automatically doubles all backslashes in the .pg file, so in this substitution, the backslashes are already escaped. (I.e., the REAL substitution is s/\\item/\$$\\bigcirc\$$\\ /, so don't be fooled.) At the end of the loop, we add the graph's label to the correct answer if it is one of the ones supposed to be checked. Finally, we produce a table that has pictures with the associated checkboes below in a 2x2 array. We add a little space between the rows (16 pixels in HTML mode and 8 points in TeX mode), and we're done. Hope one of these turns out the be useful to you. Davide <| Post or View Comments |>