Is it okay to write $\ln^2(x)$ or $\ln(x)^2$ instead of $(\ln(x))^2$? 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$$
 A: 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,

Maybe a caveat is necessary here: in many contests
  $f^2(x)=(f∘f)(x)=f(f(x))$. This is not the case of
  $\ln$ and $\sin$,$\cos$ essentially for an established traditional use,
  so normally $\sin^2(x)=(\sin(x))^2$. In other cases I
  would be cautious even in using this notation. Of course the totally
  non ambiguous notation is $(f(x))^2$. Unfortunately it is more
  costly.

A: From the existence of $\LaTeX$ it is very common in books or papers write $f(x)^2$ as a way to write $(f(x))^2$. 
The use of $f^2(x)$ is totally deprecated nowadays due to aesthetics reasons of the render of $\LaTeX$.
