[LON-CAPA-users] More elegant conditional text?

lon-capa-users@mail.lon-capa.org lon-capa-users@mail.lon-capa.org
Thu, 07 Feb 2008 18:51:14 -0500


Todd,

I think the silver bullet for which you seek is &xmlparse.

This function will take a string and parse it into whichever form for which it
is being rendered. I need to use it a lot when I was inserting long sentencing
with chemistry format into variables, and then using the variables in
the foil text blocks.

$array[1] = &xmlparse("<m>$p=mv$</m>");

for example (untested).

Let me know how this works for you. I'm sure others will chime in soon!

Mark

Quoting Todd Ruskell <truskell@mines.edu>:

> Hello master problem coders,
> 
> I'm wondering if there's a more elegant way to do something like the
> following:
> 
> <startouttext />
> A bunch of text
> <block condition="$smallChoice == 1">
>  <m>$\mathrm{KE}_1=(1/2)Mv^2$</m>
> </block>
> <block condition="$smallChoice == 2">
> <m>$p=mv$</m>
> </block>
> More text.
> <endouttext />
> 
> What I'd like to do is more like this:
> 
> <startouttext />
> A bunch of text $array[$smallChoice] More text
> <endouttext />
> 
> The difficulty for me is the math tags.  I haven't found the magic
> incantation to embed the math tags in perl variables such that it
> actually gets passed through the parser before being displayed.
> 
> I also explored randomlist, but it appears as though that is pretty
> much
> limited to choosing between different <part> or <response> tags,
> rather
> than simple text.
> 
> Can someone enlighten me?
> 
> Thanks,
> 
> Todd
> -- 
> Dr. Todd Ruskell
> Senior Lecturer, Department of Physics       Office:  Meyer Hall 326
> Colorado School of Mines                     Phone: 303-384-2080
> 1523 Illinois Street                         Fax: 303-273-3919
> Golden, CO 80401
> _______________________________________________
> LON-CAPA-users mailing list
> LON-CAPA-users@mail.lon-capa.org
> http://mail.lon-capa.org/mailman/listinfo/lon-capa-users
>