2

I started to use the cool package for my maths, especially for integrals, but also for trigonometric functions. I would like to get things like a sine-square function, for example, using a code like \Sin[2]{x} yielding sin²(x). Also, I would like to add a sinc function, e.g. I know I could simply redefine the \Sin command but it would like to keep it consistent with the cool package.

Following the cool package implementation documentation 1 stupidly I've tried the following which is not working:

\documentclass{article}
\usepackage{cool}
\renewcommand{\Sin}[2][]{\sin^{#1}\COOL@decide@paren{Sin}{#2}}
\newcommand{\COOL@notation@SincParen}{p}
\DeclareMathOperator{\SincSymb}{Si}
\newcommand{\Sinc}[1]{\SincSymb\COOL@decide@paren{Sinc}{#1}}
\begin{document}
  \begin{align}
    \Sin{x} \\ % should produce the normal cool sin
    \Sin[2]{x} \\ % should produce sin^2
    \Sinc{x} % should produce sinc
  \end{align}
\end{document}

Of course, the next step would be to make also sinc² possible.

How is any of this possible?

1

First of all you forgot \makeatletter and \makeatother; then it's straighforward:

\documentclass{article}
\usepackage{cool}

\makeatletter
\renewcommand{\Sin}[2][]{%
  \sin\if\relax\detokenize{#1}\relax\else^{#1}\fi\COOL@decide@paren{Sin}{#2}%
}
\newcommand{\COOL@notation@SincParen}{p}
\DeclareMathOperator{\sinc}{sinc}
\newcommand{\Sinc}[2][]{%
  \sinc\if\relax\detokenize{#1}\relax\else^{#1}\fi\COOL@decide@paren{Sinc}{#2}%
}
\makeatother

\begin{document}

\begin{gather*}
\Sin{x}    \\ % should produce the normal cool sin
\Sin[2]{x} \\ % should produce sin^2
\Sinc{x}   \\ % should produce sinc
\Sinc[2]{x}   % should produce sinc^2
\end{gather*}

\end{document}

I'm not sure where the advantage over \sinc^{2}(x) is.

enter image description here

  • oh right, I've never written own TeX commands using @ before. Thanks a lot! The difference between \sinc and \Sinc as defined above is a) that I might be able to change the parantheses in a consistent way, b) that they automatically change size with the content and c) I was thinking about implementing more commands in the cool package style which might profit more from the code, but sinc was an easy example. – riddleculous Feb 11 '16 at 15:04
  • 1
    @riddleculous Well, I just write \sin^2x without parentheses, as it has been common for about four centuries. ;-) – egreg Feb 12 '16 at 9:57
  • I agree, that is a method I am aware of ;) , but in my case, x is often a more complicated expression like a sum or product which makes parantheses useful. In the end, as I said, it also helps me to define other operators and functions that I use and that have a variable number of arguments. Sin and x were just chosen for simplicity. In the end it was that old \makeatletter problem – riddleculous Feb 12 '16 at 10:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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