This shows that "elementary function" needs a good definition. We do NOT want to allow, for example $f(x) = 1$ when $x$ rational and $f(x) = -1$ when $x$ irrational. Even though $f^2 = 1$, this $f$ is not an algebraic function.

So, correctly defined, an *elementary function* is an analytic function on a domain in the complex plane, such that ...... [fill in the usual conditions]

**Added later.** My advice: For "elementary function" do not use the popularized form of the
definition as in Wikipedia. Instead, use a definition from
the actual mathematics papers. (Papers with proofs, not
just quickie approximate definitions for the masses.)

For example

"Integration in Finite Terms", Maxwell Rosenlicht,

*The American Mathematical Monthly* 79 (1972), 963--972.

Stable URL: http://www.jstor.org/stable/2318066

Everything is carried out in differential fields ... In particular, every function involved is infinitely differentiable ... None of those
"discontinuous elementary functions" mentioned in the question.
Not even $|x| = \sqrt{x^2}$ is elementary.

===========

"Algebraic Properties of the Elementary Functions of Analysis",
Robert H. Risch,

*American Journal of Mathematics* 101 (1979) 743--759.

Stable URL: http://www.jstor.org/stable/2373917

He also works in differential fields. Some quotes:

The elementary functions of a complex variable $z$ are those analytic functions that are built up from the rational functions of $z$ by successively applying algebraic operations, exponentiating, and taking logarithms. As is well known, this class includes the trigonometric and basic inverse trigonometric functions.

[Part II]

Suppose $\mathbb{C}(z, \theta_1, \dots, \theta_m) = \mathcal{D}_m$ is the abstract field, isomorphic to a field of meromorphic functions on some
region $R$ of the complex plane, ...

==========