I have a list of functions I define for multiple graphs along my course
Since they’re already written, why use PythonTeX
(I thought about this interesting solution for calculations but a bazooka for a simple task) while I could use mathematical-function-in-pgf-tikz ?
However, I think the use of \pgfmathparse{int(d1(\x,\y,\KK,\RR,\SIG)/100}\pgfmathresult
is quite heavy, so I must be doing someting wrong.
I could use a \newcommand
like
xxxxxxxxxx
\newcommand{\dOne}[5]{\pgfmathparse{int(d1(#1,#3,#2,#4,#5)*100)/100}\pgfmathresult}
but I lose the ability to name \d1
my macro. I also believe what I do here is not elegant (d!mn French with elegance issues 😃)
Hence my question :
I’d like to have a fluid way of calling the functions and get the result (for a set of parameters) in my text.
NB : I don’t mention here the roundings of the results. I know it’s a limitation.
This is slight variation of Rmano’s nice answer, merely for fun. I was wondering whether it is possible to steer the keys of siunitx
with pgf keys. It is possible, but unless I am missing something basic one has to be a bit careful. (There are definitely improvements possible.) The command created here is \Formula
, which takes one mandatory argument, the function that is to be parsed. And then there are options, which simultaneously allow one to steer siunitx
stuff and pgf options. One can add siunitx
keys with si+={...}
. It does support things like \Formula[si+={round-precision=4,math-rm=\mathtt}]{binom(1,2,3)}
which contain formatting macros like \mathtt
. This works by copying the token mechanism of pgf keys. The parsed results also get remembered because sometimes one uses random numbers at some stage, and the subsequent results depend on the value of the random number. For instance, StoredResult(2)
yields the result of the next-to-last computation. As usual, the rationale of using pgf keys here is to make the macro upgradable without losing backward compatibility.
I use the declare function
a lot for my texts for students (especially exams, in order to easily create variants). The precision and range of the calculation is often a problem, so that I have to pre-scale units (forget about going with 46e-6 or things like that); having the same fuctionality in l3fp
would be great). But alas, it’s still very handy!
What I use normally is to get help by the siunitx
package for formatting and printing. I have in my preamble:
xxxxxxxxxx
\newcommand{\formula}[1]{%
\pgfmathsetmacro{\rpval}{#1}%
\num[round-mode=figures, round-precision=4]{\rpval}
}
\newcommand{\SIformula}[2]{%
\pgfmathsetmacro{\rpval}{#1}%
\SI[round-mode=figures, round-precision=4]{\rpval}{#2}%
}
and then in my text I can use
xxxxxxxxxx
blah blah glub is \formula{binom(1,2,3)} and
quack \SIformula{ZC(3,3)}{\meter\squared} quack!
obviously you can pass additional parameters to control formats for printing, if needed. These macro are not expandable, but well — they do work in most cases.
I know this answer is not exactly what you are asking for but I think it is worth mentioning and might be useful to you or somebody else in one way or another.
If the supreme WolframScript is more suitable for you than SageMath, then package latexalpha2 is your new friend.
However, it only works on Linux devices. For Windows, I got you covered by having this great answer.
You must make sure first that you have first Wolfram Engine and WolframScript are installed in this order.
Finally, run the command wolframscript
once to activate your free account created when downloading WolframScript.
Windows-tailored ‘latexalpha2Win.sty’
If you don’t mind externalization using a powerful computational engine, you might go with SageMath using sagetext.
sagetex with arara
For automating the build process, you better use the following arara rule (if you are working on Windows) posted in this answer https://tex.stackexchange.com/a/596828/2288 after making sagetex.sty
of SageMath known to your latex distribution.
Thanks to the package of the day, I discovered the powerfull numerica