1
$\begingroup$

I wrote a function called CPlot for complex plotting which is supposed to act a lot like Plot in its input format, but ever since the new versions of Mathematica (was originally written for 7) it gives an error whenever I move the cursor within the [] brackets of an expression like

CPlot[z,{z,-1-I,1+I}]

saying

During evaluation of In[136]:=
  StringMatchQ::strse: String or list of strings expected at position 1 in
  StringMatchQ[$Failed,CPlot*]. >>

2/27/15 09:25:14 
  The string '"

(yes, the last string is cut off after the quote.) After some cleaning up to make a MWE, CPlot is defined via:

Unprotect[CPlot];Clear[CPlot];Remove[CPlot];
CPlot::usage="\!\(CPlot[\*\nStyleBox[\"f\", \"TI\"], {\*\nStyleBox[\"z\", \"TI\"], \*SubscriptBox[\nStyleBox[\"z\", \"TI\"], \nStyleBox[\"min\", \"TI\"]], \*SubscriptBox[\nStyleBox[\"z\", \"TI\"], \nStyleBox[\"max\", \"TI\"]]}]\) generates a complex colored plot of \!\(\*\nStyleBox[\"f\", \"TI\"]\) as a function of the real and imaginary parts of \!\(\*\nStyleBox[\"z\", \"TI\"]\) from \!\(Re[\*SubscriptBox[\nStyleBox[\"z\", \"TI\"], \nStyleBox[\"min\", \"TI\"]]]\) to \!\(Re[\*SubscriptBox[\nStyleBox[\"z\", \"TI\"], \nStyleBox[\"max\", \"TI\"]]]\) along the \!\(\*StyleBox[\"x\", \"TI\"]\)-axis and from \!\(Im[\*SubscriptBox[\nStyleBox[\"z\", \"TI\"], \nStyleBox[\"min\", \"TI\"]]]\) to \!\(Im[\*SubscriptBox[\nStyleBox[\"z\", \"TI\"], \nStyleBox[\"max\", \"TI\"]]]\) along the \!\(\*StyleBox[\"y\", \"TI\"]\)-axis.";
CPlot[f_,x:{z_,min_,max_},opts___] := Null;
SyntaxInformation[CPlot]={"ArgumentsPattern"->{_,{_,_,_},OptionsPattern[]},"LocalVariables"->{"Plot",{2}}};
Attributes[CPlot]={HoldAll,Protected};

In particular, the CPlot::usage line appears to be essential to reproducing the bug.

Update: I have confirmed that the cause of the error is the presence of \n characters in the usage string, and have resolved the issue simply by removing them, which does not affect the presentation since they are in the code part of the string. If anyone could explain why \n causes this weird bug when it shows up after a \* style box token, I will gladly accept. (Can anyone confirm that the above code causes the bug I've described on their installations, as it does on mine?)

$\endgroup$
  • $\begingroup$ Do you maybe have SuggestionBar enabled? $\endgroup$ – Kuba Feb 27 '15 at 15:33
  • $\begingroup$ @Kuba I do, but it doesn't seem to pop up or anything here; usually it only shows after I evaluate a cell - here I'm literally just moving the caret around in the text area between the brackets, and the only work it should be doing is possibly setting the syntax highlighting for matching brackets. $\endgroup$ – Mario Carneiro Feb 27 '15 at 15:39
  • $\begingroup$ Note: If you trim down the usage text, the error goes away. So probably there is something malformed in there, even though it looks fine if you test it with ? CPlot. $\endgroup$ – Mario Carneiro Feb 27 '15 at 17:50

Your Answer

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

Browse other questions tagged or ask your own question.