Chapter 5 Authoring

A book to be published in MathPage needs the
mathpage
LaTeX package. Download the following package file to the same folder where are the files of the book.
Then open the main LaTeX file of the book and add the following line just below the line
\documentclass{...}
.
\usepackage{mathpage}
In this chapter, it is assumed that the
mathpage
package is used.

Section 1 Paragraphs

Paragraph
A group of sentences forms a paragraph.
This is the first paragraph! This is the second sentence.
This is the third sentence.
This is the first paragraph! This is the second sentence. This is the third sentence.
A new paragraph is separated from the previous paragraph by a blank line.
This is the first paragraph! This is the second sentence.
This is the third sentence.

This is the second paragraph. This is the fifth sentence.
This is the first paragraph! This is the second sentence. This is the third sentence.
This is the second paragraph. This is the fifth sentence.

Section 2 Sectioning

Chapter
\chapter{Authoring}

This is the first sentence.
Section
\section{Sectioning}

This is the first sentence.
1 Subsection
Subsection
\subsection{Subsection}

This is the first sentence.
Subsubsection
Subsubsection
\subsubsection{Subsubsection}

This is the first sentence.
Paragraph
\paragraph{Paragraph} This is the first sentence.

Section 3 Maths

Inline maths
Maths in a sentence are surrounded by
$
and
$
.
The equation $e^{\pi i}+1=0$ holds.
The equation ​\(e^{\pi i}+1=0\) holds.
Display maths
To display a math expression, it is placed between
\[
and
\]
.
The equation
\[
    e^{\pi i}+1=0
\]
holds.
The equation
\[ e^{\pi i}+1=0 \]
holds.
Numbers and variables
Variables in a formula are in italic typeface.
$1+1$
   ​\(1+1\)
$3.141592$
   ​\(3.141592\)
$1+2i$
   ​\(1+2i\)
$z=2a+3y$
   ​\(z=2a+3y\)
$f(x)=-x+5$
   ​\(f(x)=-x+5\)
Superscripts and subscripts
Use
^
to attach superscripts and use
_
for subscripts.
$x_2 + y^{-2}$
   ​\(x_2 + y^{-2}\)
$x_1 + y_2$
   ​\(x_1 + y_2\)
$e^{1234}$
   ​\(e^{1234}\)
$x^3-3x^2+3x-1=(x-1)^3$
   ​\(x^3-3x^2+3x-1=(x-1)^3\)
Fractions
$-\frac{2}{3}$
   ​\(-\frac{2}{3}\)
$\frac{c}{a+b}$
   ​\(\frac{c}{a+b}\)
Roots
$\sqrt{2}$
   ​\(\sqrt {2}\)
$\frac{-b+\sqrt{b+4ac}}{2a}$
   ​\(\frac{-b+\sqrt {b+4ac}}{2a}\)
Special symbols
$\pm$
   ​\(\pm \)
Greek letters
$\pi$
   ​\(\pi \)
Trigonometric functions
$\sin(\pi)$
   ​\(\sin (\pi )\)
$\cos(-\pi)$
   ​\(\cos (-\pi )\)
$\tan(\frac{4}{\pi})$
   ​\(\tan (\frac{4}{\pi })\)
Operators
$A\cap B$
   ​\(A\cap B\)
$A\cup B$
   ​\(A\cup B\)
Relations
$A\subset B$
   ​\(A\subset B\)
$A\supset B$
   ​\(A\supset B\)
$A\subseteq B$
   ​\(A\subseteq B\)
$A\subsetneq B$
   ​\(A\subsetneq B\)
Inequalities
$2>-3$
   ​\(2>-3\)
$2\ge -3$
   ​\(2\ge -3\)
$-2<3$
   ​\(-2<3\)
$a\le a^2$
   ​\(a\le a^2\)
Parentheses
$a(b+c)$
   ​\(a(b+c)\)
$a\left(\frac{1}{2}(b+c)\right)$
   ​\(a\left(\frac{1}{2}(b+c)\right)\)
Binomial coefficients
$\binom{10}{5}$
   ​\(\binom{10}{5}\)
$\binom{n}{k}$
   ​\(\binom{n}{k}\)
Sum and products
$\sum_{n=1}^{10}n^2$
   ​\(\sum _{n=1}^{10}n^2\)
$\prod_{n=1}^{10}n^2$
   ​\(\prod _{n=1}^{10}n^2\)
limits
$\lim_{x\to 0}\frac{1}{x}$
   ​\(\lim _{x\to 0}\frac{1}{x}\)
$\lim_{x\to\infty} a_n$
   ​\(\lim _{x\to \infty } a_n\)
Differentiations
$\frac{dy}{dx}$
   ​\(\frac{dy}{dx}\)
$f'(x)=\cos(x)$
   ​\(f'(x)=\cos (x)\)
Integrals
$\int_{-1}^2e^x dx$
   ​\(\int _{-1}^2e^x dx\)
\[
    \int_{-1}^2e^x dx
\]
\[ \int _{-1}^2e^x dx \]
$\int\sin(x)dx=-\cos(x)+C$
   ​\(\int \sin (x)dx=-\cos (x)+C\)
\[
    \int\sin(x)dx=-\cos(x)+C
\]
\[ \int \sin (x)dx=-\cos (x)+C \]
Matrices
\[
    \begin{bmatrix}
    1 & 2 \\
    3 & 4
    \end{bmatrix}
\]
\[ \begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix} \]
\[
    \begin{matrix}
    1 & 2 \\
    3 & 4
    \end{matrix}
\]
\[ \begin{matrix} 1 & 2 \\ 3 & 4 \end{matrix} \]
\[
    \left\{\begin{matrix}
    1 & 2 \\
    3 & 4
    \end{matrix}\right.
\]
\[ \left\{ \begin{matrix} 1 & 2 \\ 3 & 4 \end{matrix}\right. \]
Array
\[
    \begin{array}{|rl|}
    \hline
    a & b \\
    aa & bb \\
    \hline
    c & d \\
    cc & dd \\
    \hline
    \end{array}
\]
\[ \begin{array}{|rl|} \hline a & b \\ aa & bb \\ \hline c & d \\ cc & dd \\ \hline \end{array} \]

Section 4 List

itemize
\begin{itemize}
  \item Sine addition formula
  \item Cosine addition formula
\end{itemize}
  • Sine addition formula
  • Cosine addition formula
\begin{itemize}
  \item Sine addition formula
  \begin{itemize}
    \item $\sin(x+y)=\sin x\cos y + \cos x\sin y$
    \item $\sin(x-y)=\sin x\cos y - \cos x\sin y$
  \end{itemize}
  \item Cosine addition formula
  \begin{itemize}
    \item $\cos(x+y)=\cos x\cos y - \sin x\sin y$
    \item $\cos(x-y)=\cos x\cos y + \sin x\sin y$
    \begin{itemize}
      \item Note 1
      \item Note 2
    \end{itemize}
  \end{itemize}
\end{itemize}
  • Sine addition formula
    • ​\(\sin (x+y)=\sin x\cos y + \cos x\sin y\)
    • ​\(\sin (x-y)=\sin x\cos y - \cos x\sin y\)
  • Cosine addition formula
    • ​\(\cos (x+y)=\cos x\cos y - \sin x\sin y\)
    • ​\(\cos (x-y)=\cos x\cos y + \sin x\sin y\)
      • *
        Note 1
      • *
        Note 2
enumerate
\begin{enumerate}
  \item $\sin(x+y)=\sin x\cos y + \cos x\sin y$
  \item $\cos(x+y)=\cos x\cos y - \sin x\sin y$
\end{enumerate}
  • 1.
    ​\(\sin (x+y)=\sin x\cos y + \cos x\sin y\)
  • 2.
    ​\(\cos (x+y)=\cos x\cos y - \sin x\sin y\)
\begin{enumerate}
  \item Sine addition formula
  \begin{enumerate}
    \item $\sin(x+y)=\sin x\cos y + \cos x\sin y$
    \item $\sin(x-y)=\sin x\cos y - \cos x\sin y$
  \end{enumerate}
  \item Cosine addition formula
  \begin{enumerate}
    \item $\cos(x+y)=\cos x\cos y - \sin x\sin y$
    \item $\cos(x-y)=\cos x\cos y + \sin x\sin y$
    \begin{enumerate}
      \item Note 1
      \item Note 2
    \end{enumerate}
  \end{enumerate}
\end{enumerate}
  • 1.
    Sine addition formula
    • (a)
      ​\(\sin (x+y)=\sin x\cos y + \cos x\sin y\)
    • (b)
      ​\(\sin (x-y)=\sin x\cos y - \cos x\sin y\)
  • 2.
    Cosine addition formula
    • (a)
      ​\(\cos (x+y)=\cos x\cos y - \sin x\sin y\)
    • (b)
      ​\(\cos (x-y)=\cos x\cos y + \sin x\sin y\)
      • i.
        Note 1
      • ii.
        Note 2
description
\begin{description}
  \item[Sine addition formula:] $\sin(x+y)=\sin x\cos y + \cos x\sin y$
  \item[Cosine addition formula:] $\cos(x+y)=\cos x\cos y - \sin x\sin y$
\end{description}
  • Sine addition formula:
    ​\(\sin (x+y)=\sin x\cos y + \cos x\sin y\)
  • Cosine addition formula:
    ​\(\cos (x+y)=\cos x\cos y - \sin x\sin y\)

Section 5 Table

Table
\begin{tabular}{|c|c||c|c|}
\hline
OS & Browser & Wifi & Camera \\
\hline\hline
Windows & Chrome & O & O \\
Windows & Edge   & O & O \\
Mac & Chrome     & O & O \\
Mac & Safari     & X & O \\
\hline
\end{tabular}
OS Browser Wifi Camera
Windows Chrome O O
Windows Edge O O
Mac Chrome O O
Mac Safari X O

Section 6 Cross Reference 1

Chapter
Refer to Chapter \ref{chap:abc}
Refer to Chapter 5
Section
Refer to Section \ref{sec:abc}
Refer to Section 5.7
Equation
The equation \eqref{equ:abc} is true
The equation (5.1) is true
The equation \eqref{equ:bcd} is false
The equation (S) is false

Section 7 Cross Reference 2

Chapter
\chapter{Authoring}\label{chap:abc}
Section
\section{Cross Reference 2}\label{sec:abc}
Equation
\begin{equation}\label{equ:abc}
    1 + 1 = 2
\end{equation}
\begin{equation}\tag{5.1} 1 + 1 = 2 \end{equation}
\[\tag{S}\label{equ:bcd}
    1 + 1 = 3
\]
\[\tag{S}\label{equ:bcd} 1 + 1 = 3 \]

Section 8 Citation

Consult the TeXbook \cite{knuth1984texbook}
Consult the TeXbook [1]
\begin{thebibliography}{1}

\bibitem{knuth1984texbook}
Donald~Ervin Knuth and Duane Bibby.
\newblock The TeXbook, volume~3.
\newblock Addison-Wesley Reading, 1984.

\end{thebibliography}

Section 9 Index

Activate index
Add the following just before
\begin{document}
.
\makeindex
Print index
Add the following just before
\end{document}
.
\printindex
Add index
MathPage\index{MathPage} is a system for online publishing

Section 10 Media

Graphic file
Let us assume a picture file graph.pdf is in the pics folder.
\begin{center}
    \includegraphics{pics/graph}
\end{center}
\begin{center}
    \includegraphics[scale=1.5]{pics/graph}
\end{center}
Video file
Let us assume an animation video file sine.mp4 is in the media folder.
\begin{center}
    \includemedia{media/sine}
\end{center}
MathPage supports only mp4 and webm as video file format. If you have a video file in a different format, you need to use a format converter, such as Handbrake, to convert your video file into a supported format.
Audio file
Let us assume an audio file Star Wars.mp3 is in the media folder.
\begin{center}
    \includemedia{media/Star Wars}
\end{center}
PDF file
Let us assume a PDF file bitcoin.pdf is in the media folder.
\begin{center}
    \includemedia{media/bitcoin.pdf}
\end{center}
HTML file
Let us assume a HTML file notebook.html is in the media folder.
\begin{center}
    \includemedia{media/notebook.html}
\end{center}
File download
Let us assume a file book-ko.cls is in the supplements folder.
\begin{center}
    \includefile{supplements/book-ko.cls}
\end{center}
Webpage inclusion
An external webpage can be included.
\begin{center}
    \includewebpage{https://en.wikipedia.org/wiki/LaTeX}
\end{center}

Section 11 Code

Display code
\begin{displaycode}{python}
a = 10
b = 15
print(a / b)
\end{displaycode}
Evaluate code
\begin{evaluatecode}{python}
a = 10
b = 15
print(a / b)
\end{evaluatecode}
Interactive visualization
\begin{evaluatecode}{sage}
@interact
def _(n=input_box(10, label='n', width=10)):
    v = [(random(), random(), random()) for _ in [1..n]]
    g = sum([cube((10*a, 10*b, 10*c), size=random(), color=(a,b,c))
             for a,b,c in v])
    show(g)
\end{evaluatecode}

Section 12 Special notes

Clickable note
\begin{mathpagenote}{clickable}
This note is visible when clicked.
\end{mathpagenote}
This note is visible when clicked.
\begin{folded}
This note is visible when clicked.
\end{folded}
This note is visible when clicked.
Hoverable note
\begin{mathpagenote}{hoverable}
This note is visible when hovered.
\end{mathpagenote}
This note is visible when hovered.
\begin{covered}
This note is visible when hovered.
\end{covered}
This note is visible when hovered.
Restricted note
\begin{mathpagenote}{restricted}
This note is visible only to the instructor.
\end{mathpagenote}
\begin{note}
This note is visible only to the instructor.
\end{note}
Restricted and clickable note
\begin{mathpagenote}{restricted, clickable}
This note is visible only to the instructor when clicked.
\end{mathpagenote}
\begin{closed}
This note is visible only to the instructor when clicked.
\end{closed}

Section 13 LaTeX Packages

To use a LaTeX package
name
, put the following line below
\documentclass{...}
.
\usepackage{name}
framed
\begin{framed}
This is framed.
\end{framed}
This is framed.
hyperref
\href{https://en.wikipedia.org/wiki/Law_of_large_numbers}{Law of large numbers}
Law of large numbers
\url{http://www.sagemath.org}
http://www.sagemath.org
minted
\mintinline{python}{s = "hello"}
s = "hello"
\begin{minted}{python}
def sum(n):
    s = 0
    for i in range(1, n + 1):
        s = s + i
    return s
\end{minted}
def sum(n):
    s = 0
    for i in range(1, n + 1):
        s = s + i
    return s
\newminted{python}{}

\begin{pythoncode}
def sum(n):
    s = 0
    for i in range(1, n + 1):
        s = s + i
    return s
\end{pythoncode}
def sum(n):
    s = 0
    for i in range(1, n + 1):
        s = s + i
    return s
fancyvrb
\newenvironment{python}{\VerbatimEnvironment\begin{displaycode}{python}}{\end{displaycode}}

\begin{python}
2**10
\end{python}