# Usage displays properly only after second call

If I have a usage message containig two-dimensional stuff (subscripts or formulas) and I call the usage, then sometimes I get an improperly formatted output enclosed in "...". Linebreaks are gone, but interestingly some formulas survive. Another ?example outputs fine.

It's hard to give an example, because it happens randomly.
Is this a known issue and and if so, is there a fix?

This is the output, when evaluated the first (bad) and second time (ok):

And this is the original usage:

FlaechenPlot::usage=
"FlaechenPlot[{\!$$\*SubscriptBox[\(f$$, $$1$$]\), \!$$\*SubscriptBox[\(f$$, $$2$$]\),...}, {x, \!$$\*SubscriptBox[\(x$$, $$min$$]\), \!$$\*SubscriptBox[\(x$$, $$max$$]\)}, {\!$$\*SubscriptBox[\(f$$, $$min$$]\), \!$$\*SubscriptBox[\(f$$, $$max$$]\)}] zeichnet die Funktionen \!$$\*SubscriptBox[\(f$$, $$i$$]\) im Bereich zwischen \!$$\*SubscriptBox[\(x$$, $$min$$]\) und \!$$\*SubscriptBox[\(x$$, $$max$$]\) und f\[ADoubleDot]rbt den Bereich zwischen \!$$\*SubscriptBox[\(f$$, $$min$$]\) und \!$$\*SubscriptBox[\(f$$, $$max$$]\) gem\[ADoubleDot]\[SZ] der gew\[ADoubleDot]hlten Option Filling.
FlaechenPlot[f, {x, \!$$\*SubscriptBox[\(x$$, $$min$$]\), \!$$\*SubscriptBox[\(x$$, $$max$$]\)}, {\!$$\*SubscriptBox[\(f$$, $$min$$]\), \!$$\*SubscriptBox[\(f$$, $$max$$]\)}] zeichnet entprechend den Bereich zwischen f und der x\[Dash]Achse.
FlaechenPlot[{\!$$\*SubscriptBox[\(f$$, $$1$$]\), \!$$\*SubscriptBox[\(f$$, $$2$$]\),...}, {x, \!$$\*SubscriptBox[\(x$$, $$min$$]\), \!$$\*SubscriptBox[\(x$$, $$max$$]\)}] zeichnet und f\[ADoubleDot]rbt das Gebiet zwischen den Kurven im Bereich von \!$$\*SubscriptBox[\(x$$, $$min$$]\) bis \!$$\*SubscriptBox[\(x$$, $$max$$]\).
FlaechenPlot[f, {x, \!$$\*SubscriptBox[\(x$$, $$min$$]\), \!$$\*SubscriptBox[\(x$$, $$max$$]\)}] f\[ADoubleDot]rbt und zeichnet das Gebiet zwischen Kurve und x\[Dash]Achse im Bereich von \!$$\*SubscriptBox[\(x$$, $$min$$]\) bis \!$$\*SubscriptBox[\(x$$, $$max$$]\).
OPTIONEN sind alle Optionen von Plot. Die Plot\[Dash]Option Filling \[Rule] Axis ist default."

-
I have seen this problem myself several times. I can confirm that this happens. –  Szabolcs Apr 5 '12 at 19:27
I'm actually seeing a similar problem with Options and SyntaxInformation for a function I've defined in a custom package. When first loading a package, all the options and inputs work, but aren't highlighted properly. Loading the package twice fixes things... –  tkott Apr 6 '12 at 16:34
Hmm, only happens to me when restarting frontend. If you restart the kernel, things are fine... –  tkott Apr 6 '12 at 17:12
Trace@?example is fascinating. So is ctrl+shift+e: the difference is the addition of extra slashes  for every one present. –  tkott Apr 6 '12 at 17:27

## 1 Answer

I think I may have found a solution to this issue, which apparently has been a problem since at least version 6. The problem occurs when a user-defined usage message has complex formatting, for example, subscripts, entered using 2D input.

During evaluation, Information[symbol] and ?symbol both call a function SystemDump\fixmessagestring, with definition

SystemDumpfixmessagestring[SystemDumps_] :=
"\""<>StringReplace[SystemDumps,{"\n"->"\\n","\\"->"\\\\","\""->"\\\""}]<>"\""


If one redefines this function, by evaluating

SystemDumpfixmessagestring[SystemDumps_] := ToString@InputForm@SystemDumps


it appears to accomplish the same task, but without screwing up user-defined usage messages.

This could be done inside the user-defined package, making the fix invisible. It's always dicey messing with internal Mathematica functions, but so far I haven't seen any negative side effects as a result of this redefinition. I would be very interested if anybody finds a reason not to make this change.

Update:

I've checked this solution in Mathematica versions 6, 7, and 8, but not version 9.

Further update:

I've checked in Mathematica 9, seems to work fine also.

Further further update:

Same problem exists in Mathematica 10, same fix works.

With the command On[SystemDumpfixmessagestring], we can have Mathematica send us a trace message whenever SystemDumpfixmessagestring is called. That will let us see if the function is ever called anywhere outside of Information[], where the redefinition might have other consequences. So far it seems that the function is just confined to Information[] and ?.

-