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”.
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:
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)
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!