You can see some textbooks, like :
Definition 2.1.1 The language of propositional logic has an alphabet consisting of
(i) proposition symbols: $p_0,p_1,p_2,\ldots$,
<p><em>(ii)</em> connectives: $∧,∨,→,¬,↔,⊥$,</p>
<p><em>(iii)</em> auxiliary symbols: ( , ).</p>
Definition 2.1.2 The set $PROP$ of propositions is the smallest set $X$ with the properties
(i) $p_i \in X (i \in \mathbb N), ⊥ \in X$,
<p><em>(ii)</em> if $\varphi, \psi \in X$, then $(\varphi \square \psi) \in X$, where $\square$ is one of the connectives $∧,∨,→,↔$. </p>
<p><em>(iii)</em> if $\varphi \in X$, then $(¬ \varphi) \in X$.</p>
Properties of propositions are established by an inductive procedure analogous to Definition 2.1.2: first deal with the atoms, and then go from the parts to the composite
propositions. This is made precise in the following theorem.
Theorem 2.1.3 (Induction Principle) Let $A$ be a property, then $A(\varphi)$ holds for all $\varphi \in PROP$ if
(i) $A(p_i)$, for all $i$, and $A(⊥)$,
<p><em>(ii)</em> if $A(\varphi),A(\psi)$, then $A((\varphi \square \psi))$,</p>
<p><em>(iii)</em> if $A(\varphi)$, then $A((¬ \varphi))$.</p>
We call an application of Theorem 2.1.3 a proof by induction on $\varphi$.
[...]
Example Each proposition has an even number of brackets. Proof :
(i) Each atom has $0$ brackets and $0$ is even.
<p><em>(ii)</em> Suppose $\varphi$ and $\psi$ have $2n$, resp. $2m$ brackets, then $(\varphi \square \psi)$ has $2(n + m + 1)$ brackets.</p>
<p><em>(iii)</em> Suppose $\varphi$ has $2n$ brackets, then $(¬ \varphi)$ has $2(n +1)$ brackets.</p>
[...]
In arithmetic one often defines functions by recursion [...]. The justification is rather immediate: each value is obtained by using the preceding values (for positive arguments). There is an analogous principle in our syntax.
Example 1. The number $b(\varphi)$ of brackets of $\varphi$, can be defined as follows:
$b(\varphi) =0$ for $\varphi$ atomic,
<p>$b((\varphi \square \psi)) = b(\varphi)+b(\psi)+2$,</p>
<p>$b((¬ \varphi)) = b(\varphi)+2$.</p>
The value of $b(\varphi)$ can be computed by successively computing $b(\psi)$ for its subformulas $\psi$.
We can give this kind of definition for all sets that are defined by induction. The
principle of “definition by recursion” takes the form of “there is a unique function
such that ...”. The reader should keep in mind that the basic idea is that one can
“compute” the function value for a composition in a prescribed way from the function
values of the composing parts.
The general principle behind this practice is laid down in the following theorem.
Theorem 2.1.6 (Definition by Recursion) Let mappings $H_{\square} : A^2 \to A$ and
$H_¬ : A \to A$ be given and let $H_{at}$ be a mapping from the set of atoms into $A$, then there exists exactly one mapping $F : PROP \to A$ such that
$F(\varphi) = H_{at}(\varphi)$ for $\varphi$ atomic,
<p>$F((\varphi \square \psi)) = H_{\square}(F(\varphi),F(\psi))$,</p>
<p>$F((¬ \varphi)) = H_¬(F(\varphi))$.</p>
[...]
Example 2. The rank $r(\varphi)$ of a proposition $\varphi$ is defined by
$r(\varphi) = 0$ for atomic $\varphi$,
<p>$r((\varphi \square \psi)) = max(r(\varphi), r(\psi)) + 1$,</p>
<p>$r((¬ \varphi)) = r(\varphi)+1$.</p>
We now use the technique of definition by recursion to define the notion of subformula.
Definition 2.1.7 The set of subformulas $Sub(\varphi)$ is given by
$Sub(\varphi) = \{ \varphi \}$ for atomic $\varphi$
<p>$Sub(\varphi_1 \quad \varphi_2) = Sub(\varphi_1) \cup Sub(\varphi_2) \cup \{ \varphi_1 \square \varphi_2 \}$</p>
<p>$Sub(¬ \varphi) = Sub(\varphi) \cup \{ ¬ \varphi \}$.</p>
We say that $\psi$ is a subformula of $\varphi$ if $\psi \in Sub(\varphi)$.
For a formalization into set theory, see :
and the final remark [page 93] :
Working in set theory, the set $\mathcal W$ of symbols can have arbitrary cardinality, but if $\mathcal W$ is finite or countable, it is conventional to assume that $\mathcal W \subseteq HF$. Then [...] all expressions will lie in $HF$ also, [... i.e.] all finite mathematics lives within $HF$ [where $HF$ is the set of hereditarily finite sets (see page 74)].