PREP 2015 Question Authoring - Archived

Side by side displays for Image and text.

Side by side displays for Image and text.

by tim Payer -
Number of replies: 6
This is a similar post to the one that Gary Church asked in regard to graphics.

Is there a way to display a graph or an image side by side along with its accompanying text? This would be preferable to an isolated graph or image.

The reply in Gary Church's case was that the topic would be covered in the Workshop 4 presentation but I do not recall that the topic was addressed. (We covered a lot in the last segment!)

I did see the link at the maa site for:


But this code had problems when i tried to run it, plus it seems as if it is written primarily in PG vs PGML. 

Is there not currently a way to join text and image together with PGML?

Thanks so much illuminating on this topic...

Tim
In reply to tim Payer

Re: Side by side displays for Image and text.

by Davide Cervone -
The pieces where discussed, but an explicit example wasn't given. Plus the connection to PGML is not ideal.

The main tool for this is ColumnTable() from the unionTables.pl macro file. This takes two strings and makes a side-by-side display from them on screen, and a one-atop-the-other display in hardcopy.

The difficulty is that you need to produce the two strings, and you want the text string to be formatted using PGML. That means you need to capture the PGML output. That can be done using PGML::Format(), but we didn't talk about that.

Here is one solution:


DOCUMENT();

loadMacros(
  "PGstandard.pl",
  "PGML.pl",
  "unionTables.pl",
  "PGcourse.pl"
);

loadMacros("PGML.pl","unionTables.pl");

$column1 = PGML::Format(<<END_PGML);
A list:
* Item 1 is a longer one than the next
* Item 2

>> Centered <<
END_PGML

$column2 = image("great-wave.png",width=>400, tex_size=>800);

TEXT(ColumnTable($column1,$column2));

ENDDOCUMENT();

Here, $column1 is text that is formatted using PGML, but saved into a string. $column2 is the string that will insert the image into the page.

The TEXT() command inserts the ColumnTable() into the page, using the two halves. I have attached a screen shot of the result.

Attachment sid-by-side.jpg
In reply to Davide Cervone

Re: Side by side displays for Image and text.

by Paul Pearson -
Hi Tim and Davide,

In the busyness of everything (presenting in the PREP workshop and directing 3 student researchers), I forgot to cover this type of problem in workshop 4 as I promised.  Sorry about that.

Davide's PGML example is definitely the right way to do it, and I am glad that I now know how to use PGML::Format() to construct blocks of text that will be displayed later.  Thanks for the PGML example, Davide!

I would like to point out that the example  FortLewis/Authoring/Templates/Precalc/DynamicGraph1_PGML.pg does work, but since it uses triple star substitution [ ]***, it requires a copy of the most recent PGML.pl file in order to work.  I have attached a copy of PGML.pl that should make things work if you want to go the old-fashioned route.  I would encourage you to use Davide's template for any problems you write, though.

Best regards,

Paul Pearson


In reply to Paul Pearson

Re: Side by side displays for Image and text.

by tim Payer -
Wow! Thank you so much Paul!

I will adapt this to my current problems.

Tim
In reply to tim Payer

Re: Side by side displays for Image and text.

by tim Payer -
Thank you Davide, the unionTable macro and PGML example really helped.

I have a few questions regarding the side by side placement of text and images with the columns.

1.)  How can I include a caption or credit on column 2 for the image?
My experimentation to produce a caption base on previous examples did not succeed.

2.)  The columns work great and returned some control back to the "tex_size=>" specifier. When not working with the columns (under the unionTable macro) the "tex_size=>" specifier had no affect on changing the size of the display. The image display seemed to be defaulting to a full size regardless of the number used in the "tex_size=>" specifier. And yes I triple checked the dimensions of the image file.

Here is an example of the image code I used (without a column display):

>>[@ image("Dragonfly_BryonRoberts.png", width=>727, height=>620, tex_size=>100) @]* Bryon_Roberts_Copy_Right_2007.

3.) Just some observations: I noticed that there is no height dimension requested for images within a column? Also parameters need their brackets removed or they will display in the text column, correct? 

Without columns:  [`R = [$R]`]
Inside columns:   [`R = $R`]


Thank you for all the help!

My code is below if this helps with question 1.

Tim


DOCUMENT();

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

loadMacros("PGML.pl","unionTables.pl");

# Webwork Workshop 2015  for Payer, Homework 1, Practice:
# Exercises for Survival and Renewal applications: pg460, #34


Context("Numeric")->flags->set(
tolerance => 1.0,
tolType => 'absolute',
);
Context()->variables->add(t=>"Real");
$po = Real(random(1000, 9000,1000));
$R =Real(random(8, 40,1));
$T =Real(random(5, 14,1));
$ex =Real(random(0.01, 0.15,0.01));
$a =Real(random(5, 14,1));
$c =Real(random(5, 14,1));
$cb =Real(random(5, 14,1));
$g =Formula("($a/($cb))");
$g1 =Formula("exp(-$ex*$T)*($po+($R/$ex)*(exp($ex*$T)-1))");
$g2 =floor($g1);


$column1 = PGML::Format(<<END_PGML);
During the summer months a dragonfly population at the Musky marsh follows a survival and renewal equation with an initial population of [`P_0 = $po`] dragonflies, a renewal rate of [`R = $R`] , and a survival function of [``S(t) = e^{-$ex t}``] at time [`t`] in weeks. Find the population of dragonflies at [`T = $T`] weeks.  
*Note!*  Round your decimal answer down to the number of complete dragonflies.

 
 [______________________]{$g2}  


END_PGML
$column2 =image("Dragonfly_BryonRoberts.png", width=>756, tex_size=>800);


TEXT(ColumnTable($column1,$column2));

ENDDOCUMENT();

In reply to tim Payer

Re: Side by side displays for Image and text.

by Paul Pearson -
  • An image caption:  Use $BCENTER and $ECENTER to center the results.  Use $BR to get a line break after the image.  After the line break, use a quoted string for the caption.  Put it all together by using the Perl concatenation operator . (that is, the concatenation operator is a period).

    $column2 =$BCENTER.image("smile.png", width=>400, height=>400, tex_size=>800).$BR."Image caption".$ECENTER;

  • The tex_size argument:  The width and height arguments to image should both be specified and control the size of the image when displayed in html output mode.  Whether you use a ColumnTable or not, you should always specify width and height.  The tex_size argument to image controls the size of the image when displayed in pdf hardcopy mode.

  • PGML command substitution: The way that PGML processes the its arguments is to (1) be aware of whether it is trying to produce html or pdf output and (2) make command substitutions for various values, so that [` `] interprets things using MathJax or images in html output mode and as latex math in pdf output mode.  The [` $R `] versus [` [$R] `] difference arises from when and how the arguments get interpreted and how much explicit instruction is necessary to get them interpreted in the correct way.  Yes, there is a difference between PGML::Format() and BEGIN_PGML, and this might be one of the most obvious differences.  [` $R `] versus [` [$R] `] has nothing to do with ColumnTable().

  • A complete working example is available in the homework set "Dragonfly Column Table Example" in the 2015 PREP Problem Authoring webwork course.


In reply to Paul Pearson

Re: Side by side displays for Image and text.

by tim Payer -
Thank you Paul!

I will check it out!

I truly appreciate all the detailed explanations....!

Tim