# Custom fonts on MacOS problem

**URL:** <https://forum.generic-mapping-tools.org/t/custom-fonts-on-macos-problem/679>\
**Category:** Q&A\
**Created:** [July 17, 2020, 8:54pm UTC](https://forum.generic-mapping-tools.org/t/custom-fonts-on-macos-problem/679 "2020-07-17T20:54:49Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![KristofKoch](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/kristofkoch/32/314_2.png) [@KristofKoch](https://forum.generic-mapping-tools.org/u/KristofKoch)\
**Post date:** [July 17, 2020, 8:54pm UTC](https://forum.generic-mapping-tools.org/t/custom-fonts-on-macos-problem/679/1 "2020-07-17T20:54:50Z")

</div>

I’m trying to use some non-standard fonts with GMT on MacOS. As my own experimentation lead nowhere I made heavy use of [Gallery example 31](https://docs.generic-mapping-tools.org/latest/gallery/ex31.html#example-31) but had no luck as well.

The font is installed and usable on the system. `gmt text -L` sees it. But for some reason `coast` doesn’t like it.

I’m stumped where I’m making a mistake – maybe one of the more knowledgeable folks can point me in the right direction.

MacOS 10.15.5  
GMT 6.2.0\_479acc6\_2020.07.16 [64-bit]

Stripped script to reproduce the error:

```
#!/usr/bin/env bash

function gmt() { /usr/local/opt/gmt_dev/bin/gmt "$@"; }
export -f gmt

gmt text -L

AWK=${AWK:-awk}

$AWK '{print $1, 0.700, 0}' <<- EOF > PSL_custom_fonts.txt
GothamRounded-Book
EOF

gmt set FONT GothamRounded-Book

gmt begin fonts
gmt basemap -JL-24/16/15.5/16.5/15c -R-25.9/14.1/-22.1/17.9+r -Ba1dg1d
gmt end show

```

While the script generates a plot it doesn’t use the font and defaults to Helvetica instead:

```
kristof$ ./fonts.sh
gmt text [core] 6.2.0_479acc6_2020.07.16 [64-bit] - Plot or typeset text

[…]

	Font #	Font Name
	------------------------------------
	  0	Helvetica
[…]
	 38	GothicBBB-Medium-EUC-V
	 39	GothamRounded-Book
For additional fonts, see "Using non-default fonts with GMT" in the documentation.
PSL: Warning: Selected font (39) out of range (0-38); reset to 0
kristof$

```

Thank you for your help!

---

<div class="post-metadata">

**Author:** ![pwessel](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/pwessel/32/30_2.png) [@pwessel](https://forum.generic-mapping-tools.org/u/pwessel)\
**Post date:** [July 17, 2020, 9:20pm UTC](https://forum.generic-mapping-tools.org/t/custom-fonts-on-macos-problem/679/2 "2020-07-17T21:20:11Z")

</div>

Looks like gmt reads your list of files but postscript light does not. I see it is looking in (1) current directory, (2) your ~/.gmt/cache directory, the official GMT share/postscriptlight directory (which I dont think we install anymore), and a directory pointed to by environmental parameter PSL\_SHAREDIR. I would place a copy of your PSL\_custom\_fonts.txt in the cache dir and see if that helps. Once it works and the PS file uses the font, the next battle is to make sure ghostscript finds the actual fonts.

---

<div class="post-metadata">

**Author:** ![KristofKoch](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/kristofkoch/32/314_2.png) [@KristofKoch](https://forum.generic-mapping-tools.org/u/KristofKoch)\
**Post date:** [July 17, 2020, 9:42pm UTC](https://forum.generic-mapping-tools.org/t/custom-fonts-on-macos-problem/679/3 "2020-07-17T21:42:08Z")

</div>

Hi Paul,

thank you for looking into this. As you recommended I put `PSL_custom_fonts.txt` into `~/.gmt/cache`. Additionally I deleted the one in the current directory and commented the `awk` part out. Now GMT can’t find it and I get another error …

```
kristof$ ./fonts.sh
6.2.0_479acc6_2020.07.16
gmt text [core] 6.2.0_479acc6_2020.07.16 [64-bit] - Plot or typeset text

[…]

	Font #	Font Name
	------------------------------------
	  0	Helvetica
[…]	
	 38	GothicBBB-Medium-EUC-V
For additional fonts, see "Using non-default fonts with GMT" in the documentation.
gmtset [WARNING]: Length <unit> k not supported - revert to default unit [point]
gmtset [WARNING]: GothamRounded-Boo not a valid number and may not be decoded properly.
gmtset [WARNING]: Representation of font size not recognised. Using default.
gmtset [WARNING]: Length <unit> k not supported - revert to default unit [point]
gmtset [WARNING]: GothamRounded-Boo not a valid number and may not be decoded properly.
gmtset [WARNING]: Representation of font size not recognised. Using default.
gmtset [WARNING]: Length <unit> k not supported - revert to default unit [point]
gmtset [WARNING]: GothamRounded-Boo not a valid number and may not be decoded properly.
gmtset [WARNING]: Representation of font size not recognised. Using default.
gmtset [WARNING]: Length <unit> k not supported - revert to default unit [point]
gmtset [WARNING]: GothamRounded-Boo not a valid number and may not be decoded properly.
gmtset [WARNING]: Representation of font size not recognised. Using default.
gmtset [WARNING]: Length <unit> k not supported - revert to default unit [point]
gmtset [WARNING]: GothamRounded-Boo not a valid number and may not be decoded properly.
gmtset [WARNING]: Representation of font size not recognised. Using default.
gmtset [WARNING]: Length <unit> k not supported - revert to default unit [point]
gmtset [WARNING]: GothamRounded-Boo not a valid number and may not be decoded properly.
gmtset [WARNING]: Representation of font size not recognised. Using default.
kristof$
```

---

<div class="post-metadata">

**Author:** ![pwessel](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/pwessel/32/30_2.png) [@pwessel](https://forum.generic-mapping-tools.org/u/pwessel)\
**Post date:** [July 17, 2020, 9:54pm UTC](https://forum.generic-mapping-tools.org/t/custom-fonts-on-macos-problem/679/4 "2020-07-17T21:54:48Z")

</div>

Sorry, I did not mean to remove the one you had in the current directory, just duplicated into cache. I think GMT is reading that while postscript light is reading the other… Not ideal but if we can get it to work we can fix it. But odd if you followed the ex31 which is similar.

---

<div class="post-metadata">

**Author:** ![KristofKoch](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/kristofkoch/32/314_2.png) [@KristofKoch](https://forum.generic-mapping-tools.org/u/KristofKoch)\
**Post date:** [July 17, 2020, 10:09pm UTC](https://forum.generic-mapping-tools.org/t/custom-fonts-on-macos-problem/679/5 "2020-07-17T22:09:04Z")

</div>

Oh, ok – I missed that. My apologies. Now there is one in the script’s directory as well as in `~/.gmt/cache` and I get the same error as in my original post.

But ex31 doesn’t work here as well (I never ran it, I thoughtlessly assumed that it works):

```
ex31 kristof$ ./ex31.sh
PSL: Warning: Selected font (39) out of range (0-38); reset to 0
PSL: Warning: Selected font (42) out of range (0-38); reset to 0
PSL: Warning: Selected font (39) out of range (0-38); reset to 0
PSL: Warning: Selected font (40) out of range (0-38); reset to 0
     [22 identical lines removed]
PSL: Warning: Selected font (40) out of range (0-38); reset to 0
PSL: Warning: Selected font (41) out of range (0-38); reset to 0
PSL: Warning: Selected font (41) out of range (0-38); reset to 0
PSL: Warning: Selected font (39) out of range (0-38); reset to 0
PSL: Warning: Selected font (39) out of range (0-38); reset to 0
PSL: Warning: Selected font (39) out of range (0-38); reset to 0
PSL: Warning: Selected font (39) out of range (0-38); reset to 0
PSL: Warning: Selected font (41) out of range (0-38); reset to 0
PSL: Warning: Selected font (41) out of range (0-38); reset to 0
PSL: Warning: Selected font (39) out of range (0-38); reset to 0
     [46 identical lines removed]
PSL: Warning: Selected font (39) out of range (0-38); reset to 0
ex31 kristof$
```

---

<div class="post-metadata">

**Author:** ![pwessel](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/pwessel/32/30_2.png) [@pwessel](https://forum.generic-mapping-tools.org/u/pwessel)\
**Post date:** [July 17, 2020, 10:24pm UTC](https://forum.generic-mapping-tools.org/t/custom-fonts-on-macos-problem/679/6 "2020-07-17T22:24:09Z")

</div>

So ex31 runs for us in tests but we set this in testgmt.in

export GS\_FONTPATH="@CMAKE\_CURRENT\_SOURCE\_DIR@/ex31/fonts"

so this becomes the full path to your directory with fonts. Then psconvert can find them.

---

<div class="post-metadata">

**Author:** ![KristofKoch](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/kristofkoch/32/314_2.png) [@KristofKoch](https://forum.generic-mapping-tools.org/u/KristofKoch)\
**Post date:** [July 17, 2020, 10:27pm UTC](https://forum.generic-mapping-tools.org/t/custom-fonts-on-macos-problem/679/7 "2020-07-17T22:27:29Z")

</div>

Do I understand you correctly that both for my test script and ex31 on my machine psconvert is having trouble finding the fonts?

---

<div class="post-metadata">

**Author:** ![pwessel](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/pwessel/32/30_2.png) [@pwessel](https://forum.generic-mapping-tools.org/u/pwessel)\
**Post date:** [July 17, 2020, 10:49pm UTC](https://forum.generic-mapping-tools.org/t/custom-fonts-on-macos-problem/679/8 "2020-07-17T22:49:51Z")

</div>

That is my guess. Presumable ex31.sh runs for you and makes a PS file without any errors/warnings?. You can run psconvert and what it says and if it picks up. Run it with -S to see the gs command and try that manually and experiment with that path.

---

<div class="post-metadata">

**Author:** ![KristofKoch](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/kristofkoch/32/314_2.png) [@KristofKoch](https://forum.generic-mapping-tools.org/u/KristofKoch)\
**Post date:** [July 17, 2020, 11:14pm UTC](https://forum.generic-mapping-tools.org/t/custom-fonts-on-macos-problem/679/9 "2020-07-17T23:14:34Z")

</div>

My apologies, the last dump was from running ex31. It generates a plot but reverts to Helvetica and generates a lot of those:

```
PSL: Warning: Selected font (39) out of range (0-38); reset to 0

```

Currently I experiment with line 15

```
gmt set PS_CONVERT="C-sFONTPATH=$(dirname $0)/fonts"

```

from `ex31.sh`. It seems that the directory name doesn’t get extracted:

```
ex31 kristof$ echo $(dirname "$0")
dirname: illegal option -- b
usage: dirname path

ex31 kristof$

```

Whereas `BASH\_SOURCE[0] seems to work:

```
ex31 kristof$ echo $( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )

/usr/local/opt/gmt_dev/share/doc/examples/ex31
ex31 kristof$

```

I modified `ex31.sh` a bit from line 15:

```
CURRENT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
echo $CURRENT_DIR
FONT_DIR="C-sFONTPATH=${CURRENT_DIR}/fonts"
echo $FONT_DIR
gmt set PS_CONVERT=${FONT_DIR}

```

Unfortunately the problem persists. It generates a plot but throws a lot of `reset to 0` and doesn’t use the non-standard font.

---

<div class="post-metadata">

**Author:** ![pwessel](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/pwessel/32/30_2.png) [@pwessel](https://forum.generic-mapping-tools.org/u/pwessel)\
**Post date:** [July 17, 2020, 11:34pm UTC](https://forum.generic-mapping-tools.org/t/custom-fonts-on-macos-problem/679/10 "2020-07-17T23:34:02Z")

</div>

OK. I did this with a copy of the ex31 directory:

1. use gmt begin ex31 ps
2. Remove the show at the end
3. Ignore the reset to 0 messages for now
4. **mt psconvert ex31.ps -C-sFONTPATH=${GS\_FONTPATH} -Tf -P**

The PDF looks good.

---

<div class="post-metadata">

**Author:** ![pwessel](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/pwessel/32/30_2.png) [@pwessel](https://forum.generic-mapping-tools.org/u/pwessel)\
**Post date:** [July 17, 2020, 11:55pm UTC](https://forum.generic-mapping-tools.org/t/custom-fonts-on-macos-problem/679/11 "2020-07-17T23:55:09Z")

</div>

After moving the deletion fo the font list outside, the script works directly fine with PDF and PS with gmt end show since both gs and gv consults the GS\_FONTPATH and psconvert is passed that arg.

---

<div class="post-metadata">

**Author:** ![KristofKoch](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/kristofkoch/32/314_2.png) [@KristofKoch](https://forum.generic-mapping-tools.org/u/KristofKoch)\
**Post date:** [July 18, 2020, 12:00am UTC](https://forum.generic-mapping-tools.org/t/custom-fonts-on-macos-problem/679/12 "2020-07-18T00:00:55Z")

</div>

Mh, I get a plot but it still is in Helvetica and lots of reset to 0. Something is different.

---

<div class="post-metadata">

**Author:** ![pwessel](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/pwessel/32/30_2.png) [@pwessel](https://forum.generic-mapping-tools.org/u/pwessel)\
**Post date:** [July 18, 2020, 12:12am UTC](https://forum.generic-mapping-tools.org/t/custom-fonts-on-macos-problem/679/13 "2020-07-18T00:12:15Z")

</div>

try to reduce it to just a single pstext call of whtever you have to do to still get the error, then open an issue so we all can have a look.

---

<div class="post-metadata">

**Author:** ![KristofKoch](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/kristofkoch/32/314_2.png) [@KristofKoch](https://forum.generic-mapping-tools.org/u/KristofKoch)\
**Post date:** [August 9, 2020, 1:03pm UTC](https://forum.generic-mapping-tools.org/t/custom-fonts-on-macos-problem/679/14 "2020-08-09T13:03:46Z")

</div>

Back from vacation … and I think I found the problem:

For some reason `awk` converts my decimal point to a decimal comma. This is correct for my locale but not for PostScript.

When running

```
AWK=${AWK:-awk}

$AWK '{print $1, 0.700, 0}' <<- EOF > PSL_custom_fonts.txt
GothamRounded-Book
EOF

```

I got

`GothamRounded-Book 0,7 0`

instead of the expected

`GothamRounded-Book 0.700 0`

in my `PSL_custom_fonts.txt` file. Why? I have no idea. I suspect my locale to be the culprit, but I was unable to find a source for this.

Same problem with ex31. As soon as I change the comma to a point in `PSL_custom_fonts.txt` itself and don’t let `awk` mess with it everything runs smooth.

This might explain why you can’t reproduce the error @pwessel as you locale most probably uses the decimal point.

---

<div class="post-metadata">

**Author:** ![pwessel](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/pwessel/32/30_2.png) [@pwessel](https://forum.generic-mapping-tools.org/u/pwessel)\
**Post date:** [August 9, 2020, 5:36pm UTC](https://forum.generic-mapping-tools.org/t/custom-fonts-on-macos-problem/679/15 "2020-08-09T17:36:36Z")

</div>

Try to add this ti the top of your script.

**export LC\_ALL=C**

---

<div class="post-metadata">

**Author:** ![KristofKoch](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/kristofkoch/32/314_2.png) [@KristofKoch](https://forum.generic-mapping-tools.org/u/KristofKoch)\
**Post date:** [August 10, 2020, 8:43am UTC](https://forum.generic-mapping-tools.org/t/custom-fonts-on-macos-problem/679/16 "2020-08-10T08:43:30Z")

</div>

Thanks Paul, that did the trick.

---

<div class="post-metadata">

**Author:** ![KristofKoch](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/kristofkoch/32/314_2.png) [@KristofKoch](https://forum.generic-mapping-tools.org/u/KristofKoch)\
**Post date:** [August 10, 2020, 8:51am UTC](https://forum.generic-mapping-tools.org/t/custom-fonts-on-macos-problem/679/17 "2020-08-10T08:51:06Z")

</div>

**A hint for others with similar problems:**

**Locale**

Your set locale (= language specific settings) might not be compatible with the formats expected by `ghostscript`. Here in my case the systems locale is `de_DE.UTF-8` which uses a comma `,` instead of a point `.` as decimal point character. This confuses `ghostscript` - which does the PostScript conversion in the background - as it expects a point as decimal point character.  
You can fix this by using

`export LC_ALL=C`

at the top of your script. See [https://unix.stackexchange.com/a/87763](https://unix.stackexchange.com/a/87763) for more information on `LC_ALL`.

**Path to Font Directory**

If you want to use a custom font with GMT under macOS chances are that you have it already installed on your system. Now `ghostscript` needs to know where to look for it. This can easily be done by opening the macOS _Font Book_ App (system app, comes preinstalled) and selecting the font you want to use. Then just hit _Cmd + I_. You get a lot of information about the font. Just scroll down and have a look under _Location_. There you’ll find something like

`/Users/kristof/Library/Fonts/PoiretOne-Regular.ttf`

We need only the path to the folder without the actual font file name so we just take

`/Users/kristof/Library/Fonts`

(note the missing trailing slash) and `export` it as well at the top of your script:

`export GS_FONTPATH="/Users/kristof/Library/Fonts"`

Be aware that macOS uses several different locations for system fonts and user installed fonts.
