比例字体,逐字换行

比例字体,逐字换行

我如何才能获得一个使用比例字体并应用自动xelatex换行的verbatim兼容环境?我希望能够输入类似以下内容的内容...

命题2.3.13。

假设 f : M_1 -> M_2 是度量空间之间的映射。则 f 是连续的当且仅当对于每个在 M_2 中开的集合 U,f^-1(U) 在 M_1 中开。

证明

假设 f 是连续的,且 U 是 M_2 的开子集。我们需要证明 f^-1(U) 在 M_1 中是开子集。设 x \in f^-1(U)。则 f(x) \in U,且由于 U 在 M_2 中是开子集,存在 ε>0 使得 B_ε(f(x)) \subset U。根据定义 2.3.6,存在 δ>0 使得 f(B_δ(x)) \subset B_ε(f(x))。因此 f(B_δ(x)) \subset U,所以 B_δ(x) \subset f^-1(U),并且我们已经证明 f^-1(U) 在 M_1 中是开子集。

...并获得如下输出:

在此处输入图片描述

(如果您想知道我为什么要这样做,文本是输入到程序中的,因此需要按字面意思表示:将其排版_1为下标会产生误导,因为它不能通过这种方式输入到计算机中。) 编辑:不幸的是,下面的答案有一个小问题。单行换行符没有被保留。这是我的错,因为我没有用 MWE 清楚地说明我想要这个——抱歉。有人能告诉我如何修改环境vb以保留换行符吗?这是一个新的 MWE...

\documentclass[a4paper,10pt]{article}
\usepackage[T1]{fontenc}

\makeatletter

\begingroup
\lccode`\~`\\
\lowercase{\endgroup
\def\vb{%
\par
\parindent\z@
\parskip1\baselineskip plus 2pt\relax
\let\do\@makeother\dospecials%
\let\@xobeysp\space
\catcode`\ \active
\catcode`\\\active
\let~\scanendvb
}}
\def\scanendvb#1#2#3#4#5#6#7{%
\def\x{#1#2#3#4#5#6#7}%
\ifx\x\endvbstr
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
{\end{vb}}{\char`\\#1#2#3#4#5#6#7}}

\edef\endvbstr{end\string{vb\string}}

\makeatother
\def\endvb{\par}


\begin{document}
\begin{vb}
Definition 2.1.2.
A _metric space_ M = (A, d) consists of a non-empty set A together with a map d : A\times A -> \bfR such that:
    (M1a) d(x, y)\geq 0 for all x, y in A.
    (M1b) d(x, y) = 0 <=>  x = y  for all x, y in A.
    (M2) d(x, y) = d(y, x) for all x, y in A.
    (M3) d(x, y)+d(y, z)\geq d(x, z) for all x, y, z in A.
The elements of A are called the _points_ of the metric space M, and d is called a _metric_ on A. We sometimes also call d the _metric_ of M.
\end{vb}
\end{document}

答案1

在此处输入图片描述

\documentclass{article}
\usepackage{fontspec}
    \setmainfont{DejaVu Serif}
    \setsansfont{DejaVu Sans}
    \setmonofont{DejaVu Sans Mono}
\makeatletter

\begingroup
\lccode`\~`\\
\lowercase{\endgroup
\def\vb{%
\par
\parindent\z@
\parskip1\baselineskip plus 2pt\relax
\let\do\@makeother\dospecials%
\let\@xobeysp\space
\catcode`\ \active
\catcode`\\\active
\let~\scanendvb
}}
\def\scanendvb#1#2#3#4#5#6#7{%
\def\x{#1#2#3#4#5#6#7}%
\ifx\x\endvbstr
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
{\end{vb}}{\char`\\#1#2#3#4#5#6#7}}

\edef\endvbstr{end\string{vb\string}}

\makeatother
\def\endvb{\par}

\begin{document}

\begin{vb}


    Proposition 2.3.13.

    Suppose that f : M_1 -> M_2 is a map between metric spaces. Then f is continuous iff for every set U open in M_2, f^-1(U) is open in M_1.

    Proof

    Suppose that f is continuous, and let U be an open subset of M_2. We are required to prove that f^-1(U) is open in M_1. Let x \in f^-1(U). Then f(x) \in U, and since U is open in M_2 there exists ε>0 such that B_ε(f(x)) \subset U. By Definition 2.3.6, there exists δ>0 such that f(B_δ(x)) \subset B_ε(f(x)). Hence f(B_δ(x)) \subset U, so B_δ(x) \subset f^-1(U), and we have shown that f^-1(U) is open in M_1.
\end{vb}

\end{document}

相关内容