我的 LaTeX(数学)代码可以改进吗?

我的 LaTeX(数学)代码可以改进吗?

我感觉我的代码写得效率不太高。

\documentclass[a4paper,11pt]{article}
\usepackage[english]{babel}
\usepackage[pdftex]{graphicx}
\usepackage{tikz}
\usepackage{wasysym}
\usepackage[all]{xy}
\usepackage{amsfonts}

\title{Discrete Mathematics -- Lecture 15}
\author{Alec Taylor}
\date{August 25, 2011}

\begin{document}

\maketitle

\section{Disjoint definition}
Sets A and B are \underline{disjoint} if A $\cap$ B = \{ c,d,e \}
\\[2mm]
But if C=\{ x,y,z \} then A and C are disjoint, B and C are disjoint.
\begin{center}
\line(1,0){250}
\end{center}

Note: A $\subseteq$ A so A $\in$  $\mathcal{P}$(A)
\\[2mm]
$\mathcal{P}$ $\subseteq$ A so $\emptyset$ $\in$ $\mathcal{P}$(A)
\\[2mm]
x $\in$ A, \{x\} A, \{x\} $\in$ $\mathcal{P}$(A)

\section{Cartesian definition}
The \underline{cartesian product} of the set $A_1$, $A_2$, ..., $A_n$ is $A_1$ $\times$ $A_2$ $\times$ ... $\times$ $A_n$ 
\newline
=\{($a_1$, $a_2$, ..., $a_n$)(a, $\in$$A_1$)$\land$($a_2$$\in$$A_2$)$\land$...$\land$($a_n$$\in$$A_n$)\}
\\[2mm]
The element ($a_1$, $a_2$, ..., $a_n$) is an \underline{ordered n-tuple}.
\\[2mm]
E.g.: (x,y) in cartesian plan (i.e.: the coordiantes of a point in the plane) is an ordered pair, the Cartesian plane is the product $\mathbb{R}$x$\mathbb{R}$ or $\mathbb{R}^2$.

\section{Cardinality definition}
In general if $\|$A$\|$=n, $\|$B$\|$=m then $\|$A $\times$ B$\|$ = $\|$A$\|$ $\|$B$\|$
\\[2mm]
$\|$$A^n$$\|$=$\|$A$\|$ $\|$A$\|$ (<n times>) $\|$A$\|$ = $\|$$A^n$$\|$
\end{document}
\documentclass[a4paper,11pt]{article}
\usepackage[english]{babel}
\usepackage[pdftex]{graphicx}
\usepackage{tikz}
\usepackage{wasysym}
\usepackage[all]{xy}
\usepackage{amsfonts}

\title{Discrete Mathematics -- Lecture 16}
\author{Alec Taylor}
\date{August 25, 2011}

\begin{document}

\maketitle

\section{Laws}
Let A = \{ x $\in$ $\mathbb{Z}$ $\|$  x $\le$ 5 \}
\newline
Let B = \{ x $\in$ $\mathbb{Z}$ $\|$ x $>$ 0 \}
\\[2mm]
A $\cap$ B = \{ x $\in$ $\mathbb{Z}$ $\|$ (x $\le$ 5) $\land$ (x $>$0) \}
\newline
= \{ 1,2,3,4,5 \}
\\[2mm]
A $\cup$ B = \{ x $\in$ $\mathbb{Z}$ $\|$ (x $\le$ 5) $\lor$ (x $>$ 0) \} = $\mathbb{Z}$
\\[2mm]
$\bar{A}$ = \{ x $\in$ $\mathbb{Z}$  $\|$ x $>$ 5 \}
\newline
= \{x $\in$ $\mathbb{Z}$ $\|$-(x$\le$5) \}
\\[2mm]
A $\cap$ $\mathbb{P}$ = A
\\[2mm]
A $\cap$ $\bar{A}$ = $\diameter$
\\[2mm]
A $\cap$ $\diameter$ = $\diameter$
\\[2mm]
A $\cup$ (A $\cap$ B) $\equiv$ A
\\[2mm]
A $\cap$ B
\begin{tikzpicture}
\filldraw[fill=gray] (-2,-2) rectangle (3,2);
\scope % A \cap B
\clip (0,0) circle (1);
\fill[white] (1,0) circle (1);
\endscope
% outline
\draw (0,0) circle (1)
      (1,0) circle (1);
\end{tikzpicture}
\\[2mm]
$\overline{A \cap B}$ \tikz \fill[even odd rule] (0,0) circle (1) (1,0) circle (1);

\section{Equivalency}
Two expressions involving sets are equivalent if ew can represent them with the same venn diagram. This corresponds to using truthg tables to establish equivalence of logical expressions.

\subsection{Examples}
\subsubsection{Example 1}
Let $\mathbb{P}$ = \{ 1,2, ..., 10 \}
\newline
A = \{ 2,4,7,9 \}
\newline
B = \{ 1,4,6,7,10 \}
\newline
C = \{ 3,5,7,9 \}

\subsubsection{Example 2}
Find B $\cap$ $\bar{C}$
\newline
$\bar{C}$=\{1,2,4,6,8,10\}
\newline
So B $\cap$ $\bar{C}$ = \{1,4,6,10\}

\subsubsection{Example 3}
Find (A $\cap$ $\bar{B}$) $\cup$ C = (A $\cap$ \{ 2,3,5,9,9 \}) $\cup$ C = \{ 2,9 \} $\cup$ C = \{ 2,3,5,7,9 \}
\subsubsection{Example 4}
Find $\overline{B \cup C}$ $\cap$ C = \{ $\overline{1,3,4,5,6,7,8,10}$\} $\cap$ C = \{ 2,8 \} $\cap$ C = $\diameter$

\subsubsection{Example 5}
Show that  (A $\cup$ $\bar{B}$) $\cap$ (A $\cup$ B) = A
\newline
(A $\cup$ $\bar{B}$) $\cap$ (A $\cup$B) = ((A $\cup$ $\bar{B}$) $\cap$ A) $\cup$ ((A $\cup$ $\bar{B}$) $\cap$ B) \underline{\bf distr}
\newline
=((A $\cup$ $\bar{B}$) $\cap$ A) $\cup$ ((A $\cap$ B) $\cup$ ($\bar{B}$ $\cap$ B)) \underline{\bf distr}
\newline
= A $\cup$ ((A$\cap$B)$\cup$($\bar{B}$ $\cap$ B)) \underline{\bf absorption}
\newline
= A $\cup$ (A $\cap$ B) \underline{\bf identity}
\newline
= {\bf A}
\end{document}

有没有更好的写法?

仅供参考:我在讲座期间打印了这些笔记。

答案1

以下是我对如何重写第 16 讲的建议。新版本利用了amsmathamssymbntheorem包的构造。我还简化了大部分数学表达式,至少相对于初始形式而言。\mathstrut插入了一些 s 来稍微提高上划线部分。该命令\varnothing现在表示空集。最后,我将两个图表放入center环境中,使它们分别位于页面的中心(以及它们各自的标题)。

在此处输入图片描述

在此处输入图片描述

\documentclass[a4paper,11pt]{article}
\usepackage{graphicx,tikz}
\usepackage[all]{xy}
\usepackage{amsmath,amssymb,ntheorem}

\usepackage{ntheorem}
\theoremstyle{break}
\theorembodyfont{\upshape}
\newtheorem{example}{Example}

\title{Discrete Mathematics --- Lecture 16}
\author{Alec Taylor}
\date{August 25, 2011}

\begin{document}
\maketitle

\section{Laws}

Let $\mathbb{P}=\mathbb{Z}$, $A = \{ x\in\mathbb{Z} \mid x \le 5 \}$, 
and $B = \{ x\in\mathbb{Z} \mid x > 0 \}$. Then:
\begin{align*}
     A \cap B &= \{ x\in\mathbb{Z} \mid (x \le 5) \land (x >0) \} \\
              &= \{ 1,2,3,4,5 \} \\    
     A \cup B &= \{ x\in\mathbb{Z} \mid (x \le 5) \lor (x > 0) \} =\mathbb{Z}\\    
     \bar{A}  &= \{ x\in\mathbb{Z} \mid x > 5 \}\\                  
              &= \{ x\in\mathbb{Z} \mid -(x\le5) \}\\    
 A\cap\mathbb{P} &= A\\
 A \cap \bar{A}  &= \varnothing\\    
 A \cap \varnothing  &= \varnothing\\    
 A \cup (A \cap B) &\equiv A 
\end{align*}

\begin{center}
$A \cap B$

\medskip
\begin{tikzpicture}
\filldraw[fill=gray] (-2,-2) rectangle (3,2);
\scope % A \cap B
\clip (0,0) circle (1);
\fill[white] (1,0) circle (1);
\endscope
% outline
\draw (0,0) circle (1)
      (1,0) circle (1);
\end{tikzpicture}
\end{center}

\medskip
\begin{center}
$\overline{\mathstrut A \cap B}$ 

\medskip
\tikz \fill[even odd rule] (0,0) circle (1) (1,0) circle (1);
\end{center}


\section{Equivalency}

Two expressions involving sets are equivalent if we 
can represent them with the same venn diagram. 
This corresponds to using truth tables to establish 
equivalence of logical expressions.

\subsection{Examples}
\raggedright
Let $\mathbb{P}= \{ 1,2, \dots, 10 \}$,     
$A = \{ 2,4,7,9 \}$,  
$B = \{ 1,4,6,7,10 \}$, and   
$C = \{ 3,5,7,9 \}$.

\begin{example}    
Find $B \cap \bar{C}$.
\[
\bar{C}=\{1,2,4,6,8,10\}.\quad
\text{So $B \cap \bar{C} = \{1,4,6,10\}$}\,.
\]
\end{example}

\begin{example}    
Find $(A \cap \bar{B}) \cup C$.
\[
A \cap \bar{B} = A \cap \{ 2,3,5,9 \} = \{ 2,9 \}. 
\quad\text{Hence $(A \cap \bar{B})\cup C = \{ 2,3,5,7,9 \}$}\,.
\]
\end{example}

\begin{example}    
Find $\overline{\mathstrut B \cup C} \cap C$.
\[
\overline{\mathstrut B \cup C} \cap C = \overline{\{ 1,3,4,5,6,7,8,10\} } \cap  C 
= \{ 2,8 \} \cap C = \varnothing\,.
\]
\end{example}

\begin{example}
Show that  $(A \cup \bar{B}) \cap (A \cup B) = A$.
\begin{align*}
(A \cup \bar{B}) \cap (A \cup B) 
&= \bigl((A \cup \bar{B}) \cap A\bigr) \cup 
   \bigl((A \cup \bar{B}) \cap B\bigr) 
   \quad\textbf{distr}\\    
&= \bigl((A \cup \bar{B}) \cap A\bigr) \cup 
   \bigl((A \cap B) \cup (\bar{B} \cap B) \bigr) 
   \quad\textbf{distr}\\    
&= A \cup \bigl((A\cap B)\cup(\bar{B} \cap B)\bigr) 
     \quad\textbf{absorption}\\    
&= A \cup (A \cap B) 
   \quad\textbf{identity}\\    
&= A
\end{align*}
\end{example}

\end{document}

答案2

当然,最简单的答案是,是的- 总是有改进的空间。我能做出的一个主要观察是:LaTeX 中的数学模式不仅限于符号和运算符;您还可以在数学模式下使用字母。例如,考虑写作时的风格差异

Let A = \{ x $\in$ $\mathbb{Z}$ $\|$  x $\le$ 5 \} \newline
Let B = \{ x $\in$ $\mathbb{Z}$ $\|$ x $>$ 0 \}

和写作

Let $A=\{x \in \mathbb{Z} \mid x \leq 5\}$ \newline
Let $B=\{x \in \mathbb{Z} \mid x > 0\}$

在您的写作风格中,切换到数学模式$ $再返回文本模式会导致数学文本和符号的使用不一致。差异在相应的输出中可见(左侧是您的):

OP的数学 更好的数学模式

请注意,LaTeX 会考虑符号、字母和运算符之间的间距。

如果你有兴趣提高 LaTeX 的技术排版能力,特别是在数学方面,可以考虑阅读 Herbert Voß 的优秀mathmode文档

答案3

  • 使用amsmath高级数学功能包
    • 考虑使用以等号或关系符号对齐的多行环境。
    • 不要频繁使用\\[2mm]空行作为段落分隔符,可以\parskip在序言中增加一次。或者,在多行数学环境中使用其行距或增加\jot
    • 不要离开数学模式,考虑使用\text{...}\intertext{...}来输入数学中的文本。
  • 查看mathtools如果您想要拥有更复杂的功能。
  • 您可以使用括号和其他分隔符\left\right自动调整大小。

答案4

以下是我对如何重写第 15 讲的建议。请注意,我已定义一个命令\card{}来表示cardinality集合的。这样,如果您想更改符号,只需在文档的序言中执行一次即可。此外,我相信这也使代码更具可读性。

\documentclass[a4paper,11pt]{article}
\usepackage[english]{babel}
\usepackage{graphicx,tikz}
\usepackage{amsmath,amssymb,ntheorem}

\theoremstyle{definition}
    \theoremstyle{break}
    \theorembodyfont{\upshape}
\newtheorem{definition}{Definition}

%%\usepackage{wasysym}
\usepackage[all]{xy}

%% cardinality
\newcommand{\card}[1]{\ensuremath{\left\|#1\right\|}}

\title{Discrete Mathematics -- Lecture 15}
\author{Alec Taylor}
\date{August 25, 2011}

\begin{document}

\maketitle

\section{Definitions}

Sets $A$ and $B$ are \emph{disjoint} if $A \cap B = \varnothing$. 
Suppose $C=\{ x,y,z\}$. Then if $A$ and $C$ are disjoint, $B$ and $C$ 
are disjoint as well.


Notes: 
\begin{itemize}
\item $A \subseteq A$, so $A \in\mathcal{P}(A)$
\item $\mathcal{P}$ $\subseteq$ A so $\varnothing\in\mathcal{P}$(A) (huh?!)
\item $x \in A$, $\{x\}\subseteq A$, $\{x\} \in \mathcal{P}(A)$
\end{itemize}

\begin{definition}[Cartesian Product]
The \emph{Cartesian product} of the sets $A_1, A_2,\dots, A_n$ is
\begin{equation*}
A_1 \times A_2 \times\dots \times A_n
=\bigl\{(a_1, a_2, \dots, a_n) \bigm| (a_1 \in A_1) \land(a_2\in A_2) 
\land\dots \land(a_n\in A_n)\bigl\}\,.
\end{equation*}
Each element $(a_1, a_2, \dots, a_n)$ is an \emph{ordered $n$-tuple}.

\noindent
Example: $(x,y)$ in the Cartesian plane, i.e., the coordinates of 
a point in the plane, is an ordered pair. The Cartesian plane is 
the product $\mathbb{R}\times\mathbb{R}$ or~$\mathbb{R}^2$.
\end{definition}


\begin{definition}[Cardinality]
Denote the cardinality of a set~$A$ by~$\card{A}$. 
In general, if $\card{A}=n$ and $\card{B}=m$, 
then $\card{A\times B} = \card{A} \cdot \card{B}=mn$, and
$\card{A^n}=\underbrace{\card{A}\cdot\card{A}\dots
\card{A}}_{\text{$n$ times}} =\card{A}^n$.
\end{definition}

\end{document}

相关内容