Page 1 of 1

Field functions in math expressions

Posted: Mon Nov 15, 2010 10:05 pm
by walter55
Hi all,
I am a math teacher and would like to personalize math tests to prevent excessive copying ;) . So I tried to use serial letter functionality and it works fine as long as no math formula is involved.
Is there a way to use field variables within formulas?

Thanks for help,

Walter.

Re: Field functions in math expressions

Posted: Mon Nov 15, 2010 11:50 pm
by acknak
Sorry, no. The fields only work in Writer text. In fact, because OOo implements formulas as separate embedded objects, there is no communication between the formulas and the parent document at all. Even settings like fonts or text size do not carry over.

Can you explain exactly what you want to do? Maybe there's some other approach.

You mean that one test paper might have
   y = x + 2; solve for y when x is 3
where another paper has
   m = n + 2; solve for m when n is 3
?

Re: Field functions in math expressions

Posted: Tue Nov 16, 2010 3:22 pm
by walter55
Sad that no. We are doing some more advanced math, so something like

Code: Select all

 int from -5 to 10 {{x^b} over {1-x^a} dx} =
with some changes to the polynom in the denominator and to some constants are my target.

Of course there is a way to write equations in single lines, but this is not the professional approach the students would expect.
(copying others isn't professional either, but we all know it is happening.)

Walter

Re: Field functions in math expressions

Posted: Tue Nov 16, 2010 4:18 pm
by acknak
I think you will just need to make up different test papers. I can't think of any way to automate variations in formulas.

I suppose you could use a master/sub-document to make it a bit easier to create the variations. Each problem could be a sub-document, and you could easily make a master that included different variations and/or in a different order.

Re: Field functions in math expressions

Posted: Wed Nov 17, 2010 2:13 am
by RGB
Well, there is a possibility:
1- On Tools -> Customize -> Keyboard tab set a shortcut to insert a Math object
2- Define a text variable with value like x^2 + 1 on Insert -> Fields -> Others -> Variable tab
3- Select the variable and press the shortcut you set on 1...

Of course, you will need to change the variable value before you convert it into a Math object.

Re: Field functions in math expressions

Posted: Sun Nov 21, 2010 10:33 am
by walter55
Thank you for your tipps.
I think I will look into including text blocks rather than single values. This is not what I was heading for, but it is a step into the right direction. I really would prefer having the variables in calc to allow also the creation of the solutions paper as serial letter using the same set of variables..... Regards Walter.

Re: Field functions in math expressions

Posted: Sun Nov 21, 2010 1:35 pm
by Zizi64
I try to show another way, with Basic macro:
Math_basic.odt
(11.49 KiB) Downloaded 453 times
The example file contains Basic macro. You need to enable the macro running option.

The example macro based on Andrew Pitonyak's macro examples.
http://www.pitonyak.org/oo.php

Re: Field functions in math expressions

Posted: Sun Nov 21, 2010 7:19 pm
by Zizi64
There is an another code snippet, to modify equation named "object1".

Code: Select all

Sub my_ModifyEquation

	dim oDoc as object
	dim My_math as object
	dim My_formula, a_str, b_str as string
	
	odoc = Thiscomponent
	'define the range of constants (a and b) and convert them to string format
	a_str = CStr(Int((5 * Rnd)+2))
	b_str = CStr(Int((5 * Rnd)+2))
	
	'set the formula string:
	My_formula = "int from -5 to 10 {{x^" & b_str & "} over {1-x^" & a_str & "} dx} ={}"

	My_Math = oDoc.EmbeddedObjects.GetByName("Object1")
	My_Math.model.formula = My_formula

end sub

Re: Field functions in math expressions

Posted: Tue Nov 23, 2010 5:05 pm
by walter55
Thank you very much for providing the basic macros.

I now do understand how to create / modify a math expression inside a document.
This is very helpful, as it shows a way to create the content of a math expression from a macro. (creation seems to be a little complicated, but the modification example looks pretty and straight forward.)

I did not fully try to implement it, and am already stuck again:
--> Is there a way to get a macro executed right after every new dataset is loaded into the seriel letter fields and before the print is created? (I would like to still use the serial letter mechanics, as there are also standard text fields changed.)
--> How do I get the content of the field variables rather than the "definition" when I try to read the content?

regards,

Walter.