将数字排版为数学和数字

将数字排版为数学和数字

这是一个后续问题:将数字排版为数学

我正在寻找一个宏(可以命名为\one),用于排版数字1。数字的1排版样式(直立或斜体)应与变量(字母)的排版样式相同。

我想要这个,因为有时我在数学环境中写下实际上用作变量的数字。

注意:\mathit{1}不起作用,因为这1总是以斜体输入数字,而在\mathrm环境中,应该直立输入。

答案1

可能这就是你正在寻找的:

\documentclass{article}
\usepackage{amsmath,amsthm,thmtools}

\declaretheoremstyle[
  spaceabove=\topsep,
  spacebelow=\topsep,
  bodyfont=\itshape,
  break,
]{break}
\declaretheorem[
  style=break,
  name=Theorem,
]{theorem}

\newcommand{\vardigit}[1]{%
  \ifnum\mathgroup<0 \mathit{#1}\else #1\fi
}
\newcommand{\0}{\vardigit{0}}
\newcommand{\1}{\vardigit{1}}
\newcommand{\2}{\vardigit{2}}
\newcommand{\3}{\vardigit{3}}
\newcommand{\4}{\vardigit{4}}
\newcommand{\5}{\vardigit{5}}
\newcommand{\6}{\vardigit{6}}
\newcommand{\7}{\vardigit{7}}
\newcommand{\8}{\vardigit{8}}
\newcommand{\9}{\vardigit{9}}


\begin{document}

\begin{theorem}
Text and something else: $j \in \{\1, \ldots, J\}$
\end{theorem}

Text and something else: $j \in \{\1, \ldots, J\}$

Text and something else: $j \in \{\mathrm{\1, \ldots, J}\}$ 

\end{document}

在此处输入图片描述

如果你想输入这样的数字,

\documentclass{article}
\usepackage{amsmath,amsthm,thmtools}

\declaretheoremstyle[
  spaceabove=\topsep,
  spacebelow=\topsep,
  bodyfont=\itshape,
  break,
]{break}
\declaretheorem[
  style=break,
  name=Theorem,
]{theorem}

\makeatletter
\def\@temp#1{%
  \begingroup\lccode`~=`#1 \lowercase{%
    \endgroup
    \edef~%
  }{\noexpand\vardigit{\mathchar\the\mathcode`#1 }}
  \AtBeginDocument{\mathcode`#1="8000 }
}
\@temp{0}\@temp{1}\@temp{2}\@temp{3}\@temp{4}
\@temp{5}\@temp{6}\@temp{7}\@temp{8}\@temp{9}
\makeatother

\newcommand{\vardigit}[1]{%
  \ifnum\mathgroup<0 \mathit{#1}\else #1\fi
}

\begin{document}

\begin{theorem}
Text and something else: $j \in \{1, \ldots, J\}$
\end{theorem}

Text and something else: $j \in \{1, \ldots, J\}$

Text and something else: $j \in \{\mathrm{1, \ldots, J}\}$ 

\end{document}

答案2

您可以将数字设置为与字母相同的字体,但在现代计算机中,这可能并不完全符合您的预期

在此处输入图片描述

\documentclass{article}

\DeclareMathSymbol{0}{\mathalpha}{letters}{`0}
\DeclareMathSymbol{1}{\mathalpha}{letters}{`1}
\DeclareMathSymbol{2}{\mathalpha}{letters}{`2}
\DeclareMathSymbol{3}{\mathalpha}{letters}{`3}
\DeclareMathSymbol{4}{\mathalpha}{letters}{`4}
\DeclareMathSymbol{5}{\mathalpha}{letters}{`5}
\DeclareMathSymbol{6}{\mathalpha}{letters}{`6}
\DeclareMathSymbol{7}{\mathalpha}{letters}{`7}
\DeclareMathSymbol{8}{\mathalpha}{letters}{`8}
\DeclareMathSymbol{9}{\mathalpha}{letters}{`9}

\begin{document}

$ abc1 + \mathrm {abc1} + \mathsf{abc1}$

\end{document}

也许更接近的是用于数学的字体

在此处输入图片描述

\documentclass{article}


\DeclareSymbolFont{mathit}   {OT1}{cmr} {m}{it}% could make it share a slot with \mathit
\DeclareMathSymbol{0}{\mathalpha}{mathit}{`0}
\DeclareMathSymbol{1}{\mathalpha}{mathit}{`1}
\DeclareMathSymbol{2}{\mathalpha}{mathit}{`2}
\DeclareMathSymbol{3}{\mathalpha}{mathit}{`3}
\DeclareMathSymbol{4}{\mathalpha}{mathit}{`4}
\DeclareMathSymbol{5}{\mathalpha}{mathit}{`5}
\DeclareMathSymbol{6}{\mathalpha}{mathit}{`6}
\DeclareMathSymbol{7}{\mathalpha}{mathit}{`7}
\DeclareMathSymbol{8}{\mathalpha}{mathit}{`8}
\DeclareMathSymbol{9}{\mathalpha}{mathit}{`9}

\begin{document}

$ abc1 + \mathrm {abc1} + \mathsf{abc1}$

\end{document}

相关内容