Use extension for mathjax in Franklin app

In my pratice, I would like to use actuarial symbols in my Franklin app, but the KaTeX does not support these symbols.

Following the instruction about using mathjax, the math formula are rendered perfectly. Then maybe the actuarial symbols for mathjax is a good choice for me, but I have no idea to integrate it in my app. Could you @tlienart give me any advice about that?

In the source code of their page I see this

Summary
<script type="text/x-mathjax-config">

MathJax.Hub.Config({
    TeX: {  
        Macros: {
            
            endow: ["{\\require{enclose} {{#1}:\\enclose{actuarial}{#2}}}", 2],
            endowxn: ["{\\require{enclose} {x:\\enclose{actuarial}{n}}}"],
            
            pureendow: ["{\\require{enclose} {{#1}:\\overset{1}{\\enclose{actuarial}{#2}}}}", 2],
            pureendowxn: ["{\\require{enclose} {x:\\overset{1}{\\enclose{actuarial}{n}}}}"],
            
            term : ["{\\require{enclose} {\\overset{1}{#1}:\\enclose{actuarial}{#2}}}", 2],
            termxn : ["{\\require{enclose} {\\overset{1}{x}:\\enclose{actuarial}{n}}}"],
            
            angl: ["{\\require{enclose} \\enclose{actuarial}{#1}}", 1],
            angln: ["{\\require{enclose} \\enclose{actuarial}{n}}"],
            
            nthtop : ["\\overset{#1}{#2}", 2],
            
            joint : ["\\overline{#1}", 1],

            itop : ["\\overset{1}{#1}", 1],
            iitop : ["\\overset{2}{#1}", 1],
            iiitop : ["\\overset{3}{#1}", 1],
            
            ibottom : ["\\underset{1}{#1}", 1],
            iibottom : ["\\underset{2}{#1}", 1],
            iiibottom : ["\\underset{3}{#1}", 1],
            
            
            Ax: [ "{A^{#1}_{#2}}", 2, ""],
            bAx: [ "{\\bar{A}^{#1}_{#2}}", 2, ""],
            dAx: [ "{{\\ddot A}^{#1}_{#2}}", 2, ""],
            tAx: [ "{{\\tilde A}^{#1}_{#2}}", 2, ""],
            
            ax: [ "{a^{#1}_{#2}}", 2, ""],
            bax: [ "{\\bar{a}^{#1}_{#2}}", 2, ""],
            dax: [ "{\\ddot{a}^{#1}_{#2}}", 2, ""],
            tax: [ "{\\tilde{a}^{#1}_{#2}}", 2, ""],
            
            Aringx: [ "{\\mathring{A}^{#1}_{#2}}", 2, ""],
            aringx: [ "{\\mathring{a}^{#1}_{#2}}", 2, ""],
            
            Eringx: [ "{\\mathring{E}^{#1}_{#2}}", 2, ""],
            eringx: [ "{\\mathring{e}^{#1}_{#2}}", 2, ""],
            
            Sringx: [ "{\\mathring{S}^{#1}_{#2}}", 2, ""],
            sringx: [ "{\\mathring{s}^{#1}_{#2}}", 2, ""],
            
            dx : [ "{d^{#1}_{#2}}", 2, ""],
            Dx : ["{\\mathscr{D}^{#1}_{#2}}", 2, ""],
            
            IA : [ "(IA)"],
            IbA : [ "(I\\bar A)"],
            bIbA : [ "(\\bar I\\bar A)"],
            ImA : [ "(I^{(m)}A)"],
            ImbA : [ "(I^{(m)}\\bar A)"],
            bImbA : [ "(\\bar I^{(m)}\\bar A)"],
            Is : [ "(Is)"],
            Ibs : [ "(I \\bar s)"],
            Ids : [ "(I \\ddot s)"],
            
            Ex : ["{E^{#1}_{#2}}", 2, ""],
            
            DA : [ "(DA)"],
            DbA : [ "(D\\bar A)"],
            bDbA : [ "(\\bar D\\bar A)"],
            DmA : [ "(D^{(m)}A)"],
            DmbA : [ "(D^{(m)}\\bar A)"],
            bDmbA : [ "(\\bar D^{(m)}\\bar A)"],
            Ds : [ "(Ds)"],
            Dbs : [ "(D \\bar s)"],
            Dds : [ "(D \\ddot s)"],
            
            lx : [ "{\\ell^{#1}_{#2}}", 2, ""],
            Lx : ["{\\mathscr{L}^{#1}_{#2}}", 2, ""],
            
            px : [ "{p^{#1}_{#2}}", 2, ""],
            Px : [ "{P^{#1}_{#2}}", 2, ""],
            
            premium : [ "{P^{#1}\ \\left({#2}\\right)}", 2, ""],
            bpremium : [ "{\\bar{P}^{#1}\\left({#2}\\right)}", 2, ""],
            tpremium : [ "{\\tilde{P}^{#1}\\left({#2}\\right)}", 2, ""],

            paidup : [ "{W^{#1}\ \\left({#2}\\right)}", 2, ""],
            bpaidup : [ "{\\bar{W}^{#1}\\left({#2}\\right)}", 2, ""],
            tpaidup : [ "{\\tilde{W}^{#1}\\left({#2}\\right)}", 2, ""],


            reserve : [ "{V^{#1}\ \\left({#2}\\right)}", 2, ""],
            breserve : [ "{\\bar{V}^{#1}\\left({#2}\\right)}", 2, ""],
            treserve : [ "{\\tilde{V}^{#1}\\left({#2}\\right)}", 2, ""],

            qx : [ "{q^{#1}_{#2}}", 2, ""],
            Qx : [ "{Q^{#1}_{#2}}", 2, ""],

            sx: [ "{s^{#1}_{#2}}", 2, ""],
            bsx: [ "{\\bar{s}^{#1}_{#2}}", 2, ""],
            dsx: [ "{\\ddot{s}^{#1}_{#2}}", 2, ""],

            Vx : [ "{V^{#1}_{#2}}", 2, ""],
            Wx : [ "{W^{#1}_{#2}}", 2, ""],

            actsymb : ["{_{#1}^{#2}{#3}_{#4}^{#5}}", 5]
            

            

        }
    }
});
</script>

which you could copy paste in your layout next to the inclusion of the mathjax lib.

Note that it’s just a set of definitions as far as I can see; all of the base definitions would work just fine in KaTeX (maybe with the exception of the enclose stuff, not sure) so you could also define these commands in Franklin and use KaTeX and benefit from the faster rendering. E.g. putting in your config.md:

# dx : [ "{d^{#1}_{#2}}", 2, ""],
\newcommand{\dx}[2]{ {d^{#1}_{#2}} }

Thanks to your fast respond.

I tried to append the suggested contents behind the mathjax setup, but it seems to not work. I have little javascript knowledge and have no way to reach it.

FYI, I created a toy app, wherein the actuarial symbols were not rendered correctly. The recommended part is put here. Could you kindly check it?

I don’t know Mathjax well, and this isn’t even a released extension, so you’ll have to figure that out yourself, probably reaching out to the person who came up with that list of commands and asking them how to set things up (Franklin is not the problem here), note that in your example you’re still using KaTeX in your layout.

What I was suggesting is that this is just a bunch of fairly simple definition so you could just have these definitions yourself, I did the transformation of most of them:

Summary

\newcommand{\nthtop }[2]{\overset{#1}{#2}}
\newcommand{\joint }[1]{\overline{#1}}
\newcommand{\itop }[1]{\overset{1}{#1}}
\newcommand{\iitop }[1]{\overset{2}{#1}}
\newcommand{\iiitop }[1]{\overset{3}{#1}}
\newcommand{\ibottom }[1]{\underset{1}{#1}}
\newcommand{\iibottom }[1]{\underset{2}{#1}}
\newcommand{\iiibottom }[1]{\underset{3}{#1}}
\newcommand{\Ax}[2]{{A^{#1}_{#2}}}
\newcommand{\bAx}[2]{{\bar{A}^{#1}_{#2}}}
\newcommand{\dAx}[2]{{{\ddot A}^{#1}_{#2}}}
\newcommand{\tAx}[2]{{{\tilde A}^{#1}_{#2}}}
\newcommand{\ax}[2]{{a^{#1}_{#2}}}
\newcommand{\bax}[2]{{\bar{a}^{#1}_{#2}}}
\newcommand{\dax}[2]{{\ddot{a}^{#1}_{#2}}}
\newcommand{\tax}[2]{{\tilde{a}^{#1}_{#2}}}
\newcommand{\Aringx}[2]{{\mathring{A}^{#1}_{#2}}}
\newcommand{\aringx}[2]{{\mathring{a}^{#1}_{#2}}}
\newcommand{\Eringx}[2]{{\mathring{E}^{#1}_{#2}}}
\newcommand{\eringx}[2]{{\mathring{e}^{#1}_{#2}}}
\newcommand{\Sringx}[2]{{\mathring{S}^{#1}_{#2}}}
\newcommand{\sringx}[2]{{\mathring{s}^{#1}_{#2}}}
\newcommand{\dx }[2]{{d^{#1}_{#2}}}
\newcommand{\Dx }[2]{{\mathscr{D}^{#1}_{#2}}}
\newcommand{\IA }[0]{(IA)}
\newcommand{\IbA }[0]{(I\bar A)}
\newcommand{\bIbA }[0]{(\bar I\bar A)}
\newcommand{\ImA }[0]{(I^{(m)}A)}
\newcommand{\ImbA }[0]{(I^{(m)}\bar A)}
\newcommand{\bImbA }[0]{(\bar I^{(m)}\bar A)}
\newcommand{\Is }[0]{(Is)}
\newcommand{\Ibs }[0]{(I \bar s)}
\newcommand{\Ids }[0]{(I \ddot s)}
\newcommand{\Ex }[2]{{E^{#1}_{#2}}}
\newcommand{\DA }[0]{(DA)}
\newcommand{\DbA }[0]{(D\bar A)}
\newcommand{\bDbA }[0]{(\bar D\bar A)}
\newcommand{\DmA }[0]{(D^{(m)}A)}
\newcommand{\DmbA }[0]{(D^{(m)}\bar A)}
\newcommand{\bDmbA }[0]{(\bar D^{(m)}\bar A)}
\newcommand{\Ds }[0]{(Ds)}
\newcommand{\Dbs }[0]{(D \bar s)}
\newcommand{\Dds }[0]{(D \ddot s)}
\newcommand{\lx }[2]{{\ell^{#1}_{#2}}}
\newcommand{\Lx }[2]{{\mathscr{L}^{#1}_{#2}}}
\newcommand{\px }[2]{{p^{#1}_{#2}}}
\newcommand{\Px }[2]{{P^{#1}_{#2}}}
\newcommand{\premium }[2]{{P^{#1}\ \left({#2}\right)}}
\newcommand{\bpremium }[2]{{\bar{P}^{#1}\left({#2}\right)}}
\newcommand{\tpremium }[2]{{\tilde{P}^{#1}\left({#2}\right)}}
\newcommand{\paidup }[2]{{W^{#1}\ \left({#2}\right)}}
\newcommand{\bpaidup }[2]{{\bar{W}^{#1}\left({#2}\right)}}
\newcommand{\tpaidup }[2]{{\tilde{W}^{#1}\left({#2}\right)}}
\newcommand{\reserve }[2]{{V^{#1}\ \left({#2}\right)}}
\newcommand{\breserve }[2]{{\bar{V}^{#1}\left({#2}\right)}}
\newcommand{\treserve }[2]{{\tilde{V}^{#1}\left({#2}\right)}}
\newcommand{\qx }[2]{{q^{#1}_{#2}}}
\newcommand{\Qx }[2]{{Q^{#1}_{#2}}}
\newcommand{\sx}[2]{{s^{#1}_{#2}}}
\newcommand{\bsx}[2]{{\bar{s}^{#1}_{#2}}}
\newcommand{\dsx}[2]{{\ddot{s}^{#1}_{#2}}}
\newcommand{\Vx }[2]{{V^{#1}_{#2}}}
\newcommand{\Wx }[2]{{W^{#1}_{#2}}}
\newcommand{\actsymb }[5]{{_{#1}^{#2}{#3}_{#4}^{#5}}}

With those you can for instance do:

Summary
$$
\ax{}{\angl{K}} \\
\bax{}{P_t} \\
\bax{}{\angl{T}} \\
\bax{}{x}\\
\bax{h}{r} \\
\bax{i}{x+t}\\
\bax{r}{x+t}\\
\dax{}{\angl{K+1}}\\
\dax{(m)}{x}\\
$$

$$
\aringx{(m)}{x}\\
 \dax{\{m\}}{x}	\\\\
 _j\dax{}{x}	\\\\
 _*\dax{}{x}	\\\\
 _{n|}\ax{}{x}\\\\
$$

$$
\Ax{}{xy} \\
\hat{B}_{x + t}^{(j)} \\
\actsymb{t}{}{D}{j}{}\\

$$

Note that in Franklin the number of arguments has to be respected precisely (as in LaTeX). Not sure why they don’t with their list. For instance the command \ax takes 2 arguments, so you have to provide two braces to it possibly leaving one empty.

1 Like

Yep you are right.

I just thought as that claims the mathjax actuarial symbols coincides with a tex package. Following your definitions, I guess the self-defined commands can cover most of the symbols and are also seamlessly acceptable in tex.

Thank you!

1 Like