# Antialiased text in manipulate constantly re-evaluated, ignores TrackedSymbols

I am trying to display antialiased text (using the ImportString[ExportString[]] method shown here) but inside a manipulate so that the text can be changed interactively. I have found a way to do this, but problem is that the function is constantly being updated, even when the tracked symbol "i" is unchanging. A similar problem is outlined here.

Below are simplified versions of my code to:

Manipulate[
Style[i,86,Bold,GrayLevel[0.4],FontFamily->"Verdana"],
{{i,36890},0,99999,1},TrackedSymbols:>{i}
]

toCurves[a_]:=ImportString[ExportString[a,"PDF"],"PDF"][[1,1]];
toGraphics[a_,b_]:=Graphics[{a},Method->{"ShrinkWrap"->True},ImageSize->b];

Manipulate[
toGraphics[toCurves[Style[i,Bold,GrayLevel[0.4],FontFamily->"Verdana"]],{{Automatic},{64}}],
{{i,36890},0,99999,1},TrackedSymbols:>{i}
]


The first manipulate displays the text with jaggies and works as expected.

The second manipulate uses the custom functions toCurves and toGraphics and displays the text without jaggies but is constantly being updated.

The cause of the problem appears to be the ExportString function, but it could also be the ImportString function.

Edit 1:

I found a way to stop the manipulate from constantly updating using the If function:

style[a_] := Style[a, Bold, GrayLevel[0.4], FontFamily -> "Verdana"]
toCurves[a_] := ImportString[ExportString[a, "PDF"], "PDF"][[1, 1]];
toGraphics[a_] :=
Graphics[{a}, Method -> {"ShrinkWrap" -> True},
ImageSize -> {{Automatic}, {64}}];

Manipulate[
If[
i != j,
j = i; k = toGraphics[toCurves[style[i]]],
k
],
{{i, 36890}, 0, 99999, 1},
Initialization :> {j = ""},
TrackedSymbols :> {i}
]


I modified the toGraphics function and added a custom style function to reduce some of the clutter in the code. It isn't as elegant as I'd like it to be, but it works.

• Excellent...........! – eldo Jul 8 '14 at 18:59

The use of ExportString and/or ImportString, which in fact just use Export and Import on temporary files, seems to trigger dynamic updates. Front-End options get changed and perhaps some variables, and it must be that some of these are tracked. It's difficult to know whether they ought to be or not. In any case, a side effect is the continual updating of the Manipulate.

Now one trick I've learned over the years, and I'm not sure from where, is that tickling system parameters in the actual Dynamic updating code -- I mean, in the second argument to Dynamic -- often (or always) does not trigger another update. Such is the case here. In V10, we have access in Manipulate to the second argument to Dynamic through the TrackingFunction option.

Manipulate[
g,
{{i, 36890}, 0, 99999, 1,
TrackingFunction -> (
i = #; g = toGraphics[toCurves[Style[i, Bold, GrayLevel[0.4],
FontFamily -> "Verdana"]], {{Automatic}, {64}}]; &)},
{g, ControlType -> None},
TrackedSymbols :> {g},
Initialization :> (
g = toGraphics[toCurves[Style[i, Bold, GrayLevel[0.4],
FontFamily -> "Verdana"]], {{Automatic}, {64}}];)]