1
$\begingroup$

I have the next code:

u = {{{1, 2}, {3, 4}, {5, 6}}, {{7, 8}, {9, 10}, {11,12}}}
u = MapAt[Style[#, Blue] &, u, {{1, 2, 1}, {1, 2, 2}}]
u[[1, 1, 2]]/u[[1, 2, 2]]

I want to do operation with elements of differents colours. When I change the colour to one element of the list and after I divide by other element which I have not change the colour, Mathematica not calculate. I don´t know why happens it.

$\endgroup$
  • $\begingroup$ How can mathematica know how to divide elements in Style[***] form? You'll have to write your own rules to process these operations. Also, what you want the result to be? a 1/2 styled blue or with no style? $\endgroup$ – Wjx Sep 3 '16 at 9:26
  • $\begingroup$ I want that the result be with styled. In my example, u have possition [[1,2,1]] and [[1,2,2]] blue. I want only change the colour and after I can manipulated list (divide, etc...). $\endgroup$ – Manu Sep 3 '16 at 16:44
  • $\begingroup$ will my solution solve your problem? $\endgroup$ – Wjx Sep 3 '16 at 23:37
  • $\begingroup$ @Wjx, your solution work very well, thank so much, but there are some cases that not work and I don´t why. When I have these list, your solution not work: a={1014.24, 4807.98} and b={\!(* StyleBox["947.290786227471", StripOnInput->False, LineColor->RGBColor[0, 0, 1], FrontFaceColor->RGBColor[0, 0, 1], GraphicsColor->RGBColor[0, 0, 1], FontColor->RGBColor[0, 0, 1], $CellContextBackFaceColor -> RGBColor[0, 0, 1]]), 4385.53}. Thanks for your help. $\endgroup$ – Manu Sep 5 '16 at 13:18
  • $\begingroup$ thumbs.subefotos.com/aeda92dc7e423820166a6d785e5f101fo.jpg $\endgroup$ – Manu Sep 5 '16 at 13:38
2
$\begingroup$

Check this:

myOperation[func_][a_, b_] := 
 If[Length@a == Length@b != 0 && Head[a] =!= Style, 
  MapThread[myOperation[func], {a, b}], func[a, b]]
myDivide[x_, y_] := x/y;
myDivide[Style[x_, c_], y_] := Style[x/y, c];
myDivide[x_, Style[y_, c_]] := Style[x/y, c];
myDivide[Style[x_, c1_], Style[y_, c2_]] := 
 Style[x/y, Blend[{c1, c2}]]

myOperation[
  myDivide] @@ {{{1, 2}, {Style[3, Red], Style[4, Blue]}, {5, 
    6}}, {{7, 8}, {Style[9, Blue], 10}, {Style[11, Cyan], 12}}}

I first created myOperation to apply a function into a nested list, then create myDivide function to implement my form of divide with styling. Will the result be satisfying?

result

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.