3
$\begingroup$

I have the following code:

Remove[f];
f::usage = "f[\"message\"] prints the message";
f[message_] := Print[message];

The usage message works except the quotation marks which are not shown in the information popup.

Mathematica Wrong Usage Message

As an alternative one could use \\[OpenCurlyDoubleQuote] and \\[CloseCurlyDoubleQuote] but it is a bit long to write:

Remove[f];
f::usage = "f[\\[OpenCurlyDoubleQuote]message\\[CloseCurlyDoubleQuote]] prints the message";
f[message_] := Print[message];

With the resulting popup:

Mathematica Curly Quotes Usage Message

Do you know any way to make this shorter or get Mathematica to show the normal quotation marks?

$\endgroup$
2
  • 1
    $\begingroup$ Your first example appears to work fine in my Mathematica 12.1 on MacOS 10.15.3. $\endgroup$ – Carl Lange Mar 22 '20 at 17:54
  • $\begingroup$ @CarlLange Good to know. I’ll try it in a few days. I’m still on Mathematica 11.3 $\endgroup$ – Qbyte Mar 22 '20 at 18:32
4
$\begingroup$

Here's a way around that, making use of the very-hard-to-work-with string-embedded syntax for boxes:

Remove[f]
f[a_] := 1;
f::usage = "\!\(f[\*StyleBox[\\\"message\\\", \"TI\", ShowStringCharacters->True]]\) generates a plot of \!\(\*StyleBox[\"f\", \"TI\"]\) as a function of \!\(\*StyleBox[\"x\", \"TI\"]\) from \!\(\*SubscriptBox[StyleBox[\"x\", \"TI\"], StyleBox[\"min\", \"TI\"]]\) to \!\(\*SubscriptBox[StyleBox[\"x\", \"TI\"], StyleBox[\"max\", \"TI\"]]\).";

What did I do here? First I took the ::usage message for Plot, coped out the first line, and then made modifications of the argument structure by hand. This will look like:

enter image description here

The styling trick is that I took the first StyleBox in the message for Plot and added a ShowStringCharacters->True

One weird thing that seems to come from how Mathematica parses these templates, if you want to add spaces to the message you need to do them in a RowBox and change the formatting a bit, e.g.:

Remove[f]
f[a_] := 1;
f::usage = "\!\(f[\*StyleBox[RowBox[{\"\\\"this\", \" \", \"is\", \" \", \"a\", \" \", \"message\\\"\"}], \"TI\", ShowStringCharacters->True]]\) generates a plot of \!\(\*StyleBox[\"f\", \"TI\"]\) as a function of \!\(\*StyleBox[\"x\", \"TI\"]\) from \!\(\*SubscriptBox[StyleBox[\"x\", \"TI\"], StyleBox[\"min\", \"TI\"]]\) to \!\(\*SubscriptBox[StyleBox[\"x\", \"TI\"], StyleBox[\"max\", \"TI\"]]\).";
$\endgroup$
7
  • $\begingroup$ Thank you for your answer! Is there a tutorial how to use these boxes in general? Please, can you explain what the usage string exactly means? $\endgroup$ – Qbyte Mar 23 '20 at 0:54
  • $\begingroup$ The best tutorial is to look around at stuff on the site. In general most things that the FE renders, like Style are represented as a "box", e.g. StyleBox. The format \!\(\*<body>\) means that whatever is inside <body> will be rendered as boxes, not as a string. That's about it. $\endgroup$ – b3m2a1 Mar 23 '20 at 0:58
  • $\begingroup$ Ok thank you. The only thing which I could not find was "TI" in StringBox. How is it used/useful? $\endgroup$ – Qbyte Mar 23 '20 at 1:06
  • $\begingroup$ Ah the "TI" is an italic text style that the FE uses all over the place, but that I wouldn't worry about. The only reason I left it in was to show that I copied this stuff directly from the usage message for Plot. You can get rid of it everywhere it occurs without worry. $\endgroup$ – b3m2a1 Mar 23 '20 at 1:07
  • $\begingroup$ Thank you again. Note for others: You can reverse engineer the usage messages by printing e.g. File::usage and copy and paste it into a string literal ("") $\endgroup$ – Qbyte Mar 23 '20 at 1:22

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.