8
$\begingroup$

Why number sign "#" (known as hashtag symbol on social media) or at sign "@" are not consistent with the style of other letters of alphabet?

On the other hand "&" or "$" match the style of other letters.

Using default font:

Style[Partition[{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", 
    "K", "L", "M", "N", "#", "@", "O", "P", "Q", "R", "$", "&", "S", 
    "T", "U", "V", "W", "X", "Y", "Z"}, 6] // Grid, 50]

enter image description here

Using specific font family:

Style[Partition[{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", 
    "K", "L", "M", "N", "#", "@", "O", "P", "Q", "R", "$", "&", "S", 
    "T", "U", "V", "W", "X", "Y", "Z"}, 6] // Grid, 
 FontFamily -> "Lucida Console", 50]

enter image description here

Specifically I need mono-spaced font, like for example "Lucida Console" is, but the result is simply ugly.

Do you have recommendation for a nice mono-spaced font that correctly displays both "#"and "@"?

Update:

I found out Mathematica itself uses weird font for "@#": (see the distorted edges of "@", "#" has no distorted edges probably just because it is composed only of horizontal and vertical lines)

Rasterize["A # @ $ &" , ImageSize -> 600, RasterSize -> 1000]

enter image description here

Update 2:

On wikipedia number sign page they use non-italic font throughout the whole page but anyway the symbol of "#" is displayed as if it was italic. Why in mathematica we have this ugly "square like" shape and not nice "rhombus like" shape for "#"?

Update 3:

I even downloaded this beautiful roboto font and I tested it in other software and it nicely display "rhombus like" shape for "#" - Then I used this font in Mathematica and guess what? - All letters were OK but the same ugly "square shape" for "#". - What is wrong with Mathematica?

$\endgroup$
8
  • $\begingroup$ For some of the special operators Mathematica uses its own fonts. To get the plain number sign use the \[NumberSign] character. $\endgroup$
    – b3m2a1
    Oct 28, 2020 at 18:21
  • $\begingroup$ It does not change anything for me... the style of \[NumberSign] is similarly inconsistent with other letters as it is with ordinary "#". $\endgroup$ Oct 28, 2020 at 18:28
  • $\begingroup$ I don't know how to get mathematica to stop using its special fonts, but you can at least look through all the different font variation easily with something like Column[Style["Aa # @ \[NumberSign] "<>#, FontFamily -> #] & /@ $FontFamilies](or $FontFamilies[[i ;; j]] if you just want some) $\endgroup$
    – thorimur
    Oct 28, 2020 at 18:42
  • 1
    $\begingroup$ Also, I think the inconsistency appearing with both \[NumberSign] and # for Lucida Console miight siimply have to do with Lucida Console. Check out the other characters in Style["\[NumberSign]" <> StringJoin[Table[FromCharacterCode[n], {n, 32, 128}]], FontFamily -> "Lucida Console"]. Compare with, say, Times, which appears to format as expected except for Mathematica's slot symbol. Or, it could simply be that more characters are special Mathematica characters than I thought; I'm not sure. $\endgroup$
    – thorimur
    Oct 28, 2020 at 18:49
  • $\begingroup$ @thorimur I'm not sure what inconsistency you're seeing. I get a proper number sign when I run that code for both fonts? $\endgroup$
    – b3m2a1
    Oct 28, 2020 at 20:02

1 Answer 1

11
$\begingroup$

Style has a PrivateFontOptions option with suboption OperatorSubstitution. With the default setting "OperatorSubstitution" -> True, special characters such as {, (, or [ are replaced by the equivalent characters in a special Wolfram System font. With the setting "OperatorSubstitution" -> False, such characters are not replaced. For example,

Style[Partition[{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", 
    "K", "L", "M", "N", "#", "@", "O", "P", "Q", "R", "$", "&", "S", 
    "T", "U", "V", "W", "X", "Y", "Z"}, 6] // Grid, 50,
    PrivateFontOptions -> {"OperatorSubstitution" -> False}]

font grid

$\endgroup$
7
  • $\begingroup$ It does not work!!! I got the exact same result as without PrivateFontOptions -> {"OperatorSubstition" -> False}. What version of Mathematica are you using? By the way It was a very bad idea to set the Style option OperatorSubstitution to True by default. We are styling strings not the code. I do not need to style code. I need to style the output of the code. $\endgroup$ Oct 28, 2020 at 19:55
  • $\begingroup$ @azerbajdzan this does the exact same thing as using \[NumberSign]. If that's not working, the issue is in your chosen font, not on the Mathematica side. $\endgroup$
    – b3m2a1
    Oct 28, 2020 at 19:57
  • $\begingroup$ I used it without any family font... so the default font was used. $\endgroup$ Oct 28, 2020 at 19:59
  • $\begingroup$ @creidhne: You have a typo there: PrivateFontOptions -> {"OperatorSubstition" -> False}. OperatorSubstition should be OperatorSubstitution :-). I copied your code that is why it did not work. But anyway a very bad idea to set the option to True by default!!! $\endgroup$ Oct 28, 2020 at 20:04
  • $\begingroup$ Further more - you will not find any reference to PrivateFontOptions in documentation of Style. It is not listed in options of Style. Wasted half of my day unnecessary on a trivial thing... $\endgroup$ Oct 28, 2020 at 20:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.