答案1
这是一组可以执行的宏。该宏\interval
具有两个字母的可选参数;如果省略,则暗示打开。仅指定o
或与和分别c
相同。oo
cc
\documentclass{article}
\usepackage{amsmath}
\usepackage{stmaryrd}
\makeatletter
\newcommand{\interval}[2][oo]{%
\mathord{\vbox{\offinterlineskip\m@th
\ialign{##\cr
\csname @interval#1\endcsname\cr
$#2$\cr
}%
}}%
}
\newcommand{\leaderbar}{%
\mkern-7mu
\cleaders\hbox{$\scriptscriptstyle\mkern-2mu{\relbar}\mkern-2mu$}\hfill
\mkern-7mu
}
\newcommand{\@intervaloo}{%
$\scriptscriptstyle{\relbar}\leaderbar{\relbar}$%
}
\newcommand{\@intervalco}{%
$\scriptscriptstyle{\mapstochar\relbar}\leaderbar{\relbar}$%
}
\newcommand{\@intervaloc}{%
$\scriptscriptstyle{\relbar}\leaderbar{\relbar\mkern-1mu\mapsfromchar}$%
}
\newcommand{\@intervalcc}{%
$\scriptscriptstyle{\mapstochar\relbar}\leaderbar{\relbar\mkern-1mu\mapsfromchar}$%
}
\let\@intervalc\@intervalcc
\let\@intervalo\@intervaloo
\makeatother
\begin{document}
\emph{Intervals} are denoted by bars: $\interval{a,b}$ is an open,
$\interval[cc]{a,b}$ is a closed interval; half-open intervals are
denoted by $\interval[oc]{a,b}$ and $\interval[co]{a,b}$.
\medskip
\noindent
\begin{tabular}{@{}ll@{}}
\verb|\interval{a,b}| & $\interval{a,b}$ \\
\verb|\interval[o]{a,b}| & $\interval[o]{a,b}$ \\
\verb|\interval[oo]{a,b}| & $\interval[oo]{a,b}$ \\
\verb|\interval[c]{a,b}| & $\interval[c]{a,b}$ \\
\verb|\interval[cc]{a,b}| & $\interval[cc]{a,b}$ \\
\verb|\interval[oc]{a,b}| & $\interval[oc]{a,b}$ \\
\verb|\interval[co]{a,b}| & $\interval[co]{a,b}$
\end{tabular}
\end{document}