3

Is there a way to display a mathematical function in the following format

$f: \mathbb{N} \to \mathbb{N}$
       $x      \to    x^2$

with the x -> x^2 just below the definition of the domain and codomain?

Sorry if this has already been asked, I am not sure how to search for it.

Mico
  • 506,678
vukov
  • 155

1 Answers1

4

If you have several of these expressions in your document, it's helpful to set up a macro that collects and organizes the elements. In the code below, I define a macro named \myfunc for this purpose; it takes five arguments: the function name, the domain, the codomain, and terms for the second row.

enter image description here

\documentclass{article}
\usepackage{array,amsfonts}
\newcommand\myfunc[5]{%
  \begingroup
  \setlength\arraycolsep{0pt}
  #1\colon\begin{array}[t]{c >{{}}c<{{}} c}
             #2 & \to & #3 \\ #4 & \to & #5 
          \end{array}%
  \endgroup}
\begin{document}
The function $\myfunc{f}{\mathbb{N}}{\mathbb{N}}{x}{x^2}$ is known \dots

\bigskip
The function $\myfunc{g}{\mathbb{R}}{\mathbb{C}}{x}{\sqrt{x}}$ is called \dots
\end{document}
Mico
  • 506,678
  • 4
    For consistency i would recommend to use '\mapsto' for the second lines ($x \mapsto x^2$) as this is the standard notion in most textbooks and lectures – manthano Jan 30 '16 at 20:01
  • 1
    @manthano - Thanks. Indeed, I thought about this too, but decided to go ahead and implement the layout the OP appears to want. ("The customer is (almost!) always right.") For a layout with \mapsto in the lower row see, e.g., my answer -- and the material in the addendum, in particular -- to the query Writing a nice function. – Mico Jan 30 '16 at 20:36