Automatically crossing 7's and Z's in mathematical formulae

The simplest answer is: do not do this.

A longer answer: crossed or uncrossed 7's and z's are features of a font. A font designer spent hours and hours making his or her font aesthetically consistent, readable and pleasant. When you make this change, you basically overturn his or her decision; in most cases it looks just awful.


Also I strongly recommend choosing a math font with such digits, or design one. For learning about TeX, and for using in math homework, I don't see a big problem, however consider not doing such things with possible side effects in an important document.

To answer your question, you could do it by making 7 and Z active characters in math mode, very similar to the answer of in Can (pdf)LaTeX recognize text strings and replace (expand) them.

\documentclass[a4paper]{article}
\begingroup\lccode`~=`7\lowercase{\endgroup
  \edef~{\rlap{\noexpand\textbf{--}}\mathchar\the\mathcode`7}}
\mathcode`7="8000
\begin{document}
The 7 crossed in only math mode: $3 + 4 = 7$
\end{document}

crossed symbol

Tags:

Symbols