In most places, by convention one can write $\cos^2{x}$ to mean $(\cos(x))^2=\cos(x) \cdot \cos(x)$. Calculators additionally usually interpret $\cos(x)^2$ as $\cos^2(x)$, though as far as I can tell, this way is disliked by many mathematicians, as it implies $\cos(x^2)$, which is something completely different.
My question is, how valid are the following representations of $(\ln(x))^2$?
$$\ln^2x$$ $$\ln^2(x)$$ $$\ln(x)^2$$
What about for other (trigonometric) functions, or just functions $f(x)$ in general?
$$f^2x$$ $$f^2(x)$$ $$f(x)^2$$
For all functions in general, $f^2(x)$ is the one that I will prefer and suggest to you. $f^2x$ is also equivalently correct but the parenthesis around $x$ look better. However, the notation $f(x)^2$ is a bit confusing as to what is being squared - the function $f$ or the variable $x$. So, to use this notation, you need to use curly brackets around $f$, like $\{f(x)\}^2$.
Similarly, in accordance to the above mentioned details, $\ln^2(x)$ is the most correct notation followed by $\ln^2x$ while the notation $\ln(x)^2$ is confusing and I would dub it wrong.
Addendum: As per guestDiego's comment,