我正在尝试格式化如下所示的Association
内容:Mathematica
这是我目前所拥有的,但它看起来不一样:
\documentclass{article}
\usepackage{graphicx} % for \scalebox macro
\newcommand\rightassn{
\mathrel{\ooalign{\hss$|$\hss\cr%
\kern0.9ex\raise0.2ex\hbox{\scalebox{0.7}{$\rangle$}}}}}
\newcommand\leftassn{\mathrel{\ooalign{\hss\raise0.2ex\hbox{\scalebox{0.7}{$\langle$}}\hss\cr%
\kern0.9ex\hbox{$|$}}}}
\begin{document}
$\leftassn 1 \rightarrow a, 2 \rightarrow b \rightassn$
\end{document}
答案1
我使用 Courier New/Consolas/Source Code Pro 以及 Mathematica Mono(可以在本地安装目录中找到)来格式化它:
\documentclass{article}
\usepackage{fontspec,xcolor}
% Default colors of Mathematica
\definecolor{mma@string}{RGB}{102,102,102}
\definecolor{mma@symbol}{RGB}{0,44,195}
\definecolor{mma@comment}{RGB}{69,148,174}
\newfontfamily\mma{MathematicaMono}[%
Path=C:/Program Files/Wolfram Research/Mathematica/11.3/SystemFiles/Fonts/TrueType/,
Extension=.ttf,
UprightFont=*, BoldFont=*-Bold]
\newcommand\Association[1]{{\mma\symbol{"F113}}#1{\mma\symbol{"F114}}}
\newcommand\RightArrow{{\mma\symbol{"F522}}}
\newcommand\String[1]{"\textcolor{mma@string}{#1}"}
\newcommand\Comment[1]{\textcolor{mma@comment}{{\mma(*}\,#1\,{\mma*)}}}
\newcommand\Greek[1]{{\mma\textcolor{mma@symbol}{#1}}}
\def\TEST{%
\Association{%
1\,\,\RightArrow{}\,\,\String{a},
2\,\,\RightArrow{}\,\,\String{b},
3\,\,\RightArrow{}\,\,\Greek{αβ}}}
\begin{document}
\fontspec{Courier New}[BoldFont=* Bold]\TEST\
\Comment{Courier New}
\bfseries\TEST\
\Comment{Courier New Bold}
\fontspec{Consolas}[BoldFont=*]\TEST\
\Comment{Consolas}
\fontspec{Source Code Pro}[BoldFont=*]\TEST\
\Comment{Source Code Pro}
\end{document}
请注意,空格是手动添加的。
答案2
您可以获得自动间距,但这需要一点工作。这需要 XeLaTeX 或 LuaLaTeX。
概念证明:
\documentclass{article}
\usepackage{amsmath}
\usepackage{fontspec}
\newfontface{\assocfont}{Consolas}[NFSSFamily=assoc]
\newfontface{\wmmono}{MathematicaMono}[
Path=./,
Extension=.ttf,
NFSSFamily=wmmono,
UprightFont=*,
BoldFont=*-Bold
]
\DeclareMathVersion{mono}
\DeclareSymbolFont{assoc}{TU}{assoc}{m}{n}
\SetSymbolFont{assoc}{mono}{TU}{assoc}{m}{n}
\DeclareSymbolFontAlphabet{\mathassoc}{assoc}
\DeclareSymbolFont{wmmono}{TU}{wmmono}{bx}{n}
\SetSymbolFont{wmmono}{mono}{TU}{wmmono}{bx}{n}
\newcommand{\association}[1]{{%
\mathversion{mono}%
% alphabetical symbols from Consolas
\Umathcode`"= 7 \symassoc `"
\Umathcode`α= 7 \symassoc `α
\Umathcode`β= 7 \symassoc `β
\Umathcode`,= 6 \symassoc `,
% other symbols from MathematicaMono
\Umathcode`→= 3 \symwmmono "F522
\Umathchardef\openassociation= 4 \symwmmono "F113
\Umathchardef\closeassociation= 5 \symwmmono "F114
$\openassociation\mathassoc{#1}\closeassociation$%
}}
\begin{document}
\association{1 → "a",2 → "b"}
\association{1 → "α",2 → "β"}
\end{document}