25

I am using MathJax to display formulae on my web sites. Out of the box, MathJax recognises many functions like sin, cos, ..., but many are missing, such as sech (hyperbolic secant) and csch(hyperbolic cosecant). I know I can still use these functions in formulae by means of \text, such as

\text{sech} u

However, I would rather make \sech work. To this end, I tried

<div style="display:none">
  $\DeclareMathOperator{\sech}{sech}
   \DeclareMathOperator{\csch}{csch}$
</div>

right after <body>. (I also tried to add an asterisk after DeclareMathOperator.)

This almost works. The problem is that now

\sech^2 u

places the square above sech, instead of after it (proof). Is there a way to fix this? What is the prefered way to define new functions ('operators') in MathJax? Surely there is a good way, for who can live without a full spectrum of hyperbolic functions?!

2
  • I'm not sure if MathJax corresponds 100% to latex, but could you try \sech\nolimits^{2}? Jun 30, 2012 at 9:47
  • 1
    @phg: Thank you for your comment. Yes, that does work, but it kind of removes the benefit of making \sech work in the first place. Indeed, even \text{sech}^2 takes less characters to type than \sech\nolimits^2. Jun 30, 2012 at 9:54

1 Answer 1

20

The \DeclareMathOperator macro does not provide a means of declaring an operator that always has limits in the super- and subscript positions, which is why your \sech get the superscript placed above it when used in displayed equations.

What you want is the following:

<div style="display:none">
  $
    \newcommand{\sech}{\mathop{\rm sech}\nolimits}
    \newcommand{\csch}{\mathop{\rm csch}\nolimits}
  $
</div>

This will get you operators that work like \sin and \cos. Note that the spacing will be better with this form than with your versions using \text{...}, since \mathop will provide the proper spacing around the operator name (however there is a bug in MathJax that causes the space to be lost when there is a super- or subscript; this will be fixed in the next release).

1
  • Just put this in a macro according to the MathJaX documentation and it worked perfectly! I added <script type="text/x-mathjax-config">MathJax.Hun.Config({Tex: {Macros: {erf: "\\mathop{\\rm erf}\\nolimits"}}})<script> to my layout.html template in my _tempates folder, after making sure it the templates path was specified in my conf.py file. Aug 27, 2013 at 20:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.