I have been developing Mathematica code to interpret LaTeX code, extract formulas and apply various Mathematica operations (e.g. Simplify, FullSimplify, etc).
In doing so, I found what it seems to be a bug in Mathematica (v. 10.1 and v. 10.2, MAC OS X Yosemite), which I have already reported. However, I would like to ask two things here:
If it is really a bug (the issue arises ONLY evaluating the two expressions below FAZ followed by ATEST followed by FAZ - each of them seems to be working well and they do not depend upon each other).
Is there any simple workaround (see note in the end)
The following is a simplified portion of my code that shows this issue.
I have defined a function
FAZwhich takes a pure functionfand computes various quantities associated withf-- for example, simplifies, differentiates, etcFAZ := Function[{f}, Print @ Manipulate[ ToExpression[form] @ ToExpression[action] @ (f[x]), {action, {"Simplify", "FullSimplify"}}, {form, {"StandardForm", "TraditionalForm"}}]; Print @ Manipulate[{k, D[f[x], {x, k}]}, {k, 1, 10, 1}]; Print @ Manipulate[{k, D[InverseFunction[f][x], {x, k}]}, {k, 1, 10, 1}];];I have also defined another function
ATESTthat takes a latex string, converts it into Mathematica codeATEST := Function[{ML}, Zb := Function[frm, Manipulate[ ToExpression[frm] @ ToExpression[action] @ ToExpression[#, TeXForm], {{action, "Simplify", "Operation"}, {"Simplify", "FullSimplify"}}] &]; Eq3 := Function[LTXX, Manipulate[ Grid[Transpose[{LTXX, Map[Zb[form], LTXX]}], Frame -> All], {{form, "StandardForm", "Display form"}, {"StandardForm", "TraditionalForm", "TeXForm", "MathMLForm"}}]]; Print[Eq3[ML]];];Now here is a sample input
FAZ[# - 1 &]; MLTX = {"\n\\sum_{i=1}^n 2^i\n", "\n\t\\label{test}\n\t\\sum_{i=1}^n 2^i=2 (2^n-1)\n"}; ATEST[MLTX];and so far so good --
FAZtakes the functionx - 1and creates an interactive object that can simplify the function, differentiate it various times, etcThe problem is that if I call
FAZagain with the same argument:FAZ[# - 1 &];I get
"The kernel is not responding to a dynamic evaluation"
Regarding the workaround -- it seems that the problem lies in using a string as the argument
{form, {"StandardForm", "TraditionalForm"}}and then usingToExpression[form]to convert this string into a function. This makes coding easier as you can use manipulate objects with options that are strings that get converted into Mathematica functionsI have tried other ways to overcome this problem, but I always have the same issue, for example:
FAZ2 := DynamicModule[{}, Print @ Manipulate[ form@ action@ (#[x]), {action, {Simplify, FullSimplify}}, {form, {StandardForm, TraditionalForm}} ]; Print @ Manipulate[{k, D[#[x], {x, k}]}, {k, 1, 10, 1}]; Print @ Manipulate[{k, D[InverseFunction[#][x], {x, k}]}, {k, 1, 10, 1}]; ] &;
and (ATEST2 with MLTX defined as before)
ATEST2 := DynamicModule[{},
Manipulate[
Grid[Transpose[{MLTX,
Map[Manipulate[
frm2@actn@ ToExpression[#, TeXForm], {actn, {Simplify,
FullSimplify}}] &, MLTX]}], Frame -> All],
{frm2, {StandardForm, TraditionalForm, TeXForm, MathMLForm}}]
];
ATESTseems to entirely independent ofFAZ. So why is it needed to demonstrate your problem? DoesFAZbehave properly if the two calls to it do not have a call toATESTbetween them? – m_goldberg Nov 27 '15 at 15:19SpliceorFileTemplatefor piping LaTeX through Mma http://reference.wolfram.com/language/tutorial/SplicingWolframLanguageOutputIntoExternalFiles.html http://reference.wolfram.com/language/ref/FileTemplate.html – evanb Nov 28 '15 at 18:07