More advanced math functions

Hi there! Is there a specific reason more advanced math functions are not implemented / not mentioned in the docs? I’m mostly interested in standard trigonometric functions such as tangens and sine.

Would there be any opposition to adding these functions? Seems like a pretty minor thing.

1 Like

Lack of demand.

Sort of. Three pieces for each function: definition, documentation, and test cases.

Probably not, but not my call. It would be good to know how you intend to use them (i.e., what’s the benefit?).

I assume you want:

  • math.Acos
  • math.Asin
  • math.Atan
  • math.Cos
  • math.Sin
  • math.Tan
  • math.Pi

With the exception of math.Pi these are radian operations. Conversion to/from deg would be left to the user.

I assume there are a number of possible use cases, but I would like to do some fairly simple calculations to determine which external resources to pull (map tiles in my case) based on some input (a geographical bounding box in my case). Doable in a few lines of Python code, but that would add quite a heavy dependency and also doesn’t integrate well with the Hugo ecosystem.


Conversion between degrees and radians is fairly simple, but adding deg2rad and "rad2deg` functions would not be a big deal either.

I would be happy to submit a PR if the Hugo devs would welcome that.

1 Like

Graphs. Diagrams.

Create a proposal:

Limit it to the seven methods above, leaving unit conversion to the user.

Wait for approval before spending any time on a PR.

Done: Advanced Math Functions for Hugo Templates · Issue #10857 · gohugoio/hugo · GitHub

1 Like

Could you elaborate a bit? :slight_smile: