Differing fonts between Octave and other programs with the same fontname

Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Differing fonts between Octave and other programs with the same fontname

BGreen
For consistency with the body text of my work, I would like all my plots to use the font Latin Modern. I downloaded and installed the font, and have been able to use it in Octave.by calling e.g.
title('Text (hello, 123) \alpha')
set(gca,"fontname","Latin Modern Math","fontsize",20)
The font changes - it is no longer the default Octave font. However, it's not the font I'm looking for - it doesn't match the default LaTeX font. Strangely, when I use the same font in another program such as MS Word, I get the desired font. Can anyone explain what is going on here, and suggest how to address it?

On a side note, how does one actually use math mode with $? If I call something like
title('$Text (hello, 123) \alpha$')
the $ are interpreted literally. The documentation mentions they can be used in Octave, so I thought to try them and see how it affected my problem, but I couldn't get them to work and the section of the documentation on the text interpreter property didn't explain beyond a passing mention.

- Brett Green



Octave text.png (26K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Differing fonts between Octave and other programs with the same fontname

Dmitri A. Sergatskov
On Sun, Dec 1, 2019 at 3:37 PM Brett Green <[hidden email]> wrote:
>
> For consistency with the body text of my work, I would like all my plots to use the font Latin Modern. I downloaded and installed the font, and have been able to use it in Octave.by calling e.g.
> title('Text (hello, 123) \alpha')
> set(gca,"fontname","Latin Modern Math","fontsize",20)
> The font changes - it is no longer the default Octave font. However, it's not the font I'm looking for - it doesn't match the default LaTeX font. Strangely, when I use the same font in another program such as MS Word, I get the desired font. Can anyone explain what is going on here, and suggest how to address it?

Did you restart octave after you instaleed the font?
If you print it to svg file, which font do you get in there?

>
> On a side note, how does one actually use math mode with $? If I call something like
> title('$Text (hello, 123) \alpha$')
> the $ are interpreted literally. The documentation mentions they can be used in Octave, so I thought to try them and see how it affected my problem, but I couldn't get them to work and the section of the documentation on the text interpreter property didn't explain beyond a passing mention.

I think this has been fixed lately in dev. At least your code works on
my computer.

(Output of
print "t1.svg"
and
print "t1.pdf" "-svgconvert"

are attached.)

Dmitri.
--



t1.svg (8K) Download Attachment
t1.pdf (9K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Differing fonts between Octave and other programs with the same fontname

BGreen
Did you restart octave after you instaleed the font?
If you print it to svg file, which font do you get in there?

Yes - in fact, I actually first installed the font some months ago, and just hadn't gotten around to addressing this issue.

The font is the same when printed to an SVG with print. In fact, it displays with the unusual font in the plot window, in addition to the saved figures.

The most mysterious part is that a non-default font is being used at all. I have no idea what font is actually being used.




t1.svg (8K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Differing fonts between Octave and other programs with the same fontname

Pantxo
In reply to this post by BGreen
BGreen wrote

> For consistency with the body text of my work, I would like all my plots
> to
> use the font Latin Modern. I downloaded and installed the font, and have
> been able to use it in Octave.by calling e.g.
> title('Text (hello, 123) \alpha')
> set(gca,"fontname","Latin Modern Math","fontsize",20)
> The font changes - it is no longer the default Octave font. However, it's
> not the font I'm looking for - it doesn't match the default LaTeX font.
> Strangely, when I use the same font in another program such as MS Word, I
> get the desired font. Can anyone explain what is going on here, and
> suggest
> how to address it?
>
> On a side note, how does one actually use math mode with $? If I call
> something like
> title('$Text (hello, 123) \alpha$')
> the $ are interpreted literally. The documentation mentions they can be
> used in Octave, so I thought to try them and see how it affected my
> problem, but I couldn't get them to work and the section of the
> documentation on the text interpreter property didn't explain beyond a
> passing mention.
>
> - Brett Green
>
>
>
>
> Octave text.png (26K)
> &lt;https://octave.1599824.n4.nabble.com/attachment/4694774/0/Octave%20text.png&gt;

This works for me on linux, both onscreen and in printout (for raster format
or pdf using the -svgconvert option). Octave uses fontconfig to find font
files in your system, and eventually fallback to a suitable font. You can
see what font file is chosen using the fc-match command, e.g.:

fontname = "Latin Modern Math";
fcmatch_binary = "fc-match"; # Add .exe on Windows
system (sprintf ('%s "%s"', fcmatch_binary, fontname))

On my system this returns

  latinmodern-math.otf: "Latin Modern Math" "Regular"

If you just installed a new font, you may need to run "fc-cache" in order to
update the font cache and then restart Octave:
 
  system ("fc-cache") # Add .exe on Windows

HTH,

Pantxo





--
Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: Differing fonts between Octave and other programs with the same fontname

Pantxo
In reply to this post by BGreen
BGreen wrote

> On a side note, how does one actually use math mode with $? If I call
> something like
> title('$Text (hello, 123) \alpha$')
> the $ are interpreted literally. The documentation mentions they can be
> used in Octave, so I thought to try them and see how it affected my
> problem, but I couldn't get them to work and the section of the
> documentation on the text interpreter property didn't explain beyond a
> passing mention.
>
> - Brett Green
>
>
>
>
> Octave text.png (26K)
> &lt;https://octave.1599824.n4.nabble.com/attachment/4694774/0/Octave%20text.png&gt;

For the side note, Octave doesn't have a "latex" interpreter and thus does
not interpret "$" math environment. The only way to have LaTeX fonts and
math typesetting (in printout only) is to use pdflatex(standalone) or
epslatex formats, e.g.:

  title ('$Text (hello, 123) \alpha$', "interpreter", "latex"); # "latex" is
the same as "none"
  print -dpdflatexstandalone foo.tex
  system "pdflatex foo.tex"
  open foo.pdf

HTH,

Pantxo



--
Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: Differing fonts between Octave and other programs with the same fontname

BGreen
In reply to this post by Pantxo
This works for me on linux, both onscreen and in printout (for raster format
or pdf using the -svgconvert option). Octave uses fontconfig to find font
files in your system, and eventually fallback to a suitable font. You can
see what font file is chosen using the fc-match command, e.g.:

fontname = "Latin Modern Math";
fcmatch_binary = "fc-match"; # Add .exe on Windows
system (sprintf ('%s "%s"', fcmatch_binary, fontname))

On my system this returns

  latinmodern-math.otf: "Latin Modern Math" "Regular"

If you just installed a new font, you may need to run "fc-cache" in order to
update the font cache and then restart Octave:

  system ("fc-cache") # Add .exe on Windows

HTH,

Pantxo

--
Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html

Thank you, that gives some insight. I'm still having trouble, unforunately.

First off, I'm running Octave 5.1.0 on Windows 10 - I should have included that earlier.

Apparently, it's been using Cambria Math:

>> fontname = "Latin Modern Math";
>> fcmatch_binary = "fc-match"; # Add .exe on Windows
>> system (sprintf ('%s "%s"', fcmatch_binary, fontname))
cambria.ttc: "Cambria Math" "Regular"
ans = 0
>> system ("fc-cache") # Add .exe on Windows
ans = 0

Running your code and restarting Octave doesn't change the result; it still picks out Cambria Math.

I thought perhaps it was the install location. Most of my fonts are in
C:\Windows\Fonts
Two that I've downloaded, including Latin Modern Math, are in
C:\Users\Brett\AppData\Local\Microsoft\Windows\Fonts

I tried reinstalling by double-clicking the OTF file for Latin Modern Math in AppData, at which point Windows asserted it was not a valid font and automatically deleted it. I re-downloaded and reinstalled it. The new font installed the AppData location as well, and also was determined to be invalid and deleted by Windows.

I'm wondering if Octave only searched C:\Windows\Fonts for fonts and hence didn't find them. I do not know.in what way they could be invalid, as MS Word was still able to use any the font just fine before it was deleted, after it was reinstalled, and again, even though Windows would go on do identify the font as invalid and delete it.

For what it's worth, I've tried calling .
>> fcmatch_binary = "fc-match"; # Add .exe on Windows
>> system (sprintf ('%s "%s"', fcmatch_binary, fontname))
after changing fontname to see how that affects things. If it's anything but "Latin Modern Math", the font that is returned is Verdana. I think Cambria Math was the last font I used (successfully) in Octave before trying Latin Modern Math.

Finally... as seen in the attached image, whatever font was used isn't actually Cambria Math or Verdana either.



Octave text, Cambria Math and Verdana.png (29K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Differing fonts between Octave and other programs with the same fontname

Pantxo
BGreen wrote
> I'm wondering if Octave only searched C:\Windows\Fonts for fonts and hence
> didn't find them. I do not know.in what way they could be invalid, as MS
> Word was still able to use any the font just fine before it was deleted,
> after it was reinstalled, and again, even though Windows would go on do
> identify the font as invalid and delete it.
>
>
> Octave text, Cambria Math and Verdana.png (29K)
> &lt;https://octave.1599824.n4.nabble.com/attachment/4694781/0/Octave%20text%2C%20Cambria%20Math%20and%20Verdana.png&gt;

You may want to look at what font files are listed after "system
('fc-list.exe')". This will give you a hint on what font files are actually
found by fontconfig. As for including fonts in non standard location, you
can try

  fontdir = 'C:\Users\Brett\AppData\Local\Microsoft\Windows\Fonts';
  system (sprintf ('fc-cache.exe %s', fontdir));

This should scan the provided directory.

Pantxo





--
Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: Differing fonts between Octave and other programs with the same fontname

BGreen
On Mon, Dec 2, 2019 at 5:26 AM Pantxo <[hidden email]> wrote:

You may want to look at what font files are listed after "system
('fc-list.exe')". This will give you a hint on what font files are actually
found by fontconfig. As for including fonts in non standard location, you
can try

  fontdir = 'C:\Users\Brett\AppData\Local\Microsoft\Windows\Fonts';
  system (sprintf ('fc-cache.exe %s', fontdir));

This should scan the provided directory.

Pantxo


--
Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html

For whatever reason, after running the commands you suggested and redownloading and reinstalling the font and restarting Octave (each of which I had already done several times) several days ago, Octave just started using the font properly. I wish I could say what helped, but it looks like that will be a mystery. For now, I'm just glad to have the font working! Thank you for your help.