I have a number of trig functions raised to some powers, and the arguments are often different from just t
\sin^2{\frac{2\pi}{T}t}
for example
Now, I would like to get the argument to be in parentheses, which I know I can input manually with
\sin^2{\left(\frac{2\pi}{T}t\right)}
but I would like to get it automatically.
Now, I've tried to redefine the symbol with argument, as shown here https://tex.stackexchange.com/a/35646/106445
but when I try to add the power I get two errors: Missing { inserted, and Missing } inserted. I assume it's because it's expecting the argument and I have added the power instead. Any workaround?
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{mathtools}
\newcommand*{\redefinesymbolwitharg}[1]{%
\expandafter\newcommand\csname ltx#1\endcsname{}%
\expandafter\let\csname ltx#1\expandafter\endcsname\csname #1\endcsname
\expandafter\renewcommand\csname #1\endcsname[1]{%
\csname ltx#1\endcsname\left(##1\right)%
}%
}
\redefinesymbolwitharg{cos}
\begin{document}
\[\cos{2x}\]
\[\cos^2{2x}\]
\end{document}
There is no problem with the first one, but once I add the square as I would normally it breaks

\sindoes not take an argument. No braces{...}are needed. – Steven B. Segletes Nov 07 '18 at 04:45