Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convenience macro for hour-minute-second quantities #684

Open
schtandard opened this issue Aug 16, 2023 · 10 comments
Open

Convenience macro for hour-minute-second quantities #684

schtandard opened this issue Aug 16, 2023 · 10 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@schtandard
Copy link

A convenience macro for typesetting time quantities consisting of hours minutes and seconds would be nice, analogous to the \ang macro. For example \hms{3;22;15.3} could output 3 h 22 min 15.3 s, \hms{1.5} 1.5 h and \hms{;15;} 15 min.

@josephwright
Copy link
Owner

#70?

@schtandard
Copy link
Author

schtandard commented Aug 16, 2023

Not quite, though they are related. I am asking for a clone of \ang for typesetting time. Basically something equivalent to

\NewDocumentCommand\hms{ O{} m }{%
  \ang[%
    angle-symbol-degree = \hour,
    angle-symbol-minute = \minute,
    angle-symbol-second = \second,
    number-angle-product = \,,
    angle-separator = ~, % Not sure about this setting.
    #1,
    ]{#2}%
}

though I would expect it to use the value of quantity-product instead of a separate number-angle-product, at least by default.

This would almost give what #70 is asking for by way of (the analog of) angle-mode = arc: With that setting \hms{1.5} would give 1 h 30 min (well, I am getting a trailing 0 s, not sure if this is by design). Getting rid of the min with the preceding space could be achieved by tweaking the settings in a somewhat unorthodox way (angle-symbol-degree = \,\hour, angle-symbol-minute = , number-angle-product = ,) which is fine, I think. The format 1:30 h would not quite be possible (the issue being the trailing h).

One could of course go even further and consider an interface for generating arbitrary commands that generate cascading quantities like this, with arbitrary factors between them. This would enable users to create e.g. a command like above but including days as an additional level (\dhms{2;5;13} giving 2 d 5 h 13 min or 2.217 d depending on the settings) or one for other non-decimal units like feet and inches or stones and pounds and the like. This would require much more care and work to design an appropriate interface, though, and I don't know if the use-cases justifies this. Also, most of them would probably arise from not using SI units, which is not really what this package is about, I guess.

@josephwright josephwright self-assigned this Aug 17, 2023
@josephwright josephwright added the enhancement New feature or request label Aug 17, 2023
@josephwright josephwright added this to the v3.4 milestone Aug 17, 2023
@josephwright josephwright changed the title Feature Request: Convenience macro for hour-minute-second quantities Convenience macro for hour-minute-second quantities Aug 17, 2023
@josephwright
Copy link
Owner

I think this would be a separate sub-module from angles, or perhaps done the same way as products, etc. (core code the same, different interfaces). I guess the main question for me is the document command: I will look to see what \hms is used.

@josephwright
Copy link
Owner

I don't see \hms in use in TL, so this looks safe.

@josephwright
Copy link
Owner

OK, I'm looking at this - suggested name is \duration or shortened to \durn. I am wondering whether to go the same was as I do with 'compound' values (one code path, wrappers for products, ranges, etc.), or whether there is sufficient difference to need two separate but similar implementations. In particular, whilst for 'compound' values there is the idea they are all 'multi-part', here the relation is more tricky to explain - both have minute/second parts, but the top-level is different. (I could deal with a different conversion factor.)

@josephwright
Copy link
Owner

'Sexagesimal' perhaps?

@dbitouze
Copy link
Contributor

dbitouze commented Oct 4, 2024

OK, I'm looking at this - suggested name is \duration or shortened to \durn.

\duration is more semantic than \hms. IMHO, \durn would not be easily understandable.

@davidcarlisle
Copy link

One problem with duration is that an XML schema/ ISO: 8601 duration is optional-sign,year,month,day,hours,minutes,seconds,fractional-seconds so there might be some pressure to extend the value space on the left if it has that name.

https://www.w3.org/TR/xmlschema-2/#duration

https://en.wikipedia.org/wiki/ISO_8601#Durations

On the other hand `duration is the only one of the types that isn't anchored at a specific actual time.

@josephwright
Copy link
Owner

I'm not sure there's a lot of overlap with XML here :) For a duration of longer than hours, there's really no need to have special formatting as there's very unlikely to be a desire to convert units - this is I imagine something almost exclusively wanted for hours/minutes/seconds. But I'm not overall keen on \hms as a name - it's not really semantic at all.

@josephwright
Copy link
Owner

Better name suggestion: \timespan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants