# Octal code character use when LaTeX expression exists in the string

**URL:** <https://forum.generic-mapping-tools.org/t/octal-code-character-use-when-latex-expression-exists-in-the-string/6181>\
**Category:** Q&A\
**Tags:** gmt\
**Created:** [September 1, 2025, 1:22pm UTC](https://forum.generic-mapping-tools.org/t/octal-code-character-use-when-latex-expression-exists-in-the-string/6181 "2025-09-01T13:22:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tmerry1](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/tmerry1/32/4989_2.png) [@tmerry1](https://forum.generic-mapping-tools.org/u/tmerry1)\
**Post date:** [September 1, 2025, 1:22pm UTC](https://forum.generic-mapping-tools.org/t/octal-code-character-use-when-latex-expression-exists-in-the-string/6181/1 "2025-09-01T13:22:41Z")

</div>

If I try to print an en-dash (which I think is octal code \035 in the ISOLatin+ table) as part of an axis label that contains additionally a LaTeX expression, I get instead just the characters “35”.

If I invoke without the LaTeX symbol,

`gmt basemap -R0/1/0/1 -JX6 -BWSen -Byaf -Bxaf+l"Mean dVs (\%), 80\035200 km depth" -png tmp/test`

the en-dash looks as I would expect in the string “80–200”.

 ![test](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/f/f07ae42dc6258a9f713c243766d09a74423badde.png)

However,

`gmt basemap -R0/1/0/1 -JX6 -BWSen -Byaf -Bxaf+l"Mean @[\delta V_\mathrm{S}@[ (\%), 80\035200 km depth" -pdf tmp/test`

gives me the number 35 in place of the dash.

 ![test](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/b/bcfc26922f9c4f4a0bddd1b2935f59c2ed7b4479.png)

What am I missing here? Is this a bug, or non-advised usage? And is there a better way to print the en dash?

I found this issue when I was using PyGMT, but having tried it with plain GMT as above I see the exact same results.

I am using GMT 6.5.0.

Thanks!

Tom

EDIT: On further testing, I can use a command such as `@[\textnormal{--}@[` to typeset the dash within LaTeX math mode, but I suppose this has the drawback of not being set in the typeface of the surrounding text (Helvetica).

 ![test](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/8/85e24a9c5a9d54644ef9d2c9acfbc3dd0c800967.png)

---

<div class="post-metadata">

**Author:** ![mkononets](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/mkononets/32/4029_2.png) [@mkononets](https://forum.generic-mapping-tools.org/u/mkononets)\
**Post date:** [September 1, 2025, 2:25pm UTC](https://forum.generic-mapping-tools.org/t/octal-code-character-use-when-latex-expression-exists-in-the-string/6181/2 "2025-09-01T14:25:23Z")

</div>

When you use `@[...@[` inside a text string, the whole string gets typeset using LaTeX, and LaTeX knows nothing about `\035` literals meaning octal character code notation. With `@[...@[` you need typeset the whole string as a LaTeX expression using `--` for en dash:

```auto
gmt basemap -JX5c/0.1c -R-1/1/-1/1 -BS -Bxaf+l"Mean @[\delta V_S@[ (\%), 80--200 km depth" -png minus_delta_gmt_basemap

```

 ![minus_delta_gmt_basemap](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/a/a19b2ee7c9a697a93e8bf0a730e8521a40c02d53.png)

In PyGMT you can do the same or even try typesetting with unicode chars directly. GMT notation worked for generating subscript S for me but not for switching to Helvetica-Oblique (using `@%2%...@%%` notation):

```auto
import pygmt

fig = pygmt.Figure()

# NB unicode en dash –, unicode \delta δ:
text='Mean δV@-S@- (%), 80–200 km depth'
# the below makes no difference, @%2%...@%% does not change font to Helvetica-Oblique
# text='Mean @%2%δV@-S@-@%% (%), 80–200 km depth' 

fig=pygmt.Figure()
fig.basemap(region="-1/1/-1/1",
            projection="X5c/0.1c",
            frame=['S', f'xaf+l{text}'])

fig.savefig("minus_delta_axis_label.png", show=True)

# NB raw string r'' to prevent python from interpreting escape \'s
text=r'Mean @[\delta V_S@[ (\%), 80--200 km depth'
fig1=pygmt.Figure()
fig1.basemap(region="-1/1/-1/1",
            projection="X5c/0.1c",
            frame=['S', f'xaf+l{text}'])

fig1.savefig("minus_delta_axis_label_1.png", show=True)

```

 ![minus_delta_axis_label](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/8/8ab3f9fbb53b0a2ee76bada3194ed18932adb785.png)

 ![minus_delta_axis_label_1](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/3/38740ce43e1d884456e10f045bc6dbe4b20c33d5.png)

---

<div class="post-metadata">

**Author:** ![mkononets](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/mkononets/32/4029_2.png) [@mkononets](https://forum.generic-mapping-tools.org/u/mkononets)\
**Post date:** [September 1, 2025, 2:31pm UTC](https://forum.generic-mapping-tools.org/t/octal-code-character-use-when-latex-expression-exists-in-the-string/6181/3 "2025-09-01T14:31:49Z")

</div>

> [@tmerry1](#):
>
> On further testing, I can use a command such as `@[\textnormal{--}@[` to typeset the dash within LaTeX math mode

using `--` _ **outside** _ math mode produced en dash for me, both in CLI GMT and in PyGMT (see above):

```auto
"Mean @[\delta V_S@[ (\%), 80--200 km depth"

```

---

<div class="post-metadata">

**Author:** ![tmerry1](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/tmerry1/32/4989_2.png) [@tmerry1](https://forum.generic-mapping-tools.org/u/tmerry1)\
**Post date:** [September 1, 2025, 2:46pm UTC](https://forum.generic-mapping-tools.org/t/octal-code-character-use-when-latex-expression-exists-in-the-string/6181/4 "2025-09-01T14:46:42Z")

</div>

Oh wow, that is great. Having no idea how it worked, I blindly assumed that only the bits between `@[...@[` were interpreted by LaTeX. Now I have a way to confidently use the correct dashes in my GMT text!

Thanks!

---

<div class="post-metadata">

**Author:** ![mkononets](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/mkononets/32/4029_2.png) [@mkononets](https://forum.generic-mapping-tools.org/u/mkononets)\
**Post date:** [September 1, 2025, 2:48pm UTC](https://forum.generic-mapping-tools.org/t/octal-code-character-use-when-latex-expression-exists-in-the-string/6181/5 "2025-09-01T14:48:31Z")

</div>

see [13. Using LaTeX Expressions in GMT — GMT 6.6.0 documentation](https://docs.generic-mapping-tools.org/6.6/reference/gmt-latex.html#using-latex-expressions-in-gmt)
