# Disable templates for user defined functions with usages

It appears that fixing the template system is low on Wolfram Research's priority list. For my package, I have defined Usage info for my functions involving lots of formatting, which causes the template system to run amuck. Since this looks very unprofessional, I want to prevent the front-end from trying to render templates for these functions. How do I disable the templates only for the functions in the package I am writing (in v9 and v10)?

Here is an example (version 9.0.1):

function::usage = "function[\!$$\*StyleBox[\"x\", \"TI\"]$$] carries out some complicated algorithm.

Possible options: AlgorithmComplexity, SimplifiedOutput"


and here is what the template looks like:

• It would be extremely helpful if you could give a fake function definition which shows what you mean by causes the template system to run amok. – halirutan Oct 5 '14 at 0:50
• @halirutan I have added an example. – QuantumDot Oct 6 '14 at 11:42
• Have you seen and tested my answer? – halirutan Oct 9 '14 at 8:36

I think the problem (bug?) has been fixed in version 10.0.2. For example:

thisismytestfunction::usage =
Row[{
Style[thisismytestfunction, Red, Bold][Style[x, Italic]],
"carries out some complicated algorithm.\n",
Style["Possible options:", Bold, 16],
"AlgorithmComplexity, SimplifiedOutput"
}, " "] // ToString[#, StandardForm] &;


This doesn't really answer your question, but it is worth noting that the internal Macros package does make it easier to define nicely-formatting usage messages:

Needs["Macros"];
SetUsage[mymap,
"mymap[f$, {e$1,e$2,$$}] yields {f[e1],f[e2],$$}.", "mymap[f$, list$, n$] maps f$over list$ at level n$." ];  Which gives a usage that looks like this: Unfortunately this still doesn't render nicely in the popup usage thing. I may fix that for 10.0.2. • Is Macros' a version 10 feature? I can't seem to load it with my v9.0.1 copy. – QuantumDot Oct 8 '14 at 13:44 • I got an email from Wolfram saying that 10.0.2 is out; so, is it fixed now? – QuantumDot Dec 12 '14 at 22:42 • What would be the way to fix rendering in popups? Does it require changes in the popup rendering code (which users cannot do) or does it just require the usage message to be written in a certain way? Related. Is there documentation on how usage messages should be written to play nicely with auto-completion? – Szabolcs Oct 6 '15 at 10:53 • This appears to still fail for the pop-up as of v10.3.1. – Emilio Pisanty May 4 '16 at 21:43 Unfortunately, this will not help you because although it fixes the issue for your usage messages, I would not recommend to include this hack in your package. I found out about all this when I was investigating in usage messages for the IntelliJ Plugin. Very interesting is the file FileNames["FEKernelInit.tr", {$InstallationDirectory}, Infinity]


because it shows some routines how usage templates are automatically extracted from (user defined) usage messages. Following these lines, you see that there are functions like getTemplateFromUsage which calls things like makePlainText etc.

You can try these things for your own function:

function::usage = "function[\!$$\*StyleBox[\"x\", \"TI\"]$$] carries out some complicated...";
FEgetTemplateFromUsage[function::usage, "function"]


and you see that the StyleBox is stripped from your usage exactly as it is in the screenshot of your question. Going a bit further in this file, you will find a function named FEFTU and this looks like it is providing the information for what is shown in the template tooltip you see. The last line of this function is

MathLinkCallFrontEnd@
FrontEndTemplateTooltipPacket[FrontEndInputNotebook[], sn, name, template, usageStrings]


When you debug this function by unprotecting it and looking at the values of the parameters, you see that in usageStrings all formatting is preserved. Since this seems to be the problem, you could simply redefine this function and make your usage messages plain text for the tooltip.

Unprotect[FEFTU];
FEFTU[sn_, name_] :=
Block[{usage, usageStrings, template},
usage = ToExpression[name <> "::usage"];
If[! StringQ[usage], Return[]];
usageStrings = StringSplit[usage, Except["\*" | ","] ~~ "\n"];
template = FEgetTemplateFromUsage[#, name] & /@ usageStrings;
template =
If[template === $Failed, Return[], FEmakePlainText[#] & /@ template]; template = If[template ===$Failed, Return[],
FEreparseBoxStructure[#, name] & /@ template];
template = GridBox /@ List /@ List /@ template;
Globaltmp = {sn, name, template, usageStrings};
MathLinkCallFrontEnd@
FrontEndTemplateTooltipPacket[FrontEndInputNotebook[], sn, name,
template, FEmakePlainText /@ usageStrings]]
Protect[FEFTU]


After this, the tooltip looks fine

Please note, that you have to do this after you Quit[] the kernel, since those template tooltips seem to be cached. Therefore, (1) quit your kernel, (2) redefine FEFTU, (3) define and try you function.

• I am new to templates, what does "\!(*" accomplish before StyleBox, and where is this usage documented? – John McGee Nov 20 '15 at 19:49