3
$\begingroup$

Message knows how to convert an expression (taken as an argument) into a string before it is spliced into an actual message:

If I run the following in my terminal and in the front end

temp::mystr = "The symbol: `1`";
Message[temp::mystr, Pi];

the symbol Pi is rendered differently:

enter image description here

enter image description here

I would like to directly enter an expression into the message string so that it renders appropriately depending on where it is issued: (in the terminal -> OutputForm, or in the front end notebook -> StandardForm). temp::mystr2 = "The symbol: \!\(Pi\)"; doesn't render correctly in the front end, while temp::mystr2 = "The symbol: \[Pi]"; renders incorrectly in the terminal. Does anyone know how to do it correctly [I need a solution that works in Mathematica 8 through 11]?

$\endgroup$
  • $\begingroup$ Something to try on both cases: MeijerG::usage. $\endgroup$ – J. M.'s technical difficulties Aug 14 '17 at 1:59
  • $\begingroup$ Looking for existing examples that work I tried Pi::usage and found that it is simply "Pi is \[Pi], ..." and prints like that in the terminal. I'm not sure this is possible within a String alone. It's easy elsewhere using Format but I cannot see how to apply that to messages. $\endgroup$ – Mr.Wizard Aug 14 '17 at 2:06
  • $\begingroup$ @J.M. I tried that already, but that is not instructive because the boxes are already hard coded into usage messages. $\endgroup$ – QuantumDot Aug 14 '17 at 2:09
2
$\begingroup$

First of all, you need to define what you mean by "rendering correctly", and (b) what is "a terminal". But I'm guessing your issue really has little to do with typesetting as such.

If "The symbol: \!\(Pi\)", or even the string "\[Pi]", doesn't render with the glyph of U+03C0, then your problem is the value of $CharacterEncoding is for a character set (perhaps "WindowsANSI", more formally known as Windows Code Page 1252) that doesn't include that character. So, you'll need to (i) change the value of $CharacterEncoding which does include it, say, UTF-8, (ii) use a terminal font which includes that glyph, and (iii) make sure that the character encoding of your terminal is consistent with (i) and (ii). (My understanding of the Windows console is that (ii) automatically determines (iii), though I'm hardly an expert in the Windows API. In most Unix consoles these are independent settings.)

Now, as for the symbol Pi, it has an OutputForm formatting rule which is to format as Pi rather than \[Pi] (a decision which not doubt dates to V1, when the latter would have been almost universally useless). If you want override how that appears as an argument to a message, you'll need to use $MessagePrePrint or a custom handler in the code issueing the message to tweak its appearance.

$\endgroup$
1
$\begingroup$

Evaluating the form

Message[temp::mystr, "\:03c0"];

will give the same output

temp::mystr: The symbol: π

in both a notebook and when running a kernel in Terminal.

Edit

This is in response to @Mr.Wizard comment.

I don't understand what you are saying. On my system it has nothing to do with Message. Here is a Terminal window capture.

terminal

I am running OS X, so a terminal session is talking to a Mathematica kernel through Free-BSD Unix. Perhaps it is system dependent, but there seems to be no problem on a Unix-based system.

Edit 2

Also please note that for me "The symbol: \[Pi]" does render correctly in Terminal.

terminal_2

$\endgroup$
  • $\begingroup$ This doesn't work for me, and I don't interpret the question in the same way. In the terminal I get The symbol: \[Pi] verbatim (with the escaped [Pi] not the glyph π). But I think QD wants the specified behavior without specific template insertion with Message. $\endgroup$ – Mr.Wizard Aug 14 '17 at 5:34
  • 1
    $\begingroup$ I read the OP as wanting the appropriate version of 2D output (OutputForm[] for terminals and StandardForm[] for the usual front end) already embedded in the message itself, as opposed to being inserted there via the second and other arguments of Message[]. $\endgroup$ – J. M.'s technical difficulties Aug 14 '17 at 6:01

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.