0

we can declare a function in the tikzpicture options, in \axis option, in \pgfmathdeclarefunction, in \tikzmath, by using \tikzset, by using the \def\func, etc... That is confusing as hell (at least, for a newbie). What is the difference between these forms of function declaration?

  • 1
    \def is just tex so for tikz it's as if it were not there and you have just typed its definition directly, \tikzset can always be used as an alternative to the options to set any tikz setting not just functions, so really the only surprising thing is the \pgfmath form. but the keyval options have to have some underlying command that they invoke. The whole point of tikz is to add a higher syntax layer over pgf functionality so the fact that there is a tikz and a pgf syntax shouldn't be that surprising. – David Carlisle Oct 30 '23 at 20:56

1 Answers1

2

The most basic way of defining a PGFMath function is \pgfmathdeclarefunction.

The /pgf/declare function key is also provided by PGFMath and is simply usable with TikZ/\tikzset and PGFPlots/\pgfplotsset (as they automatically search in the /pgf namespace as well). It is just a frontend to \pgfmathdeclarefunction where you can use control sequences instead of arguments #1, #2, ….

The TikZMath function is yet another frontend to \pgfmathdeclarefunction which just puts the body of the function inside a \tikzmath statement inside the body of \pgfmathdeclarefunction. (It also deals with arguments the same as /pgf/declare function.)

The \def\func thing isn't a PGFMath function but just a macro that expands to something else. In the context of the link question, a point is made that a macro \func works independent from its context as long as its expansion is understood as well. With TikZ and PGFPlots, GNUPlot can be used to evaluate a function, however, it will not understand PGFMath functions per se. (And TikZ will not transform a PGFMath expression to an expression understood by GNUPlot.)

Qrrbrbirlbel
  • 119,821