How can I get an angstrom symbol in Octave?

classic Classic list List threaded Threaded
17 messages Options
Reply | Threaded
Open this post in threaded view
|

How can I get an angstrom symbol in Octave?

BGreen
The title says it all. I've tried copying and pasting the character (the obvious attempt) with no success, and have read several solutions using TeX interpreters such as this but those don't seem to work for me. Looking at the documentation < https://octave.org/doc/interpreter/Use-of-the-interpreter-Property.html#XREFinterpreterusage > I can't even get the degree symbol to show up - trying both of the following

>> title("\deg","interpreter","tex")
>> title("$\deg$","interpreter","tex")

just gives me titles of "deg" and "$deg$", respectively. I'm running 5.1.0 on Windows 10.

- Brett Green


Reply | Threaded
Open this post in threaded view
|

Re: How can I get an angstrom symbol in Octave?

Dmitri A. Sergatskov
On Sat, Sep 21, 2019 at 7:39 PM Brett Green <[hidden email]> wrote:
>
> The title says it all. I've tried copying and pasting the character (the obvious attempt) with no success, and have read several solutions using TeX interpreters such as this but those don't seem to work for me. Looking at the documentation < https://octave.org/doc/interpreter/Use-of-the-interpreter-Property.html#XREFinterpreterusage > I can't even get the degree symbol to show up - trying both of the following
>
> >> title("\deg","interpreter","tex")
> >> title("$\deg$","interpreter","tex")
>
> just gives me titles of "deg" and "$deg$", respectively. I'm running 5.1.0 on Windows 10.

Cut and paste seems to work on linux (at least on my machine).  If it
is an issue with the
deficient Windows rterminal, you can try to write an m- file and
execute it instead of entering
it iinteeractively.
Also with TeX you should do single quotes and no "$" signs:
title('\deg ',"interpreter","tex")

should work (it soes on my machine).


>
> - Brett Green
>

Dmitri.
--


Reply | Threaded
Open this post in threaded view
|

Re: How can I get an angstrom symbol in Octave?

BGreen
Using single quotes (without $) was all I needed to change to get the degree symbol to appear. Thank you!

Now I'm wondering why using single vs. double quotes makes a difference... what's important, though, is that it works.

...Actually, I may have written that prematurely. Although I can get the degree symbol, I still can't get the angstrom symbol. \AA and \r{A} were suggested but neither worked. Any ideas why not?

- Brett Green


On Sat, Sep 21, 2019 at 8:57 PM Dmitri A. Sergatskov <[hidden email]> wrote:
On Sat, Sep 21, 2019 at 7:39 PM Brett Green <[hidden email]> wrote:
>
> The title says it all. I've tried copying and pasting the character (the obvious attempt) with no success, and have read several solutions using TeX interpreters such as this but those don't seem to work for me. Looking at the documentation < https://octave.org/doc/interpreter/Use-of-the-interpreter-Property.html#XREFinterpreterusage > I can't even get the degree symbol to show up - trying both of the following
>
> >> title("\deg","interpreter","tex")
> >> title("$\deg$","interpreter","tex")
>
> just gives me titles of "deg" and "$deg$", respectively. I'm running 5.1.0 on Windows 10.

Cut and paste seems to work on linux (at least on my machine).  If it
is an issue with the
deficient Windows rterminal, you can try to write an m- file and
execute it instead of entering
it iinteeractively.
Also with TeX you should do single quotes and no "$" signs:
title('\deg ',"interpreter","tex")

should work (it soes on my machine).


>
> - Brett Green
>

Dmitri.
--


Reply | Threaded
Open this post in threaded view
|

Re: How can I get an angstrom symbol in Octave?

Dmitri A. Sergatskov
On Sat, Sep 21, 2019 at 9:07 PM Brett Green <[hidden email]> wrote:
>
> Using single quotes (without $) was all I needed to change to get the degree symbol to appear. Thank you!
>
> Now I'm wondering why using single vs. double quotes makes a difference... what's important, though, is that it works.
>
> ...Actually, I may have written that prematurely. Although I can get the degree symbol, I still can't get the angstrom symbol. \AA and \r{A} were suggested but neither worked. Any ideas why not?
>
> - Brett Green
>

Octave has just a tiny subset of TeX.
I think you should figure out why cat-n-paste did not work.
Was it actual pasting that did not work, or paste worked but symbols did not
show up on the plot screen? (In that case may be the default font on
Windows does not
have Å. Try Cambria instead.

I can do something like:

octave:1> plot(1:10)
octave:2> title ("Å", "fontname", "cambria", "fontsize", 24)
octave:3> xlabel("დრო", "fontname", "noto georgian")
octave:4> ylabel("Nhiệt độ", "fontname", "cambria")

And get the attached plot.

Dmitri.
--



plot_fonts.png (29K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: How can I get an angstrom symbol in Octave?

Doug Stewart-4
In reply to this post by BGreen


On Sat, Sep 21, 2019 at 10:07 PM Brett Green <[hidden email]> wrote:
Using single quotes (without $) was all I needed to change to get the degree symbol to appear. Thank you!

Now I'm wondering why using single vs. double quotes makes a difference... what's important, though, is that it works.

...Actually, I may have written that prematurely. Although I can get the degree symbol, I still can't get the angstrom symbol. \AA and \r{A} were suggested but neither worked. Any ideas why not?

- Brett Green


After a lot of trials I found this that works

set (0, "defaultaxesfontname", "Helvetica")
 set (0, "defaultaxesfontsize", 28)
 set (0, "defaulttextfontname", "Helvetica")
 set (0, "defaulttextfontsize", 28)
 
 z=[char(195) char(133)]

 title(z)
 xlabel(z)

I am not sure if you need all of this or just part of it.




 

On Sat, Sep 21, 2019 at 8:57 PM Dmitri A. Sergatskov <[hidden email]> wrote:
On Sat, Sep 21, 2019 at 7:39 PM Brett Green <[hidden email]> wrote:
>
> The title says it all. I've tried copying and pasting the character (the obvious attempt) with no success, and have read several solutions using TeX interpreters such as this but those don't seem to work for me. Looking at the documentation < https://octave.org/doc/interpreter/Use-of-the-interpreter-Property.html#XREFinterpreterusage > I can't even get the degree symbol to show up - trying both of the following
>
> >> title("\deg","interpreter","tex")
> >> title("$\deg$","interpreter","tex")
>
> just gives me titles of "deg" and "$deg$", respectively. I'm running 5.1.0 on Windows 10.

Cut and paste seems to work on linux (at least on my machine).  If it
is an issue with the
deficient Windows rterminal, you can try to write an m- file and
execute it instead of entering
it iinteeractively.
Also with TeX you should do single quotes and no "$" signs:
title('\deg ',"interpreter","tex")

should work (it soes on my machine).


>
> - Brett Green
>

Dmitri.
--



--
DASCertificate for 206392



chs
Reply | Threaded
Open this post in threaded view
|

Re: How can I get an angstrom symbol in Octave?

chs
In reply to this post by BGreen
On 2019-09-22 04:06, Brett Green wrote:
> Using single quotes (without $) was all I needed to change to get the
> degree symbol to appear. Thank you!
>
> Now I'm wondering why using single vs. double quotes makes a
> difference... what's important, though, is that it works.
>
> ...Actually, I may have written that prematurely. Although I can get the
> degree symbol, I still can't get the angstrom symbol. \AA and \r{A} were
> suggested but neither worked. Any ideas why not?

These both work in MATLAB, so this sounds like an Octave bug.

BTW, it's also worth mentioning that in LaTeX, \deg is actually an operator:

\deg:
macro:->\mathop {\operator@font deg}\nolimits

And this is what MATLAB gives you for '$\deg A$'.



Reply | Threaded
Open this post in threaded view
|

Re: How can I get an angstrom symbol in Octave?

mmuetzel
In reply to this post by BGreen
On Sat, 21 Sep 2019 22:06:59 Brett Green wrote:
> Using single quotes (without $) was all I needed to change to get the
> degree symbol to appear. Thank you!
>
> Now I'm wondering why using single vs. double quotes makes a difference...
> what's important, though, is that it works.
>
Single quoted strings take the string passed "as is". Double quoted strings
process backslash sequences. E.g. "\n" is a line feed, but '\n' is the two
characters '\' and 'n'.

> ...Actually, I may have written that prematurely. Although I can get the
> degree symbol, I still can't get the angstrom symbol. \AA and \r{A} were
> suggested but neither worked. Any ideas why not?
>
Octave 5.1 sometimes has issues "remembering" the character encoding. It
should be working if you specify the character encoding for .m files
explicitly. E.g.:
__mfile_encoding__ ("iso-8859-1");
clear functions

This has already been fixed for the next major release Octave 6.

Markus


Reply | Threaded
Open this post in threaded view
|

Re: How can I get an angstrom symbol in Octave?

BGreen
In reply to this post by chs
Thank you all very much!

Doug, your solution worked for me. This is a great relief - thank you!

Dmitri, thank you for the informative explanation and good questions. When I cut and paste "Å" into Octave, nothing appears in the terminal. If I run from a .m file with the character "Å" in the title, it instead prints "Ã..." where "Å" should be.

Doug, how did you find out that [char(195) char(133)] was the combination you needed? According to the ASCII table I looked up, those two are ├ à. I realized I also need an em dash which would be ASCII character 196, but Octave crashes whenever I try to plot something with char(196) in it.

This isn't as important because I can work around it (since the regular minus is only too small if I use e^{-qd} instead of exp(-qd) - i.e. by writing things without subscripting) but would be nice if there's a simple explanation. If it's not an easy fix, though, don't trouble yourself with it. I appreciate all that you've done already!

- Brett Green


On Sun, Sep 22, 2019 at 4:26 AM chs <[hidden email]> wrote:
On 2019-09-22 04:06, Brett Green wrote:
> Using single quotes (without $) was all I needed to change to get the
> degree symbol to appear. Thank you!
>
> Now I'm wondering why using single vs. double quotes makes a
> difference... what's important, though, is that it works.
>
> ...Actually, I may have written that prematurely. Although I can get the
> degree symbol, I still can't get the angstrom symbol. \AA and \r{A} were
> suggested but neither worked. Any ideas why not?

These both work in MATLAB, so this sounds like an Octave bug.

BTW, it's also worth mentioning that in LaTeX, \deg is actually an operator:

\deg:
macro:->\mathop {\operator@font deg}\nolimits

And this is what MATLAB gives you for '$\deg A$'.



Reply | Threaded
Open this post in threaded view
|

Re: How can I get an angstrom symbol in Octave?

BGreen
In reply to this post by mmuetzel
Ah, I see - that will be helpful for simplifying my code in the future. So far, I'd just been using \\ when I wanted the character \ in a string. I tried this:

__mfile_encoding__ ("iso-8859-1");
clear functions
title('\AA',"interpreter","tex")

and had the same result as before. Doug was able to find a solution in another thread, though. Thank you!

- Brett Green


On Sun, Sep 22, 2019 at 5:57 AM "Markus Mützel" <[hidden email]> wrote:
On Sat, 21 Sep 2019 22:06:59 Brett Green wrote:
> Using single quotes (without $) was all I needed to change to get the
> degree symbol to appear. Thank you!
>
> Now I'm wondering why using single vs. double quotes makes a difference...
> what's important, though, is that it works.
>
Single quoted strings take the string passed "as is". Double quoted strings
process backslash sequences. E.g. "\n" is a line feed, but '\n' is the two
characters '\' and 'n'.

> ...Actually, I may have written that prematurely. Although I can get the
> degree symbol, I still can't get the angstrom symbol. \AA and \r{A} were
> suggested but neither worked. Any ideas why not?
>
Octave 5.1 sometimes has issues "remembering" the character encoding. It
should be working if you specify the character encoding for .m files
explicitly. E.g.:
__mfile_encoding__ ("iso-8859-1");
clear functions

This has already been fixed for the next major release Octave 6.

Markus


Reply | Threaded
Open this post in threaded view
|

Re: How can I get an angstrom symbol in Octave?

Dmitri A. Sergatskov
On Sun, Sep 22, 2019 at 11:36 AM Brett Green <[hidden email]> wrote:

>
> Ah, I see - that will be helpful for simplifying my code in the future. So far, I'd just been using \\ when I wanted the character \ in a string. I tried this:
>
> __mfile_encoding__ ("iso-8859-1");
> clear functions
> title('\AA',"interpreter","tex")
>
> and had the same result as before. Doug was able to find a solution in another thread, though. Thank you!
>
> - Brett Green

You are mixing two different approaches to this problem.
__mfile_encoding__ should help with cut-n-paste
approach (when you put non-ASCII characters in your m-file).

Dmitri.
--


Reply | Threaded
Open this post in threaded view
|

Re: How can I get an angstrom symbol in Octave?

Doug Stewart-4
In reply to this post by BGreen


On Sun, Sep 22, 2019 at 12:35 PM Brett Green <[hidden email]> wrote:
Thank you all very much!

Doug, your solution worked for me. This is a great relief - thank you!

Dmitri, thank you for the informative explanation and good questions. When I cut and paste "Å" into Octave, nothing appears in the terminal. If I run from a .m file with the character "Å" in the title, it instead prints "Ã..." where "Å" should be.

Doug, how did you find out that [char(195) char(133)] was the combination you needed?
I found it by trial and error and try again through different numbers. I still don't understand how it works!!!
 
According to the ASCII table I looked up, those two are ├ à. I realized I also need an em dash which would be ASCII character 196, but Octave crashes whenever I try to plot something with char(196) in it.

This isn't as important because I can work around it (since the regular minus is only too small if I use e^{-qd} instead of exp(-qd) - i.e. by writing things without subscripting) but would be nice if there's a simple explanation. If it's not an easy fix, though, don't trouble yourself with it. I appreciate all that you've done already!

- Brett Green


On Sun, Sep 22, 2019 at 4:26 AM chs <[hidden email]> wrote:
On 2019-09-22 04:06, Brett Green wrote:
> Using single quotes (without $) was all I needed to change to get the
> degree symbol to appear. Thank you!
>
> Now I'm wondering why using single vs. double quotes makes a
> difference... what's important, though, is that it works.
>
> ...Actually, I may have written that prematurely. Although I can get the
> degree symbol, I still can't get the angstrom symbol. \AA and \r{A} were
> suggested but neither worked. Any ideas why not?

These both work in MATLAB, so this sounds like an Octave bug.

BTW, it's also worth mentioning that in LaTeX, \deg is actually an operator:

\deg:
macro:->\mathop {\operator@font deg}\nolimits

And this is what MATLAB gives you for '$\deg A$'.




--
DASCertificate for 206392



Reply | Threaded
Open this post in threaded view
|

Re: How can I get an angstrom symbol in Octave?

Dmitri A. Sergatskov


On Sun, Sep 22, 2019 at 11:51 AM Doug Stewart <[hidden email]> wrote:


On Sun, Sep 22, 2019 at 12:35 PM Brett Green <[hidden email]> wrote:
Thank you all very much!

Doug, your solution worked for me. This is a great relief - thank you!

Dmitri, thank you for the informative explanation and good questions. When I cut and paste "Å" into Octave, nothing appears in the terminal. If I run from a .m file with the character "Å" in the title, it instead prints "Ã..." where "Å" should be.

Doug, how did you find out that [char(195) char(133)] was the combination you needed?
I found it by trial and error and try again through different numbers. I still don't understand how it works!!!

You can go to


Click on desired symbol


And read the values in UTF-8 encodings (195 133).

So for em-dash (226 128 148). BTW you can use hex values as well.
So

title([char(0xE2),char(0x80), char(0x94)], "fontname", "cambria")

works for me.

Dmitri.
--








 


Reply | Threaded
Open this post in threaded view
|

Re: How can I get an angstrom symbol in Octave?

BGreen
Ah, I had been using the decimal values - that answers it! The en-dash is working now. Thank you very much!

- Brett Green


On Sun, Sep 22, 2019 at 1:21 PM Dmitri A. Sergatskov <[hidden email]> wrote:


On Sun, Sep 22, 2019 at 11:51 AM Doug Stewart <[hidden email]> wrote:


On Sun, Sep 22, 2019 at 12:35 PM Brett Green <[hidden email]> wrote:
Thank you all very much!

Doug, your solution worked for me. This is a great relief - thank you!

Dmitri, thank you for the informative explanation and good questions. When I cut and paste "Å" into Octave, nothing appears in the terminal. If I run from a .m file with the character "Å" in the title, it instead prints "Ã..." where "Å" should be.

Doug, how did you find out that [char(195) char(133)] was the combination you needed?
I found it by trial and error and try again through different numbers. I still don't understand how it works!!!

You can go to


Click on desired symbol


And read the values in UTF-8 encodings (195 133).

So for em-dash (226 128 148). BTW you can use hex values as well.
So

title([char(0xE2),char(0x80), char(0x94)], "fontname", "cambria")

works for me.

Dmitri.
--








 


Reply | Threaded
Open this post in threaded view
|

Re: How can I get an angstrom symbol in Octave?

Dmitri A. Sergatskov
On Sun, Sep 22, 2019 at 12:43 PM Brett Green <[hidden email]> wrote:
>
> Ah, I had been using the decimal values - that answers it! The en-dash is working now. Thank you very much!
>
> - Brett Green
>

Decimal would work too:

title([char(226),char(128), char(148)], "fontname", "cambria")

Note -- you need to use font that has the actual char in it.

E.g. this does not work:
title([char(226),char(128), char(148)], "fontname", "symbol")
warning: text_renderer: skipping missing glyph for character '2014'
warning: called from
    __axis_label__ at line 31 column 3
    title at line 51 column 8
warning: text_renderer: skipping missing glyph for character '2014'
warning: called from
    __axis_label__ at line 31 column 3
    title at line 51 column 8


Dmitri.
--


Reply | Threaded
Open this post in threaded view
|

Re: How can I get an angstrom symbol in Octave?

BGreen
Sorry - I wasn't clear. If you look at https://unicode-table.com/en/00C5/, it gives "dec 50053" and "dec (bytes) 195 133". I had mistakenly been using the former, whereas I needed the latter.

- Brett Green


On Sun, Sep 22, 2019 at 1:51 PM Dmitri A. Sergatskov <[hidden email]> wrote:
On Sun, Sep 22, 2019 at 12:43 PM Brett Green <[hidden email]> wrote:
>
> Ah, I had been using the decimal values - that answers it! The en-dash is working now. Thank you very much!
>
> - Brett Green
>

Decimal would work too:

title([char(226),char(128), char(148)], "fontname", "cambria")

Note -- you need to use font that has the actual char in it.

E.g. this does not work:
title([char(226),char(128), char(148)], "fontname", "symbol")
warning: text_renderer: skipping missing glyph for character '2014'
warning: called from
    __axis_label__ at line 31 column 3
    title at line 51 column 8
warning: text_renderer: skipping missing glyph for character '2014'
warning: called from
    __axis_label__ at line 31 column 3
    title at line 51 column 8


Dmitri.
--


Reply | Threaded
Open this post in threaded view
|

Re: How can I get an angstrom symbol in Octave?

Octave - General mailing list
In reply to this post by BGreen
On 9/21/19 10:06 PM, Brett Green wrote:
> Now I'm wondering why using single vs. double quotes makes a
> difference... what's important, though, is that it works.

The single quotes are 'absolute' whereas double quotes allow
interpolation of special characters like $ and backquote sequences, so
\deg is seen as [\d e g] which is [d e g] because \d is not one of the
anointed escapes.

So, you could use double quotes but you'd have to write it as "\\deg":
the backslash escapes the second backslash so the backend receives the
four-character string \deg.



Reply | Threaded
Open this post in threaded view
|

Re: How can I get an angstrom symbol in Octave?

BGreen
Thank you!

- Brett Green


On Tue, Sep 24, 2019 at 1:36 PM Przemek Klosowski via Help list for GNU Octave <[hidden email]> wrote:
On 9/21/19 10:06 PM, Brett Green wrote:
> Now I'm wondering why using single vs. double quotes makes a
> difference... what's important, though, is that it works.

The single quotes are 'absolute' whereas double quotes allow
interpolation of special characters like $ and backquote sequences, so
\deg is seen as [\d e g] which is [d e g] because \d is not one of the
anointed escapes.

So, you could use double quotes but you'd have to write it as "\\deg":
the backslash escapes the second backslash so the backend receives the
four-character string \deg.