Skip to content

Plot title with subtitle on a newline #4557

Closed

Description

@weiji14

Description of the desired feature

There should be a way to plot a title on two lines instead of just one. Carried on from discussion at https://forum.generic-mapping-tools.org/t/how-to-plot-title-with-a-subtitle-on-a-newline/1121

Current state

Using newline \n doesn't work on GMT 6.1.1:

gmt basemap -R0/1/0/1 -JX1 -Baf+t"Title\nSubtitle" -png map

image

Desired state

The "subtitle" should be on a second line.

It might be nice to have slightly different font sizes for the main title and subtitle. But making the newline \n work will do for now 😄

Are you willing to help implement and maintain this feature? No

Activity

  1. added
    feature request
    on Dec 8, 2020
  2. PaulWessel commented on Dec 8, 2020

    @PaulWessel
    Contributor

    Think you can use @%font%...@%% to change the font to your liking. I don't think we want a fixed system unless we assume there is at most one \n and it truly is a title/subtitle 1-2 system. But I do think your suggestion makes it simpler to implement (again, assuming anything after the first \n is a subtitle set at a smaller size, say 0.8*FONT_TITLE or a new FONT_SUBTITLE defaulting to 0.8...

  3. PaulWessel commented on Dec 8, 2020

    @PaulWessel
    Contributor

    Perhaps @joa-quim and @seisman have opinion on the font-setting issue for multiple lines? I am bored and eager to code this up before afternoon coffee.

  4. seisman commented on Dec 8, 2020

    @seisman
    Member

    Sometimes people just want to split a long title into two lines. The second line doesn't have to be a subtitle. I believe it will surprise people that the second line has different font size.

  5. joa-quim commented on Dec 8, 2020

    @joa-quim
    Member

    I agree with Dongdong, but easy to have both. Use a double \n (\n\n) to have a subtitle.

  6. PaulWessel commented on Dec 8, 2020

    @PaulWessel
    Contributor

    Yes, I like that, or perhaps \r for continuation of title (same font) and \n for smaller subtitle. None of those characters are actually used when we typeset the PS so we could just assign those two functions and be done with it (a second \n just means the subtitle continues on more than one line with no further font changes.

  7. joa-quim commented on Dec 9, 2020

    @joa-quim
    Member

    Can we make it \r => \continue and \n => \subtitle? (or #continue if \c causes troubles)
    \r & \n are very natural to our C-ish thinking but we want to go for longoptions

  8. PaulWessel commented on Dec 9, 2020

    @PaulWessel
    Contributor

    We could do both - easy to check for unique things like \continue, \subtitle. But we also want \r, \n. OK, only leftover item to discuss is FONT_SUBTITLE versus a fixed 0.8 (or some factor) of FONT_TITLE. Preferences? I an already see a feature request coming to make smaller subtitles than whatever factor we pick, hence FONT_SUBTITLE is OK with me.

  9. joa-quim commented on Dec 9, 2020

    @joa-quim
    Member

    Yes for an optional FONT_SUBTITLE. The other feature request I would foresee is "Make my subtitles Italic".
    But can we also have both here? I.e default to 0.8 * FONT_TILE but allow other FONTs.

  10. PaulWessel commented on Dec 9, 2020

    @PaulWessel
    Contributor

    Hm, I think all we can do is default to 0.8 with same font and you can change, just like the other FONT_*. Making a new scheme just for this font is not great. And anyway, you can always use @%font% as well.

  11. weiji14 commented on Dec 9, 2020

    @weiji14
    MemberAuthor

    Let's not over-engineer this yet 😅 The scaling idea is nice but I think having FONT_SUBTITLE as something like 18p,Helvetica,black will do for now (a scaled down version of FONT_TITLE). If someone wants to change the TITLE and SUBTITLE font, they can always gmt set both. And with italics, they could do FONT_SUBTITLE=18p,Helvetica-Oblique,black or similar.

  12. PaulWessel commented on Dec 9, 2020

    @PaulWessel
    Contributor

    Testing this in branch sub-titles. Since it is hard to get actual \r and \n characters into the string I cheated (at least for now) and use ^ and ~ instead, respectively. With that, these things work:

    Breaking up a long title:

    gmt basemap -R0/10/0/10 -Baf -B+t"My extremely long title and awkward title^must go over two lines^or perhaps three even" -png three

    three

    Title with subtitle(s):

    gmt basemap -R0/10/0/10/0/10 -JZ3i -Baf -B+t"My extremely long title and awkward title:~Must go over two lines~or perhaps three even" -png sub

    sub

    Some technical comments:

    1. I chose a line-spacing of 1.1 times the font size here
    2. The new FONT_SUBTITLE is set to 20p while title is 24p. Seems perhaps it should be 18?
    3. Using \r and \n means users have to do either "\\r and \\n" or '\r and \n' due to quoting rules. Even then, inside GMT these are \ two-char sequences which makes splitting words harder than if we had 1-char symbols. Same if we did #break and #subtitle. No need if ^ and ~ were acceptable. I know I am being a bit lazy here - what you think?
    4. To avoid complications I do not allow both ^ and ~ in the same title.
  13. joa-quim commented on Dec 9, 2020

    @joa-quim
    Member
    1. Looks perfect
    2. Shouldn't the SUBTITLE be a percentage of TITLE? Figures for posters require larger font sizes.
    3. I even prefer ^ and ~ to \n & \r which are very programmer specific lingo. But longoptions will require > 1 char keys.
  14. PaulWessel commented on Dec 9, 2020

    @PaulWessel
    Contributor
    1. We already have the +fontsize option to scale all fonts proprtionally. I do not want SUBTITLE to be any different from the other 4-5 font options we have.
      We can worry about adding longer keys later - note these are not program options, just escape sequences. If we can agree on what those should be (e.g., #break; #sub; ?) then I can do that coding, but for now the shorthands ^ and ~ seems OK to me too.
  15. PaulWessel commented on Dec 9, 2020

    @PaulWessel
    Contributor

    OK, once I have wrapped out the outline for the NASA proposal I can implement stuff like #break; and #sub; if that is OK with you fine folks.

  16. 7 remaining items

  17. joa-quim commented on Dec 9, 2020

    @joa-quim
    Member

    Yes, you are in serious risk that the sky falls over your head. 😄

  18. PaulWessel commented on Dec 9, 2020

    @PaulWessel
    Contributor

    Well, given the syntax for title is -B+ttitle we cannot replace GMT modifiers (+t) with a different syntax (+\title) since the vast majority of GMT modifiers have nothing to do with Latex or text. So it has to remain -B+tstring, but what is inside the string is (still) up for debate. FYI, when GMT will offer longer keyword/value from the command line then +t will become +title=title. Which begs the question, perhaps the subtitle part could be solved by adding +ssubtitle (and eventually +subtitle=text). That would eliminate the need for an escape sequence for subtitles, just need one for breaking long lines.

    Using backslashes in text given on the commandline is not straightforward and may require careful quoting or escaping, hence that route is not great for that reason. For most mortals not versed in Latex, I think #linefeed; and #subtitle; are pretty good but perhaps there are even better ones if we brainstorm more. I think the are both a bit on the long side, which is why I suggested #break; and #sub; but the latter is not obvious.

  19. PaulWessel commented on Dec 9, 2020

    @PaulWessel
    Contributor

    Hm, looks to me adding +ssubtitle to -B for the frame would simplify this whole thing, just requiring multi-line support for both title and the optional subtitle. Agree with that, @GenericMappingTools/core ?

  20. PaulWessel commented on Dec 9, 2020

    @PaulWessel
    Contributor

    This would allow us to use the shorthand ^ for multiline breaks in title and subtitle, and perhaps #break; would be acceptable to you as the single long-form command needed?

  21. maxrjones commented on Dec 9, 2020

    @maxrjones
    Member

    That works for me, unless there's a reason to have mutually exclusive modifiers for frame and axes parameters in -B. Currently it seems like there's no overlap, so +s would be the first with subtitle and upper/right axis label for frame and axes respectively.

  22. PaulWessel commented on Dec 9, 2020

    @PaulWessel
    Contributor

    Yes, there will not be a parsing conflict because frame and axes are processed separately. Furthermore, +s requires you to also set +t since you cannot have a subtitle without a title.

  23. joa-quim commented on Dec 9, 2020

    @joa-quim
    Member

    👍 +subtitle

  24. seisman commented on Dec 10, 2020

    @seisman
    Member

    +1 for +subtitle

    This would allow us to use the shorthand ^ for multiline breaks in title and subtitle

    What if users want to have the character ^ in the title? How do they escape it?

  25. PaulWessel commented on Dec 10, 2020

    @PaulWessel
    Contributor
  26. seisman commented on Dec 10, 2020

    @seisman
    Member

    I mean, if I give a title This is a title (Y=a^X+b). Will GMT split it into two lines?

    gmt basemap -R0/10/0/10 -JX10c/10c -BWSen+t'This is a title (Y=a^X+b)' -png map
    

    Edit: why the ) is missing?
    image

  27. PaulWessel commented on Dec 10, 2020

    @PaulWessel
    Contributor
  28. PaulWessel commented on Dec 10, 2020

    @PaulWessel
    Contributor
  29. weiji14 commented on Dec 10, 2020

    @weiji14
    MemberAuthor

    Would it be easier if we had a character escape sequence for newline? E.g. @^ or something else indicates a line break.

  30. PaulWessel commented on Dec 10, 2020

    @PaulWessel
    Contributor

    Yes, I can do @^ or #break;, and perhaps we don't actually need #break; unless anyone feels @^ can appear in useful text. I have already implemented the hard part so now know what to do. I will switch from ^ to @^ first and people can tell me if #break; is still needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions