> Hans Hagen: > mfunction will stay as it is also needed for tagged pdf and exporting > (basically it's an apply math function thing) so if something else is > needed another name/mechanism have to be made (with appropriate tagging) > the label itself is a special case as it's optional (and is just there > for cultural differences as not all countries use the english names) > so, \rho_{\mathlabel{air}} is something different then, some kind of > multi-character variable? Actually no, it has nothing to do with ConTeXt label texts (that is why I removed the word 'text' in it to avoid the confusion), \mathlabel was just a name that I gave to encompass two different things that are usually typeset the same way (upright): the names of functions (\mfunction) and the names often used in the subscripts of variables. But after some thought and your new suggestion (\mtext) for the latter case, I find that my 'mathlabel' is misleading and that it is better for the user to keep them separate (with \mfunction AND \mtext), and it gives him more control. > Hans Hagen: > \unexpanded\def\mtext#1{\text{\usemathematicsstyleandcolor\c!textstyle\c!textcolor#1}} > which can be used as: > $x^{\mtext{effe}}$ > and obeys > \setupmathematics[textstyle=bold, textcolor=darkgreen] Perfect! Not only \mtext is short but also very meaningful and symmetrical with \mfunction, therefore easy to memorize. I totally agree with that new definition. QUESTION 1. — Did you include the \text command as well in the definition of your new \mfunction (like below)? 1st DEFINITION of \mfunction. ——————————————————————— \unexpanded\def\mfunction#1{\text{\usemathematicsstyleandcolor\c!functionstyle\c!functioncolor#1}} ——————————————————————— Because like in \mtext, the \text command is ESSENTIAL (for the function names to have the mathcodes, kerning and ligatures of the text mode instead of the ones of the math mode). > Hans Hagen: > next beta: when one of the stylealternatives text mode else mathmode > (default nothing == mathupright) > Aditya Mahajan: > The default should be \mathupright (as is the case in amstex and latex, and probably also plaintex). No, I strongly disagree. Yes it should be upright by default, but it should always be in TEXT mode, even by default, that is why I used the \text command in the definition of \mfunction. \mathupright in math mode doesn't solve the problems of mathcodes, kerning and ligatures (if you want call your function 'AVL' or 'low-frequency' for instance, the result is terrible with \mathupright: the space between A and V is too large and the hyphen between w and f becomes a minus sign binary operator—try $\mathupright{AVL}$ and $\mathupright{low-frequency}$). \text{\rm\tf} does. Consequently \rm\tf should be the default functionstyle and textstyle in \setupmathematics. (And Aditya, don't forget that \mathupright is just a macro for \rm\tf in math mode.) So now, let us see what the user have to write to get a math function and a math text (usually used as the subscript of a variable): ——————————————————————— \setupmathematics[functionstyle=bold, functioncolor=red, textstyle=bold, textcolor=green] \starttext $\mathnolop{\mfunction{Arsinh}} x\ \text{and}\ n_{\mtext{air}}$. \stoptext ——————————————————————— The syntax is okay but a bit complicated since the symmetry is not perfect (\mtext vs \mathnolop{\mfunction}). Symmetry is important in a user interface so I think the user expects simply \mtext and \mfunction (not \mathnolop{\mfunction}). Therefore we need to wrap this \mathnolop in \mfunction. And the possibility to choose \mathop (synonym: \mathlimop) instead of \mathnolop—which should be the default—should be given to the user with an optional argument. To keep it consistent with the ConTeXt syntax, the optional argument should be [op] (synonym: [limop]). So let us redefine our \mfunction. 2nd DEFINITION of \mfunction. ——————————————————————— \unexpanded\def\mfunction{\dosingleempty\domfunction} \def\domfunction[#1]#2% {\iffirstargument \doifelse{#1}{op}{\normalmathop{\text{\usemathematicsstyleandcolor\c!functionstyle\c!functioncolor#2}}}{\doifelse{#1}{limop}{\normalmathop{\text{\usemathematicsstyleandcolor\c!functionstyle\c!functioncolor#2}}}{\normalmathop{\text{\usemathematicsstyleandcolor\c!functionstyle\c!functioncolor#2}}\nolimits}} \else \normalmathop{\text{\usemathematicsstyleandcolor\c!functionstyle\c!functioncolor#2}}\nolimits \fi} ——————————————————————— Notice in that new definition that we use \normalmathop instead of \mathop because the \mathop in ConTeXt uses a modified version of the normal \mathop (the latter is renamed \normalmathop by ConTeXt) that converts the serif font style command \rm to the math font style command \mf, which as a result makes \rm without effect in \setupmathematics[functionstyle=\rm] as I came to realize after some testing. Indeed, ConTeXt has currently the following lines in math-ini.mkiv: \let\normalmathop\mathop \unexpanded\def\mathop {\normalmathop \bgroup \let\rm\mf \let\nexttoken=} QUESTION 2. — By the way, why this conversion of \rm to \mf inside \mathop atoms (\let\rm\mf)? So with the new definition for \mfunction, the user can now simply and elegantly write this: ——————————————————————— \setupmathematics[functionstyle=bold, functioncolor=red, textstyle=bold, textcolor=green] \starttext $\mfunction{Arsinh} x\ \text{and}\ n_{\mtext{air}}$. \stoptext ——————————————————————— With that new \mfunction, ConTeXt users now have an equivalent macro to the LaTeX \operatorname macro of the amsopn package, which I think was very missing. Now, let us look at how the user can DEFINE his math function. A. With the 1st definition of \mfunction (the one that doesn't include \mathnolop or \mathop), the user can write this (notice again that we use \normalmathop \nolimits instead of \mathnolop—or equivalently [nolop]—to avoid the conversion of \rm to \mf that would make \setupmathematics[functionstyle=\rm] without effect): ——————————————————————— \definemathcommand[arsinh]{\normalmathop{\mfunction{Arsinh}}\nolimits} \setupmathematics[functionstyle=bold, functioncolor=red, textstyle=bold, textcolor=green] \starttext $\arsinh x\ \text{and}\ n_{\mtext{air}}$. \stoptext ——————————————————————— or, alternatively this (if the user wants also to define a label text for his function): ——————————————————————— \setupmathlabeltext[arsinh=Arsinh] \definemathcommand[arsinh]{\normalmathop{\mfunctionlabeltext{arsinh}}\nolimits} \setupmathematics[functionstyle=bold, functioncolor=red, textstyle=bold, textcolor=green] \starttext $\arsinh x\ \text{and}\ n_{\mtext{air}}$. \stoptext ——————————————————————— assuming that \mfunctionlabeltext is defined the following way (which I think is already the case in the last beta). 1st DEFINITION of \mfunctionlabeltext. ——————————————————————— \unexpanded\def\mfunctionlabeltext#1{\mfunction{\mathlabeltext{#1}}} ——————————————————————— Thus with the 1st definition of \mfunction (and \mfunctionlabeltext), the definition of a math function for the user is a bit complicated (he has to write \normalmathop \nolimits in addition to \mfunction or \mfunctionlabeltext, unless Hans decides to remove \let\rm\mf from his redefinition of \mathop in which case the user just has to add the optional argument [nolop] instead of the verbose and hard to remember \normalmathop \nolimits). B. With the 2nd definition of \mfunction (the one that includes \mathnolop or \mathop), the user can write this: ——————————————————————— \definemathcommand[arsinh]{\mfunction{Arsinh}} \setupmathematics[functionstyle=bold, functioncolor=red, textstyle=bold, textcolor=green] \starttext $\arsinh x\ \text{and}\ n_{\mtext{air}}$. \stoptext ——————————————————————— or, alternatively this (if the user wants also to define a label text for his function): ——————————————————————— \setupmathlabeltext[arsinh=Arsinh] \definemathcommand[arsinh]{\mfunctionlabeltext{arsinh}} \setupmathematics[functionstyle=bold, functioncolor=red, textstyle=bold, textcolor=green] \starttext $\arsinh x\ \text{and}\ n_{\mtext{air}}$. \stoptext ——————————————————————— assuming that \mfunctionlabeltext is defined the following way (the additional optional argument is for that of \mfunction). 2nd DEFINITION of \mfunctionlabeltext. ——————————————————————— \unexpanded\def\mfunctionlabeltext{\dosingleempty\domfunctionlabeltext} \def\domfunctionlabeltext[#1]#2% {\iffirstargument \mfunction[#1]{\mathlabeltext{#2}} \else \mfunction{\mathlabeltext{#2}} \fi} ——————————————————————— Thus with the 2nd definition of \mfunction (and \mfunctionlabeltext), the definition of a math function for the user is easier (no need to write \normalmathop \nolimits since it is taken into account in \mfunction, and Hans doesn't have to remove \let\rm\mf from his redefinition of \mathop). It confirms that the 2nd definition of \mfunction (and \mfunctionlabeltext) is the way to go. However the command \mfunctionlabeltext is unnecessary and inconsistent with the other ConTeXt command \labeltext since it has a style attached to it, so may confuse the user. The direct command \mathlabeltext (the math equivalent of \labeltext) should be preferred. Therefore I think Hans should remove \mfunctionlabeltext from math-ini.mkiv and the user should use \mfunction{\mathlabeltext } when needed: ——————————————————————— \setupmathlabeltext[arsinh=Arsinh] \definemathcommand[arsinh]{\mfunction{\mathlabeltext{arsinh}}} \setupmathematics[functionstyle=bold, functioncolor=red, textstyle=bold, textcolor=green] \starttext $\arsinh x\ \text{and}\ n_{\mtext{air}}$. \stoptext ——————————————————————— But we can go a little further in user friendliness by wrapping the \mfunction in a new macro, that we should name \definemathfunction to be consistent with the other macros (\definemathcommand, \definemathsymbol, \definemathcharacter, etc.). The possibility to choose between \mathop (synonym: \mathlimop) and \mathnolop—which should be the default—is once more given to the user with the optional argument [op] (synonym: [limop]) to be consistent with the ConTeXt syntax. The macro is defined as follows. DEFINITION of \definemathfunction. ——————————————————————— \unexpanded\def\definemathfunction{\dodoubleempty\dodefinemathfunction} \def\dodefinemathfunction[#1][#2]#3% {\ifsecondargument \definemathcommand[#1]{\mfunction[#2]{#3}} \else \definemathcommand[#1]{\mfunction{#3}} \fi} ——————————————————————— Notice that we use again \normalmathop for the same reasons as before. That new \definemathfunction macro now allows the user to write this: ——————————————————————— \definemathfunction[arsinh]{arsinh} \setupmathematics[functionstyle=bold, functioncolor=red, textstyle=bold, textcolor=green] \starttext $\arsinh x\ \text{and}\ n_{\mtext{air}}$. \stoptext ——————————————————————— or, alternatively this (if the user wants also to define a label text for his function): ——————————————————————— \setupmathlabeltext[arsinh=Arsinh] \definemathfunction[arsinh]{\mathlabeltext{arsinh}} \setupmathematics[functionstyle=bold, functioncolor=red, textstyle=bold, textcolor=green] \starttext $\arsinh x\ \text{and}\ n_{\mtext{air}}$. \stoptext ——————————————————————— With that new \definemathfunction, ConTeXt users now have an equivalent macro to the LaTeX \DeclareMathOperator macro of the amsopn package, which I think was very missing as well. The math functions defined in math-def.mkiv should of course use \mfunction{\mathlabeltext } instead of the old \mfunctionlabeltext, or the new macro \definemathfunction: ——————————————————————— \definemathcommand[cos]{\mfunction{\mathlabeltext{cos}}} % Or \definemathcommand[cos]{\mfunction[nolop]{\mathlabeltext{cos}}}, it is the same. \definemathcommand[det]{\mfunction[limop]{\mathlabeltext{det}}} \definemathcommand[diff]{\normalmathop{\text{\mathfunctionstyle d}}\mathopen{}} %etc. ——————————————————————— or ——————————————————————— \definemathfunction[cos]{\mathlabeltext{cos}} % Or \definemathfunction[cos][nolop]{\mathlabeltext{cos}}, it is the same. \definemathfunction[det][limop]{\mathlabeltext{det}} \definemathcommand[diff]{\normalmathop{\text{\mathfunctionstyle d}}\mathopen{}} % It is a special function so it should still be treated with the more general \definemathcommand. %etc. ——————————————————————— Notice the removal of [nolop] and [limop] which are already present in \mfunction and \mfunction[limop] respectively (since we now use the 2nd definition of \mfunction for all the reasons we gave above). Now before concluding, here is a little example illustrating the new mechanism of Hans (functionstyle, functioncolor, textstyle and textcolor keys in \setupmathematics) of which I improved the consistency and simplicity of the related macros (\mtext and \mfunction, and the new \definemathfunction) in practical use. In this example as I still don't have access to the last beta I didn't use the new keys of \setupmathematics (functionstyle, textstyle) but local definitions. For Aditya, this time the given example works correctly contrary to my last post where I realized afterwards that \rm was not working in \setupmathematics because of the use of \mathop which converts it to \mf (hence my use of \normalmathop in this post as explained earlier). EXAMPLE. ——————————————————————— \define\mathtextstyle{\rm\tf} \define[1]\mtext{\text{\mathtextstyle #1}} \define\mfunction{\dosingleempty\domfunction} \def\domfunction[#1]#2{% \iffirstargument \doifelse{#1}{op}{\normalmathop{\text{\mathfunctionstyle #2}}}{\doifelse{#1}{limop}{\normalmathop{\text{\mathfunctionstyle #2}}}{\normalmathop{\text{\mathfunctionstyle #2}}\nolimits}} \else \normalmathop{\text{\mathfunctionstyle #2}}\nolimits \fi} \define\mathfunctionstyle{\rm\tf} \define\definemathfunction{\dodoubleempty\dodefinemathfunction} \def\dodefinemathfunction[#1][#2]#3{% \ifsecondargument \definemathcommand[#1]{\mfunction[#2]{#3}} \else \definemathcommand[#1]{\mfunction{#3}} \fi} \setupmathlabeltext[arsinh=Arsinh] \definemathfunction[arsinh]{\mathlabeltext{arsinh}} \starttext \startbuffer $\arsinh x\ \text{and}\ n_{\mtext{air}}$ \stopbuffer \defineparagraphs[myparagraphs][n=5, rule=on] \setupparagraphs[myparagraphs][1][width=\dimexpr 0.3\textwidth\relax] \setupparagraphs[myparagraphs][2][width=\dimexpr 0.3\textwidth\relax] \setupparagraphs[myparagraphs][3][width=\dimexpr 0.3\textwidth\relax] \section{{\tt \backslash setupmathematics[functionstyle=\backslash rm\backslash tf,textstyle=\backslash rm\backslash tf]} (default setup)} \define\mathfunctionstyle{\rm\tf} \define\mathtextstyle{\rm\tf} \startmyparagraphs \switchtobodyfont[rm] {\tt \backslash switchtobodyfont[rm]}\crlf {\tt \backslash tf}: {\tf \getbuffer}\par {\tt \backslash it}: {\it \getbuffer}\par {\tt \backslash sl}: {\sl \getbuffer}\par {\tt \backslash bf}: {\bf \getbuffer}\par {\tt \backslash bi}: {\bi \getbuffer}\par {\tt \backslash bs}: {\bs \getbuffer}\par \nextmyparagraphs \switchtobodyfont[ss] {\tt \backslash switchtobodyfont[ss]}\crlf {\tt \backslash tf}: {\tf \getbuffer}\par {\tt \backslash it}: {\it \getbuffer}\par {\tt \backslash sl}: {\sl \getbuffer}\par {\tt \backslash bf}: {\bf \getbuffer}\par {\tt \backslash bi}: {\bi \getbuffer}\par {\tt \backslash bs}: {\bs \getbuffer}\par \nextmyparagraphs \switchtobodyfont[tt] {\tt \backslash switchtobodyfont[tt]}\crlf {\tt \backslash tf}: {\tf \getbuffer}\par {\tt \backslash it}: {\it \getbuffer}\par {\tt \backslash sl}: {\sl \getbuffer}\par {\tt \backslash bf}: {\bf \getbuffer}\par {\tt \backslash bi}: {\bi \getbuffer}\par {\tt \backslash bs}: {\bs \getbuffer}\par \stopmyparagraphs \section{{\tt \backslash setupmathematics[functionstyle=\backslash tf,textstyle=\backslash tf]}} \define\mathfunctionstyle{\tf} \define\mathtextstyle{\tf} \startmyparagraphs \switchtobodyfont[rm] {\tt \backslash switchtobodyfont[rm]}\crlf {\tt \backslash tf}: {\tf \getbuffer}\par {\tt \backslash it}: {\it \getbuffer}\par {\tt \backslash sl}: {\sl \getbuffer}\par {\tt \backslash bf}: {\bf \getbuffer}\par {\tt \backslash bi}: {\bi \getbuffer}\par {\tt \backslash bs}: {\bs \getbuffer}\par \nextmyparagraphs \switchtobodyfont[ss] {\tt \backslash switchtobodyfont[ss]}\crlf {\tt \backslash tf}: {\tf \getbuffer}\par {\tt \backslash it}: {\it \getbuffer}\par {\tt \backslash sl}: {\sl \getbuffer}\par {\tt \backslash bf}: {\bf \getbuffer}\par {\tt \backslash bi}: {\bi \getbuffer}\par {\tt \backslash bs}: {\bs \getbuffer}\par \nextmyparagraphs \switchtobodyfont[tt] {\tt \backslash switchtobodyfont[tt]}\crlf {\tt \backslash tf}: {\tf \getbuffer}\par {\tt \backslash it}: {\it \getbuffer}\par {\tt \backslash sl}: {\sl \getbuffer}\par {\tt \backslash bf}: {\bf \getbuffer}\par {\tt \backslash bi}: {\bi \getbuffer}\par {\tt \backslash bs}: {\bs \getbuffer}\par \stopmyparagraphs \section{{\tt \backslash setupmathematics[functionstyle=\backslash bf,textstyle=\backslash bf]}} \define\mathfunctionstyle{\bf} \define\mathtextstyle{\bf} \startmyparagraphs \switchtobodyfont[rm] {\tt \backslash switchtobodyfont[rm]}\crlf {\tt \backslash tf}: {\tf \getbuffer}\par {\tt \backslash it}: {\it \getbuffer}\par {\tt \backslash sl}: {\sl \getbuffer}\par {\tt \backslash bf}: {\bf \getbuffer}\par {\tt \backslash bi}: {\bi \getbuffer}\par {\tt \backslash bs}: {\bs \getbuffer}\par \nextmyparagraphs \switchtobodyfont[ss] {\tt \backslash switchtobodyfont[ss]}\crlf {\tt \backslash tf}: {\tf \getbuffer}\par {\tt \backslash it}: {\it \getbuffer}\par {\tt \backslash sl}: {\sl \getbuffer}\par {\tt \backslash bf}: {\bf \getbuffer}\par {\tt \backslash bi}: {\bi \getbuffer}\par {\tt \backslash bs}: {\bs \getbuffer}\par \nextmyparagraphs \switchtobodyfont[tt] {\tt \backslash switchtobodyfont[tt]}\crlf {\tt \backslash tf}: {\tf \getbuffer}\par {\tt \backslash it}: {\it \getbuffer}\par {\tt \backslash sl}: {\sl \getbuffer}\par {\tt \backslash bf}: {\bf \getbuffer}\par {\tt \backslash bi}: {\bi \getbuffer}\par {\tt \backslash bs}: {\bs \getbuffer}\par \stopmyparagraphs \stoptext ——————————————————————— CONCLUSION. — It all comes down to the choice of the best user interface for math functions and math texts (usually used as subscripts of variables). Their styles and colors is handled with \setupmathematics. There are two choices of user interface: 1. $\normalmathop{\mfunction{Arsinh}}\nolimits x\ \text{and}\ n_{\mtext{air}}$. 2. $\mfunction{Arsinh} x\ \text{and}\ n_{\mtext{air}}$. First, the default functionstyle and textstyle in \setupmathematics should be \rm\tf (the text mode equivalent of \mathupright, as we are always in text mode thanks to the \text hardcoded in \mfunction and \mtext). Then, in the 1st solution \normalmathop is used instead of \mathop because the latter is modified by ConTeXt to convert \rm to \mf, which makes \setupmathematics[functionstyle=\rm] without effect. The 2nd solution is obviously way cleaner, that is why I think it should be preferred. The implementation is given in my '2nd DEFINITION of \mfunction' for replacing the existing definition in math-ini.mkiv: ——————————————————————— \unexpanded\def\mfunction{\dosingleempty\domfunction} \def\domfunction[#1]#2% {\iffirstargument \doifelse{#1}{op}{\normalmathop{\text{\usemathematicsstyleandcolor\c!functionstyle\c!functioncolor#2}}}{\doifelse{#1}{limop}{\normalmathop{\text{\usemathematicsstyleandcolor\c!functionstyle\c!functioncolor#2}}}{\normalmathop{\text{\usemathematicsstyleandcolor\c!functionstyle\c!functioncolor#2}}\nolimits}} \else \normalmathop{\text{\usemathematicsstyleandcolor\c!functionstyle\c!functioncolor#2}}\nolimits \fi} ——————————————————————— We also saw that \mfunctionlabeltext is inconsistent with ConTeXt \labeltext because the former has a style attached to it, so \mfunctionlabeltext should be removed from math-ini.mkiv and \mfunction{\mathlabeltext } should be used instead when needed. To go even further in userfriendlyness, we the new macro \definemathcommand should be added in math-ini.mkiv: ——————————————————————— \unexpanded\def\definemathfunction{\dodoubleempty\dodefinemathfunction} \def\dodefinemathfunction[#1][#2]#3% {\ifsecondargument \definemathcommand[#1]{\mfunction[#2]{#3}} \else \definemathcommand[#1]{\mfunction{#3}} \fi} ——————————————————————— Finally, with this new \mfunction definition and the removal of the misleading \mfunctionlabeltext, the functions defined in math-def.mkiv should be rewrite as: ——————————————————————— \definemathcommand[cos]{\mfunction{\mathlabeltext{cos}}} % Or \definemathcommand[cos]{\mfunction[nolop]{\mathlabeltext{cos}}}, it is the same. \definemathcommand[det]{\mfunction[limop]{\mathlabeltext{det}}} \definemathcommand[diff]{\normalmathop{\text{\mathfunctionstyle d}}\mathopen{}} %etc. ——————————————————————— or ——————————————————————— \definemathfunction[cos]{\mathlabeltext{cos}} % Or \definemathfunction[cos][nolop]{\mathlabeltext{cos}}, it is the same. \definemathfunction[det][limop]{\mathlabeltext{det}} \definemathcommand[diff]{\normalmathop{\text{\mathfunctionstyle d}}\mathopen{}} % It is a special function so it should still be treated with the more general \definemathcommand. %etc. ——————————————————————— ConTeXt users are now provided, if Hans agrees to implement the code given in this conclusion, with three extremely useful macros: — \mtext (that should be used for all math texts such as subscripts of variables): $n_{\mtext{air}}$; — \mfunction (the equivalent of LaTeX \operatorname macro of the amsopn package): $\mfunction{Arsinh} x$ $\mfunction[op]{Arsinh} x$ or equivalently $\mfunction[limop]{Arsinh} x$; — \definemathfunction (the equivalent of LaTeX \DeclareMathOperator macro of the amsopn package): \definemathfunction[arsinh]{Arsinh} $\arsinh x$ \definemathfunction[arsinh][op]{Arsinh} $\arsinh x$ or equivalently \definemathfunction[arsinh][limop]{Arsinh} $\arsinh x$. Maggyero