latextypesetting

Typesetting New Functions in LaTeX


So, I just have a little question:

What is the "best way" to typeset new functions in LaTeX which aren't already included in the various packages? Right now I'm just using \mbox as my go-to method, but I just was wondering if there was a more "acceptable way of doing it (as with mbox, I have to make sure to include spaces around the text of the functions in order for it to not look too strange)

Here is an example:

$y(t)=2e^{1/2}\sqrt{\pi}\mbox{Erfi }(t)$

which comes out looking like:

$y(t)=2e^{1/2}\sqrt{\pi}\mbox{Erfi }(t)$ http://adamnbowen.com/images/error_function.jpg

Don't get me wrong... I think it looks fine, but I was just looking for some opinions (as far as best practices go).


Solution

  • Use \DeclareMathOperator from package amsmath. For example,

    \documentclass{article}
    \usepackage{amsmath}
    \DeclareMathOperator\erfi{Erfi}
    
    \begin{document}
    Consider $x + y + \erfi(t) = z$ for example.
    \end{document}
    

    produces

    result

    If you only need it once, you can also use \operatorname: you get the same output as above with

    \documentclass{article}
    \usepackage{amsmath}
    \begin{document}
    Consider $x + y + \operatorname{Erfi}(t) = z$ for example.
    \end{document}
    

    If you cannot use the amsmath package for some reason, you can manually do \mathop{\mathrm{Erfi}} like:

    \documentclass{article}
    \begin{document}
    Consider $x + y + \mathop{\mathrm{Erfi}}(t) = z$ for example.
    \end{document}
    

    See the always-useful TeX FAQ, specifically Defining a new log-like function in LaTeX.