Octal code character use when LaTeX expression exists in the string

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”.

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.

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).

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:

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

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):

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)

1 Like

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

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

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!

see 13. Using LaTeX Expressions in GMT — GMT 6.6.0 documentation

1 Like